libnet: Fix Coverity ID 1634803 Dereference after null check
[samba4-gss.git] / source3 / script / tests / test_netfileenum.sh
blobd343555d97cf126b42c8f474a092e50d4e19c9a0
1 #!/usr/bin/env bash
3 # Test rpcclient netfileenum
5 # Copyright (C) 2020 Volker Lendecke
7 if [ $# -lt 5 ]; then
8 echo Usage: $0 \
9 SMBCLIENT RPCCLIENT NET SERVER SHARE
10 exit 1
13 SMBCLIENT="$1"
14 shift 1
15 RPCCLIENT="$1"
16 shift 1
17 NET="$1"
18 shift 1
19 SERVER="$1"
20 shift 1
21 SHARE="$1"
22 shift 1
24 # Do not let deprecated option warnings muck this up
25 SAMBA_DEPRECATED_SUPPRESS=1
26 export SAMBA_DEPRECATED_SUPPRESS
28 incdir=$(dirname $0)/../../../testprogs/blackbox
29 . $incdir/subunit.sh
31 failed=0
33 cd $SELFTEST_TMPDIR || exit 1
35 rm -f smbclient-stdin smbclient-stdout smbclient-stderr
36 mkfifo smbclient-stdin smbclient-stdout smbclient-stderr
38 CLI_FORCE_INTERACTIVE=1
39 export CLI_FORCE_INTERACTIVE
41 ${SMBCLIENT} //${SERVER}/${SHARE} ${CONF} -U${USER}%${PASSWORD} \
42 <smbclient-stdin >smbclient-stdout 2>smbclient-stderr &
43 CLIENT_PID=$!
45 sleep 1
47 exec 100>smbclient-stdin 101<smbclient-stdout 102<smbclient-stderr
49 # consume the smbclient startup messages
50 head -n 1 <&101
52 FILE=x64
54 printf "open %s\\n" "$FILE" >&100
56 sleep 1
58 testit "Create builtin\\administrators group" \
59 "${NET}" groupmap add \
60 sid=S-1-5-32-544 unixgroup="${USER}"-group type=builtin ||
61 failed=$((failed + 1))
62 testit "Add ${USER} to builtin\\administrators" \
63 "${NET}" groupmap addmem S-1-5-32-544 \
64 $("${NET}" lookup name "${USER}" | cut -d' ' -f1) ||
65 failed=$((failed + 1))
67 "${RPCCLIENT}" "${SERVER}" -U"${USER}"%"${PASSWORD}" -c netfileenum |
68 grep "$FILE"\$
69 RC=$?
70 testit "netfileenum" test $RC = 0 || failed=$((failed + 1))
72 kill ${CLIENT_PID}
73 rm -f smbclient-stdin smbclient-stdout smbclient-stderr
75 testit "Remove ${USER} from builtin\\administrators" \
76 "${NET}" groupmap delmem S-1-5-32-544 \
77 $("${NET}" lookup name "${USER}" | cut -d' ' -f1) ||
78 failed=$((failed + 1))
79 testit "Remove builtin\\administrators group" \
80 "${NET}" groupmap delete \
81 sid=S-1-5-32-544 ||
82 failed=$((failed + 1))
84 testok $0 $failed