3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2007 The OpenLDAP Foundation.
6 ## All rights reserved.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 if test $SYNCPROV = syncprovno; then
20 echo "Syncrepl provider overlay not available, test skipped"
33 mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
36 # Test replication of dynamic config:
39 # - configure over ldap
40 # - populate over ldap
41 # - configure syncrepl over ldap
42 # - retrieve database over ldap and compare against expected results
45 echo "Starting master slapd on TCP/IP port $PORT1..."
46 $SLAPADD -F $CFPRO -n 0 -l $DYNAMICCONF
48 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > ../../$LOG1 2>&1 &
50 if test $WAIT != 0 ; then
59 echo "Using ldapsearch to check that master slapd is running..."
60 for i in 0 1 2 3 4 5; do
61 $LDAPSEARCH -s base -b "" -H $URI1 \
62 'objectclass=*' > /dev/null 2>&1
64 if test $RC = 0 ; then
67 echo "Waiting 5 seconds for slapd to start..."
71 if test $RC != 0 ; then
72 echo "ldapsearch failed ($RC)!"
73 test $KILLSERVERS != no && kill -HUP $KILLPIDS
77 echo "Inserting syncprov overlay on master..."
78 if [ "$SYNCPROV" = syncprovmod ]; then
79 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
80 dn: cn=module,cn=config
81 objectClass: olcModuleList
83 olcModulePath: ../../../servers/slapd/overlays
84 olcModuleLoad: syncprov.la
87 if test $RC != 0 ; then
88 echo "ldapadd failed for moduleLoad ($RC)!"
89 test $KILLSERVERS != no && kill -HUP $KILLPIDS
93 CONFIGPW=`cat $CONFIGPWF`
94 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
95 dn: olcDatabase={0}config,cn=config
98 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
99 credentials=$CONFIGPW searchbase="cn=config" type=refreshOnly
105 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
107 objectClass: olcOverlayConfig
108 objectClass: olcSyncProvConfig
112 if test $RC != 0 ; then
113 echo "ldapmodify failed for syncrepl config ($RC)!"
114 test $KILLSERVERS != no && kill -HUP $KILLPIDS
118 echo "Starting slave slapd on TCP/IP port $PORT2..."
119 $SLAPADD -F $CFCON -n 0 -l $DYNAMICCONF
121 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > ../../$LOG2 2>&1 &
123 if test $WAIT != 0 ; then
124 echo SLAVEPID $SLAVEPID
127 KILLPIDS="$KILLPIDS $SLAVEPID"
132 echo "Using ldapsearch to check that slave slapd is running..."
133 for i in 0 1 2 3 4 5; do
134 $LDAPSEARCH -s base -b "" -H $URI2 \
135 'objectclass=*' > /dev/null 2>&1
137 if test $RC = 0 ; then
140 echo "Waiting 5 seconds for slapd to start..."
144 if test $RC != 0 ; then
145 echo "ldapsearch failed ($RC)!"
146 test $KILLSERVERS != no && kill -HUP $KILLPIDS
150 echo "Configuring syncrepl on slave..."
151 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
152 dn: olcDatabase={0}config,cn=config
155 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
156 credentials=$CONFIGPW searchbase="cn=config" type=refreshOnly
163 echo "Waiting 10 seconds for syncrepl to receive changes..."
166 echo "Adding schema and databases on master..."
167 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
168 include: file:$SCHEMADIR/core.ldif
170 include: file:$SCHEMADIR/cosine.ldif
172 include: file:$SCHEMADIR/inetorgperson.ldif
174 include: file:$SCHEMADIR/openldap.ldif
176 include: file:$SCHEMADIR/nis.ldif
179 if test $RC != 0 ; then
180 echo "ldapadd failed for schema config ($RC)!"
181 test $KILLSERVERS != no && kill -HUP $KILLPIDS
185 if [ "$BACKENDTYPE" = mod ]; then
186 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
187 dn: cn=module,cn=config
188 objectClass: olcModuleList
190 olcModulePath: ../../../servers/slapd/back-$BACKEND
191 olcModuleLoad: back_$BACKEND.la
194 if test $RC != 0 ; then
195 echo "ldapadd failed for backend config ($RC)!"
196 test $KILLSERVERS != no && kill -HUP $KILLPIDS
201 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
202 dn: olcDatabase={1}$BACKEND,cn=config
203 objectClass: olcDatabaseConfig
204 objectClass: olc${BACKEND}Config
205 olcDatabase: {1}$BACKEND
208 olcRootDN: $MANAGERDN
210 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
211 credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
215 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
217 objectClass: olcOverlayConfig
218 objectClass: olcSyncProvConfig
222 if test $RC != 0 ; then
223 echo "ldapadd failed for database config ($RC)!"
224 test $KILLSERVERS != no && kill -HUP $KILLPIDS
228 echo "Using ldapadd to populate master..."
229 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
232 if test $RC != 0 ; then
233 echo "ldapadd failed for database config ($RC)!"
234 test $KILLSERVERS != no && kill -HUP $KILLPIDS
238 echo "Waiting 20 seconds for syncrepl to receive changes..."
241 echo "Using ldapsearch to read config from the master..."
242 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
243 'objectclass=*' > $MASTEROUT 2>&1
246 if test $RC != 0 ; then
247 echo "ldapsearch failed at master ($RC)!"
248 test $KILLSERVERS != no && kill -HUP $KILLPIDS
252 echo "Using ldapsearch to read config from the slave..."
253 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
254 'objectclass=*' > $SLAVEOUT 2>&1
257 if test $RC != 0 ; then
258 echo "ldapsearch failed at slave ($RC)!"
259 test $KILLSERVERS != no && kill -HUP $KILLPIDS
263 echo "Filtering master results..."
264 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
265 echo "Filtering slave results..."
266 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
268 echo "Comparing retrieved entries from master and slave..."
269 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
271 if test $? != 0 ; then
272 echo "test failed - master and slave databases differ"
273 test $KILLSERVERS != no && kill -HUP $KILLPIDS
277 echo "Using ldapsearch to read all the entries from the master..."
278 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
279 'objectclass=*' > $MASTEROUT 2>&1
282 if test $RC != 0 ; then
283 echo "ldapsearch failed at master ($RC)!"
284 test $KILLSERVERS != no && kill -HUP $KILLPIDS
288 echo "Using ldapsearch to read all the entries from the slave..."
289 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
290 'objectclass=*' > $SLAVEOUT 2>&1
293 if test $RC != 0 ; then
294 echo "ldapsearch failed at slave ($RC)!"
295 test $KILLSERVERS != no && kill -HUP $KILLPIDS
299 test $KILLSERVERS != no && kill -HUP $KILLPIDS
301 echo "Filtering master results..."
302 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
303 echo "Filtering slave results..."
304 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
306 echo "Comparing retrieved entries from master and slave..."
307 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
309 if test $? != 0 ; then
310 echo "test failed - master and slave databases differ"
314 echo ">>>>> Test succeeded"
316 test $KILLSERVERS != no && wait