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
22 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
23 WBINFO="$VALGRIND ${WBINFO}"
27 incdir=`dirname $0`/../../../testprogs/blackbox
32 # Test that a noninteractive smbclient does not prompt
33 test_noninteractive_no_prompt()
37 cmd='echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
48 echo "$out" | grep $prompt >/dev/null 2>&1
51 # got a prompt .. fail
52 echo matched interactive prompt in non-interactive mode
59 # Test that an interactive smbclient prompts to stdout
60 test_interactive_prompt_stdout()
63 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
70 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
76 if [ $ret != 0 ] ; then
83 echo "$out" | grep $prompt >/dev/null 2>&1
86 # got a prompt .. succeed
89 echo failed to match interactive prompt on stdout
94 # Test creating a bad symlink and deleting it.
97 prompt="posix_unlink deleted file /newname"
98 tmpfile=$PREFIX/smbclient_bad_symlinks_commands
103 symlink badname newname
108 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
114 if [ $ret != 0 ] ; then
116 echo "failed create then delete bad symlink with error $ret"
121 echo "$out" | grep "$prompt" >/dev/null 2>&1
124 if [ $ret = 0 ] ; then
125 # got the correct prompt .. succeed
129 echo "failed create then delete bad symlink - grep failed with $ret"
134 # Test creating a good symlink and deleting it by path.
137 tmpfile=$PREFIX/smbclient.in.$$
138 slink_name="$LOCAL_PATH/slink"
139 slink_target="$LOCAL_PATH/slink_target"
142 ln -s $slink_target $slink_name
148 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
154 if [ $ret != 0 ] ; then
156 echo "failed delete good symlink with error $ret"
163 if [ ! -e $slink_target ] ; then
164 echo "failed delete good symlink - symlink target deleted !"
171 if [ -e $slink_name ] ; then
172 echo "failed delete good symlink - symlink still exists"
177 # got the correct prompt .. succeed
183 # Test writing into a read-only directory (logon as guest) fails.
186 prompt="NT_STATUS_ACCESS_DENIED making remote directory"
187 tmpfile=$PREFIX/smbclient.in.$$
190 ## We can't do this as non-root. We always have rights to
191 ## create the directory.
193 if [ "$USERID" != 0 ] ; then
194 echo "skipping test_read_only_dir as non-root"
200 ## We can't do this with an encrypted connection. No credentials
201 ## to set up the channel.
203 if [ "$ADDARGS" = "-e" ] ; then
204 echo "skipping test_read_only_dir with encrypted connection"
214 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
220 if [ $ret != 0 ] ; then
222 echo "failed writing into read-only directory with error $ret"
228 echo "$out" | grep "$prompt" >/dev/null 2>&1
231 if [ $ret = 0 ] ; then
232 # got the correct prompt .. succeed
236 echo "failed writing into read-only directory - grep failed with $ret"
242 # Test sending a message
245 tmpfile=$PREFIX/message_in.$$
248 Test message from pid $$
251 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD -M $SERVER -p 139 $ADDARGS -n msgtest < $tmpfile 2>&1'
256 if [ $ret != 0 ] ; then
258 echo "failed sending message to $SERVER with error $ret"
264 # The server writes this into a file message.msgtest, via message.%m to test the % sub code
265 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmpguest -p 139 $ADDARGS -c "get message.msgtest $PREFIX/message_out.$$" 2>&1'
270 if [ $ret != 0 ] ; then
272 echo "failed getting sent message from $SERVER with error $ret"
277 if [ cmp $PREFIX/message_out.$$ $tmpfile != 0 ] ; then
278 echo "failed comparison of message from $SERVER"
285 # Test reading an owner-only file (logon as guest) fails.
286 test_owner_only_file()
288 prompt="NT_STATUS_ACCESS_DENIED opening remote file"
289 tmpfile=$PREFIX/smbclient.in.$$
292 ## We can't do this as non-root. We always have rights to
295 if [ "$USERID" != 0 ] ; then
296 echo "skipping test_owner_only_file as non-root"
302 ## We can't do this with an encrypted connection. No credentials
303 ## to set up the channel.
305 if [ "$ADDARGS" = "-e" ] ; then
306 echo "skipping test_owner_only_file with encrypted connection"
316 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
322 if [ $ret != 0 ] ; then
324 echo "failed reading owner-only file with error $ret"
329 echo "$out" | grep "$prompt" >/dev/null 2>&1
332 if [ $ret = 0 ] ; then
333 # got the correct prompt .. succeed
337 echo "failed reading owner-only file - grep failed with $ret"
342 # Test accessing an msdfs path.
345 tmpfile=$PREFIX/smbclient.in.$$
346 prompt=" msdfs-target "
355 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
361 if [ $ret != 0 ] ; then
363 echo "failed accessing \\msdfs-src1 link with error $ret"
368 echo "$out" | grep "$prompt" >/dev/null 2>&1
371 if [ $ret != 0 ] ; then
373 echo "failed listing \\msdfs-src1 - grep failed with $ret"
379 cd \\deeppath\\msdfs-src2
384 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
390 if [ $ret != 0 ] ; then
392 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
397 echo "$out" | grep "$prompt" >/dev/null 2>&1
400 if [ $ret != 0 ] ; then
402 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
411 # Test authenticating using the winbind ccache
414 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
417 if [ $ret != 0 ] ; then
418 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='${PASSWORD}')"
423 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
427 if [ $ret != 0 ] ; then
428 echo "smbclient failed to use cached credentials"
433 $WBINFO --ccache-save="${USERNAME}%GarBage"
436 if [ $ret != 0 ] ; then
437 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='GarBage')"
442 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
446 if [ $ret -eq 0 ] ; then
447 echo "smbclient succeeded with wrong cached credentials"
455 # Test authenticating using the winbind ccache
458 tmpfile=$PREFIX/smbclient.in.$$
464 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile \
469 if [ $ret != 0 ] ; then
470 echo "smbclient failed to use auth file"
480 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile\
485 if [ $ret -eq 0 ] ; then
486 echo "smbclient succeeded with wrong auth file credentials"
492 LOGDIR_PREFIX=test_smbclient_s3
494 # possibly remove old logdirs:
496 for OLDDIR in $(find ${PREFIX} -type d -name "${LOGDIR_PREFIX}_*") ; do
497 echo "removing old directory ${OLDDIR}"
501 LOGDIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX)
504 testit "smbclient -L $SERVER_IP" $SMBCLIENT -L $SERVER_IP -N -p 139 || failed=`expr $failed + 1`
505 testit "smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 -c quit || failed=`expr $failed + 1`
507 testit "noninteractive smbclient does not prompt" \
508 test_noninteractive_no_prompt || \
509 failed=`expr $failed + 1`
511 testit "noninteractive smbclient -l does not prompt" \
512 test_noninteractive_no_prompt -l $LOGDIR || \
513 failed=`expr $failed + 1`
515 testit "interactive smbclient prompts on stdout" \
516 test_interactive_prompt_stdout || \
517 failed=`expr $failed + 1`
519 testit "interactive smbclient -l prompts on stdout" \
520 test_interactive_prompt_stdout -l $LOGDIR || \
521 failed=`expr $failed + 1`
523 testit "creating a bad symlink and deleting it" \
524 test_bad_symlink || \
525 failed=`expr $failed + 1`
527 testit "creating a good symlink and deleting it by path" \
528 test_good_symlink || \
529 failed=`expr $failed + 1`
531 testit "writing into a read-only directory fails" \
532 test_read_only_dir || \
533 failed=`expr $failed + 1`
535 testit "Reading a owner-only file fails" \
536 test_owner_only_file || \
537 failed=`expr $failed + 1`
539 testit "Accessing an MS-DFS link" \
541 failed=`expr $failed + 1`
543 testit "ccache access works for smbclient" \
544 test_ccache_access || \
545 failed=`expr $failed + 1`
547 testit "sending a message to the remote server" \
549 failed=`expr $failed + 1`
551 testit "using an authentication file" \
553 failed=`expr $failed + 1`
555 testit "rm -rf $LOGDIR" \
557 failed=`expr $failed + 1`