f6c6a76d8f4e7aabca03ff70ad66ef4836ed8e67
[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_backlink() {
95     ldif=$release_dir/add-dangling-backlink-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-dangling-backlink.ldif
102     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb.d/DC%3DRELEASE-4-5-0-PRE1,DC%3DSAMBA,DC%3DCORP.ldb $ldif
103     if [ "$?" != "0" ]; then
104         return 1
105     fi
106 }
107
108 add_two_more_users() {
109     ldif=$release_dir/add-two-more-users.ldif
110     TZ=UTC $ldbadd -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
111     if [ "$?" != "0" ]; then
112         return 1
113     fi
114 }
115
116 add_four_more_links() {
117     ldif=$release_dir/add-four-more-links.ldif
118     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
119     if [ "$?" != "0" ]; then
120         return 1
121     fi
122 }
123
124 remove_one_link() {
125     ldif=$release_dir/remove-one-more-link.ldif
126     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
127     if [ "$?" != "0" ]; then
128         return 1
129     fi
130 }
131
132 remove_one_user() {
133     ldif=$release_dir/remove-one-more-user.ldif
134     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
135     if [ "$?" != "0" ]; then
136         return 1
137     fi
138 }
139
140 move_one_user() {
141     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'
142     if [ "$?" != "0" ]; then
143         return 1
144     fi
145 }
146
147 check_expected_after_links() {
148     tmpldif=$PREFIX_ABS/$RELEASE/expected-links-after-link-dbcheck.ldif.tmp
149     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
150     diff $tmpldif $release_dir/expected-links-after-link-dbcheck.ldif
151     if [ "$?" != "0" ]; then
152         return 1
153     fi
154 }
155
156 check_expected_after_deleted_links() {
157     tmpldif=$PREFIX_ABS/$RELEASE/expected-deleted-links-after-link-dbcheck.ldif.tmp
158     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
159     diff $tmpldif $release_dir/expected-deleted-links-after-link-dbcheck.ldif
160     if [ "$?" != "0" ]; then
161         return 1
162     fi
163 }
164
165 check_expected_after_objects() {
166     tmpldif=$PREFIX_ABS/$RELEASE/expected-objects-after-link-dbcheck.ldif.tmp
167     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
168     diff $tmpldif $release_dir/expected-objects-after-link-dbcheck.ldif
169     if [ "$?" != "0" ]; then
170         return 1
171     fi
172 }
173
174 dangling_one_way() {
175     ldif=$release_dir/dangling-one-way-link.ldif
176     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
177     if [ "$?" != "0" ]; then
178         return 1
179     fi
180 }
181
182 if [ -d $release_dir ]; then
183     testit $RELEASE undump
184     testit "add_two_more_users" add_two_more_users
185     testit "add_four_more_links" add_four_more_links
186     testit "remove_one_link" remove_one_link
187     testit "remove_one_user" remove_one_user
188     testit "move_one_user" move_one_user
189     testit "add_dangling_backlink" add_dangling_backlink
190     testit "dbcheck" dbcheck
191     testit "dbcheck_clean" dbcheck_clean
192     testit "check_expected_after_deleted_links" check_expected_after_deleted_links
193     testit "check_expected_after_links" check_expected_after_links
194     testit "check_expected_after_objects" check_expected_after_objects
195     testit "dangling_one_way" dangling_one_way
196     testit "dbcheck_clean" dbcheck_clean
197 else
198     subunit_start_test $RELEASE
199     subunit_skip_test $RELEASE <<EOF
200 no test provision
201 EOF
202
203     subunit_start_test "tombstones_expunge"
204     subunit_skip_test "tombstones_expunge" <<EOF
205 no test provision
206 EOF
207 fi
208
209 if [ -d $PREFIX_ABS/${RELEASE} ]; then
210     rm -fr $PREFIX_ABS/${RELEASE}
211 fi
212
213 exit $failed