3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2010 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"
24 CFPRO=$TESTDIR/cfpro.d
25 CFCON=$TESTDIR/cfcon.d
27 mkdir -p $TESTDIR $DBDIR1A $DBDIR1B $DBDIR2A $CFPRO $CFCON
29 $SLAPPASSWD -g -n >$CONFIGPWF
31 if test x"$SYNCMODE" = x ; then
36 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
39 SYNCTYPE="type=refreshAndPersist"
42 echo "unknown sync mode $SYNCMODE"
48 # Test replication of dynamic config with alternate slave config:
51 # - configure over ldap
52 # - populate over ldap
53 # - configure syncrepl over ldap
54 # - retrieve database over ldap and compare against expected results
57 echo "Starting provider slapd on TCP/IP port $PORT1..."
58 . $CONFFILTER $BACKEND $MONITORDB < $DYNAMICCONF > $CONFLDIF
59 $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
60 $SLAPD -F $CFPRO -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
62 if test $WAIT != 0 ; then
70 echo "Using ldapsearch to check that provider slapd is running..."
71 for i in 0 1 2 3 4 5; do
72 $LDAPSEARCH -s base -b "" -H $URI1 \
73 'objectclass=*' > /dev/null 2>&1
75 if test $RC = 0 ; then
78 echo "Waiting 5 seconds for slapd to start..."
82 if test $RC != 0 ; then
83 echo "ldapsearch failed ($RC)!"
84 test $KILLSERVERS != no && kill -HUP $KILLPIDS
88 echo "Inserting syncprov overlay on provider..."
89 if [ "$SYNCPROV" = syncprovmod ]; then
90 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
91 dn: cn=module,cn=config
92 objectClass: olcModuleList
94 olcModulePath: ../servers/slapd/overlays
95 olcModuleLoad: syncprov.la
98 if test $RC != 0 ; then
99 echo "ldapadd failed for moduleLoad ($RC)!"
100 test $KILLSERVERS != no && kill -HUP $KILLPIDS
104 read CONFIGPW < $CONFIGPWF
105 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
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 syncprov config ($RC)!"
115 test $KILLSERVERS != no && kill -HUP $KILLPIDS
119 # Slaves will not replicate the master's actual cn=config.
120 # Instead, they will use an alternate DB so that they may be
121 # configured differently from the master. This alternate DB
122 # will also be a consumer for the real cn=schema,cn=config tree.
123 # It has MirrorMode enabled so that it can be written directly
124 # while being a slave of the main schema.
125 echo "Configuring slave config DB on provider..."
126 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
132 dn: olcDatabase={1}ldif,cn=config
134 objectClass: olcDatabaseConfig
135 objectClass: olcLdifConfig
137 olcDbDirectory: $DBDIR1A
138 olcSuffix: cn=config,cn=slave
139 olcRootDN: cn=config,cn=slave
141 olcAccess: to * by dn.base="cn=config" write
143 dn: olcOverlay=syncprov,olcDatabase={1}ldif,cn=config
145 objectClass: olcOverlayConfig
146 objectClass: olcSyncProvConfig
149 dn: cn=config,cn=slave
151 objectClass: olcGlobal
154 dn: cn=schema,cn=config,cn=slave
156 objectClass: olcSchemaConfig
159 dn: olcDatabase={0}config,cn=config,cn=slave
161 objectClass: olcDatabaseConfig
162 olcDatabase: {0}config
164 olcSyncrepl: {0}rid=001 provider=$URI1 binddn="cn=config,cn=slave"
165 bindmethod=simple credentials=repsecret searchbase="cn=config,cn=slave"
166 $SYNCTYPE retry="3 5 300 5" timeout=3 suffixmassage="cn=config"
169 dn: olcDatabase={1}ldif,cn=config
172 olcSyncrepl: {0}rid=001 provider=$URI1 binddn="cn=config"
173 bindmethod=simple credentials=$CONFIGPW searchbase="cn=schema,cn=config"
174 $SYNCTYPE retry="3 5 300 5" timeout=3
175 suffixmassage="cn=schema,cn=config,cn=slave"
182 if test $RC != 0 ; then
183 echo "ldapmodify failed for slave DB config ($RC)!"
184 test $KILLSERVERS != no && kill -HUP $KILLPIDS
188 echo "Starting consumer slapd on TCP/IP port $PORT2..."
189 $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
190 $SLAPD -F $CFCON -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
192 if test $WAIT != 0 ; then
193 echo SLAVEPID $SLAVEPID
196 KILLPIDS="$KILLPIDS $SLAVEPID"
200 echo "Using ldapsearch to check that consumer slapd is running..."
201 for i in 0 1 2 3 4 5; do
202 $LDAPSEARCH -s base -b "" -H $URI2 \
203 'objectclass=*' > /dev/null 2>&1
205 if test $RC = 0 ; then
208 echo "Waiting 5 seconds for slapd to start..."
212 if test $RC != 0 ; then
213 echo "ldapsearch failed ($RC)!"
214 test $KILLSERVERS != no && kill -HUP $KILLPIDS
218 echo "Configuring syncrepl on consumer..."
219 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
220 dn: olcDatabase={0}config,cn=config
223 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config,cn=slave"
224 bindmethod=simple credentials=repsecret searchbase="cn=config,cn=slave"
225 $SYNCTYPE retry="3 5 300 5" timeout=3
226 suffixmassage="cn=config"
232 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
235 echo "Using ldapsearch to check that syncrepl received config changes..."
237 for i in 0 1 2 3 4 5; do
238 RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
239 -s base -b "olcDatabase={0}config,cn=config" \
240 '(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
241 if test "x$RESULT" = "xOK" ; then
245 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
249 if test $RC != 0 ; then
250 echo "ldapsearch failed ($RC)!"
251 test $KILLSERVERS != no && kill -HUP $KILLPIDS
255 echo "Adding schema and databases on provider..."
256 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
257 include: file://$ABS_SCHEMADIR/core.ldif
259 include: file://$ABS_SCHEMADIR/cosine.ldif
261 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
263 include: file://$ABS_SCHEMADIR/openldap.ldif
265 include: file://$ABS_SCHEMADIR/nis.ldif
268 if test $RC != 0 ; then
269 echo "ldapadd failed for schema config ($RC)!"
270 test $KILLSERVERS != no && kill -HUP $KILLPIDS
274 nullExclude="" nullOK=""
275 test $BACKEND = null && nullExclude="# " nullOK="OK"
277 if [ "$BACKENDTYPE" = mod ]; then
278 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
279 dn: cn=module,cn=config
280 objectClass: olcModuleList
282 olcModulePath: ../servers/slapd/back-$BACKEND
283 olcModuleLoad: back_$BACKEND.la
285 dn: cn=module,cn=config,cn=slave
286 objectClass: olcModuleList
288 olcModulePath: ../servers/slapd/back-$BACKEND
289 olcModuleLoad: back_$BACKEND.la
292 if test $RC != 0 ; then
293 echo "ldapadd failed for backend config ($RC)!"
294 test $KILLSERVERS != no && kill -HUP $KILLPIDS
299 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
300 dn: olcDatabase={2}$BACKEND,cn=config
301 objectClass: olcDatabaseConfig
302 ${nullExclude}objectClass: olc${BACKEND}Config
303 olcDatabase: {2}$BACKEND
305 ${nullExclude}olcDbDirectory: $DBDIR1B
306 olcRootDN: $MANAGERDN
308 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
309 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
310 retry="3 5 300 5" timeout=3
313 dn: olcOverlay=syncprov,olcDatabase={2}${BACKEND},cn=config
315 objectClass: olcOverlayConfig
316 objectClass: olcSyncProvConfig
319 dn: olcDatabase={1}$BACKEND,cn=config,cn=slave
320 objectClass: olcDatabaseConfig
321 ${nullExclude}objectClass: olc${BACKEND}Config
322 olcDatabase: {1}$BACKEND
324 ${nullExclude}olcDbDirectory: $DBDIR2A
325 olcRootDN: $MANAGERDN
327 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
328 credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
329 retry="3 5 300 5" timeout=3
334 if test $RC != 0 ; then
335 echo "ldapadd failed for database config ($RC)!"
336 test $KILLSERVERS != no && kill -HUP $KILLPIDS
342 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
343 dn: olcDatabase={2}$BACKEND,cn=config
346 olcDbIndex: objectClass,entryUUID,entryCSN eq
347 olcDbIndex: cn,uid pres,eq,sub
350 if test $RC != 0 ; then
351 echo "ldapadd modify for database config ($RC)!"
352 test $KILLSERVERS != no && kill -HUP $KILLPIDS
358 echo "Using ldapadd to populate provider..."
359 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
362 if test $RC != 0 ; then
363 echo "ldapadd failed for database config ($RC)!"
364 test $KILLSERVERS != no && kill -HUP $KILLPIDS
368 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
371 echo "Using ldapsearch to check that syncrepl received database changes..."
373 for i in 0 1 2 3 4 5; do
374 RESULT=`$LDAPSEARCH -H $URI2 \
375 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
376 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
377 if test "x$RESULT$nullOK" = "xOK" ; then
381 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
385 if test $RC != 0 ; then
386 echo "ldapsearch failed ($RC)!"
387 test $KILLSERVERS != no && kill -HUP $KILLPIDS
391 echo "Using ldapsearch to read all the entries from the provider..."
392 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
393 'objectclass=*' > $MASTEROUT 2>&1
396 if test $RC != 0 ; then
397 echo "ldapsearch failed at provider ($RC)!"
398 test $KILLSERVERS != no && kill -HUP $KILLPIDS
402 echo "Using ldapsearch to read all the entries from the consumer..."
403 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
404 'objectclass=*' > $SLAVEOUT 2>&1
407 if test $RC != 0 ; then
408 echo "ldapsearch failed at consumer ($RC)!"
409 test $KILLSERVERS != no && kill -HUP $KILLPIDS
413 test $KILLSERVERS != no && kill -HUP $KILLPIDS
415 echo "Filtering provider results..."
416 $LDIFFILTER < $MASTEROUT > $MASTERFLT
417 echo "Filtering consumer results..."
418 $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
420 echo "Comparing retrieved entries from provider and consumer..."
421 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
423 if test $? != 0 ; then
424 echo "test failed - provider and consumer databases differ"
428 echo ">>>>> Test succeeded"
430 test $KILLSERVERS != no && wait