s3: Lift the server_messaging_context from notify_job_status
[Samba/gbeck.git] / source3 / script / tests / test_smbclient_s3.sh
blob2260903312730aa54e402ab1cd4d0e30dbf6834c
1 #!/bin/sh
3 # this runs the file serving tests that are expected to pass with samba3
5 if [ $# -lt 6 ]; then
6 cat <<EOF
7 Usage: test_smbclient_s3.sh SERVER SERVER_IP USERNAME PASSWORD USERID LOCAL_PATH
8 EOF
9 exit 1;
12 SERVER="$1"
13 SERVER_IP="$2"
14 USERNAME="$3"
15 PASSWORD="$4"
16 USERID="$5"
17 LOCAL_PATH="$6"
18 SMBCLIENT="$VALGRIND ${SMBCLIENT:-$BINDIR/smbclient} $CONFIGURATION"
19 WBINFO="$VALGRIND ${WBINFO:-$BINDIR/wbinfo}"
20 shift 6
21 ADDARGS="$*"
23 test x"$TEST_FUNCTIONS_SH" != x"INCLUDED" && {
24 incdir=`dirname $0`
25 . $incdir/test_functions.sh
28 failed=0
30 # Test that a noninteractive smbclient does not prompt
31 test_noninteractive_no_prompt()
33 prompt="smb"
35 cmd='echo du | $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
36 eval echo "$cmd"
37 out=`eval $cmd`
39 if [ $? != 0 ] ; then
40 echo "$out"
41 echo "command failed"
42 false
43 return
46 echo "$out" | grep $prompt >/dev/null 2>&1
48 if [ $? = 0 ] ; then
49 # got a prompt .. fail
50 echo matched interactive prompt in non-interactive mode
51 false
52 else
53 true
57 # Test that an interactive smbclient prompts to stdout
58 test_interactive_prompt_stdout()
60 prompt="smb"
61 tmpfile=/tmp/smbclient.in.$$
63 cat > $tmpfile <<EOF
65 quit
66 EOF
68 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
69 eval echo "$cmd"
70 out=`eval $cmd`
71 ret=$?
72 rm -f $tmpfile
74 if [ $ret != 0 ] ; then
75 echo "$out"
76 echo "command failed"
77 false
78 return
81 echo "$out" | grep $prompt >/dev/null 2>&1
83 if [ $? = 0 ] ; then
84 # got a prompt .. succeed
85 true
86 else
87 echo failed to match interactive prompt on stdout
88 false
92 # Test creating a bad symlink and deleting it.
93 test_bad_symlink()
95 prompt="posix_unlink deleted file /newname"
96 tmpfile=/tmp/smbclient.in.$$
98 cat > $tmpfile <<EOF
99 posix
100 posix_unlink newname
101 symlink badname newname
102 posix_unlink newname
103 quit
106 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
107 eval echo "$cmd"
108 out=`eval $cmd`
109 ret=$?
110 rm -f $tmpfile
112 if [ $ret != 0 ] ; then
113 echo "$out"
114 echo "failed create then delete bad symlink with error $ret"
115 false
116 return
119 echo "$out" | grep "$prompt" >/dev/null 2>&1
121 ret=$?
122 if [ $ret = 0 ] ; then
123 # got the correct prompt .. succeed
124 true
125 else
126 echo "$out"
127 echo "failed create then delete bad symlink - grep failed with $ret"
128 false
132 # Test creating a good symlink and deleting it by path.
133 test_good_symlink()
135 tmpfile=/tmp/smbclient.in.$$
136 slink_name="$LOCAL_PATH/slink"
137 slink_target="$LOCAL_PATH/slink_target"
139 touch $slink_target
140 ln -s $slink_target $slink_name
141 cat > $tmpfile <<EOF
142 del slink
143 quit
146 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
147 eval echo "$cmd"
148 out=`eval $cmd`
149 ret=$?
150 rm -f $tmpfile
152 if [ $ret != 0 ] ; then
153 echo "$out"
154 echo "failed delete good symlink with error $ret"
155 rm $slink_target
156 rm $slink_name
157 false
158 return
161 if [ ! -e $slink_target ] ; then
162 echo "failed delete good symlink - symlink target deleted !"
163 rm $slink_target
164 rm $slink_name
165 false
166 return
169 if [ -e $slink_name ] ; then
170 echo "failed delete good symlink - symlink still exists"
171 rm $slink_target
172 rm $slink_name
173 false
174 else
175 # got the correct prompt .. succeed
176 rm $slink_target
177 true
181 # Test writing into a read-only directory (logon as guest) fails.
182 test_read_only_dir()
184 prompt="NT_STATUS_ACCESS_DENIED making remote directory"
185 tmpfile=/tmp/smbclient.in.$$
188 ## We can't do this as non-root. We always have rights to
189 ## create the directory.
191 if [ "$USERID" != 0 ] ; then
192 echo "skipping test_read_only_dir as non-root"
193 true
194 return
198 ## We can't do this with an encrypted connection. No credentials
199 ## to set up the channel.
201 if [ "$ADDARGS" = "-e" ] ; then
202 echo "skipping test_read_only_dir with encrypted connection"
203 true
204 return
207 cat > $tmpfile <<EOF
208 mkdir a_test_dir
209 quit
212 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
213 eval echo "$cmd"
214 out=`eval $cmd`
215 ret=$?
216 rm -f $tmpfile
218 if [ $ret != 0 ] ; then
219 echo "$out"
220 echo "failed writing into read-only directory with error $ret"
221 false
222 return
225 echo "$out" | grep "$prompt" >/dev/null 2>&1
227 ret=$?
228 if [ $ret = 0 ] ; then
229 # got the correct prompt .. succeed
230 true
231 else
232 echo "$out"
233 echo "failed writing into read-only directory - grep failed with $ret"
234 false
238 # Test reading an owner-only file (logon as guest) fails.
239 test_owner_only_file()
241 prompt="NT_STATUS_ACCESS_DENIED opening remote file"
242 tmpfile=/tmp/smbclient.in.$$
245 ## We can't do this as non-root. We always have rights to
246 ## read the file.
248 if [ "$USERID" != 0 ] ; then
249 echo "skipping test_owner_only_file as non-root"
250 true
251 return
255 ## We can't do this with an encrypted connection. No credentials
256 ## to set up the channel.
258 if [ "$ADDARGS" = "-e" ] ; then
259 echo "skipping test_owner_only_file with encrypted connection"
260 true
261 return
264 cat > $tmpfile <<EOF
265 get unreadable_file
266 quit
269 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
270 eval echo "$cmd"
271 out=`eval $cmd`
272 ret=$?
273 rm -f $tmpfile
275 if [ $ret != 0 ] ; then
276 echo "$out"
277 echo "failed reading owner-only file with error $ret"
278 false
279 return
282 echo "$out" | grep "$prompt" >/dev/null 2>&1
284 ret=$?
285 if [ $ret = 0 ] ; then
286 # got the correct prompt .. succeed
287 true
288 else
289 echo "$out"
290 echo "failed reading owner-only file - grep failed with $ret"
291 false
295 # Test accessing an msdfs path.
296 test_msdfs_link()
298 tmpfile=/tmp/smbclient.in.$$
299 prompt=" msdfs-target "
301 cat > $tmpfile <<EOF
303 cd \\msdfs-src1
304 ls msdfs-target
305 quit
308 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
309 eval echo "$cmd"
310 out=`eval $cmd`
311 ret=$?
312 rm -f $tmpfile
314 if [ $ret != 0 ] ; then
315 echo "$out"
316 echo "failed accessing \\msdfs-src1 link with error $ret"
317 false
318 return
321 echo "$out" | grep "$prompt" >/dev/null 2>&1
323 ret=$?
324 if [ $ret != 0 ] ; then
325 echo "$out"
326 echo "failed listing \\msdfs-src1 - grep failed with $ret"
327 false
330 cat > $tmpfile <<EOF
332 cd \\deeppath\\msdfs-src2
333 ls msdfs-target
334 quit
337 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT $CONFIGURATION "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
338 eval echo "$cmd"
339 out=`eval $cmd`
340 ret=$?
341 rm -f $tmpfile
343 if [ $ret != 0 ] ; then
344 echo "$out"
345 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
346 false
347 return
350 echo "$out" | grep "$prompt" >/dev/null 2>&1
352 ret=$?
353 if [ $ret != 0 ] ; then
354 echo "$out"
355 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
356 false
357 return
358 else
359 true
360 return
364 # Test authenticating using the winbind ccache
365 test_ccache_access()
367 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
368 $SMBCLIENT $CONFIGURATION //$SERVER_IP/tmp -C -U "${USERNAME}%" \
369 -c quit 2>&1
370 ret=$?
372 if [ $ret != 0 ] ; then
373 echo "smbclient failed to use cached credentials"
374 false
375 return
378 $WBINFO --ccache-save="${USERNAME}%GarBage"
379 $SMBCLIENT $CONFIGURATION //$SERVER_IP/tmp -C -U "${USERNAME}%" \
380 -c quit 2>&1
381 ret=$?
383 if [ $ret == 0 ] ; then
384 echo "smbclient succeeded with wrong cached credentials"
385 false
386 return
389 $WBINFO --logoff
393 testit "smbclient -L $SERVER_IP" $SMBCLIENT $CONFIGURATION -L $SERVER_IP -N -p 139 || failed=`expr $failed + 1`
394 testit "smbclient -L $SERVER -I $SERVER_IP" $SMBCLIENT $CONFIGURATION -L $SERVER -I $SERVER_IP -N -p 139 || failed=`expr $failed + 1`
396 testit "noninteractive smbclient does not prompt" \
397 test_noninteractive_no_prompt || \
398 failed=`expr $failed + 1`
400 testit "noninteractive smbclient -l does not prompt" \
401 test_noninteractive_no_prompt -l /tmp || \
402 failed=`expr $failed + 1`
404 testit "interactive smbclient prompts on stdout" \
405 test_interactive_prompt_stdout || \
406 failed=`expr $failed + 1`
408 testit "interactive smbclient -l prompts on stdout" \
409 test_interactive_prompt_stdout -l /tmp || \
410 failed=`expr $failed + 1`
412 testit "creating a bad symlink and deleting it" \
413 test_bad_symlink || \
414 failed=`expr $failed + 1`
416 testit "creating a good symlink and deleting it by path" \
417 test_good_symlink || \
418 failed=`expr $failed + 1`
420 testit "writing into a read-only directory fails" \
421 test_read_only_dir || \
422 failed=`expr $failed + 1`
424 testit "Reading a owner-only file fails" \
425 test_owner_only_file || \
426 failed=`expr $failed + 1`
428 testit "Accessing an MS-DFS link" \
429 test_msdfs_link || \
430 failed=`expr $failed + 1`
432 testit "ccache access works for smbclient" \
433 test_ccache_access || \
434 failed=`expr $failed + 1`
436 testok $0 $failed