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 # selftest uses the forward slash as a separator, but "net sam rights
647 # grant" requires the backslash separator
648 USER_TMP=$(printf '%s' "$USERNAME" | tr '/' '\\')
650 # If we don't have a DOMAIN component to the username, add it.
651 printf '%s' "$USER_TMP" | grep '\\' 2>&1
653 if [ $ret != 0 ] ; then
654 priv_username="$DOMAIN\\$USER_TMP"
656 priv_username="$USER_TMP"
659 $NET sam rights grant $priv_username SeBackupPrivilege 2>&1
661 if [ $ret != 0 ] ; then
662 echo "Failed to add SeBackupPrivilege to user $priv_username - $ret"
672 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
678 if [ $ret != 0 ] ; then
680 echo "failed backup privilege list $ret"
684 # Now remove all privileges from this SID.
685 $NET sam rights revoke $priv_username SeBackupPrivilege 2>&1
687 if [ $ret != 0 ] ; then
688 echo "failed to remove SeBackupPrivilege from user $priv_username - $ret"
693 # Test accessing an share with bad names (won't convert).
697 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/badname-tmp -I $SERVER_IP $ADDARGS -mNT1 -c ls 2>&1'
702 if [ $ret != 0 ] ; then
704 echo "failed accessing badname-tmp (SMB1) with error $ret"
708 echo "$out" | wc -l 2>&1 | grep 5
710 if [ $ret != 0 ] ; then
712 echo "failed listing \\badname-tmp - grep of number of lines (1) failed with $ret"
716 echo "$out" | grep '^ \. *D'
718 if [ $ret != 0 ] ; then
720 echo "failed listing \\badname-tmp - grep (1) failed with $ret"
724 echo "$out" | grep '^ \.\. *D'
726 if [ $ret != 0 ] ; then
728 echo "failed listing \\badname-tmp - grep (2) failed with $ret"
732 echo "$out" | grep '^ blank.txt *N'
734 if [ $ret != 0 ] ; then
736 echo "failed listing \\badname-tmp - grep (3) failed with $ret"
740 echo "$out" | grep '^ *$'
742 if [ $ret != 0 ] ; then
744 echo "failed listing \\badname-tmp - grep (4) failed with $ret"
748 echo "$out" | grep 'blocks of size.*blocks available'
750 if [ $ret != 0 ] ; then
752 echo "failed listing \\badname-tmp - grep (5) failed with $ret"
756 # Now check again with -mSMB3
757 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/badname-tmp -I $SERVER_IP $ADDARGS -mSMB3 -c ls 2>&1'
762 if [ $ret != 0 ] ; then
764 echo "failed accessing badname-tmp (SMB3) with error $ret"
768 echo "$out" | wc -l 2>&1 | grep 5
770 if [ $ret != 0 ] ; then
772 echo "failed listing \\badname-tmp - SMB3 grep of number of lines (1) failed with $ret"
776 echo "$out" | grep '^ \. *D'
778 if [ $ret != 0 ] ; then
780 echo "failed listing \\badname-tmp - SMB3 grep (1) failed with $ret"
784 echo "$out" | grep '^ \.\. *D'
786 if [ $ret != 0 ] ; then
788 echo "failed listing \\badname-tmp - SMB3 grep (2) failed with $ret"
792 echo "$out" | grep '^ blank.txt *N'
794 if [ $ret != 0 ] ; then
796 echo "failed listing \\badname-tmp - SMB3 grep (3) failed with $ret"
800 echo "$out" | grep '^ *$'
802 if [ $ret != 0 ] ; then
804 echo "failed listing \\badname-tmp - SMB3 grep (4) failed with $ret"
808 echo "$out" | grep 'blocks of size.*blocks available'
810 if [ $ret != 0 ] ; then
812 echo "failed listing \\badname-tmp - SMB3 grep (5) failed with $ret"
817 # Test accessing an share with a name that must be mangled - with acl_xattrs.
818 # We know foo:bar gets mangled to FF4GBY~Q with the default name-mangling algorithm (hash2).
821 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
828 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/manglenames_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
834 if [ $ret != 0 ] ; then
836 echo "failed accessing manglenames_share with error $ret"
840 echo "$out" | grep 'NT_STATUS'
842 if [ $ret = 0 ] ; then
844 echo "failed - NT_STATUS_XXXX listing \\manglenames_share\\FF4GBY~Q"
849 # Test using scopy to copy a file on the server.
852 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
853 scopy_file=$PREFIX/scopy_file
858 scopy smbclient scopy_file
866 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -mSMB3 < $tmpfile 2>&1'
870 out1=`md5sum ${SMBCLIENT} | sed -e 's/ .*//'`
871 out2=`md5sum ${scopy_file} | sed -e 's/ .*//'`
875 if [ $ret != 0 ] ; then
877 echo "failed scopy test (1) with output $ret"
881 if [ $out1 != $out2 ] ; then
883 echo "failed md5sum (1)"
888 # Now do again using SMB1
889 # to force client-side fallback.
894 scopy smbclient scopy_file
901 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -mNT1 < $tmpfile 2>&1'
905 out1=`md5sum ${SMBCLIENT} | sed -e 's/ .*//'`
906 out2=`md5sum ${scopy_file} | sed -e 's/ .*//'`
910 if [ $ret != 0 ] ; then
912 echo "failed scopy test (2) with output $ret"
916 if [ $out1 != $out2 ] ; then
918 echo "failed md5sum (2)"
923 # Test creating a stream on the root of the share directory filname - :foobar
924 test_toplevel_stream()
926 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
928 put ${PREFIX}/smbclient_interactive_prompt_commands :foobar
934 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -mSMB3 < $tmpfile 2>&1'
940 if [ $ret != 0 ] ; then
942 echo "failed creating toplevel stream :foobar with error $ret"
946 echo "$out" | grep '^stream:.*:foobar'
948 if [ $ret != 0 ] ; then
950 echo "failed creating toplevel stream :foobar"
955 # Test wide links are restricted.
958 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
964 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/widelinks_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
970 if [ $ret != 0 ] ; then
972 echo "failed accessing widelinks_share with error $ret"
976 echo "$out" | grep 'NT_STATUS'
978 if [ $ret = 0 ] ; then
980 echo "failed - NT_STATUS_XXXX listing \\widelinks_share\\dot"
988 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/widelinks_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
994 if [ $ret != 0 ] ; then
996 echo "failed accessing widelinks_share with error $ret"
1000 # This should fail with NT_STATUS_ACCESS_DENIED
1001 echo "$out" | grep 'NT_STATUS_ACCESS_DENIED'
1003 if [ $ret != 0 ] ; then
1005 echo "failed - should get NT_STATUS_ACCESS_DENIED listing \\widelinks_share\\source"
1010 # Test creating then deleting a stream file doesn't leave a lost-XXXXX directory.
1011 test_streams_depot_delete()
1013 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1014 rm -rf "$LOCAL_PATH/lost-*"
1016 cat > $tmpfile <<EOF
1017 put ${PREFIX}/smbclient_interactive_prompt_commands foo:bar
1022 # This only works with SMB3?
1023 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS -mSMB3 < $tmpfile 2>&1'
1029 if [ $ret != 0 ] ; then
1031 echo "failed creating then deleting foo:bar with error $ret"
1035 echo "$out" | grep 'NT_STATUS_NO_SUCH_FILE listing \\lost\*'
1037 if [ $ret != 0 ] ; then
1039 echo "deleting foo:bar left lost-XXX directory"
1040 rm -rf "$LOCAL_PATH/lost-*"
1045 # Test follow symlinks can't access symlinks
1049 local_test_dir="$LOCAL_PATH/nosymlinks/test"
1050 local_slink_name="$local_test_dir/source"
1051 local_slink_target="$local_test_dir/nosymlink_target_file"
1053 share_test_dir="test"
1054 share_foo_dir="$share_test_dir/foo"
1055 share_foobar_dir="$share_test_dir/foo/bar"
1056 share_target_file="$share_test_dir/foo/bar/testfile"
1058 rm -rf $local_test_dir
1060 local_nosymlink_target_file="nosymlink_target_file"
1061 echo "$local_slink_target" > $local_nosymlink_target_file
1063 local_foobar_target_file="testfile"
1064 echo "$share_target_file" > $local_foobar_target_file
1066 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1067 cat > $tmpfile <<EOF
1068 mkdir $share_test_dir
1069 mkdir $share_foo_dir
1070 mkdir $share_foobar_dir
1072 put $local_nosymlink_target_file
1073 cd /$share_foobar_dir
1074 put $local_foobar_target_file
1078 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
1083 rm -f $local_nosymlink_target_file
1084 rm -f $local_foobar_target_file
1086 if [ $ret -ne 0 ] ; then
1088 echo "failed accessing local_symlinks with error $ret"
1093 echo "$out" | grep 'NT_STATUS_'
1095 if [ $ret -eq 0 ] ; then
1097 echo "failed - got an NT_STATUS error"
1102 # Create the symlink locally
1103 ln -s $local_slink_target $local_slink_name
1105 # Getting a file through a symlink name should fail.
1106 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1107 cat > $tmpfile <<EOF
1111 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1117 if [ $ret -ne 0 ] ; then
1119 echo "failed accessing nosymlinks with error $ret"
1123 echo "$out" | grep 'NT_STATUS_ACCESS_DENIED'
1125 if [ $ret -ne 0 ] ; then
1127 echo "failed - should get NT_STATUS_ACCESS_DENIED getting \\nosymlinks\\source"
1131 # But we should be able to create and delete directories.
1132 cat > $tmpfile <<EOF
1137 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1143 if [ $ret -ne 0 ] ; then
1145 echo "failed accessing nosymlinks with error $ret"
1149 echo "$out" | grep 'NT_STATUS'
1151 if [ $ret -eq 0 ] ; then
1153 echo "failed - NT_STATUS_XXXX doing mkdir a; mkdir a\\b on \\nosymlinks"
1157 # Ensure regular file/directory access also works.
1158 cat > $tmpfile <<EOF
1164 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1170 if [ $ret -ne 0 ] ; then
1172 echo "failed accessing nosymlinks with error $ret"
1176 echo "$out" | grep 'NT_STATUS'
1178 if [ $ret -eq 0 ] ; then
1180 echo "failed - NT_STATUS_XXXX doing cd foo\\bar; get testfile on \\nosymlinks"
1185 rm -f $local_slink_name
1187 cat > $tmpfile <<EOF
1191 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1197 if [ $ret -ne 0 ] ; then
1199 echo "failed accessing nosymlinks with error $ret"
1203 echo "$out" | grep 'NT_STATUS'
1205 if [ $ret -eq 0 ] ; then
1207 echo "failed - NT_STATUS_XXXX doing cd foo\\bar; get testfile on \\nosymlinks"
1212 # Test we can follow normal symlinks.
1213 # Bug: https://bugzilla.samba.org/show_bug.cgi?id=12860
1214 # Note - this needs to be tested over SMB3, not SMB1.
1216 test_local_symlinks()
1219 LOCAL_RAWARGS="${CONFIGURATION} -mSMB3"
1220 LOCAL_ADDARGS="${LOCAL_RAWARGS} $*"
1222 share_test_dir="test"
1223 share_slink_target_dir="$share_test_dir/dir1"
1225 local_test_dir="$LOCAL_PATH/local_symlinks/$share_test_dir"
1226 local_slink_name="$local_test_dir/sym_name"
1227 local_slink_target_dir="$local_test_dir/dir1"
1229 rm -rf $local_test_dir
1231 # Create the initial directories
1232 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1233 cat > $tmpfile <<EOF
1234 mkdir $share_test_dir
1235 mkdir $share_slink_target_dir
1239 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/local_symlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
1245 if [ $ret -ne 0 ] ; then
1247 echo "failed accessing local_symlinks with error $ret"
1252 echo "$out" | grep 'NT_STATUS_'
1254 if [ $ret -eq 0 ] ; then
1256 echo "failed - got an NT_STATUS error"
1261 # Create the symlink locally
1262 ln -s $local_slink_target_dir $local_slink_name
1264 if [ $ret -ne 0 ] ; then
1266 echo "failed - unable to create symlink"
1267 ls -la $local_test_dir
1272 # Can we cd into the symlink name and ls ?
1273 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1274 cat > $tmpfile <<EOF
1275 cd $share_test_dir\\sym_name
1279 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/local_symlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
1285 if [ $ret -ne 0 ] ; then
1287 echo "failed accessing local_symlinks with error $ret"
1292 echo "$out" | grep 'NT_STATUS_'
1294 if [ $ret -eq 0 ] ; then
1296 echo "failed - got an NT_STATUS error"
1302 rm -f $local_slink_name
1304 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1305 cat > $tmpfile <<EOF
1306 deltree $share_test_dir
1309 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/local_symlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
1315 if [ $ret -ne 0 ] ; then
1317 echo "failed accessing local_symlinks with error $ret"
1322 echo "$out" | grep 'NT_STATUS_'
1324 if [ $ret -eq 0 ] ; then
1326 echo "failed - got an NT_STATUS error"
1332 # Test smbclient deltree command
1335 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1336 deltree_dir=$PREFIX/deltree_dir
1339 cat > $tmpfile <<EOF
1341 mkdir deltree_dir/foo
1342 mkdir deltree_dir/foo/bar
1343 put ${SMBCLIENT} deltree_dir/foo/bar/client
1347 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1352 if [ $ret != 0 ] ; then
1354 echo "failed deltree test with output $ret"
1359 echo "$out" | grep 'NT_STATUS_'
1361 if [ $ret -eq 0 ] ; then
1363 echo "failed - got an NT_STATUS error"
1368 if [ -d $deltree_dir ] ; then
1369 echo "deltree did not delete everything"
1375 # Test smbclient setmode command
1378 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1380 cat > $tmpfile <<EOF
1382 put ${SMBCLIENT} test_setmode
1383 setmode test_setmode +r +s +h +a
1384 allinfo test_setmode
1385 setmode test_setmode -rsha
1386 allinfo test_setmode
1390 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1395 if [ $ret != 0 ] ; then
1397 echo "failed setmode test with output $ret"
1402 echo "$out" | grep 'attributes: RHSA'
1404 if [ $ret -ne 0 ] ; then
1406 echo "failed - should get attributes: RHSA"
1411 echo "$out" | grep 'attributes: (80)'
1413 if [ $ret -ne 0 ] ; then
1415 echo "failed - should also get attributes: (80)"
1421 # Test smbclient utimes command
1424 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1433 cat > $tmpfile <<EOF
1435 put ${SMBCLIENT} utimes_test
1437 utimes utimes_test -1 17:01:01-05:10:20 -1 -1
1442 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1447 if [ -n "$saved_TZ" ] ; then
1448 export TZ="$saved_TZ"
1452 if [ -n "$saved_LANG" ] ; then
1453 export LANG="$saved_LANG"
1458 if [ $ret != 0 ] ; then
1460 echo "failed utimes test with output $ret"
1465 # Now, we should have 2 identical create_time, write_time, change_time
1466 # values, but one access_time of Jan 1 05:10:20 AM.
1467 out_sorted=`echo "$out" | sort | uniq`
1468 num_create=`echo "$out_sorted" | grep -c 'create_time:'`
1469 num_access=`echo "$out_sorted" | grep -c 'access_time:'`
1470 num_write=`echo "$out_sorted" | grep -c 'write_time:'`
1471 num_change=`echo "$out_sorted" | grep -c 'change_time:'`
1472 if [ "$num_create" != "1" ]; then
1473 echo "failed - should only get one create_time $out"
1477 if [ "$num_access" != "2" ]; then
1478 echo "failed - should get two access_time $out"
1482 if [ "$num_write" != "1" ]; then
1483 echo "failed - should only get one write_time $out"
1487 if [ "$num_change" != "1" ]; then
1488 echo "failed - should only get one change_time $out"
1493 # This could be: Sun Jan 1 05:10:20 AM 2017
1494 # or : Sun Jan 1 05:10:20 2017 CET
1495 echo "$out" | grep 'access_time:.*Sun Jan.*1 05:10:20 .*2017.*'
1497 if [ $ret -ne 0 ] ; then
1500 echo "failed - should get access_time: Sun Jan 1 05:10:20 [AM] 2017"
1506 # Test smbclient renames with pathnames containing '..'
1507 test_rename_dotdot()
1509 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1511 cat > $tmpfile <<EOF
1518 put ${SMBCLIENT} README
1519 rename README ..\\dir2\\README
1527 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1532 if [ $ret != 0 ] ; then
1534 echo "failed rename_dotdot test with output $ret"
1539 # We are allowed to get NT_STATUS_NO_SUCH_FILE listing \dotdot_test
1540 # as the top level directory should not exist, but no other errors.
1542 error_str=`echo $out | grep NT_STATUS | grep -v "NT_STATUS_NO_SUCH_FILE listing .dotdot_test"`
1543 if [ "$error_str" != "" ]; then
1544 echo "failed - unexpected NT_STATUS error in $out"
1550 # Test doing a volume command.
1553 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1554 cat > $tmpfile <<EOF
1558 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1564 if [ $ret != 0 ] ; then
1566 echo "failed doing volume command with error $ret"
1570 echo "$out" | grep '^Volume: |tmp| serial number'
1572 if [ $ret != 0 ] ; then
1574 echo "failed doing volume command"
1579 test_server_os_message()
1581 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1582 cat > $tmpfile <<EOF
1586 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1592 if [ $ret -ne 0 ] ; then
1594 echo "failed to connect error $ret"
1598 echo "$out" | grep 'Try "help" to get a list of possible commands.'
1600 if [ $ret -ne 0 ] ; then
1602 echo 'failed - should get: Try "help" to get a list of possible commands.'
1609 # Test xattr_stream correctly reports mode.
1610 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=13380
1612 test_stream_directory_xattr()
1614 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1616 # Test against streams_xattr
1618 cat > $tmpfile <<EOF
1621 put ${PREFIX}/smbclient_interactive_prompt_commands foo:bar
1627 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/streams_xattr -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1633 if [ $ret != 0 ] ; then
1635 echo "failed checking attributes on xattr stream foo:bar with error $ret"
1639 echo "$out" | grep "attributes:.*80"
1641 if [ $ret != 0 ] ; then
1643 echo "failed checking attributes on xattr stream foo:bar"
1648 # Test against streams_depot
1650 cat > $tmpfile <<EOF
1653 put ${PREFIX}/smbclient_interactive_prompt_commands foo:bar
1659 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1665 if [ $ret != 0 ] ; then
1667 echo "failed checking attributes on depot stream foo:bar with error $ret"
1671 echo "$out" | grep "attributes:.*80"
1673 if [ $ret != 0 ] ; then
1675 echo "failed checking attributes on depot stream foo:bar"
1681 LOGDIR_PREFIX=test_smbclient_s3
1683 # possibly remove old logdirs:
1685 for OLDDIR in $(find ${PREFIX} -type d -name "${LOGDIR_PREFIX}_*") ; do
1686 echo "removing old directory ${OLDDIR}"
1690 LOGDIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX)
1693 testit "smbclient -L $SERVER_IP" $SMBCLIENT -L $SERVER_IP -N -p 139 ${RAWARGS} || failed=`expr $failed + 1`
1694 testit "smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 ${RAWARGS} -c quit || failed=`expr $failed + 1`
1696 testit "noninteractive smbclient does not prompt" \
1697 test_noninteractive_no_prompt || \
1698 failed=`expr $failed + 1`
1700 testit "noninteractive smbclient -l does not prompt" \
1701 test_noninteractive_no_prompt -l $LOGDIR || \
1702 failed=`expr $failed + 1`
1704 testit "interactive smbclient prompts on stdout" \
1705 test_interactive_prompt_stdout || \
1706 failed=`expr $failed + 1`
1708 testit "interactive smbclient -l prompts on stdout" \
1709 test_interactive_prompt_stdout -l $LOGDIR || \
1710 failed=`expr $failed + 1`
1712 testit "creating a bad symlink and deleting it" \
1713 test_bad_symlink || \
1714 failed=`expr $failed + 1`
1716 testit "creating a good symlink and deleting it by path" \
1717 test_good_symlink || \
1718 failed=`expr $failed + 1`
1720 testit "writing into a read-only directory fails" \
1721 test_read_only_dir ro-tmp || \
1722 failed=`expr $failed + 1`
1724 testit "writing into a read-only share fails" \
1725 test_read_only_dir valid-users-tmp || \
1726 failed=`expr $failed + 1`
1728 testit "Reading a owner-only file fails" \
1729 test_owner_only_file || \
1730 failed=`expr $failed + 1`
1732 testit "Accessing an MS-DFS link" \
1733 test_msdfs_link || \
1734 failed=`expr $failed + 1`
1736 testit "Ensure archive bit is set correctly on file/dir rename" \
1737 test_rename_archive_bit || \
1738 failed=`expr $failed + 1`
1740 testit "ccache access works for smbclient" \
1741 test_ccache_access || \
1742 failed=`expr $failed + 1`
1744 testit "sending a message to the remote server" \
1746 failed=`expr $failed + 1`
1748 testit "using an authentication file" \
1750 failed=`expr $failed + 1`
1752 testit "list with backup privilege" \
1753 test_backup_privilege_list || \
1754 failed=`expr $failed + 1`
1756 testit "list a share with bad names (won't convert)" \
1758 failed=`expr $failed + 1`
1760 testit "list a share with a mangled name + acl_xattr object" \
1761 test_mangled_names || \
1762 failed=`expr $failed + 1`
1764 testit "server-side file copy" \
1766 failed=`expr $failed + 1`
1768 testit "creating a :stream at root of share" \
1769 test_toplevel_stream || \
1770 failed=`expr $failed + 1`
1772 testit "Ensure widelinks are restricted" \
1774 failed=`expr $failed + 1`
1776 testit "streams_depot can delete correctly" \
1777 test_streams_depot_delete || \
1778 failed=`expr $failed + 1`
1780 testit "stream_xattr attributes" \
1781 test_stream_directory_xattr || \
1782 failed=`expr $failed + 1`
1784 testit "follow symlinks = no" \
1785 test_nosymlinks || \
1786 failed=`expr $failed + 1`
1788 testit "follow local symlinks" \
1789 test_local_symlinks || \
1790 failed=`expr $failed + 1`
1792 testit "smbclient deltree command" \
1794 failed=`expr $failed + 1`
1796 testit "server os message" \
1797 test_server_os_message || \
1798 failed=`expr $failed + 1`
1800 testit "setmode test" \
1802 failed=`expr $failed + 1`
1806 failed=`expr $failed + 1`
1808 testit "rename_dotdot" \
1809 test_rename_dotdot || \
1810 failed=`expr $failed + 1`
1814 failed=`expr $failed + 1`
1816 testit "rm -rf $LOGDIR" \
1818 failed=`expr $failed + 1`