3 # this runs the file serving tests that are expected to pass with samba3
7 Usage: test_smbclient_s3.sh SERVER SERVER_IP USERNAME PASSWORD USERID LOCAL_PATH PREFIX
19 SMBCLIENT="$VALGRIND ${SMBCLIENT:-$BINDIR/smbclient}"
20 WBINFO="$VALGRIND ${WBINFO:-$BINDIR/wbinfo}"
24 incdir=`dirname $0`/../../../testprogs/blackbox
29 # Test that a noninteractive smbclient does not prompt
30 test_noninteractive_no_prompt()
34 cmd='echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
45 echo "$out" | grep $prompt >/dev/null 2>&1
48 # got a prompt .. fail
49 echo matched interactive prompt in non-interactive mode
56 # Test that an interactive smbclient prompts to stdout
57 test_interactive_prompt_stdout()
60 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
67 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
73 if [ $ret != 0 ] ; then
80 echo "$out" | grep $prompt >/dev/null 2>&1
83 # got a prompt .. succeed
86 echo failed to match interactive prompt on stdout
91 # Test creating a bad symlink and deleting it.
94 prompt="posix_unlink deleted file /newname"
95 tmpfile=$PREFIX/smbclient_bad_symlinks_commands
100 symlink badname newname
105 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
111 if [ $ret != 0 ] ; then
113 echo "failed create then delete bad symlink with error $ret"
118 echo "$out" | grep "$prompt" >/dev/null 2>&1
121 if [ $ret = 0 ] ; then
122 # got the correct prompt .. succeed
126 echo "failed create then delete bad symlink - grep failed with $ret"
131 # Test creating a good symlink and deleting it by path.
134 tmpfile=$PREFIX/smbclient.in.$$
135 slink_name="$LOCAL_PATH/slink"
136 slink_target="$LOCAL_PATH/slink_target"
139 ln -s $slink_target $slink_name
145 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
151 if [ $ret != 0 ] ; then
153 echo "failed delete good symlink with error $ret"
160 if [ ! -e $slink_target ] ; then
161 echo "failed delete good symlink - symlink target deleted !"
168 if [ -e $slink_name ] ; then
169 echo "failed delete good symlink - symlink still exists"
174 # got the correct prompt .. succeed
180 # Test writing into a read-only directory (logon as guest) fails.
183 prompt="NT_STATUS_ACCESS_DENIED making remote directory"
184 tmpfile=$PREFIX/smbclient.in.$$
187 ## We can't do this as non-root. We always have rights to
188 ## create the directory.
190 if [ "$USERID" != 0 ] ; then
191 echo "skipping test_read_only_dir as non-root"
197 ## We can't do this with an encrypted connection. No credentials
198 ## to set up the channel.
200 if [ "$ADDARGS" = "-e" ] ; then
201 echo "skipping test_read_only_dir with encrypted connection"
211 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
217 if [ $ret != 0 ] ; then
219 echo "failed writing into read-only directory with error $ret"
224 echo "$out" | grep "$prompt" >/dev/null 2>&1
227 if [ $ret = 0 ] ; then
228 # got the correct prompt .. succeed
232 echo "failed writing into read-only directory - grep failed with $ret"
237 # Test reading an owner-only file (logon as guest) fails.
238 test_owner_only_file()
240 prompt="NT_STATUS_ACCESS_DENIED opening remote file"
241 tmpfile=$PREFIX/smbclient.in.$$
244 ## We can't do this as non-root. We always have rights to
247 if [ "$USERID" != 0 ] ; then
248 echo "skipping test_owner_only_file as non-root"
254 ## We can't do this with an encrypted connection. No credentials
255 ## to set up the channel.
257 if [ "$ADDARGS" = "-e" ] ; then
258 echo "skipping test_owner_only_file with encrypted connection"
268 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
274 if [ $ret != 0 ] ; then
276 echo "failed reading owner-only file with error $ret"
281 echo "$out" | grep "$prompt" >/dev/null 2>&1
284 if [ $ret = 0 ] ; then
285 # got the correct prompt .. succeed
289 echo "failed reading owner-only file - grep failed with $ret"
294 # Test accessing an msdfs path.
297 tmpfile=$PREFIX/smbclient.in.$$
298 prompt=" msdfs-target "
307 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
313 if [ $ret != 0 ] ; then
315 echo "failed accessing \\msdfs-src1 link with error $ret"
320 echo "$out" | grep "$prompt" >/dev/null 2>&1
323 if [ $ret != 0 ] ; then
325 echo "failed listing \\msdfs-src1 - grep failed with $ret"
331 cd \\deeppath\\msdfs-src2
336 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
342 if [ $ret != 0 ] ; then
344 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
349 echo "$out" | grep "$prompt" >/dev/null 2>&1
352 if [ $ret != 0 ] ; then
354 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
363 # Test authenticating using the winbind ccache
366 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
367 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
371 if [ $ret != 0 ] ; then
372 echo "smbclient failed to use cached credentials"
377 $WBINFO --ccache-save="${USERNAME}%GarBage"
378 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
382 if [ $ret -eq 0 ] ; then
383 echo "smbclient succeeded with wrong cached credentials"
391 LOGDIR_PREFIX=test_smbclient_s3
393 # possibly remove old logdirs:
395 for OLDDIR in $(find ${PREFIX} -type d -name "${LOGDIR_PREFIX}_*") ; do
396 echo "removing old directory ${OLDDIR}"
400 LOGDIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXX)
403 testit "smbclient -L $SERVER_IP" $SMBCLIENT -L $SERVER_IP -N -p 139 || failed=`expr $failed + 1`
404 testit "smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 -c quit || failed=`expr $failed + 1`
406 testit "noninteractive smbclient does not prompt" \
407 test_noninteractive_no_prompt || \
408 failed=`expr $failed + 1`
410 testit "noninteractive smbclient -l does not prompt" \
411 test_noninteractive_no_prompt -l $LOGDIR || \
412 failed=`expr $failed + 1`
414 testit "interactive smbclient prompts on stdout" \
415 test_interactive_prompt_stdout || \
416 failed=`expr $failed + 1`
418 testit "interactive smbclient -l prompts on stdout" \
419 test_interactive_prompt_stdout -l $LOGDIR || \
420 failed=`expr $failed + 1`
422 testit "creating a bad symlink and deleting it" \
423 test_bad_symlink || \
424 failed=`expr $failed + 1`
426 testit "creating a good symlink and deleting it by path" \
427 test_good_symlink || \
428 failed=`expr $failed + 1`
430 testit "writing into a read-only directory fails" \
431 test_read_only_dir || \
432 failed=`expr $failed + 1`
434 testit "Reading a owner-only file fails" \
435 test_owner_only_file || \
436 failed=`expr $failed + 1`
438 testit "Accessing an MS-DFS link" \
440 failed=`expr $failed + 1`
442 testit "ccache access works for smbclient" \
443 test_ccache_access || \
444 failed=`expr $failed + 1`
446 testit "rm -rf $LOGDIR" \
448 failed=`expr $failed + 1`