ctdb-daemon: Consolidate basic CTDB context initialisation
[samba.git] / testprogs / blackbox / upgradeprovision-oldrelease.sh
1 #!/bin/sh
2
3 if [ $# -lt 1 ]; then
4 cat <<EOF
5 Usage: dbcheck.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 LDBDEL_BIN=ldbdel
19 if [ -x "$BINDIR/ldbdel" ]; then
20         LDBDEL_BIN=$BINDIR/ldbdel
21 fi
22
23 undump() {
24        if test -x $BINDIR/tdbrestore;
25        then
26         `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/${RELEASE}_upgrade $BINDIR/tdbrestore
27         `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/${RELEASE}_upgrade_full $BINDIR/tdbrestore
28        else
29         `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/${RELEASE}_upgrade
30         `dirname $0`/../../source4/selftest/provisions/undump.sh $release_dir $PREFIX_ABS/${RELEASE}_upgrade_full
31        fi
32        cp -a $release_dir/private/*.keytab $PREFIX_ABS/${RELEASE}_upgrade/private/
33        cp -a $release_dir/sysvol $PREFIX_ABS/${RELEASE}_upgrade/
34        mkdir $PREFIX_ABS/${RELEASE}_upgrade/etc/
35        cat $release_dir/etc/smb.conf.template | \
36               sed "s|@@PREFIX@@|$PREFIX_ABS/${RELEASE}_upgrade|g" \
37         >  $PREFIX_ABS/${RELEASE}_upgrade/etc/smb.conf
38
39        cp -a $release_dir/private/*.keytab $PREFIX_ABS/${RELEASE}_upgrade_full/private/
40        cp -a $release_dir/sysvol $PREFIX_ABS/${RELEASE}_upgrade_full/
41        mkdir $PREFIX_ABS/${RELEASE}_upgrade_full/etc/
42        cat $release_dir/etc/smb.conf.template | \
43               sed "s|@@PREFIX@@|$PREFIX_ABS/${RELEASE}_upgrade_full|g" \
44         >  $PREFIX_ABS/${RELEASE}_upgrade_full/etc/smb.conf
45 }
46
47 remove_dns_user() {
48     if [ x$RELEASE != x"release-4-0-0" ]; then
49        # This is done, because otherwise the upgrdeprovision will not run without --full
50        ${LDBDEL_BIN} -H tdb://$PREFIX_ABS/${RELEASE}_upgrade/private/sam.ldb cn=dns,cn=users,dc=${RELEASE},dc=samba,dc=corp
51     fi
52 }
53
54 reindex() {
55        $BINDIR/samba-tool dbcheck --reindex -H tdb://$PREFIX_ABS/${RELEASE}_upgrade/private/sam.ldb $@
56 }
57
58 # This should 'fail', because it returns the number of modified records
59 dbcheck() {
60        $BINDIR/samba-tool dbcheck --cross-ncs --fix --yes -H tdb://$PREFIX_ABS/${RELEASE}_upgrade/private/sam.ldb $@
61 }
62
63 dbcheck_clean() {
64        $BINDIR/samba-tool dbcheck --cross-ncs -H tdb://$PREFIX_ABS/${RELEASE}_upgrade/private/sam.ldb $@
65 }
66
67 # This should 'fail', because it returns the number of modified records
68 dbcheck_full() {
69        $BINDIR/samba-tool dbcheck --cross-ncs --fix --yes -H tdb://$PREFIX_ABS/${RELEASE}_upgrade_full/private/sam.ldb $@
70 }
71
72 dbcheck_full_clean() {
73        $BINDIR/samba-tool dbcheck --cross-ncs -H tdb://$PREFIX_ABS/${RELEASE}_upgrade_full/private/sam.ldb $@
74 }
75
76 # This checks that after the upgrade, the well known ACLs are correct, so this reset should not want to do anything
77 dbcheck_full_clean_well_known_acls() {
78        $BINDIR/samba-tool dbcheck --reset-well-known-acls --cross-ncs -H tdb://$PREFIX_ABS/${RELEASE}_upgrade_full/private/sam.ldb $@
79 }
80
81 upgradeprovision() {
82         # bring the really old Samba schema in line with a more recent 2008R2 schema
83         $PYTHON $BINDIR/samba_upgradeprovision -s "$PREFIX_ABS/${RELEASE}_upgrade/etc/smb.conf" --debugchange
84
85         # on top of this, also apply 2008R2 changes we accidentally missed in the past
86         $BINDIR/samba-tool domain schemaupgrade -H tdb://$PREFIX_ABS/${RELEASE}_upgrade/private/sam.ldb --ldf-file=samba-4.7-missing-for-schema45.ldif,fix-forest-rev.ldf
87
88         # add missing domain prep for 2008R2
89         $BINDIR/samba-tool domain functionalprep -H tdb://$PREFIX_ABS/${RELEASE}_upgrade/private/sam.ldb --domain --function-level 2008_R2
90 }
91
92 upgradeprovision_full() {
93         # add missing domain prep for 2008R2
94         $BINDIR/samba-tool domain functionalprep -H tdb://$PREFIX_ABS/${RELEASE}_upgrade_full/private/sam.ldb --domain --function-level 2008_R2
95
96         $PYTHON $BINDIR/samba_upgradeprovision -s "$PREFIX_ABS/${RELEASE}_upgrade_full/etc/smb.conf" --full --debugchange
97 }
98
99 samba_upgradedns() {
100         $PYTHON $BINDIR/samba_upgradedns --dns-backend=SAMBA_INTERNAL -s "$PREFIX_ABS/${RELEASE}_upgrade_full/etc/smb.conf"
101 }
102
103 referenceprovision() {
104         $PYTHON $BINDIR/samba-tool domain provision --server-role="dc" --domain=SAMBA --host-name=ares --realm=${RELEASE}.samba.corp --targetdir=$PREFIX_ABS/${RELEASE}_upgrade_reference --use-ntvfs --host-ip=127.0.0.1 --host-ip6=::1 --function-level=2003 --base-schema=2008_R2_old
105 }
106
107 ldapcmp() {
108     if [ x$RELEASE != x"alpha13" ]; then
109          $PYTHON $BINDIR/samba-tool ldapcmp tdb://$PREFIX_ABS/${RELEASE}_upgrade_reference/private/sam.ldb tdb://$PREFIX_ABS/${RELEASE}_upgrade/private/sam.ldb --two --skip-missing-dn --filter=dnsRecord,displayName
110     fi
111 }
112
113 ldapcmp_full() {
114         $PYTHON $BINDIR/samba-tool ldapcmp tdb://$PREFIX_ABS/${RELEASE}_upgrade_reference/private/sam.ldb tdb://$PREFIX_ABS/${RELEASE}_upgrade_full/private/sam.ldb --two --filter=dNSProperty,dnsRecord,cn,displayName,versionNumber,systemFlags,msDS-HasInstantiatedNCs --skip-missing-dn
115 }
116
117 ldapcmp_sd() {
118         $PYTHON $BINDIR/samba-tool ldapcmp tdb://$PREFIX_ABS/${RELEASE}_upgrade_reference/private/sam.ldb tdb://$PREFIX_ABS/${RELEASE}_upgrade/private/sam.ldb --two --sd --skip-missing-dn
119 }
120
121 ldapcmp_full_sd() {
122         $PYTHON $BINDIR/samba-tool ldapcmp tdb://$PREFIX_ABS/${RELEASE}_upgrade_reference/private/sam.ldb tdb://$PREFIX_ABS/${RELEASE}_upgrade_full/private/sam.ldb --two --sd --skip-missing-dn
123 }
124
125 if [ -d $PREFIX_ABS/${RELEASE}_upgrade ]; then
126   rm -fr $PREFIX_ABS/${RELEASE}_upgrade
127 fi
128
129 if [ -d $PREFIX_ABS/${RELEASE}_upgrade_full ]; then
130   rm -fr $PREFIX_ABS/${RELEASE}_upgrade_full
131 fi
132
133 if [ -d $PREFIX_ABS/${RELEASE}_upgrade_reference ]; then
134   rm -fr $PREFIX_ABS/${RELEASE}_upgrade_reference
135 fi
136
137 if [ -d $release_dir ]; then
138     testit $RELEASE undump
139     testit "remove_dns_user" remove_dns_user
140     testit "upgradeprovision" upgradeprovision
141     testit "upgradeprovision_full" upgradeprovision_full
142     testit "reindex" reindex
143     testit_expect_failure "dbcheck" dbcheck
144     testit_expect_failure "dbcheck_full" dbcheck_full
145     testit "dbcheck_clean" dbcheck_clean
146     testit "dbcheck_full_clean" dbcheck_full_clean
147     testit "dbcheck_full_clean_well_known_acls" dbcheck_full_clean_well_known_acls
148     testit "referenceprovision" referenceprovision
149     testit "samba_upgradedns" samba_upgradedns
150     testit "ldapcmp" ldapcmp
151     testit "ldapcmp_sd" ldapcmp_sd
152     testit "ldapcmp_full_sd" ldapcmp_full_sd
153 else
154     subunit_start_test "${RELEASE}"
155     subunit_skip_test "${RELEASE}" <<EOF
156 no test provision
157 EOF
158
159     subunit_start_test "remove_dns_user"
160     subunit_skip_test "remove_dns_user" <<EOF
161 no test provision
162 EOF
163
164     subunit_start_test "upgradeprovision"
165     subunit_skip_test "upgradeprovision" <<EOF
166 no test provision
167 EOF
168     subunit_start_test "upgradeprovision_full"
169     subunit_skip_test "upgradeprovision_full" <<EOF
170 no test provision
171 EOF
172     subunit_start_test "reindex"
173     subunit_skip_test "reindex" <<EOF
174 no test provision
175 EOF
176     subunit_start_test "dbcheck"
177     subunit_skip_test "dbcheck" <<EOF
178 no test provision
179 EOF
180     subunit_start_test "dbcheck_clean"
181     subunit_skip_test "dbcheck_clean" <<EOF
182 no test provision
183 EOF
184     # So far, only releases before 4.0.0rc6 need a dbcheck if upgradeprovision has already been run
185     if [ x$RELEASE != x"release-4-0-0" ]; then
186         subunit_start_test "dbcheck_full"
187         subunit_skip_test "dbcheck_full" <<EOF
188 no test provision
189 EOF
190     fi
191     subunit_start_test "dbcheck_full_clean"
192     subunit_skip_test "dbcheck_full_clean" <<EOF
193 no test provision
194 EOF
195     subunit_start_test "dbcheck_full_clean_well_known_acls"
196     subunit_skip_test "dbcheck_full_clean_well_known_acls" <<EOF
197 no test provision
198 EOF
199     subunit_start_test "samba_dnsupgrade"
200     subunit_skip_test "samba_dnsupgrade" <<EOF
201 no test provision
202 EOF
203     subunit_start_test "referenceprovision"
204     subunit_skip_test "referenceprovision" <<EOF
205 no test provision
206 EOF
207     subunit_start_test "ldapcmp"
208     subunit_skip_test "ldapcmp" <<EOF
209 no test provision
210 EOF
211     subunit_start_test "ldapcmp_full"
212     subunit_skip_test "ldapcmp_full" <<EOF
213 no test provision
214 EOF
215     subunit_start_test "ldapcmp_sd"
216     subunit_skip_test "ldapcmp_sd" <<EOF
217 no test provision
218 EOF
219     subunit_start_test "ldapcmp_full_sd"
220     subunit_skip_test "ldapcmp_full_sd" <<EOF
221 no test provision
222 EOF
223 fi
224
225 if [ -d $PREFIX_ABS/${RELEASE}_upgrade ]; then
226   rm -fr $PREFIX_ABS/${RELEASE}_upgrade
227 fi
228
229 if [ -d $PREFIX_ABS/${RELEASE}_upgrade_full ]; then
230   rm -fr $PREFIX_ABS/${RELEASE}_upgrade_full
231 fi
232
233 if [ -d $PREFIX_ABS/${RELEASE}_upgrade_reference ]; then
234   rm -fr $PREFIX_ABS/${RELEASE}_upgrade_reference
235 fi
236
237 exit $failed