summaryrefslogtreecommitdiffstats
path: root/source3/script/tests/test_netfileenum.sh
blob: d343555d97cf126b42c8f474a092e50d4e19c9a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
#
# Test rpcclient netfileenum
#
# Copyright (C) 2020 Volker Lendecke

if [ $# -lt 5 ]; then
	echo Usage: $0 \
		SMBCLIENT RPCCLIENT NET SERVER SHARE
	exit 1
fi

SMBCLIENT="$1"
shift 1
RPCCLIENT="$1"
shift 1
NET="$1"
shift 1
SERVER="$1"
shift 1
SHARE="$1"
shift 1

# Do not let deprecated option warnings muck this up
SAMBA_DEPRECATED_SUPPRESS=1
export SAMBA_DEPRECATED_SUPPRESS

incdir=$(dirname $0)/../../../testprogs/blackbox
. $incdir/subunit.sh

failed=0

cd $SELFTEST_TMPDIR || exit 1

rm -f smbclient-stdin smbclient-stdout smbclient-stderr
mkfifo smbclient-stdin smbclient-stdout smbclient-stderr

CLI_FORCE_INTERACTIVE=1
export CLI_FORCE_INTERACTIVE

${SMBCLIENT} //${SERVER}/${SHARE} ${CONF} -U${USER}%${PASSWORD} \
	<smbclient-stdin >smbclient-stdout 2>smbclient-stderr &
CLIENT_PID=$!

sleep 1

exec 100>smbclient-stdin 101<smbclient-stdout 102<smbclient-stderr

# consume the smbclient startup messages
head -n 1 <&101

FILE=x64

printf "open %s\\n" "$FILE" >&100

sleep 1

testit "Create builtin\\administrators group" \
	"${NET}" groupmap add \
	sid=S-1-5-32-544 unixgroup="${USER}"-group type=builtin ||
	failed=$((failed + 1))
testit "Add ${USER} to builtin\\administrators" \
	"${NET}" groupmap addmem S-1-5-32-544 \
	$("${NET}" lookup name "${USER}" | cut -d' ' -f1) ||
	failed=$((failed + 1))

"${RPCCLIENT}" "${SERVER}" -U"${USER}"%"${PASSWORD}" -c netfileenum |
	grep "$FILE"\$
RC=$?
testit "netfileenum" test $RC = 0 || failed=$((failed + 1))

kill ${CLIENT_PID}
rm -f smbclient-stdin smbclient-stdout smbclient-stderr

testit "Remove ${USER} from builtin\\administrators" \
	"${NET}" groupmap delmem S-1-5-32-544 \
	$("${NET}" lookup name "${USER}" | cut -d' ' -f1) ||
	failed=$((failed + 1))
testit "Remove builtin\\administrators group" \
	"${NET}" groupmap delete \
	sid=S-1-5-32-544 ||
	failed=$((failed + 1))

testok $0 $failed