3f7d708c8ad3dd8676b3dcd5c71c0536f971c8d2
[samba.git] / testprogs / blackbox / tombstones-expunge.sh
1 #!/bin/sh
2
3 if [ $# -lt 1 ]; then
4 cat <<EOF
5 Usage: tombstones-expunge.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 undump() {
39        if test -x $BINDIR/tdbrestore;
40        then
41         `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/$RELEASE $BINDIR/tdbrestore
42        else
43         `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/$RELEASE
44        fi
45 }
46
47 tombstones_expunge() {
48     tmpfile=$PREFIX_ABS/$RELEASE/expected-expunge-output.txt.tmp
49     tmpldif1=$PREFIX_ABS/$RELEASE/expected-expunge-output2.txt.tmp1
50
51     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif1
52
53     $PYTHON $BINDIR/samba-tool domain tombstones expunge -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb --current-time=2016-07-30 --tombstone-lifetime=4 > $tmpfile
54     if [ "$?" != "0" ]; then
55         return 1
56     fi
57     diff $tmpfile $release_dir/expected-expunge-output.txt
58     if [ "$?" != "0" ]; then
59         return 1
60     fi
61
62     tmpldif2=$PREFIX_ABS/$RELEASE/expected-expunge-output2.txt.tmp2
63     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb -s base -b '' | grep highestCommittedUSN > $tmpldif2
64
65     diff $tmpldif1 $tmpldif2
66     if [ "$?" != "0" ]; then
67         return 1
68     fi
69 }
70
71 add_dangling_link() {
72     ldif=$release_dir/add-dangling-link.ldif
73     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb.d/DC%3DRELEASE-4-5-0-PRE1,DC%3DSAMBA,DC%3DCORP.ldb $ldif
74     if [ "$?" != "0" ]; then
75         return 1
76     fi
77 }
78
79 add_two_more_users() {
80     ldif=$release_dir/add-two-more-users.ldif
81     TZ=UTC $ldbadd -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
82     if [ "$?" != "0" ]; then
83         return 1
84     fi
85 }
86
87 add_four_more_links() {
88     ldif=$release_dir/add-four-more-links.ldif
89     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
90     if [ "$?" != "0" ]; then
91         return 1
92     fi
93 }
94
95 remove_one_link() {
96     ldif=$release_dir/remove-one-more-link.ldif
97     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
98     if [ "$?" != "0" ]; then
99         return 1
100     fi
101 }
102
103 remove_one_user() {
104     ldif=$release_dir/remove-one-more-user.ldif
105     TZ=UTC $ldbmodify -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb $ldif
106     if [ "$?" != "0" ]; then
107         return 1
108     fi
109 }
110
111 check_match_rule_links() {
112     tmpldif=$PREFIX_ABS/$RELEASE/expected-match-rule-links.ldif.tmp
113     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=131139216000000000)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted no_attrs > $tmpldif
114     diff $tmpldif $release_dir/expected-match-rule-links.ldif
115     if [ "$?" != "0" ]; then
116         return 1
117     fi
118 }
119
120 check_match_rule_links_negative() {
121     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=-131139216000000000)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
122 }
123
124 check_match_rule_links_overflow() {
125     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=18446744073709551617)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
126 }
127
128 check_match_rule_links_null() {
129     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=18446744\073709551617)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
130 }
131
132 check_match_rule_links_hex() {
133     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=abcd)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
134 }
135
136 check_match_rule_links_hex2() {
137     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=0xabcd)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
138 }
139
140 check_match_rule_links_decimal() {
141     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(member:1.3.6.1.4.1.7165.4.5.2:=131139216000000000.00)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted member
142 }
143
144 check_match_rule_links_backlink() {
145     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(memberOf:1.3.6.1.4.1.7165.4.5.2:=131139216000000000)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted memberOf
146 }
147
148 check_match_rule_links_notlink() {
149     $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(samAccountName:1.3.6.1.4.1.7165.4.5.2:=131139216000000000)' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted samAccountName
150 }
151
152 check_expected_after_links() {
153     tmpldif=$PREFIX_ABS/$RELEASE/expected-links-after-expunge.ldif.tmp
154     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
155     diff $tmpldif $release_dir/expected-links-after-expunge.ldif
156     if [ "$?" != "0" ]; then
157         return 1
158     fi
159 }
160
161 check_expected_after_deleted_links() {
162     tmpldif=$PREFIX_ABS/$RELEASE/expected-deleted-links-after-expunge.ldif.tmp
163     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
164     diff $tmpldif $release_dir/expected-deleted-links-after-expunge.ldif
165     if [ "$?" != "0" ]; then
166         return 1
167     fi
168 }
169
170 check_expected_after_objects() {
171     tmpldif=$PREFIX_ABS/$RELEASE/expected-objects-after-expunge.ldif.tmp
172     TZ=UTC $ldbsearch -H tdb://$PREFIX_ABS/${RELEASE}/private/sam.ldb '(|(samaccountname=fred)(samaccountname=ddg)(samaccountname=usg)(samaccountname=user1)(samaccountname=user2))' -s sub -b DC=release-4-5-0-pre1,DC=samba,DC=corp --show-deleted --reveal --sorted samAccountName | grep sAMAccountName > $tmpldif
173     diff $tmpldif $release_dir/expected-objects-after-expunge.ldif
174     if [ "$?" != "0" ]; then
175         return 1
176     fi
177 }
178
179 if [ -d $release_dir ]; then
180     testit $RELEASE undump
181     testit "add_two_more_users" add_two_more_users
182     testit "add_four_more_links" add_four_more_links
183     testit "add_dangling_link" add_dangling_link
184     testit "remove_one_link" remove_one_link
185     testit "remove_one_user" remove_one_user
186     testit "check_match_rule_links" check_match_rule_links
187     testit_expect_failure "check_match_rule_links_negative" check_match_rule_links_negative
188     testit_expect_failure "check_match_rule_links_overflow" check_match_rule_links_overflow
189     testit_expect_failure "check_match_rule_links_null" check_match_rule_links_null
190     testit_expect_failure "check_match_rule_links_hex" check_match_rule_links_hex
191     testit_expect_failure "check_match_rule_links_hex2" check_match_rule_links_hex2
192     testit_expect_failure "check_match_rule_links_decimal" check_match_rule_links_decimal
193     testit_expect_failure "check_match_rule_links_backlink" check_match_rule_links_backlink
194     testit_expect_failure "check_match_rule_links_notlink" check_match_rule_links_notlink
195     testit "tombstones_expunge" tombstones_expunge
196     testit "check_expected_after_deleted_links" check_expected_after_deleted_links
197     testit "check_expected_after_links" check_expected_after_links
198     testit "check_expected_after_objects" check_expected_after_objects
199 else
200     subunit_start_test $RELEASE
201     subunit_skip_test $RELEASE <<EOF
202 no test provision
203 EOF
204
205     subunit_start_test "tombstones_expunge"
206     subunit_skip_test "tombstones_expunge" <<EOF
207 no test provision
208 EOF
209 fi
210
211 if [ -d $PREFIX_ABS/${RELEASE} ]; then
212     rm -fr $PREFIX_ABS/${RELEASE}
213 fi
214
215 exit $failed