rpcclient3: Factor out cli_rpc_pipe_open_bind_schannel()
[Samba.git] / testprogs / blackbox / dbcheck-links.sh
blob17973e974296c68af8e2474a658308d6aeac318f
1 #!/bin/sh
3 if [ $# -lt 1 ]; then
4 cat <<EOF
5 Usage: dbcheck-links.sh PREFIX RELEASE
6 EOF
7 exit 1;
8 fi
10 PREFIX_ABS="$1"
11 RELEASE="$2"
12 shift 2
14 . `dirname $0`/subunit.sh
16 release_dir=`dirname $0`/../../source4/selftest/provisions/$RELEASE
18 ldbadd="ldbadd"
19 if [ -x "$BINDIR/ldbadd" ]; then
20 ldbadd="$BINDIR/ldbadd"
23 ldbmodify="ldbmodify"
24 if [ -x "$BINDIR/ldbmodify" ]; then
25 ldbmodify="$BINDIR/ldbmodify"
28 ldbdel="ldbdel"
29 if [ -x "$BINDIR/ldbdel" ]; then
30 ldbdel="$BINDIR/ldbdel"
33 ldbsearch="ldbsearch"
34 if [ -x "$BINDIR/ldbsearch" ]; then
35 ldbsearch="$BINDIR/ldbsearch"
38 ldbrename="ldbrename"
39 if [ -x "$BINDIR/ldbrename" ]; then
40 ldbrename="$BINDIR/ldbrename"
43 undump() {
44 if test -x $BINDIR/tdbrestore;
45 then
46 `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/$RELEASE $BINDIR/tdbrestore
47 else
48 `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/$RELEASE
52 dbcheck() {
53 tmpfile=$PREFIX_ABS/$RELEASE/expected-dbcheck-link-output.txt.tmp
54 tmpldif1=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp1
56 TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif1
58 $PYTHON $BINDIR/samba-tool dbcheck -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb --fix --yes > $tmpfile
59 if [ "$?" != "1" ]; then
60 return 1
62 sort $tmpfile > $tmpfile.sorted
63 sort $release_dir/expected-dbcheck-link-output.txt > $tmpfile.expected
64 diff -u $tmpfile.sorted $tmpfile.expected
65 if [ "$?" != "0" ]; then
66 return 1
69 tmpldif2=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp2
70 TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif2
72 diff $tmpldif1 $tmpldif2
73 if [ "$?" != "0" ]; then
74 return 1
78 dbcheck_clean() {
79 tmpldif1=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp1
81 TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif1
83 $PYTHON $BINDIR/samba-tool dbcheck -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb
84 if [ "$?" != "0" ]; then
85 return 1
87 tmpldif2=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp2
88 TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif2
90 diff $tmpldif1 $tmpldif2
91 if [ "$?" != "0" ]; then
92 return 1
96 add_dangling_link() {
97 ldif=$release_dir/add-dangling-forwardlink-user.ldif
98 TZ=UTC $ldbadd -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
99 if [ "$?" != "0" ]; then
100 return 1
103 ldif=$release_dir/add-initially-normal-link.ldif
104 TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
105 if [ "$?" != "0" ]; then
106 return 1
109 ldif=$release_dir/delete-only-backlink.ldif
110 TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb.d/DC%3DRELEASE-4-5-0-PRE1,DC%3DSAMBA,DC%3DCORP.ldb $ldif
111 if [ "$?" != "0" ]; then
112 return 1
116 add_dangling_backlink() {
117 ldif=$release_dir/add-dangling-backlink-user.ldif
118 TZ=UTC $ldbadd -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
119 if [ "$?" != "0" ]; then
120 return 1
123 ldif=$release_dir/add-dangling-backlink.ldif
124 TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb.d/DC%3DRELEASE-4-5-0-PRE1,DC%3DSAMBA,DC%3DCORP.ldb $ldif
125 if [ "$?" != "0" ]; then
126 return 1
130 add_two_more_users() {
131 ldif=$release_dir/add-two-more-users.ldif
132 TZ=UTC $ldbadd -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
133 if [ "$?" != "0" ]; then
134 return 1
138 add_four_more_links() {
139 ldif=$release_dir/add-four-more-links.ldif
140 TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
141 if [ "$?" != "0" ]; then
142 return 1
146 remove_one_link() {
147 ldif=$release_dir/remove-one-more-link.ldif
148 TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
149 if [ "$?" != "0" ]; then
150 return 1
154 remove_one_user() {
155 ldif=$release_dir/remove-one-more-user.ldif
156 TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
157 if [ "$?" != "0" ]; then
158 return 1
162 move_one_user() {
163 TZ=UTC $ldbrename -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb 'cn=user1,cn=users,DC=release-4-5-0-pre1,DC=samba,DC=corp' 'cn=user1x,cn=users,DC=release-4-5-0-pre1,DC=samba,DC=corp'
164 if [ "$?" != "0" ]; then
165 return 1
169 check_expected_after_links() {
170 tmpldif=$PREFIX_ABS/$RELEASE/expected-links-after-link-dbcheck.ldif.tmp
171 TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(|(cn=swimmers)(cn=leaders)(cn=helpers))' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --sorted member > $tmpldif
172 diff $tmpldif $release_dir/expected-links-after-link-dbcheck.ldif
173 if [ "$?" != "0" ]; then
174 return 1
178 check_expected_after_deleted_links() {
179 tmpldif=$PREFIX_ABS/$RELEASE/expected-deleted-links-after-link-dbcheck.ldif.tmp
180 TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(|(cn=swimmers)(cn=leaders)(cn=helpers))' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member > $tmpldif
181 diff $tmpldif $release_dir/expected-deleted-links-after-link-dbcheck.ldif
182 if [ "$?" != "0" ]; then
183 return 1
187 check_expected_after_objects() {
188 tmpldif=$PREFIX_ABS/$RELEASE/expected-objects-after-link-dbcheck.ldif.tmp
189 TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(|(samaccountname=fred)(samaccountname=ddg)(samaccountname=usg)(samaccountname=user1)(samaccountname=user1x)(samaccountname=user2))' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted samAccountName | grep sAMAccountName > $tmpldif
190 diff $tmpldif $release_dir/expected-objects-after-link-dbcheck.ldif
191 if [ "$?" != "0" ]; then
192 return 1
196 dangling_one_way() {
197 ldif=$release_dir/dangling-one-way-link.ldif
198 TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
199 if [ "$?" != "0" ]; then
200 return 1
204 dangling_multi_valued() {
205 # multi1 - All 4 backlinks
206 # multi2 - Missing all 4 backlinks
207 # multi3 - Missing 2 backlinks
208 # Administrator - Has 2 too many backlinks
209 # multi5 - Has 2 backlinks but no forward links
210 ldif=$release_dir/add-dangling-multilink-users.ldif
211 TZ=UTC $ldbadd -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
212 if [ "$?" != "0" ]; then
213 return 1
216 ldif=$release_dir/add-initially-normal-multilink.ldif
217 TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
218 if [ "$?" != "0" ]; then
219 return 1
222 ldif=$release_dir/delete-only-multi-backlink.ldif
223 TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb.d/DC%3DRELEASE-4-5-0-PRE1,DC%3DSAMBA,DC%3DCORP.ldb $ldif
224 if [ "$?" != "0" ]; then
225 return 1
228 ldif=$release_dir/add-dangling-multi-backlink.ldif
229 TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb.d/DC%3DRELEASE-4-5-0-PRE1,DC%3DSAMBA,DC%3DCORP.ldb $ldif
230 if [ "$?" != "0" ]; then
231 return 1
234 $PYTHON $BINDIR/samba-tool dbcheck -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb --fix --yes
235 if [ "$?" != "1" ]; then
236 return 1
240 dangling_multi_valued_check_missing() {
241 WORDS=`TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(samaccountname=dangling-multi2)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted msDS-RevealedDSAs | grep msDS-RevealedDSAs | wc -l`
242 if [ $WORDS -ne 4 ]; then
243 echo Got only $WORDS links for dangling-multi2
244 return 1
246 WORDS=`TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(samaccountname=dangling-multi3)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted msDS-RevealedDSAs | grep msDS-RevealedDSAs | wc -l`
247 if [ $WORDS -ne 4 ]; then
248 echo Got only $WORDS links for dangling-multi3
249 return 1
253 dangling_multi_valued_check_equal_or_too_many() {
254 WORDS=`TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(samaccountname=dangling-multi1)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted msDS-RevealedDSAs | grep msDS-RevealedDSAs | wc -l`
255 if [ $WORDS -ne 4 ]; then
256 echo Got $WORDS links for dangling-multi1
257 return 1
260 WORDS=`TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(samaccountname=dangling-multi5)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted msDS-RevealedDSAs | grep msDS-RevealedDSAs | wc -l`
262 if [ $WORDS -ne 0 ]; then
263 echo Got $WORDS links for dangling-multi5
264 return 1
267 WORDS=`TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(samaccountname=Administrator)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted msDS-RevealedDSAs | grep msDS-RevealedDSAs | wc -l`
269 if [ $WORDS -ne 2 ]; then
270 echo Got $WORDS links for Administrator
271 return 1
276 if [ -d $release_dir ]; then
277 testit $RELEASE undump
278 testit "add_two_more_users" add_two_more_users
279 testit "add_four_more_links" add_four_more_links
280 testit "remove_one_link" remove_one_link
281 testit "remove_one_user" remove_one_user
282 testit "move_one_user" move_one_user
283 testit "add_dangling_link" add_dangling_link
284 testit "add_dangling_backlink" add_dangling_backlink
285 testit "dbcheck" dbcheck
286 testit "dbcheck_clean" dbcheck_clean
287 testit "check_expected_after_deleted_links" check_expected_after_deleted_links
288 testit "check_expected_after_links" check_expected_after_links
289 testit "check_expected_after_objects" check_expected_after_objects
290 testit "dangling_one_way" dangling_one_way
291 testit "dbcheck_clean" dbcheck_clean
292 testit "dangling_multi_valued" dangling_multi_valued
293 testit "dangling_multi_valued_check_missing" dangling_multi_valued_check_missing
294 testit "dangling_multi_valued_check_equal_or_too_many" dangling_multi_valued_check_equal_or_too_many
295 # Currently this cannot pass
296 testit "dangling_multi_valued_dbcheck" dbcheck_clean
297 else
298 subunit_start_test $RELEASE
299 subunit_skip_test $RELEASE <<EOF
300 no test provision
303 subunit_start_test "tombstones_expunge"
304 subunit_skip_test "tombstones_expunge" <<EOF
305 no test provision
309 if [ -d $PREFIX_ABS/${RELEASE} ]; then
310 rm -fr $PREFIX_ABS/${RELEASE}
313 exit $failed