3 # this runs the file serving tests that are expected to pass with samba3
7 Usage: test_smbclient_s3.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD USERID LOCAL_PATH PREFIX SMBCLIENT WBINFO
22 SMBCLIENT
="$VALGRIND ${SMBCLIENT}"
23 WBINFO
="$VALGRIND ${WBINFO}"
27 incdir
=`dirname $0`/..
/..
/..
/testprogs
/blackbox
32 # Test that a noninteractive smbclient does not prompt
33 test_noninteractive_no_prompt
()
37 cmd
='echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
48 echo "$out" |
grep $prompt >/dev
/null
2>&1
51 # got a prompt .. fail
52 echo matched interactive prompt
in non-interactive mode
59 # Test that an interactive smbclient prompts to stdout
60 test_interactive_prompt_stdout
()
63 tmpfile
=$PREFIX/smbclient_interactive_prompt_commands
70 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
76 if [ $ret != 0 ] ; then
83 echo "$out" |
grep $prompt >/dev
/null
2>&1
86 # got a prompt .. succeed
89 echo failed to match interactive prompt on stdout
94 # Test creating a bad symlink and deleting it.
97 prompt
="posix_unlink deleted file /newname"
98 tmpfile
=$PREFIX/smbclient_bad_symlinks_commands
103 symlink badname newname
108 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
114 if [ $ret != 0 ] ; then
116 echo "failed create then delete bad symlink with error $ret"
121 echo "$out" |
grep "$prompt" >/dev
/null
2>&1
124 if [ $ret = 0 ] ; then
125 # got the correct prompt .. succeed
129 echo "failed create then delete bad symlink - grep failed with $ret"
134 # Test creating a good symlink and deleting it by path.
137 tmpfile
=$PREFIX/smbclient.
in.$$
138 slink_name
="$LOCAL_PATH/slink"
139 slink_target
="$LOCAL_PATH/slink_target"
142 ln -s $slink_target $slink_name
148 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
154 if [ $ret != 0 ] ; then
156 echo "failed delete good symlink with error $ret"
163 if [ ! -e $slink_target ] ; then
164 echo "failed delete good symlink - symlink target deleted !"
171 if [ -e $slink_name ] ; then
172 echo "failed delete good symlink - symlink still exists"
177 # got the correct prompt .. succeed
183 # Test writing into a read-only directory (logon as guest) fails.
186 prompt
="NT_STATUS_ACCESS_DENIED making remote directory"
187 tmpfile
=$PREFIX/smbclient.
in.$$
190 ## We can't do this as non-root. We always have rights to
191 ## create the directory.
193 if [ "$USERID" != 0 ] ; then
194 echo "skipping test_read_only_dir as non-root"
200 ## We can't do this with an encrypted connection. No credentials
201 ## to set up the channel.
203 if [ "$ADDARGS" = "-e" ] ; then
204 echo "skipping test_read_only_dir with encrypted connection"
214 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U% //$SERVER/$1" -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
220 if [ $ret != 0 ] ; then
222 echo "failed writing into read-only directory with error $ret"
228 echo "$out" |
grep "$prompt" >/dev
/null
2>&1
231 if [ $ret = 0 ] ; then
232 # got the correct prompt .. succeed
236 echo "failed writing into read-only directory - grep failed with $ret"
242 # Test sending a message
245 tmpfile
=$PREFIX/message_in.$$
248 Test message from pid $$
251 cmd
='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD -M $SERVER -p 139 $ADDARGS -n msgtest < $tmpfile 2>&1'
256 if [ $ret != 0 ] ; then
258 echo "failed sending message to $SERVER with error $ret"
264 # The server writes this into a file message.msgtest, via message.%m to test the % sub code
265 cmd
='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmpguest -p 139 $ADDARGS -c "get message.msgtest $PREFIX/message_out.$$" 2>&1'
270 if [ $ret != 0 ] ; then
272 echo "failed getting sent message from $SERVER with error $ret"
277 if [ cmp $PREFIX/message_out.$$
$tmpfile != 0 ] ; then
278 echo "failed comparison of message from $SERVER"
285 # Test reading an owner-only file (logon as guest) fails.
286 test_owner_only_file
()
288 prompt
="NT_STATUS_ACCESS_DENIED opening remote file"
289 tmpfile
=$PREFIX/smbclient.
in.$$
292 ## We can't do this as non-root. We always have rights to
295 if [ "$USERID" != 0 ] ; then
296 echo "skipping test_owner_only_file as non-root"
302 ## We can't do this with an encrypted connection. No credentials
303 ## to set up the channel.
305 if [ "$ADDARGS" = "-e" ] ; then
306 echo "skipping test_owner_only_file with encrypted connection"
316 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
322 if [ $ret != 0 ] ; then
324 echo "failed reading owner-only file with error $ret"
329 echo "$out" |
grep "$prompt" >/dev
/null
2>&1
332 if [ $ret = 0 ] ; then
333 # got the correct prompt .. succeed
337 echo "failed reading owner-only file - grep failed with $ret"
342 # Test accessing an msdfs path.
345 tmpfile
=$PREFIX/smbclient.
in.$$
346 prompt
=" msdfs-target "
355 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
361 if [ $ret != 0 ] ; then
363 echo "failed accessing \\msdfs-src1 link with error $ret"
368 echo "$out" |
grep "$prompt" >/dev
/null
2>&1
371 if [ $ret != 0 ] ; then
373 echo "failed listing \\msdfs-src1 - grep failed with $ret"
379 cd \\deeppath\\msdfs-src2
384 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
390 if [ $ret != 0 ] ; then
392 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
397 echo "$out" |
grep "$prompt" >/dev
/null
2>&1
400 if [ $ret != 0 ] ; then
402 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
411 # Archive bits are correctly set on file/dir creation and rename.
412 test_rename_archive_bit
()
414 prompt_file
="attributes: A (20)"
415 prompt_dir
="attributes: D (10)"
416 tmpfile
="$PREFIX/smbclient.in.$$"
418 filename_ren
="bar.$$"
420 dirname_ren
="bardir.$$"
421 filename_path
="$PREFIX/$filename"
422 local_name1
="$LOCAL_PATH/$filename"
423 local_name2
="$LOCAL_PATH/$filename_ren"
424 local_dir_name1
="$LOCAL_PATH/$dirname"
425 local_dir_name2
="$LOCAL_PATH/$dirname_ren"
431 # Create a new file, ensure it has 'A' attributes.
441 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
447 if [ $ret != 0 ] ; then
449 echo "failed creating file $filename with error $ret"
454 echo "$out" |
grep "$prompt_file" >/dev
/null
2>&1
462 if [ $ret = 0 ] ; then
463 # got the correct prompt .. succeed
467 echo "Attributes incorrect on new file $ret"
471 # Now check if we remove 'A' and rename, the A comes back.
478 ren $filename $filename_ren
479 allinfo $filename_ren
483 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
489 if [ $ret != 0 ] ; then
491 echo "failed creating file and renaming $filename with error $ret"
496 echo "$out" |
grep "$prompt_file" >/dev
/null
2>&1
504 if [ $ret = 0 ] ; then
505 # got the correct prompt .. succeed
509 echo "Attributes incorrect on renamed file $ret"
513 rm -rf $local_dir_name1
514 rm -rf $local_dir_name2
516 # Create a new directory, ensure it has 'D' but not 'A' attributes.
524 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
530 if [ $ret != 0 ] ; then
532 echo "failed creating directory $dirname with error $ret"
537 echo "$out" |
grep "$prompt_dir" >/dev
/null
2>&1
541 rm -rf $local_dir_name1
542 rm -rf $local_dir_name2
544 if [ $ret = 0 ] ; then
545 # got the correct prompt .. succeed
549 echo "Attributes incorrect on new directory $ret"
553 # Now check if we rename, we still only have 'D' attributes
557 ren $dirname $dirname_ren
562 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
568 if [ $ret != 0 ] ; then
570 echo "failed creating directory $dirname and renaming with error $ret"
575 echo "$out" |
grep "$prompt_dir" >/dev
/null
2>&1
582 if [ $ret = 0 ] ; then
583 # got the correct prompt .. succeed
587 echo "Attributes incorrect on renamed directory $ret"
592 # Test authenticating using the winbind ccache
595 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
598 if [ $ret != 0 ] ; then
599 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='${PASSWORD}')"
604 $SMBCLIENT //$SERVER_IP/tmp
-C -U "${USERNAME}%" \
608 if [ $ret != 0 ] ; then
609 echo "smbclient failed to use cached credentials"
614 $WBINFO --ccache-save="${USERNAME}%GarBage"
617 if [ $ret != 0 ] ; then
618 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='GarBage')"
623 $SMBCLIENT //$SERVER_IP/tmp
-C -U "${USERNAME}%" \
627 if [ $ret -eq 0 ] ; then
628 echo "smbclient succeeded with wrong cached credentials"
636 # Test authenticating using the winbind ccache
639 tmpfile
=$PREFIX/smbclient.
in.$$
645 $SMBCLIENT //$SERVER_IP/tmp
--authentication-file=$tmpfile \
650 if [ $ret != 0 ] ; then
651 echo "smbclient failed to use auth file"
661 $SMBCLIENT //$SERVER_IP/tmp
--authentication-file=$tmpfile\
666 if [ $ret -eq 0 ] ; then
667 echo "smbclient succeeded with wrong auth file credentials"
674 LOGDIR_PREFIX
=test_smbclient_s3
676 # possibly remove old logdirs:
678 for OLDDIR
in $
(find ${PREFIX} -type d
-name "${LOGDIR_PREFIX}_*") ; do
679 echo "removing old directory ${OLDDIR}"
683 LOGDIR
=$
(mktemp
-d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX
)
686 testit
"smbclient -L $SERVER_IP" $SMBCLIENT -L $SERVER_IP -N -p 139 || failed
=`expr $failed + 1`
687 testit
"smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 -c quit || failed
=`expr $failed + 1`
689 testit
"noninteractive smbclient does not prompt" \
690 test_noninteractive_no_prompt || \
691 failed
=`expr $failed + 1`
693 testit
"noninteractive smbclient -l does not prompt" \
694 test_noninteractive_no_prompt
-l $LOGDIR || \
695 failed
=`expr $failed + 1`
697 testit
"interactive smbclient prompts on stdout" \
698 test_interactive_prompt_stdout || \
699 failed
=`expr $failed + 1`
701 testit
"interactive smbclient -l prompts on stdout" \
702 test_interactive_prompt_stdout
-l $LOGDIR || \
703 failed
=`expr $failed + 1`
705 testit
"creating a bad symlink and deleting it" \
706 test_bad_symlink || \
707 failed
=`expr $failed + 1`
709 testit
"creating a good symlink and deleting it by path" \
710 test_good_symlink || \
711 failed
=`expr $failed + 1`
713 testit
"writing into a read-only directory fails" \
714 test_read_only_dir ro-tmp || \
715 failed
=`expr $failed + 1`
717 testit
"writing into a read-only share fails" \
718 test_read_only_dir valid-users-tmp || \
719 failed
=`expr $failed + 1`
721 testit
"Reading a owner-only file fails" \
722 test_owner_only_file || \
723 failed
=`expr $failed + 1`
725 testit
"Accessing an MS-DFS link" \
727 failed
=`expr $failed + 1`
729 testit
"Ensure archive bit is set correctly on file/dir rename" \
730 test_rename_archive_bit || \
731 failed
=`expr $failed + 1`
733 testit
"ccache access works for smbclient" \
734 test_ccache_access || \
735 failed
=`expr $failed + 1`
737 testit
"sending a message to the remote server" \
739 failed
=`expr $failed + 1`
741 testit
"using an authentication file" \
743 failed
=`expr $failed + 1`
745 testit
"rm -rf $LOGDIR" \
747 failed
=`expr $failed + 1`