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 NET
23 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
24 WBINFO="$VALGRIND ${WBINFO}"
28 incdir=`dirname $0`/../../../testprogs/blackbox
33 # Test that a noninteractive smbclient does not prompt
34 test_noninteractive_no_prompt()
38 cmd='echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
49 echo "$out" | grep $prompt >/dev/null 2>&1
52 # got a prompt .. fail
53 echo matched interactive prompt in non-interactive mode
60 # Test that an interactive smbclient prompts to stdout
61 test_interactive_prompt_stdout()
64 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
71 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
77 if [ $ret != 0 ] ; then
84 echo "$out" | grep $prompt >/dev/null 2>&1
87 # got a prompt .. succeed
90 echo failed to match interactive prompt on stdout
95 # Test creating a bad symlink and deleting it.
98 prompt="posix_unlink deleted file /newname"
99 tmpfile=$PREFIX/smbclient_bad_symlinks_commands
104 symlink badname newname
109 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
115 if [ $ret != 0 ] ; then
117 echo "failed create then delete bad symlink with error $ret"
122 echo "$out" | grep "$prompt" >/dev/null 2>&1
125 if [ $ret = 0 ] ; then
126 # got the correct prompt .. succeed
130 echo "failed create then delete bad symlink - grep failed with $ret"
135 # Test creating a good symlink and deleting it by path.
138 tmpfile=$PREFIX/smbclient.in.$$
139 slink_name="$LOCAL_PATH/slink"
140 slink_target="$LOCAL_PATH/slink_target"
143 ln -s $slink_target $slink_name
149 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
155 if [ $ret != 0 ] ; then
157 echo "failed delete good symlink with error $ret"
164 if [ ! -e $slink_target ] ; then
165 echo "failed delete good symlink - symlink target deleted !"
172 if [ -e $slink_name ] ; then
173 echo "failed delete good symlink - symlink still exists"
178 # got the correct prompt .. succeed
184 # Test writing into a read-only directory (logon as guest) fails.
187 prompt="NT_STATUS_ACCESS_DENIED making remote directory"
188 tmpfile=$PREFIX/smbclient.in.$$
191 ## We can't do this as non-root. We always have rights to
192 ## create the directory.
194 if [ "$USERID" != 0 ] ; then
195 echo "skipping test_read_only_dir as non-root"
201 ## We can't do this with an encrypted connection. No credentials
202 ## to set up the channel.
204 if [ "$ADDARGS" = "-e" ] ; then
205 echo "skipping test_read_only_dir with encrypted connection"
215 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U% "//$SERVER/$1" -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
221 if [ $ret != 0 ] ; then
223 echo "failed writing into read-only directory with error $ret"
229 echo "$out" | grep "$prompt" >/dev/null 2>&1
232 if [ $ret = 0 ] ; then
233 # got the correct prompt .. succeed
237 echo "failed writing into read-only directory - grep failed with $ret"
243 # Test sending a message
246 tmpfile=$PREFIX/message_in.$$
249 Test message from pid $$
252 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD -M $SERVER -p 139 $ADDARGS -n msgtest < $tmpfile 2>&1'
257 if [ $ret != 0 ] ; then
259 echo "failed sending message to $SERVER with error $ret"
265 # The server writes this into a file message.msgtest, via message.%m to test the % sub code
266 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmpguest -p 139 $ADDARGS -c "get message.msgtest $PREFIX/message_out.$$" 2>&1'
271 if [ $ret != 0 ] ; then
273 echo "failed getting sent message from $SERVER with error $ret"
278 if [ cmp $PREFIX/message_out.$$ $tmpfile != 0 ] ; then
279 echo "failed comparison of message from $SERVER"
286 # Test reading an owner-only file (logon as guest) fails.
287 test_owner_only_file()
289 prompt="NT_STATUS_ACCESS_DENIED opening remote file"
290 tmpfile=$PREFIX/smbclient.in.$$
293 ## We can't do this as non-root. We always have rights to
296 if [ "$USERID" != 0 ] ; then
297 echo "skipping test_owner_only_file as non-root"
303 ## We can't do this with an encrypted connection. No credentials
304 ## to set up the channel.
306 if [ "$ADDARGS" = "-e" ] ; then
307 echo "skipping test_owner_only_file with encrypted connection"
317 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
323 if [ $ret != 0 ] ; then
325 echo "failed reading owner-only file with error $ret"
330 echo "$out" | grep "$prompt" >/dev/null 2>&1
333 if [ $ret = 0 ] ; then
334 # got the correct prompt .. succeed
338 echo "failed reading owner-only file - grep failed with $ret"
343 # Test accessing an msdfs path.
346 tmpfile=$PREFIX/smbclient.in.$$
347 prompt=" msdfs-target "
356 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
362 if [ $ret != 0 ] ; then
364 echo "failed accessing \\msdfs-src1 link with error $ret"
369 echo "$out" | grep "$prompt" >/dev/null 2>&1
372 if [ $ret != 0 ] ; then
374 echo "failed listing \\msdfs-src1 - grep failed with $ret"
380 cd \\deeppath\\msdfs-src2
385 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
391 if [ $ret != 0 ] ; then
393 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
398 echo "$out" | grep "$prompt" >/dev/null 2>&1
401 if [ $ret != 0 ] ; then
403 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
412 # Archive bits are correctly set on file/dir creation and rename.
413 test_rename_archive_bit()
415 prompt_file="attributes: A (20)"
416 prompt_dir="attributes: D (10)"
417 tmpfile="$PREFIX/smbclient.in.$$"
419 filename_ren="bar.$$"
421 dirname_ren="bardir.$$"
422 filename_path="$PREFIX/$filename"
423 local_name1="$LOCAL_PATH/$filename"
424 local_name2="$LOCAL_PATH/$filename_ren"
425 local_dir_name1="$LOCAL_PATH/$dirname"
426 local_dir_name2="$LOCAL_PATH/$dirname_ren"
432 # Create a new file, ensure it has 'A' attributes.
442 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
448 if [ $ret != 0 ] ; then
450 echo "failed creating file $filename with error $ret"
455 echo "$out" | grep "$prompt_file" >/dev/null 2>&1
463 if [ $ret = 0 ] ; then
464 # got the correct prompt .. succeed
468 echo "Attributes incorrect on new file $ret"
472 # Now check if we remove 'A' and rename, the A comes back.
479 ren $filename $filename_ren
480 allinfo $filename_ren
484 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
490 if [ $ret != 0 ] ; then
492 echo "failed creating file and renaming $filename with error $ret"
497 echo "$out" | grep "$prompt_file" >/dev/null 2>&1
505 if [ $ret = 0 ] ; then
506 # got the correct prompt .. succeed
510 echo "Attributes incorrect on renamed file $ret"
514 rm -rf $local_dir_name1
515 rm -rf $local_dir_name2
517 # Create a new directory, ensure it has 'D' but not 'A' attributes.
525 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
531 if [ $ret != 0 ] ; then
533 echo "failed creating directory $dirname with error $ret"
538 echo "$out" | grep "$prompt_dir" >/dev/null 2>&1
542 rm -rf $local_dir_name1
543 rm -rf $local_dir_name2
545 if [ $ret = 0 ] ; then
546 # got the correct prompt .. succeed
550 echo "Attributes incorrect on new directory $ret"
554 # Now check if we rename, we still only have 'D' attributes
558 ren $dirname $dirname_ren
563 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
569 if [ $ret != 0 ] ; then
571 echo "failed creating directory $dirname and renaming with error $ret"
576 echo "$out" | grep "$prompt_dir" >/dev/null 2>&1
583 if [ $ret = 0 ] ; then
584 # got the correct prompt .. succeed
588 echo "Attributes incorrect on renamed directory $ret"
593 # Test authenticating using the winbind ccache
596 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
599 if [ $ret != 0 ] ; then
600 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='${PASSWORD}')"
605 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}" \
609 if [ $ret != 0 ] ; then
610 echo "smbclient failed to use cached credentials"
615 $WBINFO --ccache-save="${USERNAME}%GarBage"
618 if [ $ret != 0 ] ; then
619 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='GarBage')"
624 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}" \
628 if [ $ret -eq 0 ] ; then
629 echo "smbclient succeeded with wrong cached credentials"
637 # Test authenticating using the winbind ccache
640 tmpfile=$PREFIX/smbclient.in.$$
646 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile \
651 if [ $ret != 0 ] ; then
652 echo "smbclient failed to use auth file"
662 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile\
667 if [ $ret -eq 0 ] ; then
668 echo "smbclient succeeded with wrong auth file credentials"
674 # Test doing a directory listing with backup privilege.
675 test_backup_privilege_list()
677 tmpfile=$PREFIX/smbclient_backup_privilege_list
679 # If we don't have a DOMAIN component to the username, add it.
680 echo "$USERNAME" | grep '\\' 2>&1
682 if [ $ret != 0 ] ; then
683 priv_username="$DOMAIN\\$USERNAME"
685 priv_username=$USERNAME
688 $NET sam rights grant $priv_username SeBackupPrivilege 2>&1
690 if [ $ret != 0 ] ; then
691 echo "Failed to add SeBackupPrivilege to user $priv_username - $ret"
702 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
708 if [ $ret != 0 ] ; then
710 echo "failed backup privilege list $ret"
715 # Now remove all privileges from this SID.
716 $NET sam rights revoke $priv_username SeBackupPrivilege 2>&1
718 if [ $ret != 0 ] ; then
719 echo "failed to remove SeBackupPrivilege from user $priv_username - $ret"
725 # Test accessing an share with bad names (won't convert).
728 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/badname-tmp -I $SERVER_IP $ADDARGS -c ls 2>&1'
733 if [ $ret != 0 ] ; then
735 echo "failed accessing badname-tmp (SMB1) with error $ret"
740 echo "$out" | wc -l 2>&1 | grep 6
742 if [ $ret != 0 ] ; then
744 echo "failed listing \\badname-tmp - grep of number of lines (1) failed with $ret"
748 echo "$out" | grep 'Domain=.*OS=.*Server='
750 if [ $ret != 0 ] ; then
752 echo "failed listing \\badname-tmp - grep (1) failed with $ret"
756 echo "$out" | grep '^ \. *D'
758 if [ $ret != 0 ] ; then
760 echo "failed listing \\badname-tmp - grep (2) failed with $ret"
764 echo "$out" | grep '^ \.\. *D'
766 if [ $ret != 0 ] ; then
768 echo "failed listing \\badname-tmp - grep (3) failed with $ret"
772 echo "$out" | grep '^ blank.txt *N'
774 if [ $ret != 0 ] ; then
776 echo "failed listing \\badname-tmp - grep (4) failed with $ret"
780 echo "$out" | grep '^ *$'
782 if [ $ret != 0 ] ; then
784 echo "failed listing \\badname-tmp - grep (5) failed with $ret"
788 echo "$out" | grep 'blocks of size.*blocks available'
790 if [ $ret != 0 ] ; then
792 echo "failed listing \\badname-tmp - grep (6) failed with $ret"
796 # Now check again with -mSMB3
797 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/badname-tmp -I $SERVER_IP -mSMB3 $ADDARGS -c ls 2>&1'
802 if [ $ret != 0 ] ; then
804 echo "failed accessing badname-tmp (SMB3) with error $ret"
809 echo "$out" | wc -l 2>&1 | grep 6
811 if [ $ret != 0 ] ; then
813 echo "failed listing \\badname-tmp - SMB3 grep of number of lines (1) failed with $ret"
817 echo "$out" | grep 'Domain=.*OS=.*Server='
819 if [ $ret != 0 ] ; then
821 echo "failed listing \\badname-tmp - SMB3 grep (1) failed with $ret"
825 echo "$out" | grep '^ \. *D'
827 if [ $ret != 0 ] ; then
829 echo "failed listing \\badname-tmp - SMB3 grep (2) failed with $ret"
833 echo "$out" | grep '^ \.\. *D'
835 if [ $ret != 0 ] ; then
837 echo "failed listing \\badname-tmp - SMB3 grep (3) failed with $ret"
841 echo "$out" | grep '^ blank.txt *N'
843 if [ $ret != 0 ] ; then
845 echo "failed listing \\badname-tmp - SMB3 grep (4) failed with $ret"
849 echo "$out" | grep '^ *$'
851 if [ $ret != 0 ] ; then
853 echo "failed listing \\badname-tmp - SMB3 grep (5) failed with $ret"
857 echo "$out" | grep 'blocks of size.*blocks available'
859 if [ $ret != 0 ] ; then
861 echo "failed listing \\badname-tmp - SMB3 grep (6) failed with $ret"
866 # Test accessing an share with a name that must be mangled - with acl_xattrs.
867 # We know foo:bar gets mangled to FF4GBY~Q with the default name-mangling algorithm (hash2).
870 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
877 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/manglenames_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
883 if [ $ret != 0 ] ; then
885 echo "failed accessing manglenames_share with error $ret"
890 echo "$out" | grep 'NT_STATUS'
892 if [ $ret == 0 ] ; then
894 echo "failed - NT_STATUS_XXXX listing \\manglenames_share\\FF4GBY~Q"
900 LOGDIR_PREFIX=test_smbclient_s3
902 # possibly remove old logdirs:
904 for OLDDIR in $(find ${PREFIX} -type d -name "${LOGDIR_PREFIX}_*") ; do
905 echo "removing old directory ${OLDDIR}"
909 LOGDIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX)
912 testit "smbclient -L $SERVER_IP" $SMBCLIENT -L $SERVER_IP -N -p 139 || failed=`expr $failed + 1`
913 testit "smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 -c quit || failed=`expr $failed + 1`
915 testit "noninteractive smbclient does not prompt" \
916 test_noninteractive_no_prompt || \
917 failed=`expr $failed + 1`
919 testit "noninteractive smbclient -l does not prompt" \
920 test_noninteractive_no_prompt -l $LOGDIR || \
921 failed=`expr $failed + 1`
923 testit "interactive smbclient prompts on stdout" \
924 test_interactive_prompt_stdout || \
925 failed=`expr $failed + 1`
927 testit "interactive smbclient -l prompts on stdout" \
928 test_interactive_prompt_stdout -l $LOGDIR || \
929 failed=`expr $failed + 1`
931 testit "creating a bad symlink and deleting it" \
932 test_bad_symlink || \
933 failed=`expr $failed + 1`
935 testit "creating a good symlink and deleting it by path" \
936 test_good_symlink || \
937 failed=`expr $failed + 1`
939 testit "writing into a read-only directory fails" \
940 test_read_only_dir ro-tmp || \
941 failed=`expr $failed + 1`
943 testit "writing into a read-only share fails" \
944 test_read_only_dir valid-users-tmp || \
945 failed=`expr $failed + 1`
947 testit "Reading a owner-only file fails" \
948 test_owner_only_file || \
949 failed=`expr $failed + 1`
951 testit "Accessing an MS-DFS link" \
953 failed=`expr $failed + 1`
955 testit "Ensure archive bit is set correctly on file/dir rename" \
956 test_rename_archive_bit || \
957 failed=`expr $failed + 1`
959 testit "ccache access works for smbclient" \
960 test_ccache_access || \
961 failed=`expr $failed + 1`
963 testit "sending a message to the remote server" \
965 failed=`expr $failed + 1`
967 testit "using an authentication file" \
969 failed=`expr $failed + 1`
971 testit "list with backup privilege" \
972 test_backup_privilege_list || \
973 failed=`expr $failed + 1`
975 testit "list a share with bad names (won't convert)" \
977 failed=`expr $failed + 1`
979 testit "list a share with a mangled name + acl_xattr object" \
980 test_mangled_names || \
981 failed=`expr $failed + 1`
983 testit "rm -rf $LOGDIR" \
985 failed=`expr $failed + 1`