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 test x
"$TEST_FUNCTIONS_SH" != x
"INCLUDED" && {
25 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
=/tmp
/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
=/tmp
/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"
226 echo "$out" |
grep "$prompt" >/dev
/null
2>&1
229 if [ $ret = 0 ] ; then
230 # got the correct prompt .. succeed
234 echo "failed writing into read-only directory - grep failed with $ret"
239 # Test reading an owner-only file (logon as guest) fails.
240 test_owner_only_file
()
242 prompt
="NT_STATUS_ACCESS_DENIED opening remote file"
243 tmpfile
=/tmp
/smbclient.
in.$$
246 ## We can't do this as non-root. We always have rights to
249 if [ "$USERID" != 0 ] ; then
250 echo "skipping test_owner_only_file as non-root"
256 ## We can't do this with an encrypted connection. No credentials
257 ## to set up the channel.
259 if [ "$ADDARGS" = "-e" ] ; then
260 echo "skipping test_owner_only_file with encrypted connection"
270 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
276 if [ $ret != 0 ] ; then
278 echo "failed reading owner-only file with error $ret"
283 echo "$out" |
grep "$prompt" >/dev
/null
2>&1
286 if [ $ret = 0 ] ; then
287 # got the correct prompt .. succeed
291 echo "failed reading owner-only file - grep failed with $ret"
296 # Test accessing an msdfs path.
299 tmpfile
=/tmp
/smbclient.
in.$$
300 prompt
=" msdfs-target "
309 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
315 if [ $ret != 0 ] ; then
317 echo "failed accessing \\msdfs-src1 link with error $ret"
322 echo "$out" |
grep "$prompt" >/dev
/null
2>&1
325 if [ $ret != 0 ] ; then
327 echo "failed listing \\msdfs-src1 - grep failed with $ret"
333 cd \\deeppath\\msdfs-src2
338 cmd
='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
344 if [ $ret != 0 ] ; then
346 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
351 echo "$out" |
grep "$prompt" >/dev
/null
2>&1
354 if [ $ret != 0 ] ; then
356 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
365 # Test authenticating using the winbind ccache
368 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
369 $SMBCLIENT //$SERVER_IP/tmp
-C -U "${USERNAME}%" \
373 if [ $ret != 0 ] ; then
374 echo "smbclient failed to use cached credentials"
379 $WBINFO --ccache-save="${USERNAME}%GarBage"
380 $SMBCLIENT //$SERVER_IP/tmp
-C -U "${USERNAME}%" \
384 if [ $ret -eq 0 ] ; then
385 echo "smbclient succeeded with wrong cached credentials"
393 LOGDIR_PREFIX
=test_smbclient_s3
395 # possibly remove old logdirs:
397 for OLDDIR
in $
(find ${PREFIX} -type d
-name "${LOGDIR_PREFIX}_*") ; do
398 echo "removing old directory ${OLDDIR}"
402 LOGDIR
=$
(mktemp
-d ${PREFIX}/${LOGDIR_PREFIX}_XXXX
)
405 testit
"smbclient -L $SERVER_IP" $SMBCLIENT -L $SERVER_IP -N -p 139 || failed
=`expr $failed + 1`
406 testit
"smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT -L $SERVER -I $SERVER_IP -N -p 139 -c quit || failed
=`expr $failed + 1`
408 testit
"noninteractive smbclient does not prompt" \
409 test_noninteractive_no_prompt || \
410 failed
=`expr $failed + 1`
412 testit
"noninteractive smbclient -l does not prompt" \
413 test_noninteractive_no_prompt
-l $LOGDIR || \
414 failed
=`expr $failed + 1`
416 testit
"interactive smbclient prompts on stdout" \
417 test_interactive_prompt_stdout || \
418 failed
=`expr $failed + 1`
420 testit
"interactive smbclient -l prompts on stdout" \
421 test_interactive_prompt_stdout
-l $LOGDIR || \
422 failed
=`expr $failed + 1`
424 testit
"creating a bad symlink and deleting it" \
425 test_bad_symlink || \
426 failed
=`expr $failed + 1`
428 testit
"creating a good symlink and deleting it by path" \
429 test_good_symlink || \
430 failed
=`expr $failed + 1`
432 testit
"writing into a read-only directory fails" \
433 test_read_only_dir || \
434 failed
=`expr $failed + 1`
436 testit
"Reading a owner-only file fails" \
437 test_owner_only_file || \
438 failed
=`expr $failed + 1`
440 testit
"Accessing an MS-DFS link" \
442 failed
=`expr $failed + 1`
444 testit
"ccache access works for smbclient" \
445 test_ccache_access || \
446 failed
=`expr $failed + 1`
448 testit
"rm -rf $LOGDIR" \
450 failed
=`expr $failed + 1`