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 producer 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 producer 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 producer..."
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 consumer 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 consumer 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 consumer..."
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
164 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
167 echo "Using ldapsearch to check that syncrepl received config changes..."
169 for i in 0 1 2 3 4 5; do
170 RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
171 -s base -b "olcDatabase={0}config,cn=config" \
172 '(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
173 if test "x$RESULT" = "xOK" ; then
177 echo "Waiting 5 seconds for syncrepl to receive changes..."
181 if test $RC != 0 ; then
182 echo "ldapsearch failed ($RC)!"
183 test $KILLSERVERS != no && kill -HUP $KILLPIDS
187 echo "Adding schema and databases on producer..."
188 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
189 include: file:$SCHEMADIR/core.ldif
191 include: file:$SCHEMADIR/cosine.ldif
193 include: file:$SCHEMADIR/inetorgperson.ldif
195 include: file:$SCHEMADIR/openldap.ldif
197 include: file:$SCHEMADIR/nis.ldif
200 if test $RC != 0 ; then
201 echo "ldapadd failed for schema config ($RC)!"
202 test $KILLSERVERS != no && kill -HUP $KILLPIDS
206 if [ "$BACKENDTYPE" = mod ]; then
207 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
208 dn: cn=module,cn=config
209 objectClass: olcModuleList
211 olcModulePath: ../../../servers/slapd/back-$BACKEND
212 olcModuleLoad: back_$BACKEND.la
215 if test $RC != 0 ; then
216 echo "ldapadd failed for backend config ($RC)!"
217 test $KILLSERVERS != no && kill -HUP $KILLPIDS
222 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
223 dn: olcDatabase={1}$BACKEND,cn=config
224 objectClass: olcDatabaseConfig
225 objectClass: olc${BACKEND}Config
226 olcDatabase: {1}$BACKEND
229 olcRootDN: $MANAGERDN
231 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
232 credentials=$PASSWD searchbase="$BASEDN" type=refreshOnly
236 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
238 objectClass: olcOverlayConfig
239 objectClass: olcSyncProvConfig
243 if test $RC != 0 ; then
244 echo "ldapadd failed for database config ($RC)!"
245 test $KILLSERVERS != no && kill -HUP $KILLPIDS
249 echo "Using ldapadd to populate producer..."
250 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
253 if test $RC != 0 ; then
254 echo "ldapadd failed for database config ($RC)!"
255 test $KILLSERVERS != no && kill -HUP $KILLPIDS
260 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
263 echo "Using ldapsearch to check that syncrepl received database changes..."
265 for i in 0 1 2 3 4 5; do
266 RESULT=`$LDAPSEARCH -H $URI2 \
267 -s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
268 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
269 if test "x$RESULT" = "xOK" ; then
273 echo "Waiting 5 seconds for syncrepl to receive changes..."
277 if test $RC != 0 ; then
278 echo "ldapsearch failed ($RC)!"
279 test $KILLSERVERS != no && kill -HUP $KILLPIDS
283 echo "Using ldapsearch to read config from the producer..."
284 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF \
285 'objectclass=*' > $MASTEROUT 2>&1
288 if test $RC != 0 ; then
289 echo "ldapsearch failed at producer ($RC)!"
290 test $KILLSERVERS != no && kill -HUP $KILLPIDS
294 echo "Using ldapsearch to read config from the consumer..."
295 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
296 'objectclass=*' > $SLAVEOUT 2>&1
299 if test $RC != 0 ; then
300 echo "ldapsearch failed at consumer ($RC)!"
301 test $KILLSERVERS != no && kill -HUP $KILLPIDS
305 echo "Filtering producer results..."
306 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
307 echo "Filtering consumer results..."
308 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
310 echo "Comparing retrieved configs from producer and consumer..."
311 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
313 if test $? != 0 ; then
314 echo "test failed - producer and consumer configs differ"
315 test $KILLSERVERS != no && kill -HUP $KILLPIDS
319 echo "Using ldapsearch to read all the entries from the producer..."
320 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD \
321 'objectclass=*' > $MASTEROUT 2>&1
324 if test $RC != 0 ; then
325 echo "ldapsearch failed at producer ($RC)!"
326 test $KILLSERVERS != no && kill -HUP $KILLPIDS
330 echo "Using ldapsearch to read all the entries from the consumer..."
331 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD \
332 'objectclass=*' > $SLAVEOUT 2>&1
335 if test $RC != 0 ; then
336 echo "ldapsearch failed at consumer ($RC)!"
337 test $KILLSERVERS != no && kill -HUP $KILLPIDS
341 test $KILLSERVERS != no && kill -HUP $KILLPIDS
343 echo "Filtering producer results..."
344 . $LDIFFILTER < $MASTEROUT > $MASTERFLT
345 echo "Filtering consumer results..."
346 . $LDIFFILTER < $SLAVEOUT > $SLAVEFLT
348 echo "Comparing retrieved entries from producer and consumer..."
349 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
351 if test $? != 0 ; then
352 echo "test failed - producer and consumer databases differ"
356 echo ">>>>> Test succeeded"
358 test $KILLSERVERS != no && wait