s3: Remove a call to procid_self()
[Samba/gebeck_regimport.git] / source3 / script / tests / test_smbclient_s3.sh
blob3341c62f4b98eac4d1b72f861f8dfd4cd9b108b3
1 #!/bin/sh
3 # this runs the file serving tests that are expected to pass with samba3
5 if [ $# -lt 7 ]; then
6 cat <<EOF
7 Usage: test_smbclient_s3.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD USERID LOCAL_PATH PREFIX SMBCLIENT WBINFO
8 EOF
9 exit 1;
12 SERVER="${1}"
13 SERVER_IP="${2}"
14 DOMAIN="${3}"
15 USERNAME="${4}"
16 PASSWORD="${5}"
17 USERID="${6}"
18 LOCAL_PATH="${7}"
19 PREFIX="${8}"
20 SMBCLIENT="${9}"
21 WBINFO="${10}"
22 SMBCLIENT="$VALGRIND ${SMBCLIENT}"
23 WBINFO="$VALGRIND ${WBINFO}"
24 shift 10
25 ADDARGS="$*"
27 incdir=`dirname $0`/../../../testprogs/blackbox
28 . $incdir/subunit.sh
30 failed=0
32 # Test that a noninteractive smbclient does not prompt
33 test_noninteractive_no_prompt()
35 prompt="smb"
37 cmd='echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
38 eval echo "$cmd"
39 out=`eval $cmd`
41 if [ $? != 0 ] ; then
42 echo "$out"
43 echo "command failed"
44 false
45 return
48 echo "$out" | grep $prompt >/dev/null 2>&1
50 if [ $? = 0 ] ; then
51 # got a prompt .. fail
52 echo matched interactive prompt in non-interactive mode
53 false
54 else
55 true
59 # Test that an interactive smbclient prompts to stdout
60 test_interactive_prompt_stdout()
62 prompt="smb"
63 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
65 cat > $tmpfile <<EOF
67 quit
68 EOF
70 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
71 eval echo "$cmd"
72 out=`eval $cmd`
73 ret=$?
74 rm -f $tmpfile
76 if [ $ret != 0 ] ; then
77 echo "$out"
78 echo "command failed"
79 false
80 return
83 echo "$out" | grep $prompt >/dev/null 2>&1
85 if [ $? = 0 ] ; then
86 # got a prompt .. succeed
87 true
88 else
89 echo failed to match interactive prompt on stdout
90 false
94 # Test creating a bad symlink and deleting it.
95 test_bad_symlink()
97 prompt="posix_unlink deleted file /newname"
98 tmpfile=$PREFIX/smbclient_bad_symlinks_commands
100 cat > $tmpfile <<EOF
101 posix
102 posix_unlink newname
103 symlink badname newname
104 posix_unlink newname
105 quit
108 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
109 eval echo "$cmd"
110 out=`eval $cmd`
111 ret=$?
112 rm -f $tmpfile
114 if [ $ret != 0 ] ; then
115 echo "$out"
116 echo "failed create then delete bad symlink with error $ret"
117 false
118 return
121 echo "$out" | grep "$prompt" >/dev/null 2>&1
123 ret=$?
124 if [ $ret = 0 ] ; then
125 # got the correct prompt .. succeed
126 true
127 else
128 echo "$out"
129 echo "failed create then delete bad symlink - grep failed with $ret"
130 false
134 # Test creating a good symlink and deleting it by path.
135 test_good_symlink()
137 tmpfile=$PREFIX/smbclient.in.$$
138 slink_name="$LOCAL_PATH/slink"
139 slink_target="$LOCAL_PATH/slink_target"
141 touch $slink_target
142 ln -s $slink_target $slink_name
143 cat > $tmpfile <<EOF
144 del slink
145 quit
148 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
149 eval echo "$cmd"
150 out=`eval $cmd`
151 ret=$?
152 rm -f $tmpfile
154 if [ $ret != 0 ] ; then
155 echo "$out"
156 echo "failed delete good symlink with error $ret"
157 rm $slink_target
158 rm $slink_name
159 false
160 return
163 if [ ! -e $slink_target ] ; then
164 echo "failed delete good symlink - symlink target deleted !"
165 rm $slink_target
166 rm $slink_name
167 false
168 return
171 if [ -e $slink_name ] ; then
172 echo "failed delete good symlink - symlink still exists"
173 rm $slink_target
174 rm $slink_name
175 false
176 else
177 # got the correct prompt .. succeed
178 rm $slink_target
179 true
183 # Test writing into a read-only directory (logon as guest) fails.
184 test_read_only_dir()
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"
195 true
196 return
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"
205 true
206 return
209 cat > $tmpfile <<EOF
210 mkdir a_test_dir
211 quit
214 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
215 eval echo "$cmd"
216 out=`eval $cmd`
217 ret=$?
218 rm -f $tmpfile
220 if [ $ret != 0 ] ; then
221 echo "$out"
222 echo "failed writing into read-only directory with error $ret"
224 false
225 return
228 echo "$out" | grep "$prompt" >/dev/null 2>&1
230 ret=$?
231 if [ $ret = 0 ] ; then
232 # got the correct prompt .. succeed
233 true
234 else
235 echo "$out"
236 echo "failed writing into read-only directory - grep failed with $ret"
237 false
242 # Test sending a message
243 test_message()
245 tmpfile=$PREFIX/message_in.$$
247 cat > $tmpfile <<EOF
248 Test message from pid $$
251 cmd='$SMBCLIENT "$@" -U$USERNAME%$PASSWORD -M $SERVER -p 139 $ADDARGS -n msgtest < $tmpfile 2>&1'
252 eval echo "$cmd"
253 out=`eval $cmd`
254 ret=$?
256 if [ $ret != 0 ] ; then
257 echo "$out"
258 echo "failed sending message to $SERVER with error $ret"
259 false
260 rm -f $tmpfile
261 return
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'
266 eval echo "$cmd"
267 out=`eval $cmd`
268 ret=$?
270 if [ $ret != 0 ] ; then
271 echo "$out"
272 echo "failed getting sent message from $SERVER with error $ret"
273 false
274 return
277 if [ cmp $PREFIX/message_out.$$ $tmpfile != 0 ] ; then
278 echo "failed comparison of message from $SERVER"
279 false
280 return
282 true
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
293 ## read the file.
295 if [ "$USERID" != 0 ] ; then
296 echo "skipping test_owner_only_file as non-root"
297 true
298 return
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"
307 true
308 return
311 cat > $tmpfile <<EOF
312 get unreadable_file
313 quit
316 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
317 eval echo "$cmd"
318 out=`eval $cmd`
319 ret=$?
320 rm -f $tmpfile
322 if [ $ret != 0 ] ; then
323 echo "$out"
324 echo "failed reading owner-only file with error $ret"
325 false
326 return
329 echo "$out" | grep "$prompt" >/dev/null 2>&1
331 ret=$?
332 if [ $ret = 0 ] ; then
333 # got the correct prompt .. succeed
334 true
335 else
336 echo "$out"
337 echo "failed reading owner-only file - grep failed with $ret"
338 false
342 # Test accessing an msdfs path.
343 test_msdfs_link()
345 tmpfile=$PREFIX/smbclient.in.$$
346 prompt=" msdfs-target "
348 cat > $tmpfile <<EOF
350 cd \\msdfs-src1
351 ls msdfs-target
352 quit
355 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
356 eval echo "$cmd"
357 out=`eval $cmd`
358 ret=$?
359 rm -f $tmpfile
361 if [ $ret != 0 ] ; then
362 echo "$out"
363 echo "failed accessing \\msdfs-src1 link with error $ret"
364 false
365 return
368 echo "$out" | grep "$prompt" >/dev/null 2>&1
370 ret=$?
371 if [ $ret != 0 ] ; then
372 echo "$out"
373 echo "failed listing \\msdfs-src1 - grep failed with $ret"
374 false
377 cat > $tmpfile <<EOF
379 cd \\deeppath\\msdfs-src2
380 ls msdfs-target
381 quit
384 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
385 eval echo "$cmd"
386 out=`eval $cmd`
387 ret=$?
388 rm -f $tmpfile
390 if [ $ret != 0 ] ; then
391 echo "$out"
392 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
393 false
394 return
397 echo "$out" | grep "$prompt" >/dev/null 2>&1
399 ret=$?
400 if [ $ret != 0 ] ; then
401 echo "$out"
402 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
403 false
404 return
405 else
406 true
407 return
411 # Test authenticating using the winbind ccache
412 test_ccache_access()
414 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
415 ret=$?
417 if [ $ret != 0 ] ; then
418 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='${PASSWORD}')"
419 false
420 return
423 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
424 -c quit 2>&1
425 ret=$?
427 if [ $ret != 0 ] ; then
428 echo "smbclient failed to use cached credentials"
429 false
430 return
433 $WBINFO --ccache-save="${USERNAME}%GarBage"
434 ret=$?
436 if [ $ret != 0 ] ; then
437 echo "wbinfo failed to store creds in cache (user='${USERNAME}', pass='GarBage')"
438 false
439 return
442 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
443 -c quit 2>&1
444 ret=$?
446 if [ $ret -eq 0 ] ; then
447 echo "smbclient succeeded with wrong cached credentials"
448 false
449 return
452 $WBINFO --logoff
455 # Test authenticating using the winbind ccache
456 test_auth_file()
458 tmpfile=$PREFIX/smbclient.in.$$
459 cat > $tmpfile <<EOF
460 username=${USERNAME}
461 password=${PASSWORD}
462 domain=${DOMAIN}
464 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile \
465 -c quit 2>&1
466 ret=$?
467 rm $tmpfile
469 if [ $ret != 0 ] ; then
470 echo "smbclient failed to use auth file"
471 false
472 return
475 cat > $tmpfile <<EOF
476 username=${USERNAME}
477 password=xxxx
478 domain=${DOMAIN}
480 $SMBCLIENT //$SERVER_IP/tmp --authentication-file=$tmpfile\
481 -c quit 2>&1
482 ret=$?
483 rm $tmpfile
485 if [ $ret -eq 0 ] ; then
486 echo "smbclient succeeded with wrong auth file credentials"
487 false
488 return
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}"
498 rm -rf ${OLDDIR}
499 done
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" \
540 test_msdfs_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" \
548 test_message || \
549 failed=`expr $failed + 1`
551 testit "using an authentication file" \
552 test_auth_file || \
553 failed=`expr $failed + 1`
555 testit "rm -rf $LOGDIR" \
556 rm -rf $LOGDIR || \
557 failed=`expr $failed + 1`
559 testok $0 $failed