s3:smb2_server: don't reset the tid and session id in the out hdr of compound requests
[Samba.git] / source3 / script / tests / test_smbclient_s3.sh
blob772802f77b1428b8c5ed133aa6727cd97fa18440
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 USERNAME PASSWORD USERID LOCAL_PATH PREFIX
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 PREFIX="$7"
19 SMBCLIENT="$VALGRIND ${SMBCLIENT:-$BINDIR/smbclient}"
20 WBINFO="$VALGRIND ${WBINFO:-$BINDIR/wbinfo}"
21 shift 7
22 ADDARGS="$*"
24 test x"$TEST_FUNCTIONS_SH" != x"INCLUDED" && {
25 incdir=`dirname $0`/../../../testprogs/blackbox
26 . $incdir/subunit.sh
29 failed=0
31 # Test that a noninteractive smbclient does not prompt
32 test_noninteractive_no_prompt()
34 prompt="smb"
36 cmd='echo du | $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS 2>&1'
37 eval echo "$cmd"
38 out=`eval $cmd`
40 if [ $? != 0 ] ; then
41 echo "$out"
42 echo "command failed"
43 false
44 return
47 echo "$out" | grep $prompt >/dev/null 2>&1
49 if [ $? = 0 ] ; then
50 # got a prompt .. fail
51 echo matched interactive prompt in non-interactive mode
52 false
53 else
54 true
58 # Test that an interactive smbclient prompts to stdout
59 test_interactive_prompt_stdout()
61 prompt="smb"
62 tmpfile=$PREFIX/smbclient_interactive_prompt_commands
64 cat > $tmpfile <<EOF
66 quit
67 EOF
69 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
70 eval echo "$cmd"
71 out=`eval $cmd`
72 ret=$?
73 rm -f $tmpfile
75 if [ $ret != 0 ] ; then
76 echo "$out"
77 echo "command failed"
78 false
79 return
82 echo "$out" | grep $prompt >/dev/null 2>&1
84 if [ $? = 0 ] ; then
85 # got a prompt .. succeed
86 true
87 else
88 echo failed to match interactive prompt on stdout
89 false
93 # Test creating a bad symlink and deleting it.
94 test_bad_symlink()
96 prompt="posix_unlink deleted file /newname"
97 tmpfile=$PREFIX/smbclient_bad_symlinks_commands
99 cat > $tmpfile <<EOF
100 posix
101 posix_unlink newname
102 symlink badname newname
103 posix_unlink newname
104 quit
107 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
108 eval echo "$cmd"
109 out=`eval $cmd`
110 ret=$?
111 rm -f $tmpfile
113 if [ $ret != 0 ] ; then
114 echo "$out"
115 echo "failed create then delete bad symlink with error $ret"
116 false
117 return
120 echo "$out" | grep "$prompt" >/dev/null 2>&1
122 ret=$?
123 if [ $ret = 0 ] ; then
124 # got the correct prompt .. succeed
125 true
126 else
127 echo "$out"
128 echo "failed create then delete bad symlink - grep failed with $ret"
129 false
133 # Test creating a good symlink and deleting it by path.
134 test_good_symlink()
136 tmpfile=/tmp/smbclient.in.$$
137 slink_name="$LOCAL_PATH/slink"
138 slink_target="$LOCAL_PATH/slink_target"
140 touch $slink_target
141 ln -s $slink_target $slink_name
142 cat > $tmpfile <<EOF
143 del slink
144 quit
147 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
148 eval echo "$cmd"
149 out=`eval $cmd`
150 ret=$?
151 rm -f $tmpfile
153 if [ $ret != 0 ] ; then
154 echo "$out"
155 echo "failed delete good symlink with error $ret"
156 rm $slink_target
157 rm $slink_name
158 false
159 return
162 if [ ! -e $slink_target ] ; then
163 echo "failed delete good symlink - symlink target deleted !"
164 rm $slink_target
165 rm $slink_name
166 false
167 return
170 if [ -e $slink_name ] ; then
171 echo "failed delete good symlink - symlink still exists"
172 rm $slink_target
173 rm $slink_name
174 false
175 else
176 # got the correct prompt .. succeed
177 rm $slink_target
178 true
182 # Test writing into a read-only directory (logon as guest) fails.
183 test_read_only_dir()
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"
194 true
195 return
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"
204 true
205 return
208 cat > $tmpfile <<EOF
209 mkdir a_test_dir
210 quit
213 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
214 eval echo "$cmd"
215 out=`eval $cmd`
216 ret=$?
217 rm -f $tmpfile
219 if [ $ret != 0 ] ; then
220 echo "$out"
221 echo "failed writing into read-only directory with error $ret"
222 false
223 return
226 echo "$out" | grep "$prompt" >/dev/null 2>&1
228 ret=$?
229 if [ $ret = 0 ] ; then
230 # got the correct prompt .. succeed
231 true
232 else
233 echo "$out"
234 echo "failed writing into read-only directory - grep failed with $ret"
235 false
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
247 ## read the file.
249 if [ "$USERID" != 0 ] ; then
250 echo "skipping test_owner_only_file as non-root"
251 true
252 return
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"
261 true
262 return
265 cat > $tmpfile <<EOF
266 get unreadable_file
267 quit
270 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U% //$SERVER/ro-tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
271 eval echo "$cmd"
272 out=`eval $cmd`
273 ret=$?
274 rm -f $tmpfile
276 if [ $ret != 0 ] ; then
277 echo "$out"
278 echo "failed reading owner-only file with error $ret"
279 false
280 return
283 echo "$out" | grep "$prompt" >/dev/null 2>&1
285 ret=$?
286 if [ $ret = 0 ] ; then
287 # got the correct prompt .. succeed
288 true
289 else
290 echo "$out"
291 echo "failed reading owner-only file - grep failed with $ret"
292 false
296 # Test accessing an msdfs path.
297 test_msdfs_link()
299 tmpfile=/tmp/smbclient.in.$$
300 prompt=" msdfs-target "
302 cat > $tmpfile <<EOF
304 cd \\msdfs-src1
305 ls msdfs-target
306 quit
309 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
310 eval echo "$cmd"
311 out=`eval $cmd`
312 ret=$?
313 rm -f $tmpfile
315 if [ $ret != 0 ] ; then
316 echo "$out"
317 echo "failed accessing \\msdfs-src1 link with error $ret"
318 false
319 return
322 echo "$out" | grep "$prompt" >/dev/null 2>&1
324 ret=$?
325 if [ $ret != 0 ] ; then
326 echo "$out"
327 echo "failed listing \\msdfs-src1 - grep failed with $ret"
328 false
331 cat > $tmpfile <<EOF
333 cd \\deeppath\\msdfs-src2
334 ls msdfs-target
335 quit
338 cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/msdfs-share -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
339 eval echo "$cmd"
340 out=`eval $cmd`
341 ret=$?
342 rm -f $tmpfile
344 if [ $ret != 0 ] ; then
345 echo "$out"
346 echo "failed accessing \\deeppath\\msdfs-src2 link with error $ret"
347 false
348 return
351 echo "$out" | grep "$prompt" >/dev/null 2>&1
353 ret=$?
354 if [ $ret != 0 ] ; then
355 echo "$out"
356 echo "failed listing \\deeppath\\msdfs-src2 - grep failed with $ret"
357 false
358 return
359 else
360 true
361 return
365 # Test authenticating using the winbind ccache
366 test_ccache_access()
368 $WBINFO --ccache-save="${USERNAME}%${PASSWORD}"
369 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
370 -c quit 2>&1
371 ret=$?
373 if [ $ret != 0 ] ; then
374 echo "smbclient failed to use cached credentials"
375 false
376 return
379 $WBINFO --ccache-save="${USERNAME}%GarBage"
380 $SMBCLIENT //$SERVER_IP/tmp -C -U "${USERNAME}%" \
381 -c quit 2>&1
382 ret=$?
384 if [ $ret -eq 0 ] ; then
385 echo "smbclient succeeded with wrong cached credentials"
386 false
387 return
390 $WBINFO --logoff
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}"
399 rm -rf ${OLDDIR}
400 done
402 LOGDIR=$(mktemp -d ${PREFIX}/${LOGDIR_PREFIX}_XXXXXX)
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" \
441 test_msdfs_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" \
449 rm -rf $LOGDIR || \
450 failed=`expr $failed + 1`
452 testok $0 $failed