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 CONFIGURATION PROTOCOL
25 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
26 WBINFO="$VALGRIND ${WBINFO}"
28 RAWARGS="${CONFIGURATION} -m${PROTOCOL}"
29 ADDARGS="${RAWARGS} $*"
31 incdir=`dirname $0`/../../../testprogs/blackbox
36 # Test that a noninteractive smbclient does not prompt
37 test_noninteractive_no_prompt()
41 cmd='echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
51 echo "$out" | grep $prompt >/dev/null 2>&1
54 # got a prompt .. fail
55 echo matched interactive prompt in non-interactive mode
62 # Test that an interactive smbclient prompts to stdout
63 test_interactive_prompt_stdout()
66 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
73 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
79 if [ $ret != 0 ] ; then
85 echo "$out" | grep $prompt >/dev/null 2>&1
88 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"
121 echo "$out" | grep "$prompt" >/dev/null 2>&1
124 if [ $ret != 0 ] ; then
126 echo "failed create then delete bad symlink - grep failed with $ret"
133 # Test creating a good symlink and deleting it by path.
136 tmpfile=$PREFIX/smbclient.in.$$
137 slink_name="$LOCAL_PATH/slink"
138 slink_target="$LOCAL_PATH/slink_target"
141 ln -s $slink_target $slink_name
147 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
153 if [ $ret != 0 ] ; then
155 echo "failed delete good symlink with error $ret"
161 if [ ! -e $slink_target ] ; then
162 echo "failed delete good symlink - symlink target deleted !"
168 if [ -e $slink_name ] ; then
169 echo "failed delete good symlink - symlink still exists"
179 # Test writing into a read-only directory (logon as guest) fails.
182 prompt="NT_STATUS_ACCESS_DENIED making remote directory"
183 tmpfile=$PREFIX/smbclient.in.$$
186 ## We can't do this as non-root. We always have rights to
187 ## create the directory.
189 if [ "$USERID" != 0 ] ; then
190 echo "skipping test_read_only_dir as non-root"
195 ## We can't do this with an encrypted connection. No credentials
196 ## to set up the channel.
198 if [ "$ADDARGS" = "-e" ] ; then
199 echo "skipping test_read_only_dir with encrypted connection"
208 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U% "//$SERVER/$1" -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
214 if [ $ret != 0 ] ; then
216 echo "failed writing into read-only directory with error $ret"
221 echo "$out" | grep "$prompt" >/dev/null 2>&1
224 if [ $ret != 0 ] ; then
226 echo "failed writing into read-only directory - grep failed with $ret"
234 # Test sending a message
237 tmpfile=$PREFIX/message_in.$$
240 Test message from pid $$
243 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD -M $SERVER -p 139 $ADDARGS -n msgtest < $tmpfile 2>&1'
248 if [ $ret != 0 ] ; then
250 echo "failed sending message to $SERVER with error $ret"
255 # The server writes this into a file message.msgtest, via message.%m to test the % sub code
256 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmpguest -p 139 $ADDARGS -c "get message.msgtest $PREFIX/message_out.$$" 2>&1'
261 if [ $ret != 0 ] ; then
263 echo "failed getting sent message from $SERVER with error $ret"
267 if [ cmp $PREFIX/message_out.$$ $tmpfile != 0 ] ; then
268 echo "failed comparison of message from $SERVER"
275 # Test reading an owner-only file (logon as guest) fails.
276 test_owner_only_file()
278 prompt="NT_STATUS_ACCESS_DENIED opening remote file"
279 tmpfile=$PREFIX/smbclient.in.$$
282 ## We can't do this as non-root. We always have rights to
285 if [ "$USERID" != 0 ] ; then
286 echo "skipping test_owner_only_file as non-root"
291 ## We can't do this with an encrypted connection. No credentials
292 ## to set up the channel.
294 if [ "$ADDARGS" = "-e" ] ; then
295 echo "skipping test_owner_only_file with encrypted connection"
304 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
310 if [ $ret != 0 ] ; then
312 echo "failed reading owner-only file with error $ret"
316 echo "$out" | grep "$prompt" >/dev/null 2>&1
319 if [ $ret != 0 ] ; then
321 echo "failed reading owner-only file - grep failed with $ret"
328 # Test accessing an msdfs path.
331 tmpfile=$PREFIX/smbclient.in.$$
332 prompt=" msdfs-target "
334 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS -m nt1 -c dir 2>&1'
338 if [ $ret != 0 ] ; then
340 echo "failed listing msfds-share\ with error $ret"
351 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
357 if [ $ret != 0 ] ; then
359 echo "failed accessing \\msdfs-src1 link with error $ret"
363 echo "$out" | grep "$prompt" >/dev/null 2>&1
366 if [ $ret != 0 ] ; then
368 echo "failed listing \\msdfs-src1 - grep failed with $ret"
374 cd \\deeppath\\msdfs-src2
379 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
385 if [ $ret != 0 ] ; then
387 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
391 echo "$out" | grep "$prompt" >/dev/null 2>&1
394 if [ $ret != 0 ] ; then
396 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
403 # Archive bits are correctly set on file/dir creation and rename.
404 test_rename_archive_bit()
406 prompt_file="attributes: A (20)"
407 prompt_dir="attributes: D (10)"
408 tmpfile="$PREFIX/smbclient.in.$$"
410 filename_ren="bar.$$"
412 dirname_ren="bardir.$$"
413 filename_path="$PREFIX/$filename"
414 local_name1="$LOCAL_PATH/$filename"
415 local_name2="$LOCAL_PATH/$filename_ren"
416 local_dir_name1="$LOCAL_PATH/$dirname"
417 local_dir_name2="$LOCAL_PATH/$dirname_ren"
423 # Create a new file, ensure it has 'A' attributes.
433 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
439 if [ $ret != 0 ] ; then
441 echo "failed creating file $filename with error $ret"
445 echo "$out" | grep "$prompt_file" >/dev/null 2>&1
453 if [ $ret != 0 ] ; then
455 echo "Attributes incorrect on new file $ret"
459 # Now check if we remove 'A' and rename, the A comes back.
466 ren $filename $filename_ren
467 allinfo $filename_ren
471 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
477 if [ $ret != 0 ] ; then
479 echo "failed creating file and renaming $filename with error $ret"
483 echo "$out" | grep "$prompt_file" >/dev/null 2>&1
491 if [ $ret != 0 ] ; then
493 echo "Attributes incorrect on renamed file $ret"
497 rm -rf $local_dir_name1
498 rm -rf $local_dir_name2
500 # Create a new directory, ensure it has 'D' but not 'A' attributes.
508 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
514 if [ $ret != 0 ] ; then
516 echo "failed creating directory $dirname with error $ret"
520 echo "$out" | grep "$prompt_dir" >/dev/null 2>&1
524 rm -rf $local_dir_name1
525 rm -rf $local_dir_name2
527 if [ $ret != 0 ] ; then
529 echo "Attributes incorrect on new directory $ret"
533 # Now check if we rename, we still only have 'D' attributes
537 ren $dirname $dirname_ren
542 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
548 if [ $ret != 0 ] ; then
550 echo "failed creating directory $dirname and renaming with error $ret"
554 echo "$out" | grep "$prompt_dir" >/dev/null 2>&1
561 if [ $ret != 0 ] ; then
563 echo "Attributes incorrect on renamed directory $ret"
570 # Test authenticating using the winbind ccache
573 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
576 if [ $ret != 0 ] ; then
577 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='${PASSWORD}')"
581 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}" $ADDARGS -c quit 2>&1
584 if [ $ret != 0 ] ; then
585 echo "smbclient failed to use cached credentials"
589 $WBINFO --ccache-save="${USERNAME}%GarBage"
592 if [ $ret != 0 ] ; then
593 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='GarBage')"
597 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}" $ADDARGS -c quit 2>&1
600 if [ $ret -eq 0 ] ; then
601 echo "smbclient succeeded with wrong cached credentials"
608 # Test authenticating using the winbind ccache
611 tmpfile=$PREFIX/smbclient.in.$$
617 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile $ADDARGS -c quit 2>&1
621 if [ $ret != 0 ] ; then
622 echo "smbclient failed to use auth file"
631 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile $ADDARGS -c quit 2>&1
635 if [ $ret -eq 0 ] ; then
636 echo "smbclient succeeded with wrong auth file credentials"
641 # Test doing a directory listing with backup privilege.
642 test_backup_privilege_list()
644 tmpfile=$PREFIX/smbclient_backup_privilege_list
646 # If we don't have a DOMAIN component to the username, add it.
647 echo "$USERNAME" | grep '\\' 2>&1
649 if [ $ret != 0 ] ; then
650 priv_username="$DOMAIN\\$USERNAME"
652 priv_username=$USERNAME
655 $NET sam rights grant $priv_username SeBackupPrivilege 2>&1
657 if [ $ret != 0 ] ; then
658 echo "Failed to add SeBackupPrivilege to user $priv_username - $ret"
668 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
674 if [ $ret != 0 ] ; then
676 echo "failed backup privilege list $ret"
680 # Now remove all privileges from this SID.
681 $NET sam rights revoke $priv_username SeBackupPrivilege 2>&1
683 if [ $ret != 0 ] ; then
684 echo "failed to remove SeBackupPrivilege from user $priv_username - $ret"
689 # Test accessing an share with bad names (won't convert).
693 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/badname-tmp -I $SERVER_IP $ADDARGS -mNT1 -c ls 2>&1'
698 if [ $ret != 0 ] ; then
700 echo "failed accessing badname-tmp (SMB1) with error $ret"
704 echo "$out" | wc -l 2>&1 | grep 5
706 if [ $ret != 0 ] ; then
708 echo "failed listing \\badname-tmp - grep of number of lines (1) failed with $ret"
712 echo "$out" | grep '^ \. *D'
714 if [ $ret != 0 ] ; then
716 echo "failed listing \\badname-tmp - grep (1) failed with $ret"
720 echo "$out" | grep '^ \.\. *D'
722 if [ $ret != 0 ] ; then
724 echo "failed listing \\badname-tmp - grep (2) failed with $ret"
728 echo "$out" | grep '^ blank.txt *N'
730 if [ $ret != 0 ] ; then
732 echo "failed listing \\badname-tmp - grep (3) failed with $ret"
736 echo "$out" | grep '^ *$'
738 if [ $ret != 0 ] ; then
740 echo "failed listing \\badname-tmp - grep (4) failed with $ret"
744 echo "$out" | grep 'blocks of size.*blocks available'
746 if [ $ret != 0 ] ; then
748 echo "failed listing \\badname-tmp - grep (5) failed with $ret"
752 # Now check again with -mSMB3
753 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/badname-tmp -I $SERVER_IP $ADDARGS -mSMB3 -c ls 2>&1'
758 if [ $ret != 0 ] ; then
760 echo "failed accessing badname-tmp (SMB3) with error $ret"
764 echo "$out" | wc -l 2>&1 | grep 5
766 if [ $ret != 0 ] ; then
768 echo "failed listing \\badname-tmp - SMB3 grep of number of lines (1) failed with $ret"
772 echo "$out" | grep '^ \. *D'
774 if [ $ret != 0 ] ; then
776 echo "failed listing \\badname-tmp - SMB3 grep (1) failed with $ret"
780 echo "$out" | grep '^ \.\. *D'
782 if [ $ret != 0 ] ; then
784 echo "failed listing \\badname-tmp - SMB3 grep (2) failed with $ret"
788 echo "$out" | grep '^ blank.txt *N'
790 if [ $ret != 0 ] ; then
792 echo "failed listing \\badname-tmp - SMB3 grep (3) failed with $ret"
796 echo "$out" | grep '^ *$'
798 if [ $ret != 0 ] ; then
800 echo "failed listing \\badname-tmp - SMB3 grep (4) failed with $ret"
804 echo "$out" | grep 'blocks of size.*blocks available'
806 if [ $ret != 0 ] ; then
808 echo "failed listing \\badname-tmp - SMB3 grep (5) failed with $ret"
813 # Test accessing an share with a name that must be mangled - with acl_xattrs.
814 # We know foo:bar gets mangled to FF4GBY~Q with the default name-mangling algorithm (hash2).
817 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
824 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/manglenames_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
830 if [ $ret != 0 ] ; then
832 echo "failed accessing manglenames_share with error $ret"
836 echo "$out" | grep 'NT_STATUS'
838 if [ $ret == 0 ] ; then
840 echo "failed - NT_STATUS_XXXX listing \\manglenames_share\\FF4GBY~Q"
845 # Test using scopy to copy a file on the server.
848 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
849 scopy_file=$PREFIX/scopy_file
854 scopy smbclient scopy_file
862 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -mSMB3 < $tmpfile 2>&1'
866 out1=`md5sum ${SMBCLIENT} | sed -e 's/ .*//'`
867 out2=`md5sum ${scopy_file} | sed -e 's/ .*//'`
871 if [ $ret != 0 ] ; then
873 echo "failed scopy test (1) with output $ret"
877 if [ $out1 != $out2 ] ; then
879 echo "failed md5sum (1)"
884 # Now do again using SMB1
885 # to force client-side fallback.
890 scopy smbclient scopy_file
897 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -mNT1 < $tmpfile 2>&1'
901 out1=`md5sum ${SMBCLIENT} | sed -e 's/ .*//'`
902 out2=`md5sum ${scopy_file} | sed -e 's/ .*//'`
906 if [ $ret != 0 ] ; then
908 echo "failed scopy test (2) with output $ret"
912 if [ $out1 != $out2 ] ; then
914 echo "failed md5sum (2)"
919 # Test creating a stream on the root of the share directory filname - :foobar
920 test_toplevel_stream()
922 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
924 put ${PREFIX}/smbclient_interactive_prompt_commands :foobar
930 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -mSMB3 < $tmpfile 2>&1'
936 if [ $ret != 0 ] ; then
938 echo "failed creating toplevel stream :foobar with error $ret"
942 echo "$out" | grep '^stream:.*:foobar'
944 if [ $ret != 0 ] ; then
946 echo "failed creating toplevel stream :foobar"
951 # Test wide links are restricted.
954 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
960 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/widelinks_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
966 if [ $ret != 0 ] ; then
968 echo "failed accessing widelinks_share with error $ret"
972 echo "$out" | grep 'NT_STATUS'
974 if [ $ret == 0 ] ; then
976 echo "failed - NT_STATUS_XXXX listing \\widelinks_share\\dot"
984 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/widelinks_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
990 if [ $ret != 0 ] ; then
992 echo "failed accessing widelinks_share with error $ret"
996 # This should fail with NT_STATUS_ACCESS_DENIED
997 echo "$out" | grep 'NT_STATUS_ACCESS_DENIED'
999 if [ $ret != 0 ] ; then
1001 echo "failed - should get NT_STATUS_ACCESS_DENIED listing \\widelinks_share\\source"
1006 # Test creating then deleting a stream file doesn't leave a lost-XXXXX directory.
1007 test_streams_depot_delete()
1009 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1010 rm -rf "$LOCAL_PATH/lost-*"
1012 cat > $tmpfile <<EOF
1013 put ${PREFIX}/smbclient_interactive_prompt_commands foo:bar
1018 # This only works with SMB3?
1019 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -mSMB3 < $tmpfile 2>&1'
1025 if [ $ret != 0 ] ; then
1027 echo "failed creating then deleting foo:bar with error $ret"
1031 echo "$out" | grep 'NT_STATUS_NO_SUCH_FILE listing \\lost\*'
1033 if [ $ret != 0 ] ; then
1035 echo "deleting foo:bar left lost-XXX directory"
1036 rm -rf "$LOCAL_PATH/lost-*"
1041 # Test follow symlinks can't access symlinks
1045 local_test_dir="$LOCAL_PATH/nosymlinks/test"
1046 local_slink_name="$local_test_dir/source"
1047 local_slink_target="$local_test_dir/nosymlink_target_file"
1049 share_test_dir="test"
1050 share_foo_dir="$share_test_dir/foo"
1051 share_foobar_dir="$share_test_dir/foo/bar"
1052 share_target_file="$share_test_dir/foo/bar/testfile"
1054 rm -rf $local_test_dir
1056 local_nosymlink_target_file="nosymlink_target_file"
1057 echo "$local_slink_target" > $local_nosymlink_target_file
1059 local_foobar_target_file="testfile"
1060 echo "$share_target_file" > $local_foobar_target_file
1062 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1063 cat > $tmpfile <<EOF
1064 mkdir $share_test_dir
1065 mkdir $share_foo_dir
1066 mkdir $share_foobar_dir
1068 put $local_nosymlink_target_file
1069 cd /$share_foobar_dir
1070 put $local_foobar_target_file
1074 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
1079 rm -f $local_nosymlink_target_file
1080 rm -f $local_foobar_target_file
1082 if [ $ret -ne 0 ] ; then
1084 echo "failed accessing local_symlinks with error $ret"
1089 echo "$out" | grep 'NT_STATUS_'
1091 if [ $ret -eq 0 ] ; then
1093 echo "failed - got an NT_STATUS error"
1098 # Create the symlink locally
1099 ln -s $local_slink_target $local_slink_name
1101 # Getting a file through a symlink name should fail.
1102 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1103 cat > $tmpfile <<EOF
1107 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1113 if [ $ret -ne 0 ] ; then
1115 echo "failed accessing nosymlinks with error $ret"
1119 echo "$out" | grep 'NT_STATUS_ACCESS_DENIED'
1121 if [ $ret -ne 0 ] ; then
1123 echo "failed - should get NT_STATUS_ACCESS_DENIED getting \\nosymlinks\\source"
1127 # But we should be able to create and delete directories.
1128 cat > $tmpfile <<EOF
1133 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1139 if [ $ret -ne 0 ] ; then
1141 echo "failed accessing nosymlinks with error $ret"
1145 echo "$out" | grep 'NT_STATUS'
1147 if [ $ret -eq 0 ] ; then
1149 echo "failed - NT_STATUS_XXXX doing mkdir a; mkdir a\\b on \\nosymlinks"
1153 # Ensure regular file/directory access also works.
1154 cat > $tmpfile <<EOF
1160 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1166 if [ $ret -ne 0 ] ; then
1168 echo "failed accessing nosymlinks with error $ret"
1172 echo "$out" | grep 'NT_STATUS'
1174 if [ $ret -eq 0 ] ; then
1176 echo "failed - NT_STATUS_XXXX doing cd foo\\bar; get testfile on \\nosymlinks"
1181 rm -f $local_slink_name
1183 cat > $tmpfile <<EOF
1187 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1193 if [ $ret -ne 0 ] ; then
1195 echo "failed accessing nosymlinks with error $ret"
1199 echo "$out" | grep 'NT_STATUS'
1201 if [ $ret -eq 0 ] ; then
1203 echo "failed - NT_STATUS_XXXX doing cd foo\\bar; get testfile on \\nosymlinks"
1208 # Test we can follow normal symlinks.
1209 # Bug: https://bugzilla.samba.org/show_bug.cgi?id=12860
1210 # Note - this needs to be tested over SMB3, not SMB1.
1212 test_local_symlinks()
1215 LOCAL_RAWARGS="${CONFIGURATION} -mSMB3"
1216 LOCAL_ADDARGS="${LOCAL_RAWARGS} $*"
1218 share_test_dir="test"
1219 share_slink_target_dir="$share_test_dir/dir1"
1221 local_test_dir="$LOCAL_PATH/local_symlinks/$share_test_dir"
1222 local_slink_name="$local_test_dir/sym_name"
1223 local_slink_target_dir="$local_test_dir/dir1"
1225 rm -rf $local_test_dir
1227 # Create the initial directories
1228 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1229 cat > $tmpfile <<EOF
1230 mkdir $share_test_dir
1231 mkdir $share_slink_target_dir
1235 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/local_symlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
1241 if [ $ret -ne 0 ] ; then
1243 echo "failed accessing local_symlinks with error $ret"
1248 echo "$out" | grep 'NT_STATUS_'
1250 if [ $ret -eq 0 ] ; then
1252 echo "failed - got an NT_STATUS error"
1257 # Create the symlink locally
1258 ln -s $local_slink_target_dir $local_slink_name
1260 if [ $ret -ne 0 ] ; then
1262 echo "failed - unable to create symlink"
1263 ls -la $local_test_dir
1268 # Can we cd into the symlink name and ls ?
1269 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1270 cat > $tmpfile <<EOF
1271 cd $share_test_dir\\sym_name
1275 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/local_symlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
1281 if [ $ret -ne 0 ] ; then
1283 echo "failed accessing local_symlinks with error $ret"
1288 echo "$out" | grep 'NT_STATUS_'
1290 if [ $ret -eq 0 ] ; then
1292 echo "failed - got an NT_STATUS error"
1298 rm -f $local_slink_name
1300 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1301 cat > $tmpfile <<EOF
1302 deltree $share_test_dir
1305 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/local_symlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
1311 if [ $ret -ne 0 ] ; then
1313 echo "failed accessing local_symlinks with error $ret"
1318 echo "$out" | grep 'NT_STATUS_'
1320 if [ $ret -eq 0 ] ; then
1322 echo "failed - got an NT_STATUS error"
1328 # Test smbclient deltree command
1331 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1332 deltree_dir=$PREFIX/deltree_dir
1335 cat > $tmpfile <<EOF
1337 mkdir deltree_dir/foo
1338 mkdir deltree_dir/foo/bar
1339 put ${SMBCLIENT} deltree_dir/foo/bar/client
1343 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1348 if [ $ret != 0 ] ; then
1350 echo "failed deltree test with output $ret"
1355 echo "$out" | grep 'NT_STATUS_'
1357 if [ $ret -eq 0 ] ; then
1359 echo "failed - got an NT_STATUS error"
1364 if [ -d $deltree_dir ] ; then
1365 echo "deltree did not delete everything"
1371 # Test smbclient setmode command
1374 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1376 cat > $tmpfile <<EOF
1378 put ${SMBCLIENT} test_setmode
1379 setmode test_setmode +r +s +h +a
1380 allinfo test_setmode
1381 setmode test_setmode -rsha
1382 allinfo test_setmode
1386 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1391 if [ $ret != 0 ] ; then
1393 echo "failed setmode test with output $ret"
1398 echo "$out" | grep 'attributes: RHSA'
1400 if [ $ret -ne 0 ] ; then
1402 echo "failed - should get attributes: RHSA"
1407 echo "$out" | grep 'attributes: (80)'
1409 if [ $ret -ne 0 ] ; then
1411 echo "failed - should also get attributes: (80)"
1418 test_server_os_message()
1420 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1421 cat > $tmpfile <<EOF
1425 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1431 if [ $ret -ne 0 ] ; then
1433 echo "failed to connect error $ret"
1437 echo "$out" | grep 'Try "help" to get a list of possible commands.'
1439 if [ $ret -ne 0 ] ; then
1441 echo 'failed - should get: Try "help" to get a list of possible commands.'
1448 LOGDIR_PREFIX=test_smbclient_s3
1450 # possibly remove old logdirs:
1452 for OLDDIR in $(find ${PREFIX} -type d -name "${LOGDIR_PREFIX}_*") ; do
1453 echo "removing old directory ${OLDDIR}"
1457 LOGDIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX)
1460 testit "smbclient -L $SERVER_IP" $SMBCLIENT -L $SERVER_IP -N -p 139 ${RAWARGS} || failed=`expr $failed + 1`
1461 testit "smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 ${RAWARGS} -c quit || failed=`expr $failed + 1`
1463 testit "noninteractive smbclient does not prompt" \
1464 test_noninteractive_no_prompt || \
1465 failed=`expr $failed + 1`
1467 testit "noninteractive smbclient -l does not prompt" \
1468 test_noninteractive_no_prompt -l $LOGDIR || \
1469 failed=`expr $failed + 1`
1471 testit "interactive smbclient prompts on stdout" \
1472 test_interactive_prompt_stdout || \
1473 failed=`expr $failed + 1`
1475 testit "interactive smbclient -l prompts on stdout" \
1476 test_interactive_prompt_stdout -l $LOGDIR || \
1477 failed=`expr $failed + 1`
1479 testit "creating a bad symlink and deleting it" \
1480 test_bad_symlink || \
1481 failed=`expr $failed + 1`
1483 testit "creating a good symlink and deleting it by path" \
1484 test_good_symlink || \
1485 failed=`expr $failed + 1`
1487 testit "writing into a read-only directory fails" \
1488 test_read_only_dir ro-tmp || \
1489 failed=`expr $failed + 1`
1491 testit "writing into a read-only share fails" \
1492 test_read_only_dir valid-users-tmp || \
1493 failed=`expr $failed + 1`
1495 testit "Reading a owner-only file fails" \
1496 test_owner_only_file || \
1497 failed=`expr $failed + 1`
1499 testit "Accessing an MS-DFS link" \
1500 test_msdfs_link || \
1501 failed=`expr $failed + 1`
1503 testit "Ensure archive bit is set correctly on file/dir rename" \
1504 test_rename_archive_bit || \
1505 failed=`expr $failed + 1`
1507 testit "ccache access works for smbclient" \
1508 test_ccache_access || \
1509 failed=`expr $failed + 1`
1511 testit "sending a message to the remote server" \
1513 failed=`expr $failed + 1`
1515 testit "using an authentication file" \
1517 failed=`expr $failed + 1`
1519 testit "list with backup privilege" \
1520 test_backup_privilege_list || \
1521 failed=`expr $failed + 1`
1523 testit "list a share with bad names (won't convert)" \
1525 failed=`expr $failed + 1`
1527 testit "list a share with a mangled name + acl_xattr object" \
1528 test_mangled_names || \
1529 failed=`expr $failed + 1`
1531 testit "server-side file copy" \
1533 failed=`expr $failed + 1`
1535 testit "creating a :stream at root of share" \
1536 test_toplevel_stream || \
1537 failed=`expr $failed + 1`
1539 testit "Ensure widelinks are restricted" \
1541 failed=`expr $failed + 1`
1543 testit "streams_depot can delete correctly" \
1544 test_streams_depot_delete || \
1545 failed=`expr $failed + 1`
1547 testit "follow symlinks = no" \
1548 test_nosymlinks || \
1549 failed=`expr $failed + 1`
1551 testit "follow local symlinks" \
1552 test_local_symlinks || \
1553 failed=`expr $failed + 1`
1555 testit "smbclient deltree command" \
1557 failed=`expr $failed + 1`
1559 testit "server os message" \
1560 test_server_os_message || \
1561 failed=`expr $failed + 1`
1563 testit "setmode test" \
1565 failed=`expr $failed + 1`
1567 testit "rm -rf $LOGDIR" \
1569 failed=`expr $failed + 1`