summaryrefslogtreecommitdiff
path: root/source3/script/tests/test_net_tdb.sh
blob: 46fc4a6943a2803a9e115aca6535455c7e84cc15 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/sh
#
# Test 'net tdb' command.
#
# Verify that the command returns the correct information in the
# expected format. The 'dump' option is tested, but the output is not
# checked, since the internal data structure could change in the
# future.
#
# Copyright (C) 2017 Christof Schmitt

if [ $# -lt 7 ]; then
	cat <<EOF
Usage: $0 SMBCLIENT SERVER SHARE USER PASS CONFIGURATION LOCALPATH LOCKDIR
EOF
	exit 1
fi

SMBCLIENT=$1
SERVER=$2
SHARE=$3
USER=$4
PASS=$5
CONFIGURATION=$6
LOCALPATH=$7
LOCKDIR=$8

FILENAME=net_tdb_testfile

samba_tdbtool=tdbtool
if test -x "$BINDIR/tdbtool"; then
	samba_tdbtool="$BINDIR/tdbtool"
fi

failed=0

incdir=$(dirname "$0")/../../../testprogs/blackbox
# shellcheck source=testprogs/blackbox/subunit.sh
. "$incdir/subunit.sh"

touch "$LOCALPATH/$FILENAME"

printf "open %s\n"'!sleep 10'"\n" ${FILENAME} |
	"$SMBCLIENT" "//$SERVER/$SHARE" -U"$USER%$PASS" &
SMBCLIENTPID=$!

# Give smbclient a chance to open the file
sleep 1

testit "Looking for record key of open file" \
	"$samba_tdbtool" "$LOCKDIR/locking.tdb" hexkeys ||
	failed=$((failed + 1))

# The assumption here is that only one file is open, so only one
# record can exist in the database.

echo "=== Debug Output for 'tdbtool locking.tdb hexkeys' =="
$samba_tdbtool "$LOCKDIR/locking.tdb" hexkeys
echo "=== End Debug Output ==="

# The above code produces the following output:
#
# === Debug Output for 'tdbtool locking.tdb hexkeys' ==
# key 24 bytes
# [000] 2B 00 00 00 00 00 00 00  24 40 17 03 00 00 00 00  +...... $@.....
# [010] 00 00 00 00 00 00 00 00                           .......
#
# === End Debug Output ===
#
# Select only valid hex byte values and join them together
key="0x$("$samba_tdbtool" "$LOCKDIR/locking.tdb" hexkeys |
      awk '/^key/ && seen { exit }
           /^key/ { seen=1; next }
           /^\[/ { for(i=2; i<=NF; i++) if($i ~ /^[0-9A-Fa-f][0-9A-Fa-f]$/) printf "%s", $i }')"

echo "=== Debug Output for key =="
echo "${key}"
echo "=== End Debug Output ==="

testit "Looking for open file in locking.tdb" \
	"$BINDIR/net" "$CONFIGURATION" tdb locking "$key" ||
	failed=$((failed + 1))
out=$("$BINDIR/net" "$CONFIGURATION" tdb locking "$key")

out=$("$BINDIR/net" "$CONFIGURATION" tdb locking "$key" |
	grep 'Share path: ' | sed -e 's/Share path: \+//')
testit "Verify pathname in output" \
	test "$out" = "$LOCALPATH" ||
	failed=$((failed + 1))

out=$("$BINDIR/net" "$CONFIGURATION" tdb locking "$key" |
	grep 'Name:' | sed -e 's/Name: \+//')
testit "Verify filename in output" \
	test "$out" = "$FILENAME" ||
	failed=$((failed + 1))

out=$("$BINDIR/net" "$CONFIGURATION" tdb locking "$key" |
	grep 'Number of share modes:' |
	sed -e 's/Number of share modes: \+//')
testit "Verify number of share modes in output" \
	test "$out" = "1" ||
	failed=$((failed + 1))

testit "Complete record dump" \
	"$BINDIR/net" "$CONFIGURATION" tdb locking "$key" dump ||
	failed=$((failed + 1))

"$BINDIR/net" "$CONFIGURATION" tdb locking "$key" dump | grep -q "$FILENAME"
RC=$?
testit "Verify filename in dump output" \
	test $RC = 0 ||
	failed=$((failed + 1))
"$BINDIR/net" "$CONFIGURATION" tdb locking "$key" dump | grep -q "$LOCALPATH"
RC=$?
testit "Verify share path in dump output" \
	test $RC = 0 ||
	failed=$((failed + 1))

kill $SMBCLIENTPID

testok "$0" "$failed"