tests/dbcheck: Add a test for two live objects, with a dangling forward link
[sfrench/samba-autobuild/.git] / testprogs / blackbox / dbcheck-links.sh
1 #!/bin/sh
2
3 if [ $# -lt 1 ]; then
4 cat <<EOF
5 Usage: dbcheck-links.sh PREFIX RELEASE
6 EOF
7 exit 1;
8 fi
9
10 PREFIX_ABS="$1"
11 RELEASE="$2"
12 shift 2
13
14 . `dirname $0`/subunit.sh
15
16 release_dir=`dirname $0`/../../source4/selftest/provisions/$RELEASE
17
18 ldbadd="ldbadd"
19 if [ -x "$BINDIR/ldbadd" ]; then
20     ldbadd="$BINDIR/ldbadd"
21 fi
22
23 ldbmodify="ldbmodify"
24 if [ -x "$BINDIR/ldbmodify" ]; then
25     ldbmodify="$BINDIR/ldbmodify"
26 fi
27
28 ldbdel="ldbdel"
29 if [ -x "$BINDIR/ldbdel" ]; then
30     ldbdel="$BINDIR/ldbdel"
31 fi
32
33 ldbsearch="ldbsearch"
34 if [ -x "$BINDIR/ldbsearch" ]; then
35     ldbsearch="$BINDIR/ldbsearch"
36 fi
37
38 ldbrename="ldbrename"
39 if [ -x "$BINDIR/ldbrename" ]; then
40     ldbrename="$BINDIR/ldbrename"
41 fi
42
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
49        fi
50 }
51
52 dbcheck() {
53     tmpfile=$PREFIX_ABS/$RELEASE/expected-dbcheck-link-output.txt.tmp
54     tmpldif1=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp1
55
56     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif1
57
58     $PYTHON $BINDIR/samba-tool dbcheck -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb --fix --yes > $tmpfile
59     if [ "$?" != "1" ]; then
60         return 1
61     fi
62     diff $tmpfile $release_dir/expected-dbcheck-link-output.txt
63     if [ "$?" != "0" ]; then
64         return 1
65     fi
66
67     tmpldif2=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp2
68     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif2
69
70     diff $tmpldif1 $tmpldif2
71     if [ "$?" != "0" ]; then
72         return 1
73     fi
74 }
75
76 dbcheck_clean() {
77     tmpldif1=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp1
78
79     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif1
80
81     $PYTHON $BINDIR/samba-tool dbcheck -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb
82     if [ "$?" != "0" ]; then
83         return 1
84     fi
85     tmpldif2=$PREFIX_ABS/$RELEASE/expected-dbcheck-output2.txt.tmp2
86     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif2
87
88     diff $tmpldif1 $tmpldif2
89     if [ "$?" != "0" ]; then
90         return 1
91     fi
92 }
93
94 add_dangling_link() {
95     ldif=$release_dir/add-dangling-forwardlink-user.ldif
96     TZ=UTC $ldbadd -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
97     if [ "$?" != "0" ]; then
98         return 1
99     fi
100
101     ldif=$release_dir/add-initially-normal-link.ldif
102     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
103     if [ "$?" != "0" ]; then
104         return 1
105     fi
106     sleep 6
107
108     ldif=$release_dir/delete-only-backlink.ldif
109     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb.d/DC%3DRELEASE-4-5-0-PRE1,DC%3DSAMBA,DC%3DCORP.ldb $ldif
110     if [ "$?" != "0" ]; then
111         return 1
112     fi
113 }
114
115 add_dangling_backlink() {
116     ldif=$release_dir/add-dangling-backlink-user.ldif
117     TZ=UTC $ldbadd -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
118     if [ "$?" != "0" ]; then
119         return 1
120     fi
121
122     ldif=$release_dir/add-dangling-backlink.ldif
123     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb.d/DC%3DRELEASE-4-5-0-PRE1,DC%3DSAMBA,DC%3DCORP.ldb $ldif
124     if [ "$?" != "0" ]; then
125         return 1
126     fi
127 }
128
129 add_two_more_users() {
130     ldif=$release_dir/add-two-more-users.ldif
131     TZ=UTC $ldbadd -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
132     if [ "$?" != "0" ]; then
133         return 1
134     fi
135 }
136
137 add_four_more_links() {
138     ldif=$release_dir/add-four-more-links.ldif
139     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
140     if [ "$?" != "0" ]; then
141         return 1
142     fi
143 }
144
145 remove_one_link() {
146     ldif=$release_dir/remove-one-more-link.ldif
147     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
148     if [ "$?" != "0" ]; then
149         return 1
150     fi
151 }
152
153 remove_one_user() {
154     ldif=$release_dir/remove-one-more-user.ldif
155     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
156     if [ "$?" != "0" ]; then
157         return 1
158     fi
159 }
160
161 move_one_user() {
162     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'
163     if [ "$?" != "0" ]; then
164         return 1
165     fi
166 }
167
168 check_expected_after_links() {
169     tmpldif=$PREFIX_ABS/$RELEASE/expected-links-after-link-dbcheck.ldif.tmp
170     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
171     diff $tmpldif $release_dir/expected-links-after-link-dbcheck.ldif
172     if [ "$?" != "0" ]; then
173         return 1
174     fi
175 }
176
177 check_expected_after_deleted_links() {
178     tmpldif=$PREFIX_ABS/$RELEASE/expected-deleted-links-after-link-dbcheck.ldif.tmp
179     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
180     diff $tmpldif $release_dir/expected-deleted-links-after-link-dbcheck.ldif
181     if [ "$?" != "0" ]; then
182         return 1
183     fi
184 }
185
186 check_expected_after_objects() {
187     tmpldif=$PREFIX_ABS/$RELEASE/expected-objects-after-link-dbcheck.ldif.tmp
188     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
189     diff $tmpldif $release_dir/expected-objects-after-link-dbcheck.ldif
190     if [ "$?" != "0" ]; then
191         return 1
192     fi
193 }
194
195 dangling_one_way() {
196     ldif=$release_dir/dangling-one-way-link.ldif
197     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
198     if [ "$?" != "0" ]; then
199         return 1
200     fi
201 }
202
203 if [ -d $release_dir ]; then
204     testit $RELEASE undump
205     testit "add_two_more_users" add_two_more_users
206     testit "add_four_more_links" add_four_more_links
207     testit "remove_one_link" remove_one_link
208     testit "remove_one_user" remove_one_user
209     testit "move_one_user" move_one_user
210     testit "add_dangling_link" add_dangling_link
211     testit "add_dangling_backlink" add_dangling_backlink
212     testit "dbcheck" dbcheck
213     testit "dbcheck_clean" dbcheck_clean
214     testit "check_expected_after_deleted_links" check_expected_after_deleted_links
215     testit "check_expected_after_links" check_expected_after_links
216     testit "check_expected_after_objects" check_expected_after_objects
217     testit "dangling_one_way" dangling_one_way
218     testit "dbcheck_clean" dbcheck_clean
219 else
220     subunit_start_test $RELEASE
221     subunit_skip_test $RELEASE <<EOF
222 no test provision
223 EOF
224
225     subunit_start_test "tombstones_expunge"
226     subunit_skip_test "tombstones_expunge" <<EOF
227 no test provision
228 EOF
229 fi
230
231 if [ -d $PREFIX_ABS/${RELEASE} ]; then
232     rm -fr $PREFIX_ABS/${RELEASE}
233 fi
234
235 exit $failed