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 # Test authenticating using the winbind ccache
415 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
418 if [ $ret != 0 ] ; then
419 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='${PASSWORD}')"
424 $SMBCLIENT //$SERVER_IP/tmp
-C -U "${USERNAME}%" \
428 if [ $ret != 0 ] ; then
429 echo "smbclient failed to use cached credentials"
434 $WBINFO --ccache-save="${USERNAME}%GarBage"
437 if [ $ret != 0 ] ; then
438 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='GarBage')"
443 $SMBCLIENT //$SERVER_IP/tmp
-C -U "${USERNAME}%" \
447 if [ $ret -eq 0 ] ; then
448 echo "smbclient succeeded with wrong cached credentials"
456 # Test authenticating using the winbind ccache
459 tmpfile
=$PREFIX/smbclient.
in.$$
465 $SMBCLIENT //$SERVER_IP/tmp
--authentication-file=$tmpfile \
470 if [ $ret != 0 ] ; then
471 echo "smbclient failed to use auth file"
481 $SMBCLIENT //$SERVER_IP/tmp
--authentication-file=$tmpfile\
486 if [ $ret -eq 0 ] ; then
487 echo "smbclient succeeded with wrong auth file credentials"
493 # Test doing a directory listing with backup privilege.
494 test_backup_privilege_list
()
496 tmpfile
=$PREFIX/smbclient_backup_privilege_list
498 # If we don't have a DOMAIN component to the username, add it.
499 echo "$USERNAME" |
grep '\\' 2>&1
501 if [ $ret != 0 ] ; then
502 priv_username
="$DOMAIN\\$USERNAME"
504 priv_username
=$USERNAME
507 $NET sam rights grant
$priv_username SeBackupPrivilege
2>&1
509 if [ $ret != 0 ] ; then
510 echo "Failed to add SeBackupPrivilege to user $priv_username - $ret"
521 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
527 if [ $ret != 0 ] ; then
529 echo "failed backup privilege list $ret"
534 # Now remove all privileges from this SID.
535 $NET sam rights revoke
$priv_username SeBackupPrivilege
2>&1
537 if [ $ret != 0 ] ; then
538 echo "failed to remove SeBackupPrivilege from user $priv_username - $ret"
544 LOGDIR_PREFIX
=test_smbclient_s3
546 # possibly remove old logdirs:
548 for OLDDIR
in $
(find ${PREFIX} -type d
-name "${LOGDIR_PREFIX}_*") ; do
549 echo "removing old directory ${OLDDIR}"
553 LOGDIR
=$
(mktemp
-d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX
)
556 testit
"smbclient -L $SERVER_IP" $SMBCLIENT -L $SERVER_IP -N -p 139 || failed
=`expr $failed + 1`
557 testit
"smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 -c quit || failed
=`expr $failed + 1`
559 testit
"noninteractive smbclient does not prompt" \
560 test_noninteractive_no_prompt || \
561 failed
=`expr $failed + 1`
563 testit
"noninteractive smbclient -l does not prompt" \
564 test_noninteractive_no_prompt
-l $LOGDIR || \
565 failed
=`expr $failed + 1`
567 testit
"interactive smbclient prompts on stdout" \
568 test_interactive_prompt_stdout || \
569 failed
=`expr $failed + 1`
571 testit
"interactive smbclient -l prompts on stdout" \
572 test_interactive_prompt_stdout
-l $LOGDIR || \
573 failed
=`expr $failed + 1`
575 testit
"creating a bad symlink and deleting it" \
576 test_bad_symlink || \
577 failed
=`expr $failed + 1`
579 testit
"creating a good symlink and deleting it by path" \
580 test_good_symlink || \
581 failed
=`expr $failed + 1`
583 testit
"writing into a read-only directory fails" \
584 test_read_only_dir ro-tmp || \
585 failed
=`expr $failed + 1`
587 testit
"writing into a read-only share fails" \
588 test_read_only_dir valid-users-tmp || \
589 failed
=`expr $failed + 1`
591 testit
"Reading a owner-only file fails" \
592 test_owner_only_file || \
593 failed
=`expr $failed + 1`
595 testit
"Accessing an MS-DFS link" \
597 failed
=`expr $failed + 1`
599 testit
"ccache access works for smbclient" \
600 test_ccache_access || \
601 failed
=`expr $failed + 1`
603 testit
"sending a message to the remote server" \
605 failed
=`expr $failed + 1`
607 testit
"using an authentication file" \
609 failed
=`expr $failed + 1`
611 testit
"list with backup privilege" \
612 test_backup_privilege_list || \
613 failed
=`expr $failed + 1`
615 testit
"rm -rf $LOGDIR" \
617 failed
=`expr $failed + 1`