summaryrefslogtreecommitdiff
path: root/source3/script/tests/test_net_registry_check.sh
blob: 1e3522d697cb221fbcb8c7b277aa808576d8ce82 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh
#
# Blackbox tests for the "net registry check" command.
#
# Copyright (C) 2011 Björn Baumbach <bb@sernet.de>

if [ $# -lt 5 ]; then
	echo "Usage: test_net_registry.sh SCRIPTDIR SERVERCONFFILE NET CONFIGURATION DBWRAP_TOOL"
	exit 1
fi

SCRIPTDIR="$1"
SERVERCONFFILE="$2"
NET="$3"
CONFIGURATION="$4"
DBWRAP_TOOL="$5 --persistent"

NET="$VALGRIND ${NET:-$BINDIR/net} $CONFIGURATION"

NETREG="${NET} registry"
REGORIG="$(grep 'state directory = ' $SERVERCONFFILE | sed 's/[^=]*=//')/registry.tdb"
REG=$REGORIG.wip

incdir=`dirname $0`/../../../testprogs/blackbox
. $incdir/subunit.sh

failed=0

# run registry check and filter allowed errors
regcheck()
{
	ALLOWEDERR="Check database:|INFO: version ="
	ERRSTR=$(${NETREG} check $REG $@ 2>&1 | egrep -v "$ALLOWEDERR")
}

# try to repair registry
regrepair()
{
	regcheck -a
}

# check if $ERRSTR contains expected error
checkerr()
{
	EXPERR=$1

	ERRCNT=$(echo "$ERRSTR" | grep "$EXPERR" | wc -l)
	return $ERRCNT
}

regchecknrepair()
{
	EXPERR="$1"
	EXPERRCNT="$2"

	regcheck
	checkerr "$EXPERR"
	test "x$?" = "x$ERRCNT" || {
		echo "Expected $EXPERRCNT of error $EXPERR. Received $ERRCNT"
		return 1
	}

	regrepair
	regcheck
	test "x$ERRSTR" = "x" || {
		echo "Error: Can't repair database"
		return 1
	}
}

test_simple()
(
	ERRSTR=""
	cp $REGORIG $REG

	regcheck
	test "x$ERRSTR" = "x" || {
		echo $ERRSTR
		return 1
	}
)

test_damage()
{
	diff $REGORIG $REG
}

test_duplicate()
(
	ERRSTR=""
	$DBWRAP_TOOL $REG store 'HKLM/SOFTWARE' hex '02000000534F4654574152450053595354454D00'

	regchecknrepair "Duplicate subkeylist" 1
)

test_slashes()
(
	ERRSTR=""
	$DBWRAP_TOOL $REG store 'HKLM/SOFTWARE' hex '02000000534F4654574152450053595354454D00'

	regchecknrepair "Unnormal key:" 1
)

test_uppercase()
(
	ERRSTR=""
	$DBWRAP_TOOL $REG store 'HKLM\Software' hex '02000000534F4654574152450053595354454D00'

	regchecknrepair "Unnormal key:" 1
)

test_strangeletters()
(
	ERRSTR=""
	$DBWRAP_TOOL $REG store 'HKLM\SOFTWARE' hex '02000000534F4654574FABFABFABFAB354454D00'

	regchecknrepair "Conversion error: Incomplete multibyte sequence" 1
)

testit "simple" \
	test_simple || \
	failed=`expr $failed + 1`

testit "damages_registry" \
	test_damage || \
	failed=`expr $failed + 1`

testit "duplicate" \
	test_duplicate || \
	failed=`expr $failed + 1`

testit "slashes" \
	test_slashes || \
	failed=`expr $failed + 1`

testit "uppercase" \
	test_uppercase || \
	failed=`expr $failed + 1`

#Can't repair this atm
#testit "strangeletters" \
#	test_strangeletters || \
#	failed=`expr $failed + 1`

testok $0 $failed