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"
31 mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
33 $SLAPPASSWD -g -n >$CONFIGPWF
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 producer slapd on TCP/IP port $PORT1..."
46 . $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF
47 $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
49 $SLAPD -F ./slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
51 if test $WAIT != 0 ; then
60 echo "Using ldapsearch to check that producer slapd is running..."
61 for i in 0 1 2 3 4 5; do
62 $LDAPSEARCH -s base -b "" -H $URI1 \
63 'objectclass=*' > /dev/null 2>&1
65 if test $RC = 0 ; then
68 echo "Waiting 5 seconds for slapd to start..."
72 if test $RC != 0 ; then
73 echo "ldapsearch failed ($RC)!"
74 test $KILLSERVERS != no && kill -HUP $KILLPIDS
78 echo "Inserting syncprov overlay on producer..."
79 if [ "$SYNCPROV" = syncprovmod ]; then
80 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
81 dn: cn=module,cn=config
82 objectClass: olcModuleList
84 olcModulePath: ../../../servers/slapd/overlays
85 olcModuleLoad: syncprov.la
88 if test $RC != 0 ; then
89 echo "ldapadd failed for moduleLoad ($RC)!"
90 test $KILLSERVERS != no && kill -HUP $KILLPIDS
94 read CONFIGPW < $CONFIGPWF
95 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
96 dn: olcDatabase={0}config,cn=config
99 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
100 credentials=$CONFIGPW searchbase="cn=config" type=refreshOnly
106 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
108 objectClass: olcOverlayConfig
109 objectClass: olcSyncProvConfig
113 if test $RC != 0 ; then
114 echo "ldapmodify failed for syncrepl config ($RC)!"
115 test $KILLSERVERS != no && kill -HUP $KILLPIDS
119 echo "Starting consumer slapd on TCP/IP port $PORT2..."
120 $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
122 $SLAPD -F ./slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
124 if test $WAIT != 0 ; then
125 echo SLAVEPID $SLAVEPID
128 KILLPIDS="$KILLPIDS $SLAVEPID"
133 echo "Using ldapsearch to check that consumer slapd is running..."
134 for i in 0 1 2 3 4 5; do
135 $LDAPSEARCH -s base -b "" -H $URI2 \
136 'objectclass=*' > /dev/null 2>&1
138 if test $RC = 0 ; then
141 echo "Waiting 5 seconds for slapd to start..."
145 if test $RC != 0 ; then
146 echo "ldapsearch failed ($RC)!"
147 test $KILLSERVERS != no && kill -HUP $KILLPIDS
151 echo "Configuring syncrepl on consumer..."
152 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
153 dn: olcDatabase={0}config,cn=config
156 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
157 credentials=$CONFIGPW searchbase="cn=config" type=refreshOnly
165 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
168 echo "Using ldapsearch to check that syncrepl received config changes..."
170 for i in 0 1 2 3 4 5; do
171 RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
172 -s base -b "olcDatabase={0}config,cn=config" \
173 '(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
174 if test "x$RESULT" = "xOK" ; then
178 echo "Waiting 5 seconds for syncrepl to receive changes..."
182 if test $RC != 0 ; then
183 echo "ldapsearch failed ($RC)!"
184 test $KILLSERVERS != no && kill -HUP $KILLPIDS
188 echo "Adding schema and databases on producer..."
189 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
190 include: file://$ABS_SCHEMADIR/core.ldif
192 include: file://$ABS_SCHEMADIR/cosine.ldif
194 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
196 include: file://$ABS_SCHEMADIR/openldap.ldif
198 include: file://$ABS_SCHEMADIR/nis.ldif
201 if test $RC != 0 ; then
202 echo "ldapadd failed for schema config ($RC)!"
203 test $KILLSERVERS != no && kill -HUP $KILLPIDS
207 if [ "$BACKENDTYPE" = mod ]; then
208 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
209 dn: cn=module,cn=config
210 objectClass: olcModuleList
212 olcModulePath: ../../../servers/slapd/back-$BACKEND
213 olcModuleLoad: back_$BACKEND.la
216 if test $RC != 0 ; then
217 echo "ldapadd failed for backend config ($RC)!"
218 test $KILLSERVERS != no && kill -HUP $KILLPIDS
223 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
224 dn: olcDatabase={1}$BACKEND,cn=config
225 objectClass: olcDatabaseConfig
226 objectClass: olc${BACKEND}Config
227 olcDatabase: {1}$BACKEND
230 olcRootDN: $MANAGERDN
232 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
233 credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
237 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
239 objectClass: olcOverlayConfig
240 objectClass: olcSyncProvConfig
244 if test $RC != 0 ; then
245 echo "ldapadd failed for database config ($RC)!"
246 test $KILLSERVERS != no && kill -HUP $KILLPIDS
250 echo "Using ldapadd to populate producer..."
251 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
254 if test $RC != 0 ; then
255 echo "ldapadd failed for database config ($RC)!"
256 test $KILLSERVERS != no && kill -HUP $KILLPIDS
261 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
264 echo "Using ldapsearch to check that syncrepl received database changes..."
266 for i in 0 1 2 3 4 5; do
267 RESULT=`$LDAPSEARCH -H $URI2 \
268 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
269 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
270 if test "x$RESULT" = "xOK" ; then
274 echo "Waiting 5 seconds for syncrepl to receive changes..."
278 if test $RC != 0 ; then
279 echo "ldapsearch failed ($RC)!"
280 test $KILLSERVERS != no && kill -HUP $KILLPIDS
284 echo "Using ldapsearch to read config from the producer..."
285 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
286 'objectclass=*' > $MASTEROUT 2>&1
289 if test $RC != 0 ; then
290 echo "ldapsearch failed at producer ($RC)!"
291 test $KILLSERVERS != no && kill -HUP $KILLPIDS
295 echo "Using ldapsearch to read config from the consumer..."
296 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
297 'objectclass=*' > $SLAVEOUT 2>&1
300 if test $RC != 0 ; then
301 echo "ldapsearch failed at consumer ($RC)!"
302 test $KILLSERVERS != no && kill -HUP $KILLPIDS
306 echo "Filtering producer results..."
307 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
308 echo "Filtering consumer results..."
309 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
311 echo "Comparing retrieved configs from producer and consumer..."
312 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
314 if test $? != 0 ; then
315 echo "test failed - producer and consumer configs differ"
316 test $KILLSERVERS != no && kill -HUP $KILLPIDS
320 echo "Using ldapsearch to read all the entries from the producer..."
321 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
322 'objectclass=*' > $MASTEROUT 2>&1
325 if test $RC != 0 ; then
326 echo "ldapsearch failed at producer ($RC)!"
327 test $KILLSERVERS != no && kill -HUP $KILLPIDS
331 echo "Using ldapsearch to read all the entries from the consumer..."
332 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
333 'objectclass=*' > $SLAVEOUT 2>&1
336 if test $RC != 0 ; then
337 echo "ldapsearch failed at consumer ($RC)!"
338 test $KILLSERVERS != no && kill -HUP $KILLPIDS
342 test $KILLSERVERS != no && kill -HUP $KILLPIDS
344 echo "Filtering producer results..."
345 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
346 echo "Filtering consumer results..."
347 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
349 echo "Comparing retrieved entries from producer and consumer..."
350 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
352 if test $? != 0 ; then
353 echo "test failed - producer and consumer databases differ"
357 echo ">>>>> Test succeeded"
359 test $KILLSERVERS != no && wait