tombstones-expunge: Add a test for deleting links to recycled objects
[Samba.git] / source3 / script / tests / test_smbclient_s3.sh
blob22849bd503181c11155da2b10268d06e92361176
1 #!/bin/sh
3 # this runs the file serving tests that are expected to pass with samba3
5 if [ $# -lt 11 ]; then
6 cat <<EOF
7 Usage: test_smbclient_s3.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD USERID LOCAL_PATH PREFIX SMBCLIENT WBINFO NET
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 WBINFO="${10}"
22 NET="${11}"
23 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
24 WBINFO="$VALGRIND ${WBINFO}"
25 shift 11
26 ADDARGS="$*"
28 incdir=`dirname $0`/../../../testprogs/blackbox
29 . $incdir/subunit.sh
31 failed=0
33 # Test that a noninteractive smbclient does not prompt
34 test_noninteractive_no_prompt()
36 prompt="smb"
38 cmd='echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
39 eval echo "$cmd"
40 out=`eval $cmd`
42 if [ $? != 0 ] ; then
43 echo "$out"
44 echo "command failed"
45 false
46 return
49 echo "$out" | grep $prompt >/dev/null 2>&1
51 if [ $? = 0 ] ; then
52 # got a prompt .. fail
53 echo matched interactive prompt in non-interactive mode
54 false
55 else
56 true
60 # Test that an interactive smbclient prompts to stdout
61 test_interactive_prompt_stdout()
63 prompt="smb"
64 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
66 cat > $tmpfile <<EOF
68 quit
69 EOF
71 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
72 eval echo "$cmd"
73 out=`eval $cmd`
74 ret=$?
75 rm -f $tmpfile
77 if [ $ret != 0 ] ; then
78 echo "$out"
79 echo "command failed"
80 false
81 return
84 echo "$out" | grep $prompt >/dev/null 2>&1
86 if [ $? = 0 ] ; then
87 # got a prompt .. succeed
88 true
89 else
90 echo failed to match interactive prompt on stdout
91 false
95 # Test creating a bad symlink and deleting it.
96 test_bad_symlink()
98 prompt="posix_unlink deleted file /newname"
99 tmpfile=$PREFIX/smbclient_bad_symlinks_commands
101 cat > $tmpfile <<EOF
102 posix
103 posix_unlink newname
104 symlink badname newname
105 posix_unlink newname
106 quit
109 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
110 eval echo "$cmd"
111 out=`eval $cmd`
112 ret=$?
113 rm -f $tmpfile
115 if [ $ret != 0 ] ; then
116 echo "$out"
117 echo "failed create then delete bad symlink with error $ret"
118 false
119 return
122 echo "$out" | grep "$prompt" >/dev/null 2>&1
124 ret=$?
125 if [ $ret = 0 ] ; then
126 # got the correct prompt .. succeed
127 true
128 else
129 echo "$out"
130 echo "failed create then delete bad symlink - grep failed with $ret"
131 false
135 # Test creating a good symlink and deleting it by path.
136 test_good_symlink()
138 tmpfile=$PREFIX/smbclient.in.$$
139 slink_name="$LOCAL_PATH/slink"
140 slink_target="$LOCAL_PATH/slink_target"
142 touch $slink_target
143 ln -s $slink_target $slink_name
144 cat > $tmpfile <<EOF
145 del slink
146 quit
149 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
150 eval echo "$cmd"
151 out=`eval $cmd`
152 ret=$?
153 rm -f $tmpfile
155 if [ $ret != 0 ] ; then
156 echo "$out"
157 echo "failed delete good symlink with error $ret"
158 rm $slink_target
159 rm $slink_name
160 false
161 return
164 if [ ! -e $slink_target ] ; then
165 echo "failed delete good symlink - symlink target deleted !"
166 rm $slink_target
167 rm $slink_name
168 false
169 return
172 if [ -e $slink_name ] ; then
173 echo "failed delete good symlink - symlink still exists"
174 rm $slink_target
175 rm $slink_name
176 false
177 else
178 # got the correct prompt .. succeed
179 rm $slink_target
180 true
184 # Test writing into a read-only directory (logon as guest) fails.
185 test_read_only_dir()
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"
196 true
197 return
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"
206 true
207 return
210 cat > $tmpfile <<EOF
211 mkdir a_test_dir
212 quit
215 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U% "//$SERVER/$1" -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
216 eval echo "$cmd"
217 out=`eval $cmd`
218 ret=$?
219 rm -f $tmpfile
221 if [ $ret != 0 ] ; then
222 echo "$out"
223 echo "failed writing into read-only directory with error $ret"
225 false
226 return
229 echo "$out" | grep "$prompt" >/dev/null 2>&1
231 ret=$?
232 if [ $ret = 0 ] ; then
233 # got the correct prompt .. succeed
234 true
235 else
236 echo "$out"
237 echo "failed writing into read-only directory - grep failed with $ret"
238 false
243 # Test sending a message
244 test_message()
246 tmpfile=$PREFIX/message_in.$$
248 cat > $tmpfile <<EOF
249 Test message from pid $$
252 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD -M $SERVER -p 139 $ADDARGS -n msgtest < $tmpfile 2>&1'
253 eval echo "$cmd"
254 out=`eval $cmd`
255 ret=$?
257 if [ $ret != 0 ] ; then
258 echo "$out"
259 echo "failed sending message to $SERVER with error $ret"
260 false
261 rm -f $tmpfile
262 return
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'
267 eval echo "$cmd"
268 out=`eval $cmd`
269 ret=$?
271 if [ $ret != 0 ] ; then
272 echo "$out"
273 echo "failed getting sent message from $SERVER with error $ret"
274 false
275 return
278 if [ cmp $PREFIX/message_out.$$ $tmpfile != 0 ] ; then
279 echo "failed comparison of message from $SERVER"
280 false
281 return
283 true
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
294 ## read the file.
296 if [ "$USERID" != 0 ] ; then
297 echo "skipping test_owner_only_file as non-root"
298 true
299 return
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"
308 true
309 return
312 cat > $tmpfile <<EOF
313 get unreadable_file
314 quit
317 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
318 eval echo "$cmd"
319 out=`eval $cmd`
320 ret=$?
321 rm -f $tmpfile
323 if [ $ret != 0 ] ; then
324 echo "$out"
325 echo "failed reading owner-only file with error $ret"
326 false
327 return
330 echo "$out" | grep "$prompt" >/dev/null 2>&1
332 ret=$?
333 if [ $ret = 0 ] ; then
334 # got the correct prompt .. succeed
335 true
336 else
337 echo "$out"
338 echo "failed reading owner-only file - grep failed with $ret"
339 false
343 # Test accessing an msdfs path.
344 test_msdfs_link()
346 tmpfile=$PREFIX/smbclient.in.$$
347 prompt=" msdfs-target "
349 cat > $tmpfile <<EOF
351 cd \\msdfs-src1
352 ls msdfs-target
353 quit
356 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
357 eval echo "$cmd"
358 out=`eval $cmd`
359 ret=$?
360 rm -f $tmpfile
362 if [ $ret != 0 ] ; then
363 echo "$out"
364 echo "failed accessing \\msdfs-src1 link with error $ret"
365 false
366 return
369 echo "$out" | grep "$prompt" >/dev/null 2>&1
371 ret=$?
372 if [ $ret != 0 ] ; then
373 echo "$out"
374 echo "failed listing \\msdfs-src1 - grep failed with $ret"
375 false
378 cat > $tmpfile <<EOF
380 cd \\deeppath\\msdfs-src2
381 ls msdfs-target
382 quit
385 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
386 eval echo "$cmd"
387 out=`eval $cmd`
388 ret=$?
389 rm -f $tmpfile
391 if [ $ret != 0 ] ; then
392 echo "$out"
393 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
394 false
395 return
398 echo "$out" | grep "$prompt" >/dev/null 2>&1
400 ret=$?
401 if [ $ret != 0 ] ; then
402 echo "$out"
403 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
404 false
405 return
406 else
407 true
408 return
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.$$"
418 filename="foo.$$"
419 filename_ren="bar.$$"
420 dirname="foodir.$$"
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"
428 rm -f $filename_path
429 rm -f $local_name1
430 rm -f $local_name2
432 # Create a new file, ensure it has 'A' attributes.
433 touch $filename_path
435 cat > $tmpfile <<EOF
436 lcd $PREFIX
437 put $filename
438 allinfo $filename
439 quit
442 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
443 eval echo "$cmd"
444 out=`eval $cmd`
445 ret=$?
446 rm -f $tmpfile
448 if [ $ret != 0 ] ; then
449 echo "$out"
450 echo "failed creating file $filename with error $ret"
451 false
452 return
455 echo "$out" | grep "$prompt_file" >/dev/null 2>&1
457 ret=$?
459 rm -f $filename_path
460 rm -f $local_name1
461 rm -f $local_name2
463 if [ $ret = 0 ] ; then
464 # got the correct prompt .. succeed
465 true
466 else
467 echo "$out"
468 echo "Attributes incorrect on new file $ret"
469 false
472 # Now check if we remove 'A' and rename, the A comes back.
473 touch $filename_path
475 cat > $tmpfile <<EOF
476 lcd $PREFIX
477 put $filename
478 setmode $filename -a
479 ren $filename $filename_ren
480 allinfo $filename_ren
481 quit
484 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
485 eval echo "$cmd"
486 out=`eval $cmd`
487 ret=$?
488 rm -f $tmpfile
490 if [ $ret != 0 ] ; then
491 echo "$out"
492 echo "failed creating file and renaming $filename with error $ret"
493 false
494 return
497 echo "$out" | grep "$prompt_file" >/dev/null 2>&1
499 ret=$?
501 rm -f $filename_path
502 rm -f $local_name1
503 rm -f $local_name2
505 if [ $ret = 0 ] ; then
506 # got the correct prompt .. succeed
507 true
508 else
509 echo "$out"
510 echo "Attributes incorrect on renamed file $ret"
511 false
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.
519 cat > $tmpfile <<EOF
520 mkdir $dirname
521 allinfo $dirname
522 quit
525 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
526 eval echo "$cmd"
527 out=`eval $cmd`
528 ret=$?
529 rm -f $tmpfile
531 if [ $ret != 0 ] ; then
532 echo "$out"
533 echo "failed creating directory $dirname with error $ret"
534 false
535 return
538 echo "$out" | grep "$prompt_dir" >/dev/null 2>&1
540 ret=$?
542 rm -rf $local_dir_name1
543 rm -rf $local_dir_name2
545 if [ $ret = 0 ] ; then
546 # got the correct prompt .. succeed
547 true
548 else
549 echo "$out"
550 echo "Attributes incorrect on new directory $ret"
551 false
554 # Now check if we rename, we still only have 'D' attributes
556 cat > $tmpfile <<EOF
557 mkdir $dirname
558 ren $dirname $dirname_ren
559 allinfo $dirname_ren
560 quit
563 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
564 eval echo "$cmd"
565 out=`eval $cmd`
566 ret=$?
567 rm -f $tmpfile
569 if [ $ret != 0 ] ; then
570 echo "$out"
571 echo "failed creating directory $dirname and renaming with error $ret"
572 false
573 return
576 echo "$out" | grep "$prompt_dir" >/dev/null 2>&1
578 ret=$?
580 rm -f $local_name1
581 rm -f $local_name2
583 if [ $ret = 0 ] ; then
584 # got the correct prompt .. succeed
585 true
586 else
587 echo "$out"
588 echo "Attributes incorrect on renamed directory $ret"
589 false
593 # Test authenticating using the winbind ccache
594 test_ccache_access()
596 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
597 ret=$?
599 if [ $ret != 0 ] ; then
600 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='${PASSWORD}')"
601 false
602 return
605 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}" \
606 -c quit 2>&1
607 ret=$?
609 if [ $ret != 0 ] ; then
610 echo "smbclient failed to use cached credentials"
611 false
612 return
615 $WBINFO --ccache-save="${USERNAME}%GarBage"
616 ret=$?
618 if [ $ret != 0 ] ; then
619 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='GarBage')"
620 false
621 return
624 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}" \
625 -c quit 2>&1
626 ret=$?
628 if [ $ret -eq 0 ] ; then
629 echo "smbclient succeeded with wrong cached credentials"
630 false
631 return
634 $WBINFO --logoff
637 # Test authenticating using the winbind ccache
638 test_auth_file()
640 tmpfile=$PREFIX/smbclient.in.$$
641 cat > $tmpfile <<EOF
642 username=${USERNAME}
643 password=${PASSWORD}
644 domain=${DOMAIN}
646 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile \
647 -c quit 2>&1
648 ret=$?
649 rm $tmpfile
651 if [ $ret != 0 ] ; then
652 echo "smbclient failed to use auth file"
653 false
654 return
657 cat > $tmpfile <<EOF
658 username=${USERNAME}
659 password=xxxx
660 domain=${DOMAIN}
662 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile\
663 -c quit 2>&1
664 ret=$?
665 rm $tmpfile
667 if [ $ret -eq 0 ] ; then
668 echo "smbclient succeeded with wrong auth file credentials"
669 false
670 return
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
681 ret=$?
682 if [ $ret != 0 ] ; then
683 priv_username="$DOMAIN\\$USERNAME"
684 else
685 priv_username=$USERNAME
688 $NET sam rights grant $priv_username SeBackupPrivilege 2>&1
689 ret=$?
690 if [ $ret != 0 ] ; then
691 echo "Failed to add SeBackupPrivilege to user $priv_username - $ret"
692 false
693 return
696 cat > $tmpfile <<EOF
697 backup
699 quit
702 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
703 eval echo "$cmd"
704 out=`eval $cmd`
705 ret=$?
706 rm -f $tmpfile
708 if [ $ret != 0 ] ; then
709 echo "$out"
710 echo "failed backup privilege list $ret"
711 false
712 return
715 # Now remove all privileges from this SID.
716 $NET sam rights revoke $priv_username SeBackupPrivilege 2>&1
717 ret=$?
718 if [ $ret != 0 ] ; then
719 echo "failed to remove SeBackupPrivilege from user $priv_username - $ret"
720 false
721 return
725 # Test accessing an share with bad names (won't convert).
726 test_bad_names()
728 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/badname-tmp -I $SERVER_IP $ADDARGS -c ls 2>&1'
729 eval echo "$cmd"
730 out=`eval $cmd`
731 ret=$?
733 if [ $ret != 0 ] ; then
734 echo "$out"
735 echo "failed accessing badname-tmp (SMB1) with error $ret"
736 false
737 return
740 echo "$out" | wc -l 2>&1 | grep 6
741 ret=$?
742 if [ $ret != 0 ] ; then
743 echo "$out"
744 echo "failed listing \\badname-tmp - grep of number of lines (1) failed with $ret"
745 false
748 echo "$out" | grep 'Domain=.*OS=.*Server='
749 ret=$?
750 if [ $ret != 0 ] ; then
751 echo "$out"
752 echo "failed listing \\badname-tmp - grep (1) failed with $ret"
753 false
756 echo "$out" | grep '^ \. *D'
757 ret=$?
758 if [ $ret != 0 ] ; then
759 echo "$out"
760 echo "failed listing \\badname-tmp - grep (2) failed with $ret"
761 false
764 echo "$out" | grep '^ \.\. *D'
765 ret=$?
766 if [ $ret != 0 ] ; then
767 echo "$out"
768 echo "failed listing \\badname-tmp - grep (3) failed with $ret"
769 false
772 echo "$out" | grep '^ blank.txt *N'
773 ret=$?
774 if [ $ret != 0 ] ; then
775 echo "$out"
776 echo "failed listing \\badname-tmp - grep (4) failed with $ret"
777 false
780 echo "$out" | grep '^ *$'
781 ret=$?
782 if [ $ret != 0 ] ; then
783 echo "$out"
784 echo "failed listing \\badname-tmp - grep (5) failed with $ret"
785 false
788 echo "$out" | grep 'blocks of size.*blocks available'
789 ret=$?
790 if [ $ret != 0 ] ; then
791 echo "$out"
792 echo "failed listing \\badname-tmp - grep (6) failed with $ret"
793 false
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'
798 eval echo "$cmd"
799 out=`eval $cmd`
800 ret=$?
802 if [ $ret != 0 ] ; then
803 echo "$out"
804 echo "failed accessing badname-tmp (SMB3) with error $ret"
805 false
806 return
809 echo "$out" | wc -l 2>&1 | grep 6
810 ret=$?
811 if [ $ret != 0 ] ; then
812 echo "$out"
813 echo "failed listing \\badname-tmp - SMB3 grep of number of lines (1) failed with $ret"
814 false
817 echo "$out" | grep 'Domain=.*OS=.*Server='
818 ret=$?
819 if [ $ret != 0 ] ; then
820 echo "$out"
821 echo "failed listing \\badname-tmp - SMB3 grep (1) failed with $ret"
822 false
825 echo "$out" | grep '^ \. *D'
826 ret=$?
827 if [ $ret != 0 ] ; then
828 echo "$out"
829 echo "failed listing \\badname-tmp - SMB3 grep (2) failed with $ret"
830 false
833 echo "$out" | grep '^ \.\. *D'
834 ret=$?
835 if [ $ret != 0 ] ; then
836 echo "$out"
837 echo "failed listing \\badname-tmp - SMB3 grep (3) failed with $ret"
838 false
841 echo "$out" | grep '^ blank.txt *N'
842 ret=$?
843 if [ $ret != 0 ] ; then
844 echo "$out"
845 echo "failed listing \\badname-tmp - SMB3 grep (4) failed with $ret"
846 false
849 echo "$out" | grep '^ *$'
850 ret=$?
851 if [ $ret != 0 ] ; then
852 echo "$out"
853 echo "failed listing \\badname-tmp - SMB3 grep (5) failed with $ret"
854 false
857 echo "$out" | grep 'blocks of size.*blocks available'
858 ret=$?
859 if [ $ret != 0 ] ; then
860 echo "$out"
861 echo "failed listing \\badname-tmp - SMB3 grep (6) failed with $ret"
862 false
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).
868 test_mangled_names()
870 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
871 cat > $tmpfile <<EOF
873 cd FF4GBY~Q
875 quit
877 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/manglenames_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
878 eval echo "$cmd"
879 out=`eval $cmd`
880 ret=$?
881 rm -f $tmpfile
883 if [ $ret != 0 ] ; then
884 echo "$out"
885 echo "failed accessing manglenames_share with error $ret"
886 false
887 return
890 echo "$out" | grep 'NT_STATUS'
891 ret=$?
892 if [ $ret == 0 ] ; then
893 echo "$out"
894 echo "failed - NT_STATUS_XXXX listing \\manglenames_share\\FF4GBY~Q"
895 false
899 # Test using scopy to copy a file on the server.
900 test_scopy()
902 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
903 scopy_file=$PREFIX/scopy_file
905 rm -f $scopy_file
906 cat > $tmpfile <<EOF
907 put ${SMBCLIENT}
908 scopy smbclient scopy_file
909 lcd ${PREFIX}
910 get scopy_file
911 del smbclient
912 del scopy_file
913 quit
915 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -mSMB3 -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
916 eval echo "$cmd"
917 out=`eval $cmd`
918 ret=$?
919 out1=`md5sum ${SMBCLIENT} | sed -e 's/ .*//'`
920 out2=`md5sum ${scopy_file} | sed -e 's/ .*//'`
921 rm -f $tmpfile
922 rm -f $scopy_file
924 if [ $ret != 0 ] ; then
925 echo "$out"
926 echo "failed scopy test (1) with output $ret"
927 false
928 return
931 if [ $out1 != $out2 ] ; then
932 echo "$out1 $out2"
933 echo "failed md5sum (1)"
934 false
938 # Now do again using SMB1
939 # to force client-side fallback.
942 cat > $tmpfile <<EOF
943 put ${SMBCLIENT}
944 scopy smbclient scopy_file
945 lcd ${PREFIX}
946 get scopy_file
947 del smbclient
948 del scopy_file
949 quit
951 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -mNT1 -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
952 eval echo "$cmd"
953 out=`eval $cmd`
954 ret=$?
955 out1=`md5sum ${SMBCLIENT} | sed -e 's/ .*//'`
956 out2=`md5sum ${scopy_file} | sed -e 's/ .*//'`
957 rm -f $tmpfile
958 rm -f $scopy_file
960 if [ $ret != 0 ] ; then
961 echo "$out"
962 echo "failed scopy test (2) with output $ret"
963 false
964 return
967 if [ $out1 != $out2 ] ; then
968 echo "$out1 $out2"
969 echo "failed md5sum (2)"
970 false
974 # Test creating a stream on the root of the share directory filname - :foobar
975 test_toplevel_stream()
977 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
978 cat > $tmpfile <<EOF
979 put ${PREFIX}/smbclient_interactive_prompt_commands :foobar
980 allinfo \\
981 setmode \\ -a
982 quit
984 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP -mSMB3 $ADDARGS < $tmpfile 2>&1'
985 eval echo "$cmd"
986 out=`eval $cmd`
987 ret=$?
988 rm -f $tmpfile
990 if [ $ret != 0 ] ; then
991 echo "$out"
992 echo "failed creating toplevel stream :foobar with error $ret"
993 false
994 return
997 echo "$out" | grep '^stream:.*:foobar'
998 ret=$?
999 if [ $ret != 0 ] ; then
1000 echo "$out"
1001 echo "failed creating toplevel stream :foobar"
1002 false
1006 # Test wide links are restricted.
1007 test_widelinks()
1009 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1010 cat > $tmpfile <<EOF
1011 cd dot
1013 quit
1015 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/widelinks_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1016 eval echo "$cmd"
1017 out=`eval $cmd`
1018 ret=$?
1019 rm -f $tmpfile
1021 if [ $ret != 0 ] ; then
1022 echo "$out"
1023 echo "failed accessing widelinks_share with error $ret"
1024 false
1025 return
1028 echo "$out" | grep 'NT_STATUS'
1029 ret=$?
1030 if [ $ret == 0 ] ; then
1031 echo "$out"
1032 echo "failed - NT_STATUS_XXXX listing \\widelinks_share\\dot"
1033 false
1036 cat > $tmpfile <<EOF
1037 allinfo source
1038 quit
1040 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/widelinks_share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
1041 eval echo "$cmd"
1042 out=`eval $cmd`
1043 ret=$?
1044 rm -f $tmpfile
1046 if [ $ret != 0 ] ; then
1047 echo "$out"
1048 echo "failed accessing widelinks_share with error $ret"
1049 false
1050 return
1053 # This should fail with NT_STATUS_ACCESS_DENIED
1054 echo "$out" | grep 'NT_STATUS_ACCESS_DENIED'
1055 ret=$?
1056 if [ $ret != 0 ] ; then
1057 echo "$out"
1058 echo "failed - should get NT_STATUS_ACCESS_DENIED listing \\widelinks_share\\source"
1059 false
1063 # Test creating then deleting a stream file doesn't leave a lost-XXXXX directory.
1064 test_streams_depot_delete()
1066 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
1067 rm -rf "$LOCAL_PATH/lost-*"
1069 cat > $tmpfile <<EOF
1070 put ${PREFIX}/smbclient_interactive_prompt_commands foo:bar
1071 del foo
1072 ls lost*
1073 quit
1075 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP -mSMB3 $ADDARGS < $tmpfile 2>&1'
1076 eval echo "$cmd"
1077 out=`eval $cmd`
1078 ret=$?
1079 rm -f $tmpfile
1081 if [ $ret != 0 ] ; then
1082 echo "$out"
1083 echo "failed creating then deleting foo:bar with error $ret"
1084 false
1085 return
1088 echo "$out" | grep 'NT_STATUS_NO_SUCH_FILE listing \\lost\*'
1089 ret=$?
1090 if [ $ret != 0 ] ; then
1091 echo "$out"
1092 echo "deleting foo:bar left lost-XXX directory"
1093 rm -rf "$LOCAL_PATH/lost-*"
1094 false
1095 return
1100 LOGDIR_PREFIX=test_smbclient_s3
1102 # possibly remove old logdirs:
1104 for OLDDIR in $(find ${PREFIX} -type d -name "${LOGDIR_PREFIX}_*") ; do
1105 echo "removing old directory ${OLDDIR}"
1106 rm -rf ${OLDDIR}
1107 done
1109 LOGDIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX)
1112 testit "smbclient -L $SERVER_IP" $SMBCLIENT -L $SERVER_IP -N -p 139 || failed=`expr $failed + 1`
1113 testit "smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 -c quit || failed=`expr $failed + 1`
1115 testit "noninteractive smbclient does not prompt" \
1116 test_noninteractive_no_prompt || \
1117 failed=`expr $failed + 1`
1119 testit "noninteractive smbclient -l does not prompt" \
1120 test_noninteractive_no_prompt -l $LOGDIR || \
1121 failed=`expr $failed + 1`
1123 testit "interactive smbclient prompts on stdout" \
1124 test_interactive_prompt_stdout || \
1125 failed=`expr $failed + 1`
1127 testit "interactive smbclient -l prompts on stdout" \
1128 test_interactive_prompt_stdout -l $LOGDIR || \
1129 failed=`expr $failed + 1`
1131 testit "creating a bad symlink and deleting it" \
1132 test_bad_symlink || \
1133 failed=`expr $failed + 1`
1135 testit "creating a good symlink and deleting it by path" \
1136 test_good_symlink || \
1137 failed=`expr $failed + 1`
1139 testit "writing into a read-only directory fails" \
1140 test_read_only_dir ro-tmp || \
1141 failed=`expr $failed + 1`
1143 testit "writing into a read-only share fails" \
1144 test_read_only_dir valid-users-tmp || \
1145 failed=`expr $failed + 1`
1147 testit "Reading a owner-only file fails" \
1148 test_owner_only_file || \
1149 failed=`expr $failed + 1`
1151 testit "Accessing an MS-DFS link" \
1152 test_msdfs_link || \
1153 failed=`expr $failed + 1`
1155 testit "Ensure archive bit is set correctly on file/dir rename" \
1156 test_rename_archive_bit || \
1157 failed=`expr $failed + 1`
1159 testit "ccache access works for smbclient" \
1160 test_ccache_access || \
1161 failed=`expr $failed + 1`
1163 testit "sending a message to the remote server" \
1164 test_message || \
1165 failed=`expr $failed + 1`
1167 testit "using an authentication file" \
1168 test_auth_file || \
1169 failed=`expr $failed + 1`
1171 testit "list with backup privilege" \
1172 test_backup_privilege_list || \
1173 failed=`expr $failed + 1`
1175 testit "list a share with bad names (won't convert)" \
1176 test_bad_names || \
1177 failed=`expr $failed + 1`
1179 testit "list a share with a mangled name + acl_xattr object" \
1180 test_mangled_names || \
1181 failed=`expr $failed + 1`
1183 testit "server-side file copy" \
1184 test_scopy || \
1185 failed=`expr $failed + 1`
1187 testit "creating a :stream at root of share" \
1188 test_toplevel_stream || \
1189 failed=`expr $failed + 1`
1191 testit "Ensure widelinks are restricted" \
1192 test_widelinks || \
1193 failed=`expr $failed + 1`
1195 testit "streams_depot can delete correctly" \
1196 test_streams_depot_delete || \
1197 failed=`expr $failed + 1`
1199 testit "rm -rf $LOGDIR" \
1200 rm -rf $LOGDIR || \
1201 failed=`expr $failed + 1`
1203 testok $0 $failed