s4-drs: additional delete test cases
[Samba/eduardoll.git] / source3 / script / tests / test_smbclient_s3.sh
blobdc9853d6907935e6f6bc0f724eff6ae78ba795f1
1 #!/bin/sh
3 # this runs the file serving tests that are expected to pass with samba3
5 if [ $# -lt 6 ]; then
6 cat <<EOF
7 Usage: test_smbclient_s3.sh SERVER SERVER_IP USERNAME PASSWORD USERID LOCAL_PATH
8 EOF
9 exit 1;
12 SERVER="$1"
13 SERVER_IP="$2"
14 USERNAME="$3"
15 PASSWORD="$4"
16 USERID="$5"
17 LOCAL_PATH="$6"
18 SMBCLIENT="$VALGRIND ${SMBCLIENT:-$BINDIR/smbclient} $CONFIGURATION"
19 shift 6
20 ADDARGS="$*"
22 test x"$TEST_FUNCTIONS_SH" != x"INCLUDED" && {
23 incdir=`dirname $0`
24 . $incdir/test_functions.sh
27 failed=0
29 # Test that a noninteractive smbclient does not prompt
30 test_noninteractive_no_prompt()
32 prompt="smb"
34 cmd='echo du | $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
35 eval echo "$cmd"
36 out=`eval $cmd`
38 if [ $? != 0 ] ; then
39 echo "$out"
40 echo "command failed"
41 false
42 return
45 echo "$out" | grep $prompt >/dev/null 2>&1
47 if [ $? = 0 ] ; then
48 # got a prompt .. fail
49 echo matched interactive prompt in non-interactive mode
50 false
51 else
52 true
56 # Test that an interactive smbclient prompts to stdout
57 test_interactive_prompt_stdout()
59 prompt="smb"
60 tmpfile=/tmp/smbclient.in.$$
62 cat > $tmpfile <<EOF
64 quit
65 EOF
67 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
68 eval echo "$cmd"
69 out=`eval $cmd`
70 ret=$?
71 rm -f $tmpfile
73 if [ $ret != 0 ] ; then
74 echo "$out"
75 echo "command failed"
76 false
77 return
80 echo "$out" | grep $prompt >/dev/null 2>&1
82 if [ $? = 0 ] ; then
83 # got a prompt .. succeed
84 true
85 else
86 echo failed to match interactive prompt on stdout
87 false
91 # Test creating a bad symlink and deleting it.
92 test_bad_symlink()
94 prompt="posix_unlink deleted file /newname"
95 tmpfile=/tmp/smbclient.in.$$
97 cat > $tmpfile <<EOF
98 posix
99 posix_unlink newname
100 symlink badname newname
101 posix_unlink newname
102 quit
105 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
106 eval echo "$cmd"
107 out=`eval $cmd`
108 ret=$?
109 rm -f $tmpfile
111 if [ $ret != 0 ] ; then
112 echo "$out"
113 echo "failed create then delete bad symlink with error $ret"
114 false
115 return
118 echo "$out" | grep "$prompt" >/dev/null 2>&1
120 ret=$?
121 if [ $ret = 0 ] ; then
122 # got the correct prompt .. succeed
123 true
124 else
125 echo "$out"
126 echo "failed create then delete bad symlink - grep failed with $ret"
127 false
131 # Test creating a good symlink and deleting it by path.
132 test_good_symlink()
134 tmpfile=/tmp/smbclient.in.$$
135 slink_name="$LOCAL_PATH/slink"
136 slink_target="$LOCAL_PATH/slink_target"
138 touch $slink_target
139 ln -s $slink_target $slink_name
140 cat > $tmpfile <<EOF
141 del slink
142 quit
145 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
146 eval echo "$cmd"
147 out=`eval $cmd`
148 ret=$?
149 rm -f $tmpfile
151 if [ $ret != 0 ] ; then
152 echo "$out"
153 echo "failed delete good symlink with error $ret"
154 rm $slink_target
155 rm $slink_name
156 false
157 return
160 if [ ! -e $slink_target ] ; then
161 echo "failed delete good symlink - symlink target deleted !"
162 rm $slink_target
163 rm $slink_name
164 false
165 return
168 if [ -e $slink_name ] ; then
169 echo "failed delete good symlink - symlink still exists"
170 rm $slink_target
171 rm $slink_name
172 false
173 else
174 # got the correct prompt .. succeed
175 rm $slink_target
176 true
180 # Test writing into a read-only directory (logon as guest) fails.
181 test_read_only_dir()
183 prompt="NT_STATUS_ACCESS_DENIED making remote directory"
184 tmpfile=/tmp/smbclient.in.$$
187 ## We can't do this as non-root. We always have rights to
188 ## create the directory.
190 if [ "$USERID" != 0 ] ; then
191 echo "skipping test_read_only_dir as non-root"
192 true
193 return
197 ## We can't do this with an encrypted connection. No credentials
198 ## to set up the channel.
200 if [ "$ADDARGS" = "-e" ] ; then
201 echo "skipping test_read_only_dir with encrypted connection"
202 true
203 return
206 cat > $tmpfile <<EOF
207 mkdir a_test_dir
208 quit
211 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
212 eval echo "$cmd"
213 out=`eval $cmd`
214 ret=$?
215 rm -f $tmpfile
217 if [ $ret != 0 ] ; then
218 echo "$out"
219 echo "failed writing into read-only directory with error $ret"
220 false
221 return
224 echo "$out" | grep "$prompt" >/dev/null 2>&1
226 ret=$?
227 if [ $ret = 0 ] ; then
228 # got the correct prompt .. succeed
229 true
230 else
231 echo "$out"
232 echo "failed writing into read-only directory - grep failed with $ret"
233 false
237 # Test reading an owner-only file (logon as guest) fails.
238 test_owner_only_file()
240 prompt="NT_STATUS_ACCESS_DENIED opening remote file"
241 tmpfile=/tmp/smbclient.in.$$
244 ## We can't do this as non-root. We always have rights to
245 ## read the file.
247 if [ "$USERID" != 0 ] ; then
248 echo "skipping test_owner_only_file as non-root"
249 true
250 return
254 ## We can't do this with an encrypted connection. No credentials
255 ## to set up the channel.
257 if [ "$ADDARGS" = "-e" ] ; then
258 echo "skipping test_owner_only_file with encrypted connection"
259 true
260 return
263 cat > $tmpfile <<EOF
264 get unreadable_file
265 quit
268 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
269 eval echo "$cmd"
270 out=`eval $cmd`
271 ret=$?
272 rm -f $tmpfile
274 if [ $ret != 0 ] ; then
275 echo "$out"
276 echo "failed reading owner-only file with error $ret"
277 false
278 return
281 echo "$out" | grep "$prompt" >/dev/null 2>&1
283 ret=$?
284 if [ $ret = 0 ] ; then
285 # got the correct prompt .. succeed
286 true
287 else
288 echo "$out"
289 echo "failed reading owner-only file - grep failed with $ret"
290 false
294 testit "smbclient -L $SERVER_IP" $SMBCLIENT $CONFIGURATION -L $SERVER_IP -N -p 139 || failed=`expr $failed + 1`
295 testit "smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT $CONFIGURATION -L $SERVER -I $SERVER_IP -N -p 139 || failed=`expr $failed + 1`
297 testit "noninteractive smbclient does not prompt" \
298 test_noninteractive_no_prompt || \
299 failed=`expr $failed + 1`
301 testit "noninteractive smbclient -l does not prompt" \
302 test_noninteractive_no_prompt -l /tmp || \
303 failed=`expr $failed + 1`
305 testit "interactive smbclient prompts on stdout" \
306 test_interactive_prompt_stdout || \
307 failed=`expr $failed + 1`
309 testit "interactive smbclient -l prompts on stdout" \
310 test_interactive_prompt_stdout -l /tmp || \
311 failed=`expr $failed + 1`
313 testit "creating a bad symlink and deleting it" \
314 test_bad_symlink || \
315 failed=`expr $failed + 1`
317 testit "creating a good symlink and deleting it by path" \
318 test_good_symlink || \
319 failed=`expr $failed + 1`
321 testit "writing into a read-only directory fails" \
322 test_read_only_dir || \
323 failed=`expr $failed + 1`
325 testit "Reading a owner-only file fails" \
326 test_owner_only_file || \
327 failed=`expr $failed + 1`
329 testok $0 $failed