3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2008 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"
31 mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
33 $SLAPPASSWD -g -n >$CONFIGPWF
35 if test x"$SYNCMODE" = x ; then
40 SYNCTYPE="type=refreshOnly interval=00:00:00:10"
43 SYNCTYPE="type=refreshAndPersist"
46 echo "unknown sync mode $SYNCMODE"
52 # Test replication of dynamic config:
55 # - configure over ldap
56 # - populate over ldap
57 # - configure syncrepl over ldap
58 # - retrieve database over ldap and compare against expected results
61 echo "Starting producer slapd on TCP/IP port $PORT1..."
62 . $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF
63 $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
65 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
67 if test $WAIT != 0 ; then
76 echo "Using ldapsearch to check that producer slapd is running..."
77 for i in 0 1 2 3 4 5; do
78 $LDAPSEARCH -s base -b "" -H $URI1 \
79 'objectclass=*' > /dev/null 2>&1
81 if test $RC = 0 ; then
84 echo "Waiting 5 seconds for slapd to start..."
88 if test $RC != 0 ; then
89 echo "ldapsearch failed ($RC)!"
90 test $KILLSERVERS != no && kill -HUP $KILLPIDS
94 echo "Inserting syncprov overlay on producer..."
95 if [ "$SYNCPROV" = syncprovmod ]; then
96 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
97 dn: cn=module,cn=config
98 objectClass: olcModuleList
100 olcModulePath: ../../../servers/slapd/overlays
101 olcModuleLoad: syncprov.la
104 if test $RC != 0 ; then
105 echo "ldapadd failed for moduleLoad ($RC)!"
106 test $KILLSERVERS != no && kill -HUP $KILLPIDS
110 read CONFIGPW < $CONFIGPWF
111 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
112 dn: olcDatabase={0}config,cn=config
115 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
116 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
121 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
123 objectClass: olcOverlayConfig
124 objectClass: olcSyncProvConfig
128 if test $RC != 0 ; then
129 echo "ldapmodify failed for syncrepl config ($RC)!"
130 test $KILLSERVERS != no && kill -HUP $KILLPIDS
134 echo "Starting consumer slapd on TCP/IP port $PORT2..."
135 $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
137 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
139 if test $WAIT != 0 ; then
140 echo SLAVEPID $SLAVEPID
143 KILLPIDS="$KILLPIDS $SLAVEPID"
148 echo "Using ldapsearch to check that consumer slapd is running..."
149 for i in 0 1 2 3 4 5; do
150 $LDAPSEARCH -s base -b "" -H $URI2 \
151 'objectclass=*' > /dev/null 2>&1
153 if test $RC = 0 ; then
156 echo "Waiting 5 seconds for slapd to start..."
160 if test $RC != 0 ; then
161 echo "ldapsearch failed ($RC)!"
162 test $KILLSERVERS != no && kill -HUP $KILLPIDS
166 echo "Configuring syncrepl on consumer..."
167 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
168 dn: olcDatabase={0}config,cn=config
171 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
172 credentials=$CONFIGPW searchbase="cn=config" $SYNCTYPE
179 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
182 echo "Using ldapsearch to check that syncrepl received config changes..."
184 for i in 0 1 2 3 4 5; do
185 RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
186 -s base -b "olcDatabase={0}config,cn=config" \
187 '(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
188 if test "x$RESULT" = "xOK" ; then
192 echo "Waiting 5 seconds for syncrepl to receive changes..."
196 if test $RC != 0 ; then
197 echo "ldapsearch failed ($RC)!"
198 test $KILLSERVERS != no && kill -HUP $KILLPIDS
202 echo "Adding schema and databases on producer..."
203 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
204 include: file://$ABS_SCHEMADIR/core.ldif
206 include: file://$ABS_SCHEMADIR/cosine.ldif
208 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
210 include: file://$ABS_SCHEMADIR/openldap.ldif
212 include: file://$ABS_SCHEMADIR/nis.ldif
215 if test $RC != 0 ; then
216 echo "ldapadd failed for schema config ($RC)!"
217 test $KILLSERVERS != no && kill -HUP $KILLPIDS
221 if [ "$BACKENDTYPE" = mod ]; then
222 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
223 dn: cn=module,cn=config
224 objectClass: olcModuleList
226 olcModulePath: ../../../servers/slapd/back-$BACKEND
227 olcModuleLoad: back_$BACKEND.la
230 if test $RC != 0 ; then
231 echo "ldapadd failed for backend config ($RC)!"
232 test $KILLSERVERS != no && kill -HUP $KILLPIDS
237 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
238 dn: olcDatabase={1}$BACKEND,cn=config
239 objectClass: olcDatabaseConfig
240 objectClass: olc${BACKEND}Config
241 olcDatabase: {1}$BACKEND
244 olcRootDN: $MANAGERDN
246 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
247 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
250 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
252 objectClass: olcOverlayConfig
253 objectClass: olcSyncProvConfig
257 if test $RC != 0 ; then
258 echo "ldapadd failed for database config ($RC)!"
259 test $KILLSERVERS != no && kill -HUP $KILLPIDS
263 echo "Using ldapadd to populate producer..."
264 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
267 if test $RC != 0 ; then
268 echo "ldapadd failed for database config ($RC)!"
269 test $KILLSERVERS != no && kill -HUP $KILLPIDS
274 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
277 echo "Using ldapsearch to check that syncrepl received database changes..."
279 for i in 0 1 2 3 4 5; do
280 RESULT=`$LDAPSEARCH -H $URI2 \
281 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
282 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
283 if test "x$RESULT" = "xOK" ; then
287 echo "Waiting 5 seconds for syncrepl to receive changes..."
291 if test $RC != 0 ; then
292 echo "ldapsearch failed ($RC)!"
293 test $KILLSERVERS != no && kill -HUP $KILLPIDS
297 echo "Using ldapsearch to read config from the producer..."
298 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
299 'objectclass=*' > $MASTEROUT 2>&1
302 if test $RC != 0 ; then
303 echo "ldapsearch failed at producer ($RC)!"
304 test $KILLSERVERS != no && kill -HUP $KILLPIDS
308 echo "Using ldapsearch to read config from the consumer..."
309 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
310 'objectclass=*' > $SLAVEOUT 2>&1
313 if test $RC != 0 ; then
314 echo "ldapsearch failed at consumer ($RC)!"
315 test $KILLSERVERS != no && kill -HUP $KILLPIDS
319 echo "Filtering producer results..."
320 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
321 echo "Filtering consumer results..."
322 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
324 echo "Comparing retrieved configs from producer and consumer..."
325 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
327 if test $? != 0 ; then
328 echo "test failed - producer and consumer configs differ"
329 test $KILLSERVERS != no && kill -HUP $KILLPIDS
333 echo "Using ldapsearch to read all the entries from the producer..."
334 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
335 'objectclass=*' > $MASTEROUT 2>&1
338 if test $RC != 0 ; then
339 echo "ldapsearch failed at producer ($RC)!"
340 test $KILLSERVERS != no && kill -HUP $KILLPIDS
344 echo "Using ldapsearch to read all the entries from the consumer..."
345 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
346 'objectclass=*' > $SLAVEOUT 2>&1
349 if test $RC != 0 ; then
350 echo "ldapsearch failed at consumer ($RC)!"
351 test $KILLSERVERS != no && kill -HUP $KILLPIDS
355 test $KILLSERVERS != no && kill -HUP $KILLPIDS
357 echo "Filtering producer results..."
358 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
359 echo "Filtering consumer results..."
360 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
362 echo "Comparing retrieved entries from producer and consumer..."
363 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
365 if test $? != 0 ; then
366 echo "test failed - producer and consumer databases differ"
370 echo ">>>>> Test succeeded"
372 test $KILLSERVERS != no && wait