s3:test: fix the smbclient_s3 test on older systems
[Samba/gebeck_regimport.git] / source3 / script / tests / test_smbclient_s3.sh
blob167b5ae993a1bc50de2a12211076616f6a1778bd
1 #!/bin/sh
3 # this runs the file serving tests that are expected to pass with samba3
5 if [ $# -lt 7 ]; then
6 cat <<EOF
7 Usage: test_smbclient_s3.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD USERID LOCAL_PATH PREFIX SMBCLIENT
8 EOF
9 exit 1;
12 SERVER="$1"
13 SERVER_IP="$2"
14 DOMAIN="$3"
15 USERNAME="$4"
16 PASSWORD="$5"
17 USERID="$6"
18 LOCAL_PATH="$7"
19 PREFIX="$8"
20 SMBCLIENT="$9"
21 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
22 WBINFO="$VALGRIND ${WBINFO:-$BINDIR/wbinfo}"
23 shift 9
24 ADDARGS="$*"
26 incdir=`dirname $0`/../../../testprogs/blackbox
27 . $incdir/subunit.sh
29 failed=0
31 # Test that a noninteractive smbclient does not prompt
32 test_noninteractive_no_prompt()
34 prompt="smb"
36 cmd='echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
37 eval echo "$cmd"
38 out=`eval $cmd`
40 if [ $? != 0 ] ; then
41 echo "$out"
42 echo "command failed"
43 false
44 return
47 echo "$out" | grep $prompt >/dev/null 2>&1
49 if [ $? = 0 ] ; then
50 # got a prompt .. fail
51 echo matched interactive prompt in non-interactive mode
52 false
53 else
54 true
58 # Test that an interactive smbclient prompts to stdout
59 test_interactive_prompt_stdout()
61 prompt="smb"
62 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
64 cat > $tmpfile <<EOF
66 quit
67 EOF
69 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
70 eval echo "$cmd"
71 out=`eval $cmd`
72 ret=$?
73 rm -f $tmpfile
75 if [ $ret != 0 ] ; then
76 echo "$out"
77 echo "command failed"
78 false
79 return
82 echo "$out" | grep $prompt >/dev/null 2>&1
84 if [ $? = 0 ] ; then
85 # got a prompt .. succeed
86 true
87 else
88 echo failed to match interactive prompt on stdout
89 false
93 # Test creating a bad symlink and deleting it.
94 test_bad_symlink()
96 prompt="posix_unlink deleted file /newname"
97 tmpfile=$PREFIX/smbclient_bad_symlinks_commands
99 cat > $tmpfile <<EOF
100 posix
101 posix_unlink newname
102 symlink badname newname
103 posix_unlink newname
104 quit
107 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
108 eval echo "$cmd"
109 out=`eval $cmd`
110 ret=$?
111 rm -f $tmpfile
113 if [ $ret != 0 ] ; then
114 echo "$out"
115 echo "failed create then delete bad symlink with error $ret"
116 false
117 return
120 echo "$out" | grep "$prompt" >/dev/null 2>&1
122 ret=$?
123 if [ $ret = 0 ] ; then
124 # got the correct prompt .. succeed
125 true
126 else
127 echo "$out"
128 echo "failed create then delete bad symlink - grep failed with $ret"
129 false
133 # Test creating a good symlink and deleting it by path.
134 test_good_symlink()
136 tmpfile=$PREFIX/smbclient.in.$$
137 slink_name="$LOCAL_PATH/slink"
138 slink_target="$LOCAL_PATH/slink_target"
140 touch $slink_target
141 ln -s $slink_target $slink_name
142 cat > $tmpfile <<EOF
143 del slink
144 quit
147 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
148 eval echo "$cmd"
149 out=`eval $cmd`
150 ret=$?
151 rm -f $tmpfile
153 if [ $ret != 0 ] ; then
154 echo "$out"
155 echo "failed delete good symlink with error $ret"
156 rm $slink_target
157 rm $slink_name
158 false
159 return
162 if [ ! -e $slink_target ] ; then
163 echo "failed delete good symlink - symlink target deleted !"
164 rm $slink_target
165 rm $slink_name
166 false
167 return
170 if [ -e $slink_name ] ; then
171 echo "failed delete good symlink - symlink still exists"
172 rm $slink_target
173 rm $slink_name
174 false
175 else
176 # got the correct prompt .. succeed
177 rm $slink_target
178 true
182 # Test writing into a read-only directory (logon as guest) fails.
183 test_read_only_dir()
185 prompt="NT_STATUS_ACCESS_DENIED making remote directory"
186 tmpfile=$PREFIX/smbclient.in.$$
189 ## We can't do this as non-root. We always have rights to
190 ## create the directory.
192 if [ "$USERID" != 0 ] ; then
193 echo "skipping test_read_only_dir as non-root"
194 true
195 return
199 ## We can't do this with an encrypted connection. No credentials
200 ## to set up the channel.
202 if [ "$ADDARGS" = "-e" ] ; then
203 echo "skipping test_read_only_dir with encrypted connection"
204 true
205 return
208 cat > $tmpfile <<EOF
209 mkdir a_test_dir
210 quit
213 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
214 eval echo "$cmd"
215 out=`eval $cmd`
216 ret=$?
217 rm -f $tmpfile
219 if [ $ret != 0 ] ; then
220 echo "$out"
221 echo "failed writing into read-only directory with error $ret"
223 false
224 return
227 echo "$out" | grep "$prompt" >/dev/null 2>&1
229 ret=$?
230 if [ $ret = 0 ] ; then
231 # got the correct prompt .. succeed
232 true
233 else
234 echo "$out"
235 echo "failed writing into read-only directory - grep failed with $ret"
236 false
241 # Test sending a message
242 test_message()
244 tmpfile=$PREFIX/message_in.$$
246 cat > $tmpfile <<EOF
247 Test message from pid $$
250 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD -M $SERVER -p 139 $ADDARGS -n msgtest < $tmpfile 2>&1'
251 eval echo "$cmd"
252 out=`eval $cmd`
253 ret=$?
255 if [ $ret != 0 ] ; then
256 echo "$out"
257 echo "failed sending message to $SERVER with error $ret"
258 false
259 rm -f $tmpfile
260 return
263 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmpguest -p 139 $ADDARGS -c "get message.msgtest $PREFIX/message_out.$$" 2>&1'
264 eval echo "$cmd"
265 out=`eval $cmd`
266 ret=$?
268 if [ $ret != 0 ] ; then
269 echo "$out"
270 echo "failed getting sent message from $SERVER with error $ret"
271 false
272 return
275 if [ cmp $PREFIX/message_out.$$ $tmpfile != 0 ] ; then
276 echo "failed comparison of message from $SERVER"
277 false
278 return
280 true
283 # Test reading an owner-only file (logon as guest) fails.
284 test_owner_only_file()
286 prompt="NT_STATUS_ACCESS_DENIED opening remote file"
287 tmpfile=$PREFIX/smbclient.in.$$
290 ## We can't do this as non-root. We always have rights to
291 ## read the file.
293 if [ "$USERID" != 0 ] ; then
294 echo "skipping test_owner_only_file as non-root"
295 true
296 return
300 ## We can't do this with an encrypted connection. No credentials
301 ## to set up the channel.
303 if [ "$ADDARGS" = "-e" ] ; then
304 echo "skipping test_owner_only_file with encrypted connection"
305 true
306 return
309 cat > $tmpfile <<EOF
310 get unreadable_file
311 quit
314 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
315 eval echo "$cmd"
316 out=`eval $cmd`
317 ret=$?
318 rm -f $tmpfile
320 if [ $ret != 0 ] ; then
321 echo "$out"
322 echo "failed reading owner-only file with error $ret"
323 false
324 return
327 echo "$out" | grep "$prompt" >/dev/null 2>&1
329 ret=$?
330 if [ $ret = 0 ] ; then
331 # got the correct prompt .. succeed
332 true
333 else
334 echo "$out"
335 echo "failed reading owner-only file - grep failed with $ret"
336 false
340 # Test accessing an msdfs path.
341 test_msdfs_link()
343 tmpfile=$PREFIX/smbclient.in.$$
344 prompt=" msdfs-target "
346 cat > $tmpfile <<EOF
348 cd \\msdfs-src1
349 ls msdfs-target
350 quit
353 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
354 eval echo "$cmd"
355 out=`eval $cmd`
356 ret=$?
357 rm -f $tmpfile
359 if [ $ret != 0 ] ; then
360 echo "$out"
361 echo "failed accessing \\msdfs-src1 link with error $ret"
362 false
363 return
366 echo "$out" | grep "$prompt" >/dev/null 2>&1
368 ret=$?
369 if [ $ret != 0 ] ; then
370 echo "$out"
371 echo "failed listing \\msdfs-src1 - grep failed with $ret"
372 false
375 cat > $tmpfile <<EOF
377 cd \\deeppath\\msdfs-src2
378 ls msdfs-target
379 quit
382 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
383 eval echo "$cmd"
384 out=`eval $cmd`
385 ret=$?
386 rm -f $tmpfile
388 if [ $ret != 0 ] ; then
389 echo "$out"
390 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
391 false
392 return
395 echo "$out" | grep "$prompt" >/dev/null 2>&1
397 ret=$?
398 if [ $ret != 0 ] ; then
399 echo "$out"
400 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
401 false
402 return
403 else
404 true
405 return
409 # Test authenticating using the winbind ccache
410 test_ccache_access()
412 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
413 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
414 -c quit 2>&1
415 ret=$?
417 if [ $ret != 0 ] ; then
418 echo "smbclient failed to use cached credentials"
419 false
420 return
423 $WBINFO --ccache-save="${USERNAME}%GarBage"
424 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
425 -c quit 2>&1
426 ret=$?
428 if [ $ret -eq 0 ] ; then
429 echo "smbclient succeeded with wrong cached credentials"
430 false
431 return
434 $WBINFO --logoff
437 # Test authenticating using the winbind ccache
438 test_auth_file()
440 tmpfile=$PREFIX/smbclient.in.$$
441 cat > $tmpfile <<EOF
442 username=${USERNAME}
443 password=${PASSWORD}
444 domain=${DOMAIN}
446 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile \
447 -c quit 2>&1
448 ret=$?
449 rm $tmpfile
451 if [ $ret != 0 ] ; then
452 echo "smbclient failed to use auth file"
453 false
454 return
457 cat > $tmpfile <<EOF
458 username=${USERNAME}
459 password=xxxx
460 domain=${DOMAIN}
462 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile\
463 -c quit 2>&1
464 ret=$?
465 rm $tmpfile
467 if [ $ret -eq 0 ] ; then
468 echo "smbclient succeeded with wrong auth file credentials"
469 false
470 return
474 LOGDIR_PREFIX=test_smbclient_s3
476 # possibly remove old logdirs:
478 for OLDDIR in $(find ${PREFIX} -type d -name "${LOGDIR_PREFIX}_*") ; do
479 echo "removing old directory ${OLDDIR}"
480 rm -rf ${OLDDIR}
481 done
483 LOGDIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX)
486 testit "smbclient -L $SERVER_IP" $SMBCLIENT -L $SERVER_IP -N -p 139 || failed=`expr $failed + 1`
487 testit "smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 -c quit || failed=`expr $failed + 1`
489 testit "noninteractive smbclient does not prompt" \
490 test_noninteractive_no_prompt || \
491 failed=`expr $failed + 1`
493 testit "noninteractive smbclient -l does not prompt" \
494 test_noninteractive_no_prompt -l $LOGDIR || \
495 failed=`expr $failed + 1`
497 testit "interactive smbclient prompts on stdout" \
498 test_interactive_prompt_stdout || \
499 failed=`expr $failed + 1`
501 testit "interactive smbclient -l prompts on stdout" \
502 test_interactive_prompt_stdout -l $LOGDIR || \
503 failed=`expr $failed + 1`
505 testit "creating a bad symlink and deleting it" \
506 test_bad_symlink || \
507 failed=`expr $failed + 1`
509 testit "creating a good symlink and deleting it by path" \
510 test_good_symlink || \
511 failed=`expr $failed + 1`
513 testit "writing into a read-only directory fails" \
514 test_read_only_dir || \
515 failed=`expr $failed + 1`
517 testit "Reading a owner-only file fails" \
518 test_owner_only_file || \
519 failed=`expr $failed + 1`
521 testit "Accessing an MS-DFS link" \
522 test_msdfs_link || \
523 failed=`expr $failed + 1`
525 testit "ccache access works for smbclient" \
526 test_ccache_access || \
527 failed=`expr $failed + 1`
529 testit "sending a message to the remote server" \
530 test_message || \
531 failed=`expr $failed + 1`
533 testit "using an authentication file" \
534 test_auth_file || \
535 failed=`expr $failed + 1`
537 testit "rm -rf $LOGDIR" \
538 rm -rf $LOGDIR || \
539 failed=`expr $failed + 1`
541 testok $0 $failed