3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2009 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 if test $BACKEND = null; then
25 echo "$BACKEND backend does not support cn=config, test skipped"
31 if [ $MMR -gt 9 ]; then
40 $SLAPPASSWD -g -n >$CONFIGPWF
42 if test x"$SYNCMODE" = x ; then
47 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
50 SYNCTYPE="type=refreshAndPersist"
53 echo "unknown sync mode $SYNCMODE"
59 # Test replication of dynamic config:
61 # - configure over ldap
62 # - populate over ldap
63 # - configure syncrepl over ldap
64 # - retrieve database over ldap and compare against expected results
67 echo "Initializing server configurations..."
69 while [ $n -le $MMR ]; do
72 CFDIR=${XDIR}$n/slapd.d
74 mkdir -p ${XDIR}$n $DBDIR $CFDIR
76 $SLAPADD -F $CFDIR -n 0 <<EOF
78 objectClass: olcGlobal
82 dn: olcDatabase={0}config,cn=config
83 objectClass: olcDatabaseConfig
84 olcDatabase: {0}config
85 olcRootPW:< file://$CONFIGPWF
91 echo "Starting server 1 on TCP/IP port $PORT1..."
93 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
95 if test $WAIT != 0 ; then
104 echo "Using ldapsearch to check that server 1 is running..."
105 for i in 0 1 2 3 4 5; do
106 $LDAPSEARCH -s base -b "" -H $URI1 \
107 'objectclass=*' > /dev/null 2>&1
109 if test $RC = 0 ; then
112 echo "Waiting 5 seconds for slapd to start..."
116 if test $RC != 0 ; then
117 echo "ldapsearch failed ($RC)!"
118 test $KILLSERVERS != no && kill -HUP $KILLPIDS
122 echo "Inserting syncprov overlay on server 1..."
124 if [ "$SYNCPROV" = syncprovmod ]; then
126 dn: cn=module,cn=config
128 objectClass: olcModuleList
130 olcModulePath: ../../../servers/slapd/overlays
131 olcModuleLoad: syncprov.la
136 # Note that we configure a timeout here; it's possible for both
137 # servers to attempt to bind to each other while a modify to
138 # cn=config is in progress. When the modify pauses the thread pool
139 # neither server will progress. The timeout will drop the syncrepl
140 # attempt and allow the modifies to complete.
142 read CONFIGPW < $CONFIGPWF
143 echo "dn: cn=config" >> $TMP
144 echo "changetype: modify" >> $TMP
145 echo "replace: olcServerID" >> $TMP
147 while [ $n -le $MMR ]; do
148 PORT=`expr $BASEPORT + $n`
149 URI="ldap://${LOCALHOST}:$PORT/"
150 echo "olcServerID: $n $URI" >> $TMP
156 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
158 objectClass: olcOverlayConfig
159 objectClass: olcSyncProvConfig
162 dn: olcDatabase={0}config,cn=config
168 while [ $n -le $MMR ]; do
169 PORT=`expr $BASEPORT + $n`
170 URI="ldap://${LOCALHOST}:$PORT/"
171 echo "olcSyncRepl: rid=00$n provider=$URI binddn=\"cn=config\" bindmethod=simple" >> $TMP
172 echo " credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP
173 echo " retry=\"3 10 300 5\" timeout=3" >> $TMP
177 echo "add: olcMirrorMode" >> $TMP
178 echo "olcMirrorMode: TRUE" >> $TMP
179 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >> $TESTOUT 2>&1
181 if test $RC != 0 ; then
182 echo "ldapmodify failed for syncrepl config ($RC)!"
183 test $KILLSERVERS != no && kill -HUP $KILLPIDS
188 while [ $n -le $MMR ]; do
189 PORT=`expr $BASEPORT + $n`
190 URI="ldap://${LOCALHOST}:$PORT/"
191 LOG=$TESTDIR/slapd.$n.log
192 echo "Starting server $n on TCP/IP port $PORT..."
194 $SLAPD -F ./slapd.d -h $URI -d $LVL $TIMING > $LOG 2>&1 &
196 if test $WAIT != 0 ; then
197 echo SLAVEPID $SLAVEPID
200 KILLPIDS="$KILLPIDS $SLAVEPID"
205 echo "Using ldapsearch to check that server $n is running..."
206 for i in 0 1 2 3 4 5; do
207 $LDAPSEARCH -s base -b "" -H $URI \
208 'objectclass=*' > /dev/null 2>&1
210 if test $RC = 0 ; then
213 echo "Waiting 5 seconds for slapd to start..."
217 if test $RC != 0 ; then
218 echo "ldapsearch failed ($RC)!"
219 test $KILLSERVERS != no && kill -HUP $KILLPIDS
223 echo "Configuring syncrepl on server $n..."
225 dn: olcDatabase={0}config,cn=config
230 while [ $j -le $MMR ]; do
231 P2=`expr $BASEPORT + $j`
232 U2="ldap://${LOCALHOST}:$P2/"
233 echo "olcSyncRepl: rid=00$j provider=$U2 binddn=\"cn=config\" bindmethod=simple" >> $TMP
234 echo " credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP
235 echo " retry=\"3 10 300 5\" timeout=3" >> $TMP
243 $LDAPMODIFY -D cn=config -H $URI -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1
247 echo "Adding schema and databases on server 1..."
248 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
249 include: file://$ABS_SCHEMADIR/core.ldif
251 include: file://$ABS_SCHEMADIR/cosine.ldif
253 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
255 include: file://$ABS_SCHEMADIR/openldap.ldif
257 include: file://$ABS_SCHEMADIR/nis.ldif
260 if test $RC != 0 ; then
261 echo "ldapadd failed for schema config ($RC)!"
262 test $KILLSERVERS != no && kill -HUP $KILLPIDS
267 if [ "$BACKENDTYPE" = mod ]; then
269 dn: cn=module,cn=config
270 objectClass: olcModuleList
272 olcModulePath: ../../../servers/slapd/back-$BACKEND
273 olcModuleLoad: back_$BACKEND.la
279 dn: olcDatabase={1}$BACKEND,cn=config
280 objectClass: olcDatabaseConfig
281 objectClass: olc${BACKEND}Config
282 olcDatabase: {1}$BACKEND
285 olcRootDN: $MANAGERDN
290 while [ $n -le $MMR ]; do
291 PORT=`expr $BASEPORT + $n`
292 URI="ldap://${LOCALHOST}:$PORT/"
294 echo "olcSyncRepl: rid=01$n provider=$URI binddn=\"$MANAGERDN\" bindmethod=simple" >> $TMP
295 echo " credentials=$PASSWD searchbase=\"$BASEDN\" $SYNCTYPE" >> $TMP
296 echo " retry=\"3 10 300 5\" timeout=3" >> $TMP
303 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
304 objectClass: olcOverlayConfig
305 objectClass: olcSyncProvConfig
308 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1
310 if test $RC != 0 ; then
311 echo "ldapadd failed for database config ($RC)!"
312 test $KILLSERVERS != no && kill -HUP $KILLPIDS
318 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
319 dn: olcDatabase={1}$BACKEND,cn=config
322 olcDbIndex: objectClass,entryUUID,entryCSN eq
323 olcDbIndex: cn,uid pres,eq,sub
326 if test $RC != 0 ; then
327 echo "ldapadd modify for database config ($RC)!"
328 test $KILLSERVERS != no && kill -HUP $KILLPIDS
334 echo "Using ldapadd to populate server 1..."
335 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
338 if test $RC != 0 ; then
339 echo "ldapadd failed for server 1 database ($RC)!"
340 test $KILLSERVERS != no && kill -HUP $KILLPIDS
344 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
348 while [ $n -le $MMR ]; do
349 PORT=`expr $BASEPORT + $n`
350 URI="ldap://${LOCALHOST}:$PORT/"
352 echo "Using ldapsearch to read config from server $n..."
353 $LDAPSEARCH -b cn=config -D cn=config -H $URI -y $CONFIGPWF \
354 'objectclass=*' > $TESTDIR/server$n.out 2>&1
357 if test $RC != 0 ; then
358 echo "ldapsearch failed at server $n ($RC)!"
359 test $KILLSERVERS != no && kill -HUP $KILLPIDS
363 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
369 while [ $n -le $MMR ]; do
370 echo "Comparing retrieved configs from server 1 and server $n..."
371 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
373 if test $? != 0 ; then
374 echo "test failed - server 1 and server $n configs differ"
375 test $KILLSERVERS != no && kill -HUP $KILLPIDS
382 while [ $n -le $MMR ]; do
383 PORT=`expr $BASEPORT + $n`
384 URI="ldap://${LOCALHOST}:$PORT/"
386 echo "Using ldapsearch to read all the entries from server $n..."
387 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
388 'objectclass=*' > $TESTDIR/server$n.out 2>&1
391 if test $RC != 0 ; then
392 echo "ldapsearch failed at server $n ($RC)!"
393 test $KILLSERVERS != no && kill -HUP $KILLPIDS
396 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
401 while [ $n -le $MMR ]; do
402 echo "Comparing retrieved entries from server 1 and server $n..."
403 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
405 if test $? != 0 ; then
406 echo "test failed - server 1 and server $n databases differ"
407 test $KILLSERVERS != no && kill -HUP $KILLPIDS
413 echo "Using ldapadd to populate server 2..."
414 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \
417 if test $RC != 0 ; then
418 echo "ldapadd failed for server 2 database ($RC)!"
419 test $KILLSERVERS != no && kill -HUP $KILLPIDS
423 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
427 while [ $n -le $MMR ]; do
428 PORT=`expr $BASEPORT + $n`
429 URI="ldap://${LOCALHOST}:$PORT/"
431 echo "Using ldapsearch to read all the entries from server $n..."
432 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
433 'objectclass=*' > $TESTDIR/server$n.out 2>&1
436 if test $RC != 0 ; then
437 echo "ldapsearch failed at server $n ($RC)!"
438 test $KILLSERVERS != no && kill -HUP $KILLPIDS
441 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
446 while [ $n -le $MMR ]; do
447 echo "Comparing retrieved entries from server 1 and server $n..."
448 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
450 if test $? != 0 ; then
451 echo "test failed - server 1 and server $n databases differ"
452 test $KILLSERVERS != no && kill -HUP $KILLPIDS
458 echo "Using ldapadd to populate server 3..."
459 $LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \
460 << EOMODS >> $TESTOUT 2>&1
461 dn: cn=Server 3 Test,dc=example,dc=com
467 if test $RC != 0 ; then
468 echo "ldapadd failed for server 3 database ($RC)!"
469 test $KILLSERVERS != no && kill -HUP $KILLPIDS
473 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
477 while [ $n -le $MMR ]; do
478 PORT=`expr $BASEPORT + $n`
479 URI="ldap://${LOCALHOST}:$PORT/"
481 echo "Using ldapsearch to read all the entries from server $n..."
482 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
483 'objectclass=*' > $TESTDIR/server$n.out 2>&1
486 if test $RC != 0 ; then
487 echo "ldapsearch failed at server $n ($RC)!"
488 test $KILLSERVERS != no && kill -HUP $KILLPIDS
491 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
496 while [ $n -le $MMR ]; do
497 echo "Comparing retrieved entries from server 1 and server $n..."
498 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
500 if test $? != 0 ; then
501 echo "test failed - server 1 and server $n databases differ"
502 test $KILLSERVERS != no && kill -HUP $KILLPIDS
508 echo "Using ldapmodify to add to server 1 entries that will be deleted..."
509 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
510 >> $TESTOUT 2>&1 << EOADDS
511 dn: cn=To be deleted by server 1,dc=example,dc=com
514 # no distinguished values, will be added by DSA
516 dn: cn=To be deleted by server 2,dc=example,dc=com
519 # no distinguished values, will be added by DSA
521 dn: cn=To be deleted by server 3,dc=example,dc=com
524 # no distinguished values, will be added by DSA
526 dn: cn=To be deleted by server 1,dc=example,dc=com
530 if test $RC != 0 ; then
531 echo "ldapmodify failed for server 1 database ($RC)!"
532 test $KILLSERVERS != no && kill -HUP $KILLPIDS
536 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
540 while [ $n -le $MMR ]; do
541 PORT=`expr $BASEPORT + $n`
542 URI="ldap://${LOCALHOST}:$PORT/"
544 echo "Using ldapsearch to read all the entries from server $n..."
545 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
546 'objectclass=*' > $TESTDIR/server$n.out 2>&1
549 if test $RC != 0 ; then
550 echo "ldapsearch failed at server $n ($RC)!"
551 test $KILLSERVERS != no && kill -HUP $KILLPIDS
554 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
559 while [ $n -le $MMR ]; do
560 echo "Comparing retrieved entries from server 1 and server $n..."
561 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
563 if test $? != 0 ; then
564 echo "test failed - server 1 and server $n databases differ"
565 test $KILLSERVERS != no && kill -HUP $KILLPIDS
571 echo "Using ldapmodify to delete entries from server 2..."
572 $LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \
573 >> $TESTOUT 2>&1 << EOADDS
574 dn: cn=To be deleted by server 2,dc=example,dc=com
578 if test $RC != 0 ; then
579 echo "ldapmodify failed for server 2 database ($RC)!"
580 test $KILLSERVERS != no && kill -HUP $KILLPIDS
584 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
587 echo "Using ldapmodify to delete entries from server 3..."
588 $LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \
589 >> $TESTOUT 2>&1 << EOADDS
590 dn: cn=To be deleted by server 3,dc=example,dc=com
594 if test $RC != 0 ; then
595 echo "ldapmodify failed for server 3 database ($RC)!"
596 test $KILLSERVERS != no && kill -HUP $KILLPIDS
600 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
604 while [ $n -le $MMR ]; do
605 PORT=`expr $BASEPORT + $n`
606 URI="ldap://${LOCALHOST}:$PORT/"
608 echo "Using ldapsearch to read all the entries from server $n..."
609 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
610 'objectclass=*' > $TESTDIR/server$n.out 2>&1
613 if test $RC != 0 ; then
614 echo "ldapsearch failed at server $n ($RC)!"
615 test $KILLSERVERS != no && kill -HUP $KILLPIDS
618 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
623 while [ $n -le $MMR ]; do
624 echo "Comparing retrieved entries from server 1 and server $n..."
625 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
627 if test $? != 0 ; then
628 echo "test failed - server 1 and server $n databases differ"
629 test $KILLSERVERS != no && kill -HUP $KILLPIDS
636 # test $KILLSERVERS != no && kill -HUP $KILLPIDS
640 # test $KILLSERVERS != no && wait
643 echo "Restarting servers..."
646 echo "Starting server 1 on TCP/IP port $PORT1..."
647 echo "======================= RESTART =======================" >> $LOG1
649 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
651 if test $WAIT != 0 ; then
660 echo "Using ldapsearch to check that server 1 is running..."
661 for i in 0 1 2 3 4 5; do
662 $LDAPSEARCH -s base -b "" -H $URI1 \
663 'objectclass=*' > /dev/null 2>&1
665 if test $RC = 0 ; then
668 echo "Waiting 5 seconds for slapd to start..."
672 if test $RC != 0 ; then
673 echo "ldapsearch failed ($RC)!"
674 test $KILLSERVERS != no && kill -HUP $KILLPIDS
679 while [ $n -le $MMR ]; do
680 PORT=`expr $BASEPORT + $n`
681 URI="ldap://${LOCALHOST}:$PORT/"
682 LOG=$TESTDIR/slapd.$n.log
683 echo "Starting server $n on TCP/IP port $PORT..."
685 echo "======================= RESTART =======================" >> $LOG
686 $SLAPD -F ./slapd.d -h $URI -d $LVL $TIMING >> $LOG 2>&1 &
688 if test $WAIT != 0 ; then
692 KILLPIDS="$KILLPIDS $PID"
698 while [ $n -le $MMR ]; do
699 PORT=`expr $BASEPORT + $n`
700 URI="ldap://${LOCALHOST}:$PORT/"
701 echo "Using ldapsearch to check that server $n is running..."
702 for i in 0 1 2 3 4 5; do
703 $LDAPSEARCH -s base -b "" -H $URI \
704 'objectclass=*' > /dev/null 2>&1
706 if test $RC = 0 ; then
709 echo "Waiting 5 seconds for slapd to start..."
713 if test $RC != 0 ; then
714 echo "ldapsearch failed ($RC)!"
715 test $KILLSERVERS != no && kill -HUP $KILLPIDS
721 # Insert modifications and more tests here.
722 echo "Waiting $SLEEP1 seconds for servers to resync..."
725 echo "Using ldapmodify to add/modify/delete entries from server 1..."
726 for i in 1 2 3 4 5 6 7 8 9 10; do
728 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
729 >> $TESTOUT 2>&1 << EOMODS
730 dn: cn=Add-Mod-Del,dc=example,dc=com
733 objectclass: organizationalRole
735 dn: cn=Add-Mod-Del,dc=example,dc=com
738 description: guinea pig
741 dn: cn=Add-Mod-Del,dc=example,dc=com
745 if test $RC != 0 ; then
746 echo "ldapmodify failed for server 1 database ($RC)!"
747 test $KILLSERVERS != no && kill -HUP $KILLPIDS
752 echo "Waiting $SLEEP1 seconds for servers to resync..."
756 while [ $n -le $MMR ]; do
757 PORT=`expr $BASEPORT + $n`
758 URI="ldap://${LOCALHOST}:$PORT/"
760 echo "Using ldapsearch to read all the entries from server $n..."
761 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \
762 'objectclass=*' > $TESTDIR/server$n.out 2>&1
765 if test $RC != 0 ; then
766 echo "ldapsearch failed at server $n ($RC)!"
767 test $KILLSERVERS != no && kill -HUP $KILLPIDS
770 $LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt
775 while [ $n -le $MMR ]; do
776 echo "Comparing retrieved entries from server 1 and server $n..."
777 $CMP $MASTERFLT $TESTDIR/server$n.flt > $CMPOUT
779 if test $? != 0 ; then
780 echo "test failed - server 1 and server $n databases differ"
781 test $KILLSERVERS != no && kill -HUP $KILLPIDS
787 test $KILLSERVERS != no && kill -HUP $KILLPIDS
789 echo ">>>>> Test succeeded"
791 test $KILLSERVERS != no && wait