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
21 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
22 WBINFO="$VALGRIND ${WBINFO:-$BINDIR/wbinfo}"
26 incdir=`dirname $0`/../../../testprogs/blackbox
31 # Test that a noninteractive smbclient does not prompt
32 test_noninteractive_no_prompt()
36 cmd='echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
47 echo "$out" | grep $prompt >/dev/null 2>&1
50 # got a prompt .. fail
51 echo matched interactive prompt in non-interactive mode
58 # Test that an interactive smbclient prompts to stdout
59 test_interactive_prompt_stdout()
62 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
69 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
75 if [ $ret != 0 ] ; then
82 echo "$out" | grep $prompt >/dev/null 2>&1
85 # got a prompt .. succeed
88 echo failed to match interactive prompt on stdout
93 # Test creating a bad symlink and deleting it.
96 prompt="posix_unlink deleted file /newname"
97 tmpfile=$PREFIX/smbclient_bad_symlinks_commands
102 symlink badname newname
107 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
113 if [ $ret != 0 ] ; then
115 echo "failed create then delete bad symlink with error $ret"
120 echo "$out" | grep "$prompt" >/dev/null 2>&1
123 if [ $ret = 0 ] ; then
124 # got the correct prompt .. succeed
128 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"
162 if [ ! -e $slink_target ] ; then
163 echo "failed delete good symlink - symlink target deleted !"
170 if [ -e $slink_name ] ; then
171 echo "failed delete good symlink - symlink still exists"
176 # got the correct prompt .. succeed
182 # Test writing into a read-only directory (logon as guest) fails.
185 prompt="NT_STATUS_ACCESS_DENIED making remote directory"
186 tmpfile=$PREFIX/smbclient.in.$$
189 ## We can't do this as non-root. We always have rights to
190 ## create the directory.
192 if [ "$USERID" != 0 ] ; then
193 echo "skipping test_read_only_dir as non-root"
199 ## We can't do this with an encrypted connection. No credentials
200 ## to set up the channel.
202 if [ "$ADDARGS" = "-e" ] ; then
203 echo "skipping test_read_only_dir with encrypted connection"
213 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
219 if [ $ret != 0 ] ; then
221 echo "failed writing into read-only directory with error $ret"
227 echo "$out" | grep "$prompt" >/dev/null 2>&1
230 if [ $ret = 0 ] ; then
231 # got the correct prompt .. succeed
235 echo "failed writing into read-only directory - grep failed with $ret"
241 # Test sending a message
244 tmpfile=$PREFIX/message_in.$$
247 Test message from pid $$
250 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD -M $SERVER -p 139 $ADDARGS -n msgtest < $tmpfile 2>&1'
255 if [ $ret != 0 ] ; then
257 echo "failed sending message to $SERVER with error $ret"
263 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmpguest -p 139 $ADDARGS -c "get message.msgtest $PREFIX/message_out.$$" 2>&1'
268 if [ $ret != 0 ] ; then
270 echo "failed getting sent message from $SERVER with error $ret"
275 if [ cmp $PREFIX/message_out.$$ $tmpfile != 0 ] ; then
276 echo "failed comparison of message from $SERVER"
283 # Test reading an owner-only file (logon as guest) fails.
284 test_owner_only_file()
286 prompt="NT_STATUS_ACCESS_DENIED opening remote file"
287 tmpfile=$PREFIX/smbclient.in.$$
290 ## We can't do this as non-root. We always have rights to
293 if [ "$USERID" != 0 ] ; then
294 echo "skipping test_owner_only_file as non-root"
300 ## We can't do this with an encrypted connection. No credentials
301 ## to set up the channel.
303 if [ "$ADDARGS" = "-e" ] ; then
304 echo "skipping test_owner_only_file with encrypted connection"
314 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
320 if [ $ret != 0 ] ; then
322 echo "failed reading owner-only file with error $ret"
327 echo "$out" | grep "$prompt" >/dev/null 2>&1
330 if [ $ret = 0 ] ; then
331 # got the correct prompt .. succeed
335 echo "failed reading owner-only file - grep failed with $ret"
340 # Test accessing an msdfs path.
343 tmpfile=$PREFIX/smbclient.in.$$
344 prompt=" msdfs-target "
353 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
359 if [ $ret != 0 ] ; then
361 echo "failed accessing \\msdfs-src1 link with error $ret"
366 echo "$out" | grep "$prompt" >/dev/null 2>&1
369 if [ $ret != 0 ] ; then
371 echo "failed listing \\msdfs-src1 - grep failed with $ret"
377 cd \\deeppath\\msdfs-src2
382 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
388 if [ $ret != 0 ] ; then
390 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
395 echo "$out" | grep "$prompt" >/dev/null 2>&1
398 if [ $ret != 0 ] ; then
400 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
409 # Test authenticating using the winbind ccache
412 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
413 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
417 if [ $ret != 0 ] ; then
418 echo "smbclient failed to use cached credentials"
423 $WBINFO --ccache-save="${USERNAME}%GarBage"
424 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
428 if [ $ret -eq 0 ] ; then
429 echo "smbclient succeeded with wrong cached credentials"
437 # Test authenticating using the winbind ccache
440 tmpfile=$PREFIX/smbclient.in.$$
446 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile \
451 if [ $ret != 0 ] ; then
452 echo "smbclient failed to use auth file"
462 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile\
467 if [ $ret -eq 0 ] ; then
468 echo "smbclient succeeded with wrong auth file credentials"
474 LOGDIR_PREFIX=test_smbclient_s3
476 # possibly remove old logdirs:
478 for OLDDIR in $(find ${PREFIX} -type d -name "${LOGDIR_PREFIX}_*") ; do
479 echo "removing old directory ${OLDDIR}"
483 LOGDIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXX)
486 testit "smbclient -L $SERVER_IP" $SMBCLIENT -L $SERVER_IP -N -p 139 || failed=`expr $failed + 1`
487 testit "smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 -c quit || failed=`expr $failed + 1`
489 testit "noninteractive smbclient does not prompt" \
490 test_noninteractive_no_prompt || \
491 failed=`expr $failed + 1`
493 testit "noninteractive smbclient -l does not prompt" \
494 test_noninteractive_no_prompt -l $LOGDIR || \
495 failed=`expr $failed + 1`
497 testit "interactive smbclient prompts on stdout" \
498 test_interactive_prompt_stdout || \
499 failed=`expr $failed + 1`
501 testit "interactive smbclient -l prompts on stdout" \
502 test_interactive_prompt_stdout -l $LOGDIR || \
503 failed=`expr $failed + 1`
505 testit "creating a bad symlink and deleting it" \
506 test_bad_symlink || \
507 failed=`expr $failed + 1`
509 testit "creating a good symlink and deleting it by path" \
510 test_good_symlink || \
511 failed=`expr $failed + 1`
513 testit "writing into a read-only directory fails" \
514 test_read_only_dir || \
515 failed=`expr $failed + 1`
517 testit "Reading a owner-only file fails" \
518 test_owner_only_file || \
519 failed=`expr $failed + 1`
521 testit "Accessing an MS-DFS link" \
523 failed=`expr $failed + 1`
525 testit "ccache access works for smbclient" \
526 test_ccache_access || \
527 failed=`expr $failed + 1`
529 testit "sending a message to the remote server" \
531 failed=`expr $failed + 1`
533 testit "using an authentication file" \
535 failed=`expr $failed + 1`
537 testit "rm -rf $LOGDIR" \
539 failed=`expr $failed + 1`