libnet: Fix Coverity ID 1634803 Dereference after null check
[samba4-gss.git] / source3 / script / tests / test_force_close_share.sh
blobc9f943ae3f75cdb932c8bd833aceff2e16773cba
1 #!/usr/bin/env bash
3 # Test smbcontrol close-share command.
5 # Copyright (C) 2020 Volker Lendecke
6 # Copyright (C) 2020 Jeremy Allison
8 # Note this is designed to be run against
9 # the aio_delay_inject share which is preconfigured
10 # with 2 second delays on pread/pwrite.
12 if [ $# -lt 6 ]; then
13 echo Usage: $0 SERVERCONFFILE SMBCLIENT SMBCONTROL IP aio_delay_inject_sharename PREFIX
14 exit 1
17 CONFIGURATION=$1
18 smbclient=$2
19 SMBCONTROL=$3
20 SERVER=$4
21 SHARE=$5
22 PREFIX=$6
23 shift 6
25 # Do not let deprecated option warnings muck this up
26 SAMBA_DEPRECATED_SUPPRESS=1
27 export SAMBA_DEPRECATED_SUPPRESS
29 incdir=$(dirname $0)/../../../testprogs/blackbox
30 . $incdir/subunit.sh
31 . $incdir/common_test_fns.inc
33 failed=0
35 mkdir -p $PREFIX/private
37 FIFO_STDIN="$PREFIX/smbclient-stdin"
38 FIFO_STDOUT="$PREFIX/smbclient-stdout"
39 FIFO_STDERR="$PREFIX/smbclient-stderr"
40 TESTFILE="$PREFIX/testfile"
42 rm -f $FIFO_STDIN $FIFO_STDOUT $FIFO_STDERR $TESTFILE 2>/dev/null
44 # Create the smbclient communication pipes.
45 mkfifo $FIFO_STDIN $FIFO_STDOUT $FIFO_STDERR
46 if [ $? -ne 0 ]; then
47 echo "Failed to create fifos"
48 exit 1
51 # Create a large-ish testfile
52 head -c 100MB /dev/zero >$TESTFILE
54 CLI_FORCE_INTERACTIVE=1
55 export CLI_FORCE_INTERACTIVE
57 ${smbclient} //${SERVER}/${SHARE} ${CONFIGURATION} -U${USER}%${PASSWORD} \
58 <$FIFO_STDIN >$FIFO_STDOUT 2>$FIFO_STDERR &
59 CLIENT_PID=$!
61 count=0
62 while [ 1 ]; do
63 if [ $count -ge 20 ]; then
64 echo "Failed to start smbclient"
65 exit 1
67 kill -0 $CLIENT_PID
68 if [ $? -eq 0 ]; then
69 break
71 sleep 0.5
72 count=$((count + 1))
73 done
75 exec 100>$FIFO_STDIN 101<$FIFO_STDOUT 102<$FIFO_STDERR
77 # consume the smbclient startup messages
78 head -n 1 <&101
80 # Ensure we're putting a fresh file.
81 echo "lcd $(dirname $TESTFILE)" >&100
82 echo "del testfile" >&100
83 echo "put testfile" >&100
85 sleep 0.2
87 # Close the aio_delay_inject share whilst we have outstanding writes.
89 testit "smbcontrol" ${SMBCONTROL} ${CONFIGURATION} smbd close-share ${SHARE} ||
90 failed=$(expr $failed + 1)
92 sleep 0.5
94 # If we get one or more NT_STATUS_NETWORK_NAME_DELETED
95 # or NT_STATUS_INVALID_HANDLE on stderr from the writes we
96 # know the server stayed up and didn't crash when the
97 # close-share removed the share.
99 # BUG: https://bugzilla.samba.org/show_bug.cgi?id=14301
101 COUNT=$(head -n 2 <&102 |
102 grep -e NT_STATUS_NETWORK_NAME_DELETED -e NT_STATUS_INVALID_HANDLE |
103 wc -l)
105 testit "Verify close-share did cancel the file put" \
106 test $COUNT -ge 1 || failed=$(expr $failed + 1)
108 kill ${CLIENT_PID}
110 # Remove the testfile from the server
111 test_smbclient "remove_testfile" \
112 'del testfile; quit' //${SERVER}/${SHARE} -U${USER}%${PASSWORD} ||
113 failed=$(expr $failed + 1)
115 testok $0 $failed