3 # This runs smbstatus tests
6 echo "Usage: test_smbstatus.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD USERID LOCAL_PATH PREFIX SMBCLIENT CONFIGURATION PROTOCOL"
25 RAWARGS
="${CONFIGURATION} -m${PROTOCOL}"
26 ADDARGS
="${RAWARGS} $@"
28 incdir
=$
(dirname $0)/..
/..
/..
/testprogs
/blackbox
35 local cmdfile
=$PREFIX/smbclient_commands
36 local tmpfile
=$PREFIX/smclient_lock_file
37 local file=smclient_lock_file
40 local userid
=$
(id
-u $USERNAME)
49 !UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $SMBSTATUS
55 cmd
="CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS --quiet < $cmdfile 2>&1"
62 if [ $ret -ne 0 ]; then
63 echo "Failed to run smbclient with error $ret"
69 echo "$out" |
grep -c 'NT_STATUS_'
71 if [ $ret -eq 0 ]; then
72 echo "Failed: got an NT_STATUS error!"
78 echo "$out" |
grep "$userid[ ]*DENY_NONE"
80 if [ $ret != 0 ]; then
81 echo "Failed to find userid in smbstatus locked file output"
90 test_smbstatus_resolve_uids
()
92 local cmdfile
=$PREFIX/smbclient_commands
93 local tmpfile
=$PREFIX/smclient_lock_file
94 local file=smclient_lock_file
97 local userid
=$
(id
-u $USERNAME)
106 !UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $SMBSTATUS --resolve-uids
112 cmd
="CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS --quiet < $cmdfile 2>&1"
119 if [ $ret -ne 0 ]; then
120 echo "Failed to run smbclient with error $ret"
126 echo "$out" |
grep -c 'NT_STATUS_'
128 if [ $ret -eq 0 ]; then
129 echo "Failed: got an NT_STATUS error!"
135 echo "$out" |
grep "$USERNAME[ ]*DENY_NONE"
137 if [ $ret != 0 ]; then
138 echo "Failed to find userid in smbstatus locked file output"
147 test_smbstatus_output
()
149 local cmdfile
=$PREFIX/smbclient_commands
150 local tmpfile
=$PREFIX/smbclient_lock_file
151 local file=smbclient_lock_file
152 local status_shares
=smbstatus_output_shares
153 local status_processes
=smbstatus_output_processes
154 local status_locks
=smbstatus_output_locks
163 !UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $SMBSTATUS --shares > $status_shares
164 !UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $SMBSTATUS --processes > $status_processes
165 !UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $SMBSTATUS --locks > $status_locks
171 cmd
="CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS --quiet < $cmdfile 2>&1"
179 if [ $ret -ne 0 ]; then
180 echo "Failed to run smbclient with error $ret"
185 out
=$
(cat $PREFIX/$status_processes)
186 echo "$out" |
grep -c 'PID *Username'
188 if [ $ret -eq 1 ]; then
189 echo "Failed: Could not start smbstatus"
193 echo "$out" |
grep -c "$USERNAME"
195 if [ $ret -eq 1 ]; then
196 echo "Failed: open connection not found"
201 out
=$
(cat $PREFIX/$status_shares)
202 echo "$out" |
grep -c 'Service *pid'
204 if [ $ret -eq 1 ]; then
205 echo "Failed: Could not start smbstatus"
209 echo "$out" |
grep -c "tmp"
211 if [ $ret -eq 1 ]; then
212 echo "Failed: shares not found"
217 out
=$
(cat $PREFIX/$status_locks)
218 echo "$out" |
grep -c "Locked files:"
220 if [ $ret -eq 1 ]; then
221 echo "Failed: locked file not found"
225 echo "$out" |
grep -c "$file"
227 if [ $ret -eq 1 ]; then
228 echo "Failed: wrong file locked"
233 rm $PREFIX/$status_shares
234 rm $PREFIX/$status_processes
235 rm $PREFIX/$status_locks
240 test_smbstatus_json
()
242 local cmdfile
=$PREFIX/smbclient_commands
243 local tmpfile
=$PREFIX/smbclient_lock_file
244 local file=smbclient_lock_file
245 local status_json
=smbstatus_output_json
246 local status_json_long
=smbstatus_output_json_long
256 !UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $SMBSTATUS --json > $status_json
257 !UID_WRAPPER_INITIAL_RUID=0 UID_WRAPPER_INITIAL_EUID=0 $SMBSTATUS --json -vBN > $status_json_long
263 cmd
="CLI_FORCE_INTERACTIVE=yes $SMBCLIENT -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS --quiet < $cmdfile 2>&1"
271 if [ $ret -ne 0 ]; then
272 echo "Failed to run smbclient with error $ret"
277 echo $out |
grep -c 'JSON support not available, please install lib Jansson'
279 if [ $ret -eq 0 ]; then
280 subunit_start_test
"test_smbstatus_json"
281 subunit_skip_test
"test_smbstatus_json" <<EOF
287 out
=$
(cat $PREFIX/$status_json)
289 if [ $ret -ne 0 ]; then
290 echo "Failed: Could not print json output with error $ret"
295 out
=$
(cat $PREFIX/$status_json | jq
".")
296 echo $out |
grep -c 'jq: not found'
298 if [ $ret -eq 0 ]; then
299 subunit_start_test
"test_smbstatus_json"
300 subunit_skip_test
"test_smbstatus_json" <<EOF
306 out
=$
(cat $PREFIX/$status_json | jq
".")
308 if [ $ret -ne 0 ]; then
309 echo "Failed: Could not parse json output from smbstatus with error $ret"
315 expected
='["open_files","sessions","smb_conf","tcons","timestamp","version"]'
316 out
=$
(cat $PREFIX/$status_json | jq keys
-c)
317 if [ "$expected" != "$out" ]; then
318 echo "Failed: Unexpected keys in smbstatus --json"
319 echo "Expected: $expected"
324 # keys in --json -vBN
325 expected
='["byte_range_locks","notifies","open_files","sessions","smb_conf","tcons","timestamp","version"]'
326 out
=$
(cat $PREFIX/$status_json_long | jq keys
-c)
327 if [ "$expected" != "$out" ]; then
328 echo "Failed: Unexpected keys in smbstatus --json"
329 echo "Expected: $expected"
334 # shares information in --json
335 out
=$
(cat $PREFIX/$status_json | jq
".tcons|.[].machine")
336 if [ "\"$SERVER_IP\"" != "$out" ]; then
337 echo "Failed: Unexpected value for tcons.machine in smbstatus --json"
338 echo "Expected: $SERVER_IP"
342 out
=$
(cat $PREFIX/$status_json | jq
".tcons|.[].service")
343 if [ '"tmp"' != "$out" ]; then
344 echo "Failed: Unexpected value for tcons.service in smbstatus --json"
350 # session information in --json
351 out
=$
(cat $PREFIX/$status_json | jq
".sessions|.[].username")
352 if [ "\"$USER\"" != "$out" ]; then
353 echo "Failed: Unexpected value for sessions.username in smbstatus --json"
354 echo "Expected: $USER"
358 out
=$
(cat $PREFIX/$status_json | jq
-c ".sessions|.[].signing")
359 expected
='{"cipher":"AES-128-GMAC","degree":"partial"}'
360 if [ "$expected" != "$out" ]; then
361 echo "Failed: Unexpected value for sessions.signing in smbstatus --json"
362 echo "Expected: partial(AES-128-GMAC)"
366 out
=$
(cat $PREFIX/$status_json | jq
".sessions|.[].remote_machine")
367 if [ "\"$SERVER_IP\"" != "$out" ]; then
368 echo "Failed: Unexpected value for sessions.remote_machine in smbstatus --json"
369 echo "Expected: $SERVER_IP"
374 # open_files information in --json
375 out
=$
(cat $PREFIX/$status_json | jq
".open_files|.[].filename")
376 if [ "\"$file\"" != "$out" ]; then
377 echo "Failed: Unexpected value for open_files.denymode in smbstatus --json"
378 echo "Expected: \"$file\""
382 out
=$
(cat $PREFIX/$status_json | jq
".open_files|.[].opens|.[].access_mask.hex")
383 if [ '"0x00000003"' != "$out" ]; then
384 echo "Failed: Unexpected value for open_files.access_mask.hex in smbstatus --json"
385 echo "Expected: 0x00000003"
390 rm $PREFIX/$status_json
391 rm $PREFIX/$status_json_long
398 failed
=$
(expr $failed + 1)
400 testit
"resolve_uids" \
402 failed
=$
(expr $failed + 1)
404 testit
"test_output" \
405 test_smbstatus_output ||
406 failed
=$
(expr $failed + 1)
409 test_smbstatus_json || \
410 failed
=`expr $failed + 1`