]> git.sur5r.net Git - openldap/blob - tests/scripts/test058-syncrepl-asymmetric
Happy New Year
[openldap] / tests / scripts / test058-syncrepl-asymmetric
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2018 The OpenLDAP Foundation.
6 ## All rights reserved.
7 ##
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
10 ## Public License.
11 ##
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>.
15
16 # This script tests a configuration scenario as described in these URLs:
17 #
18 # http://www.openldap.org/lists/openldap-devel/200806/msg00041.html
19 # http://www.openldap.org/lists/openldap-devel/200806/msg00054.html
20 #
21 # Search for "TEST:" to find each major test this script performs.
22
23 # The configuration here consist of 3 "sites", each with a "master" and
24 # a "search" server. One of the sites is the "central", the other two
25 # are called "site1" and "site2".
26
27 # The following notations are used in variable names below to identify
28 # these servers, the first number defines the $URL# and $PORT# variable
29 # that server uses:
30 #
31 # 1: SMC_*      Site Master Central
32 # 2: SM1_*      Site Master 1
33 # 3: SM2_*      Site Master 2
34 # 4: SSC_*      Search Site Central
35 # 5: SS1_*      Search Site 1
36 # 6: SS2_*      Search Site 2
37
38 # The master servers all have a set of subordinate databases glued below
39 # the same suffix database.  Each of the masters are the master for at
40 # least one of these subordinate databases, but there are never more
41 # than one master for any single database.  I.e, this is neither a
42 # traditional single-master configuration, nor what most people think
43 # of as multi-master, but more what can be called multiple masters.
44
45 # The central master replicates to the two other masters, and receives
46 # updates from them of the backends they are the master for.  There is
47 # no direct connection between the other two master servers.  All of the
48 # masters have the syncprov overlay configured on the glue database.
49
50 # The search servers replicates from the master server at their site.
51 # They all have a single database with the glue suffix, but their
52 # database configuration doesn't matter much in this test.  (This
53 # database layout was originally created before gluing was introduced
54 # in OpenLDAP, which is why the search servers doesn't use it).
55
56 # The primary objective for gluing the backend databases is not to make
57 # them look like one huge database but to create a common search suffix
58 # for the clients.  Searching is mostly done on the search servers, only
59 # updates are done on the masters.
60
61 # It varies which backends that are replicated to which server (hence
62 # the name asymmetric in this test).  Access control rules on the
63 # masters are used to control what their consumers receives.  The table
64 # below gives an overview of which backend (the columns) that are
65 # replicated to which server (the rows).  A "M" defines the master for
66 # the backend, a "S" is a slave, and "-" means it is not replicated
67 # there.  Oh, the table probably looks wrong without the 4-position
68 # tab-stops OpenLDAP uses...
69
70 #               glue    ou1             ou2             sm1ou1  sm1ou2  sm2ou1  sm2ou2
71 # smc   M               M               M               S               S               S               -
72 # sm1   S               S               -               M               M               -               -
73 # sm2   S               S               S               S               -               M               M
74 # ssc   S               S               -               -               S               -               -
75 # ss1   S               S               -               S               S               -               -
76 # ss2   S               S               S               -               -               S               S
77
78 # On the central master syncrepl is configured on the subordinate
79 # databases, as it varies which backends that exists on its providers.
80 # Had it been used on the glue database then syncrepl would have removed
81 # the backends replicated from site1 but not present on site2 when it
82 # synchronizes with site2 (and vice versa).
83 #
84 # All the other servers uses syncrepl on the glue database, since
85 # replicating more than one subordinate database from the same master
86 # creates (as of the writing of this test script) race conditions that
87 # causes the replication to fail, as the race tests at the end shows.
88
89 # The databases controlled by syncrepl all have $UPDATEDN as their
90 # RootDN, while the master servers has other RootDN values for the
91 # backends they are the backend for them self.  This violates the current
92 # guidelines for gluing databases, which states that the same rootdn
93 # should be used on all of them.  Unfortunately, this cannot be done on
94 # site masters 1 and 2.  The backends they manage locally are either not
95 # present on the central master, or when so they are not replicated back
96 # to their source, which causes syncrepl to try to remove the content of
97 # these backends when it synchronizes with the central master.  The
98 # differing rootdn values used on the backends controlled by syncrepl
99 # and those managed locally prevents it from succeeding in this.  As
100 # noted above, moving syncrepl to the subordinate databases is currently
101 # not an option since that creates race conditions.
102
103 # The binddn values used in the syncrepl configurations are chosen to
104 # make the configuration and access control rules easiest to set up.  It
105 # occasionally uses a DN that is also used as a RootDN.  This is not a
106 # good practice and should not be taken as an example for real
107 # configurations!
108
109 # This script will print the content of any invalid contextCSN values it
110 # detects if the environment variable CSN_VERBOSE is non-empty.  The
111 # environment variable RACE_TESTS can be set to the number of race test
112 # iterations the script should perform.
113
114 if test "$BACKEND" = ldif ; then
115         echo "$BACKEND backend does not support access controls, test skipped"
116         exit 0
117 fi
118
119 #echo "Test 058 is currently disabled"
120 #exit 0
121
122 echo "running defines.sh"
123 . $SRCDIR/scripts/defines.sh
124
125 if test $SYNCPROV = syncprovno; then
126         echo "Syncrepl provider overlay not available, test skipped"
127         exit 0
128 fi
129
130 SMC_DIR=$TESTDIR/smc
131 SM1_DIR=$TESTDIR/sm1
132 SM2_DIR=$TESTDIR/sm2
133 SS1_DIR=$TESTDIR/ss1
134 SS2_DIR=$TESTDIR/ss2
135 SSC_DIR=$TESTDIR/ssc
136
137 MNUM=1
138
139 mkdir -p $TESTDIR
140
141 for dir in $SMC_DIR $SM1_DIR $SM2_DIR $SS1_DIR $SS2_DIR $SSC_DIR; do
142         mkdir -p $dir $dir/slapd.d $dir/db
143 done
144
145 mkdir -p $SMC_DIR/ou1 $SMC_DIR/sm1ou1 $SMC_DIR/sm1ou2
146 mkdir -p $SMC_DIR/ou2 $SMC_DIR/sm2ou1
147 mkdir -p $SM1_DIR/ou1 $SM1_DIR/sm1ou1 $SM1_DIR/sm1ou2
148 mkdir -p $SM2_DIR/ou2 $SM2_DIR/sm1ou1 $SM2_DIR/sm2ou1 $SM2_DIR/sm2ou2
149
150 cd $TESTDIR
151
152 KILLPIDS=
153
154 $SLAPPASSWD -g -n >$CONFIGPWF
155
156 ID=1
157
158 if test $WAIT != 0 ; then
159         RETRY="1 60"
160 else
161         RETRY="1 10"
162 fi
163
164 echo "Initializing master configurations..."
165 for dir in $SMC_DIR $SM1_DIR $SM2_DIR; do
166         $SLAPADD -F $dir/slapd.d -n 0 <<EOF
167 dn: cn=config
168 objectClass: olcGlobal
169 cn: config
170 olcServerID: $ID
171
172 dn: olcDatabase={0}config,cn=config
173 objectClass: olcDatabaseConfig
174 olcDatabase: {0}config
175 olcRootPW:< file://$CONFIGPWF
176
177 EOF
178         ID=`expr $ID + 1`
179 done
180
181 echo "Initializing search configurations..."
182 for dir in $SS1_DIR $SS2_DIR $SSC_DIR; do
183         $SLAPADD -F $dir/slapd.d -n 0 <<EOF
184 dn: cn=config
185 objectClass: olcGlobal
186 cn: config
187
188 dn: olcDatabase={0}config,cn=config
189 objectClass: olcDatabaseConfig
190 olcDatabase: {0}config
191 olcRootPW:< file://$CONFIGPWF
192
193 EOF
194 done
195
196 echo "Starting central master slapd on TCP/IP port $PORT1..."
197 cd $SMC_DIR
198 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
199 SMC_PID=$!
200 if test $WAIT != 0 ; then
201         echo PID $SMC_PID
202         read foo
203 fi
204 KILLPIDS="$KILLPIDS $SMC_PID"
205 cd $TESTWD
206 sleep 1
207 echo "Using ldapsearch to check that central master slapd is running..."
208 for i in 1 2 3 4 5; do
209         $LDAPSEARCH -s base -b "" -H $URI1 \
210                 'objectclass=*' > /dev/null 2>&1
211         RC=$?
212         test $RC = 0 && break
213         echo "Waiting $i seconds for slapd to start..."
214         sleep $i
215 done
216 if test $RC != 0 ; then
217         echo "ldapsearch failed ($RC)!"
218         test $KILLSERVERS != no && kill -HUP $KILLPIDS
219         exit $RC
220 fi
221
222 echo "Starting site1 master slapd on TCP/IP port $PORT2..."
223 cd $SM1_DIR
224 $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
225 SM1_PID=$!
226 if test $WAIT != 0 ; then
227         echo PID $SM1_PID
228         read foo
229 fi
230 KILLPIDS="$KILLPIDS $SM1_PID"
231 cd $TESTWD
232 sleep 1
233 echo "Using ldapsearch to check that site1 master is running..."
234 for i in 1 2 3 4 5; do
235         $LDAPSEARCH -s base -b "" -H $URI2 \
236                 'objectclass=*' > /dev/null 2>&1
237         RC=$?
238         test $RC = 0 && break
239         echo "Waiting $i seconds for slapd to start..."
240         sleep $i
241 done
242 if test $RC != 0 ; then
243         echo "ldapsearch failed ($RC)!"
244         test $KILLSERVERS != no && kill -HUP $KILLPIDS
245         exit $RC
246 fi
247
248 echo "Starting site2 master slapd on TCP/IP port $PORT3..."
249 cd $SM2_DIR
250 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
251 SM2_PID=$!
252 if test $WAIT != 0 ; then
253         echo PID $SM2_PID
254         read foo
255 fi
256 KILLPIDS="$KILLPIDS $SM2_PID"
257 cd $TESTWD
258 sleep 1
259 echo "Using ldapsearch to check that site2 master is running..."
260 for i in 1 2 3 4 5; do
261         $LDAPSEARCH -s base -b "" -H $URI3 \
262                 'objectclass=*' > /dev/null 2>&1
263         RC=$?
264         test $RC = 0 && break
265         echo "Waiting $i seconds for slapd to start..."
266         sleep $i
267 done
268 if test $RC != 0 ; then
269         echo "ldapsearch failed ($RC)!"
270         test $KILLSERVERS != no && kill -HUP $KILLPIDS
271         exit $RC
272 fi
273
274 echo "Starting central search slapd on TCP/IP port $PORT4..."
275 cd $SSC_DIR
276 $SLAPD -F slapd.d -h $URI4 -d $LVL $TIMING > $LOG4 2>&1 &
277 SSC_PID=$!
278 if test $WAIT != 0 ; then
279         echo PID $SSC_PID
280         read foo
281 fi
282 KILLPIDS="$KILLPIDS $SSC_PID"
283 cd $TESTWD
284 sleep 1
285 echo "Using ldapsearch to check that central search slapd is running..."
286 for i in 1 2 3 4 5; do
287         $LDAPSEARCH -s base -b "" -H $URI4 \
288                 'objectclass=*' > /dev/null 2>&1
289         RC=$?
290         test $RC = 0 && break
291         echo "Waiting $i seconds for slapd to start..."
292         sleep $i
293 done
294 if test $RC != 0 ; then
295         echo "ldapsearch failed ($RC)!"
296         test $KILLSERVERS != no && kill -HUP $KILLPIDS
297         exit $RC
298 fi
299
300
301 echo "Starting site1 search slapd on TCP/IP port $PORT5..."
302 cd $SS1_DIR
303 $SLAPD -F slapd.d -h $URI5 -d $LVL $TIMING > $LOG5 2>&1 &
304 SS1_PID=$!
305 if test $WAIT != 0 ; then
306         echo PID $SS1_PID
307         read foo
308 fi
309 KILLPIDS="$KILLPIDS $SS1_PID"
310 cd $TESTWD
311 sleep 1
312 echo "Using ldapsearch to check that site1 search slapd is running..."
313 for i in 1 2 3 4 5; do
314         $LDAPSEARCH -s base -b "" -H $URI5 \
315                 'objectclass=*' > /dev/null 2>&1
316         RC=$?
317         test $RC = 0 && break
318         echo "Waiting $i seconds for slapd to start..."
319         sleep $i
320 done
321 if test $RC != 0 ; then
322         echo "ldapsearch failed ($RC)!"
323         test $KILLSERVERS != no && kill -HUP $KILLPIDS
324         exit $RC
325 fi
326
327
328 echo "Starting site2 search slapd on TCP/IP port $PORT6..."
329 cd $SS2_DIR
330 $SLAPD -F slapd.d -h $URI6 -d $LVL $TIMING > $LOG6 2>&1 &
331 SS2_PID=$!
332 if test $WAIT != 0 ; then
333         echo PID $SS2_PID
334         read foo
335 fi
336 KILLPIDS="$KILLPIDS $SS2_PID"
337 cd $TESTWD
338 sleep 1
339 echo "Using ldapsearch to check that site2 search slapd is running..."
340 for i in 1 2 3 4 5; do
341         $LDAPSEARCH -s base -b "" -H $URI6 \
342                 'objectclass=*' > /dev/null 2>&1
343         RC=$?
344         test $RC = 0 && break
345         echo "Waiting $i seconds for slapd to start..."
346         sleep $i
347 done
348 if test $RC != 0 ; then
349         echo "ldapsearch failed ($RC)!"
350         test $KILLSERVERS != no && kill -HUP $KILLPIDS
351         exit $RC
352 fi
353
354 for uri in $URI1 $URI2 $URI3 $URI4 $URI5 $URI6; do
355         echo "Adding schema on $uri..."
356         $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
357 include: file://$ABS_SCHEMADIR/core.ldif
358
359 include: file://$ABS_SCHEMADIR/cosine.ldif
360
361 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
362
363 include: file://$ABS_SCHEMADIR/openldap.ldif
364
365 include: file://$ABS_SCHEMADIR/nis.ldif
366 EOF
367         RC=$?
368         if test $RC != 0 ; then
369                 echo "ldapadd failed for schema config ($RC)!"
370                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
371                 exit $RC
372         fi
373
374         [ "$BACKENDTYPE" = mod ] || continue
375
376         echo "Adding backend module on $uri..."
377         $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
378 dn: cn=module,cn=config
379 objectClass: olcModuleList
380 cn: module
381 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
382 olcModuleLoad: back_$BACKEND.la
383 EOF
384         RC=$?
385         if test $RC != 0 ; then
386                 echo "ldapadd failed for backend module ($RC)!"
387                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
388                 exit $RC
389         fi
390 done
391
392 echo "Adding database config on central master..."
393 if [ "$SYNCPROV" = syncprovmod ]; then
394         $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
395 dn: cn=module,cn=config
396 objectClass: olcModuleList
397 cn: module
398 olcModulePath: $TESTWD/../servers/slapd/overlays
399 olcModuleLoad: syncprov.la
400
401 EOF
402         RC=$?
403         if test $RC != 0 ; then
404                 echo "ldapadd failed for moduleLoad ($RC)!"
405                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
406                 exit $RC
407         fi
408 fi
409
410 nullExclude="" nullOK="" wantNoObj=32
411 test $BACKEND = null && nullExclude="# " nullOK="OK" wantNoObj=0
412
413 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
414 dn: olcDatabase={1}$BACKEND,cn=config
415 objectClass: olcDatabaseConfig
416 ${nullExclude}objectClass: olc${BACKEND}Config
417 olcDatabase: {1}$BACKEND
418 ${nullExclude}olcDbDirectory: $SMC_DIR/db
419 olcSuffix: $BASEDN
420 olcRootDN: $MANAGERDN
421 olcRootPW: $PASSWD
422
423 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
424 objectClass: olcOverlayConfig
425 olcOverlay: {0}glue
426
427 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
428 objectClass: olcOverlayConfig
429 objectClass: olcSyncProvConfig
430 olcOverlay: {1}syncprov
431 olcSpCheckpoint: 3 1
432
433 dn: olcDatabase={1}$BACKEND,cn=config
434 objectClass: olcDatabaseConfig
435 ${nullExclude}objectClass: olc${BACKEND}Config
436 olcDatabase: {1}$BACKEND
437 ${nullExclude}olcDbDirectory: $SMC_DIR/ou1
438 olcSubordinate: TRUE
439 olcSuffix: ou=ou1,$BASEDN
440 olcRootDN: $MANAGERDN
441
442 dn: olcDatabase={2}$BACKEND,cn=config
443 objectClass: olcDatabaseConfig
444 ${nullExclude}objectClass: olc${BACKEND}Config
445 olcDatabase: {2}$BACKEND
446 ${nullExclude}olcDbDirectory: $SMC_DIR/ou2
447 olcSubordinate: TRUE
448 olcSuffix: ou=ou2,$BASEDN
449 olcRootDN: $MANAGERDN
450
451 dn: olcDatabase={3}$BACKEND,cn=config
452 objectClass: olcDatabaseConfig
453 ${nullExclude}objectClass: olc${BACKEND}Config
454 olcDatabase: {3}$BACKEND
455 ${nullExclude}olcDbDirectory: $SMC_DIR/sm1ou1
456 olcSubordinate: TRUE
457 olcSuffix: ou=sm1ou1,$BASEDN
458 olcRootDN: $UPDATEDN
459
460 dn: olcDatabase={4}$BACKEND,cn=config
461 objectClass: olcDatabaseConfig
462 ${nullExclude}objectClass: olc${BACKEND}Config
463 olcDatabase: {4}$BACKEND
464 ${nullExclude}olcDbDirectory: $SMC_DIR/sm1ou2
465 olcSubordinate: TRUE
466 olcSuffix: ou=sm1ou2,$BASEDN
467 olcRootDN: $UPDATEDN
468
469 dn: olcDatabase={5}$BACKEND,cn=config
470 objectClass: olcDatabaseConfig
471 ${nullExclude}objectClass: olc${BACKEND}Config
472 olcDatabase: {5}$BACKEND
473 ${nullExclude}olcDbDirectory: $SMC_DIR/sm2ou1
474 olcSubordinate: TRUE
475 olcSuffix: ou=sm2ou1,$BASEDN
476 olcRootDN: $UPDATEDN
477
478 EOF
479 RC=$?
480 if test $RC != 0 ; then
481         echo "ldapadd failed for central master database config ($RC)!"
482         test $KILLSERVERS != no && kill -HUP $KILLPIDS
483         exit $RC
484 fi
485
486 echo "Adding database config on site1 master..."
487 if [ "$SYNCPROV" = syncprovmod ]; then
488         $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
489 dn: cn=module,cn=config
490 objectClass: olcModuleList
491 cn: module
492 olcModulePath: $TESTWD/../servers/slapd/overlays
493 olcModuleLoad: syncprov.la
494
495 EOF
496         RC=$?
497         if test $RC != 0 ; then
498                 echo "ldapadd failed for moduleLoad ($RC)!"
499                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
500                 exit $RC
501         fi
502 fi
503
504 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
505 dn: olcDatabase={1}$BACKEND,cn=config
506 objectClass: olcDatabaseConfig
507 ${nullExclude}objectClass: olc${BACKEND}Config
508 olcDatabase: {1}$BACKEND
509 ${nullExclude}olcDbDirectory: $SM1_DIR/db
510 olcSuffix: $BASEDN
511 olcRootDN: $UPDATEDN
512
513 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
514 objectClass: olcOverlayConfig
515 olcOverlay: {0}glue
516
517 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
518 objectClass: olcOverlayConfig
519 objectClass: olcSyncProvConfig
520 olcOverlay: {1}syncprov
521
522 dn: olcDatabase={1}$BACKEND,cn=config
523 objectClass: olcDatabaseConfig
524 ${nullExclude}objectClass: olc${BACKEND}Config
525 olcDatabase: {1}$BACKEND
526 ${nullExclude}olcDbDirectory: $SM1_DIR/ou1
527 olcSubordinate: TRUE
528 olcSuffix: ou=ou1,$BASEDN
529 olcRootDN: $UPDATEDN
530
531 dn: olcDatabase={2}$BACKEND,cn=config
532 objectClass: olcDatabaseConfig
533 ${nullExclude}objectClass: olc${BACKEND}Config
534 olcDatabase: {2}$BACKEND
535 ${nullExclude}olcDbDirectory: $SM1_DIR/sm1ou1
536 olcSubordinate: TRUE
537 olcSuffix: ou=sm1ou1,$BASEDN
538 olcRootDN: ou=sm1ou1,$BASEDN
539 olcRootPW: $PASSWD
540
541 dn: olcDatabase={3}$BACKEND,cn=config
542 objectClass: olcDatabaseConfig
543 ${nullExclude}objectClass: olc${BACKEND}Config
544 olcDatabase: {3}$BACKEND
545 ${nullExclude}olcDbDirectory: $SM1_DIR/sm1ou2
546 olcSubordinate: TRUE
547 olcSuffix: ou=sm1ou2,$BASEDN
548 olcRootDN: ou=sm1ou1,$BASEDN
549
550 EOF
551
552 RC=$?
553 if test $RC != 0 ; then
554         echo "ldapadd failed for site1 master database config ($RC)!"
555         test $KILLSERVERS != no && kill -HUP $KILLPIDS
556         exit $RC
557 fi
558
559 echo "Adding database config on site2 master..."
560 if [ "$SYNCPROV" = syncprovmod ]; then
561         $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
562 dn: cn=module,cn=config
563 objectClass: olcModuleList
564 cn: module
565 olcModulePath: $TESTWD/../servers/slapd/overlays
566 olcModuleLoad: syncprov.la
567
568 EOF
569         RC=$?
570         if test $RC != 0 ; then
571                 echo "ldapadd failed for moduleLoad ($RC)!"
572                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
573                 exit $RC
574         fi
575 fi
576
577 $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
578 dn: olcDatabase={1}$BACKEND,cn=config
579 objectClass: olcDatabaseConfig
580 ${nullExclude}objectClass: olc${BACKEND}Config
581 olcDatabase: {1}$BACKEND
582 ${nullExclude}olcDbDirectory: $SM2_DIR/db
583 olcSuffix: $BASEDN
584 olcRootDN: $UPDATEDN
585
586 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
587 objectClass: olcOverlayConfig
588 olcOverlay: {0}glue
589
590 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
591 objectClass: olcOverlayConfig
592 objectClass: olcSyncProvConfig
593 olcOverlay: {1}syncprov
594 olcSpCheckpoint: 1 1
595
596 dn: olcDatabase={1}$BACKEND,cn=config
597 objectClass: olcDatabaseConfig
598 ${nullExclude}objectClass: olc${BACKEND}Config
599 olcDatabase: {1}$BACKEND
600 ${nullExclude}olcDbDirectory: $SM2_DIR/ou2
601 olcSubordinate: TRUE
602 olcSuffix: ou=ou2,$BASEDN
603 olcRootDN: $UPDATEDN
604
605 dn: olcDatabase={2}$BACKEND,cn=config
606 objectClass: olcDatabaseConfig
607 ${nullExclude}objectClass: olc${BACKEND}Config
608 olcDatabase: {2}$BACKEND
609 ${nullExclude}olcDbDirectory: $SM2_DIR/sm1ou1
610 olcSubordinate: TRUE
611 olcSuffix: ou=sm1ou1,$BASEDN
612 olcRootDN: $UPDATEDN
613
614 dn: olcDatabase={3}$BACKEND,cn=config
615 objectClass: olcDatabaseConfig
616 ${nullExclude}objectClass: olc${BACKEND}Config
617 olcDatabase: {3}$BACKEND
618 ${nullExclude}olcDbDirectory: $SM2_DIR/sm2ou1
619 olcSubordinate: TRUE
620 olcSuffix: ou=sm2ou1,$BASEDN
621 olcRootDN: ou=sm2ou1,$BASEDN
622 olcRootPW: $PASSWD
623
624 dn: olcDatabase={4}$BACKEND,cn=config
625 objectClass: olcDatabaseConfig
626 ${nullExclude}objectClass: olc${BACKEND}Config
627 olcDatabase: {4}$BACKEND
628 ${nullExclude}olcDbDirectory: $SM2_DIR/sm2ou2
629 olcSubordinate: TRUE
630 olcSuffix: ou=sm2ou2,$BASEDN
631 olcRootDN: ou=sm2ou1,$BASEDN
632
633 EOF
634
635 RC=$?
636 if test $RC != 0 ; then
637         echo "ldapadd failed for site2 master database config ($RC)!"
638         test $KILLSERVERS != no && kill -HUP $KILLPIDS
639         exit $RC
640 fi
641
642 echo "Adding access rules on central master..."
643 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
644 dn: olcDatabase={-1}frontend,cn=config
645 changetype: modify
646 add: olcAccess
647 olcAccess: to dn.exact=dc=example,dc=com
648   by * read
649 olcAccess: to dn.subtree=ou=ou1,dc=example,dc=com
650   by * read
651 olcAccess: to dn.subtree=ou=ou2,dc=example,dc=com
652   by dn.exact=ou=ou1,dc=example,dc=com none
653   by dn.exact=ou=ou2,dc=example,dc=com read
654   by dn.exact=dc=example,dc=com none
655   by * read
656 olcAccess: to dn.subtree=ou=sm1ou1,dc=example,dc=com
657   by dn.exact=ou=ou1,dc=example,dc=com none
658   by dn.exact=ou=ou2,dc=example,dc=com read
659   by dn.exact=dc=example,dc=com none
660   by * read
661 olcAccess: to dn.subtree=ou=sm1ou2,dc=example,dc=com
662   by dn.exact=ou=ou1,dc=example,dc=com none
663   by dn.exact=ou=ou2,dc=example,dc=com none
664   by dn.exact=dc=example,dc=com read
665   by * read
666 olcAccess: to dn.subtree=ou=sm2ou1,dc=example,dc=com
667   by dn.exact=ou=ou1,dc=example,dc=com none
668   by dn.exact=ou=ou2,dc=example,dc=com none
669   by dn.exact=dc=example,dc=com none
670   by * read
671 olcAccess: to * by * read
672
673 EOF
674 RC=$?
675 if test $RC != 0 ; then
676         echo "ldapmodify failed for central master access config ($RC)!"
677         test $KILLSERVERS != no && kill -HUP $KILLPIDS
678         exit $RC
679 fi
680
681 echo "Adding access rules on site1 master..."
682 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
683 dn: olcDatabase={-1}frontend,cn=config
684 changetype: modify
685 add: olcAccess
686 olcAccess: to dn.subtree=dc=example,dc=com
687   by * read
688 olcAccess: to * by * read
689
690 EOF
691 RC=$?
692 if test $RC != 0 ; then
693         echo "ldapmodify failed for site1 master access config ($RC)!"
694         test $KILLSERVERS != no && kill -HUP $KILLPIDS
695         exit $RC
696 fi
697
698 echo "Adding access rules on site2 master..."
699 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
700 dn: olcDatabase={-1}frontend,cn=config
701 changetype: modify
702 add: olcAccess
703 olcAccess: to dn.exact=dc=example,dc=com
704   by * read
705 olcAccess: to dn.subtree=ou=ou2,dc=example,dc=com
706   by * read
707 olcAccess: to dn.subtree=ou=sm1ou1,dc=example,dc=com
708   by users none
709   by * read
710 olcAccess: to dn.subtree=ou=sm2ou1,dc=example,dc=com
711   by * read
712 olcAccess: to dn.subtree=ou=sm2ou2,dc=example,dc=com
713   by dn.exact=dc=example,dc=com read
714   by users none
715   by * read
716 olcAccess: to * by * read
717
718 EOF
719 RC=$?
720 if test $RC != 0 ; then
721         echo "ldapmodify failed for site2 master access config ($RC)!"
722         test $KILLSERVERS != no && kill -HUP $KILLPIDS
723         exit $RC
724 fi
725
726 echo "Adding database config on central search..."
727 $LDAPADD -D cn=config -H $URI4 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
728 dn: olcDatabase={1}$BACKEND,cn=config
729 objectClass: olcDatabaseConfig
730 ${nullExclude}objectClass: olc${BACKEND}Config
731 olcDatabase: {1}$BACKEND
732 ${nullExclude}olcDbDirectory: $SSC_DIR/db
733 olcSuffix: $BASEDN
734 olcRootDN: $UPDATEDN
735
736 EOF
737 RC=$?
738 if test $RC != 0 ; then
739         echo "ldapadd failed for central search database config ($RC)!"
740         test $KILLSERVERS != no && kill -HUP $KILLPIDS
741         exit $RC
742 fi
743
744 echo "Adding database config on site1 search..."
745 $LDAPADD -D cn=config -H $URI5 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
746 dn: olcDatabase={1}$BACKEND,cn=config
747 objectClass: olcDatabaseConfig
748 ${nullExclude}objectClass: olc${BACKEND}Config
749 olcDatabase: {1}$BACKEND
750 ${nullExclude}olcDbDirectory: $SS1_DIR/db
751 olcSuffix: $BASEDN
752 olcRootDN: $UPDATEDN
753
754 EOF
755 RC=$?
756 if test $RC != 0 ; then
757         echo "ldapadd failed for site1 search database config ($RC)!"
758         test $KILLSERVERS != no && kill -HUP $KILLPIDS
759         exit $RC
760 fi
761
762 echo "Adding database config on site2 search..."
763 $LDAPADD -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
764 dn: olcDatabase={1}$BACKEND,cn=config
765 objectClass: olcDatabaseConfig
766 ${nullExclude}objectClass: olc${BACKEND}Config
767 olcDatabase: {1}$BACKEND
768 ${nullExclude}olcDbDirectory: $SS2_DIR/db
769 olcSuffix: $BASEDN
770 olcRootDN: $UPDATEDN
771
772 EOF
773 RC=$?
774 if test $RC != 0 ; then
775         echo "ldapadd failed for site2 search database config ($RC)!"
776         test $KILLSERVERS != no && kill -HUP $KILLPIDS
777         exit $RC
778 fi
779
780 echo "Populating central master..."
781 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
782 dn: dc=example,dc=com
783 objectClass: top
784 objectClass: organization
785 objectClass: dcObject
786 dc: example
787 o: Example, Inc
788 userPassword: $PASSWD
789
790 dn: ou=ou1,dc=example,dc=com
791 objectClass: top
792 objectClass: organizationalUnit
793 ou: ou1
794 userPassword: $PASSWD
795
796 dn: ou=ou2,dc=example,dc=com
797 objectClass: top
798 objectClass: organizationalUnit
799 ou: ou2
800 userPassword: $PASSWD
801
802 EOF
803 RC=$?
804 if test $RC != 0 ; then
805         echo "ldapadd failed to populate central master entry ($RC)!"
806         test $KILLSERVERS != no && kill -HUP $KILLPIDS
807         exit $RC
808 fi
809
810 echo "Adding syncrepl on site1 master..."
811 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
812 dn: olcDatabase={4}$BACKEND,cn=config
813 changetype: modify
814 add: olcSyncRepl
815 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
816   binddn="ou=ou1,$BASEDN" bindmethod=simple credentials=$PASSWD
817   type=refreshAndPersist retry="$RETRY" timeout=1
818
819 EOF
820 RC=$?
821 if test $RC != 0 ; then
822         echo "ldapmodify failed to add syncrepl on site1 master ($RC)!"
823         test $KILLSERVERS != no && kill -HUP $KILLPIDS
824         exit $RC
825 fi
826
827 echo "Adding syncrepl on site2 master..."
828 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
829 dn: olcDatabase={5}$BACKEND,cn=config
830 changetype: modify
831 add: olcSyncRepl
832 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
833   binddn="ou=ou2,$BASEDN" bindmethod=simple credentials=$PASSWD
834   type=refreshAndPersist retry="$RETRY" timeout=1
835
836 EOF
837 RC=$?
838 if test $RC != 0 ; then
839         echo "ldapmodify failed to add syncrepl on site2 master ($RC)!"
840         test $KILLSERVERS != no && kill -HUP $KILLPIDS
841         exit $RC
842 fi
843 sleep 1
844
845 echo "Using ldapsearch to check that site1 master received changes..."
846 RC=32
847 for i in 1 2 3 4 5; do
848         RESULT=`$LDAPSEARCH -H $URI2 \
849                 -s base -b "ou=ou1,$BASEDN" \
850                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
851         if test "x$RESULT$nullOK" = "xOK" ; then
852                 RC=0
853                 break
854         fi
855         echo "Waiting $i seconds for syncrepl to receive changes..."
856         sleep $i
857 done
858 if test $RC != 0 ; then
859         echo "ldapsearch failed ($RC)!"
860         test $KILLSERVERS != no && kill -HUP $KILLPIDS
861         exit $RC
862 fi
863
864 echo "Using ldapsearch to check that site2 master received changes..."
865 RC=32
866 for i in 1 2 3 4 5; do
867         RESULT=`$LDAPSEARCH -H $URI3 \
868                 -s base -b "ou=ou1,$BASEDN" \
869                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
870         if test "x$RESULT$nullOK" = "xOK" ; then
871                 RC=0
872                 break
873         fi
874         echo "Waiting $i seconds for syncrepl to receive changes..."
875         sleep $i
876 done
877 if test $RC != 0 ; then
878         echo "ldapsearch failed ($RC)!"
879         test $KILLSERVERS != no && kill -HUP $KILLPIDS
880         exit $RC
881 fi
882
883 sleep 1
884
885 echo "Populating site1 master..."
886 $LDAPADD -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
887 dn: ou=sm1ou1,dc=example,dc=com
888 objectClass: top
889 objectClass: organizationalUnit
890 ou: sm1ou1
891
892 dn: ou=sm1ou2,dc=example,dc=com
893 objectClass: top
894 objectClass: organizationalUnit
895 ou: sm1ou2
896
897 EOF
898 RC=$?
899 if test $RC != 0 ; then
900         echo "ldapadd failed to populate site1 master ($RC)!"
901         test $KILLSERVERS != no && kill -HUP $KILLPIDS
902         exit $RC
903 fi
904
905 sleep 1
906
907 echo "Populating site2 master..."
908 $LDAPADD -D "ou=sm2ou1,$BASEDN" -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
909 dn: ou=sm2ou1,dc=example,dc=com
910 objectClass: top
911 objectClass: organizationalUnit
912 ou: sm2ou1
913
914 dn: ou=sm2ou2,dc=example,dc=com
915 objectClass: top
916 objectClass: organizationalUnit
917 ou: sm2ou2
918
919 EOF
920 RC=$?
921 if test $RC != 0 ; then
922         echo "ldapadd failed to populate site2 master ($RC)!"
923         test $KILLSERVERS != no && kill -HUP $KILLPIDS
924         exit $RC
925 fi
926
927 ERRORS=0
928
929 # TEST:
930 # Stop site1 master when adding syncrepl to the central master.  When
931 # site1 master is started again both it and the central master will have
932 # the same number of contextCSN values, but the ones on central master
933 # will be the newest.  The central master will not update its contextCSN
934 # values unless the bug in ITS#5597 have been fixed.
935 echo "Stopping site1 master..."
936 kill -HUP "$SM1_PID"
937 wait "$SM1_PID"
938 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SM1_PID / /"`;
939 SM1_PID=
940
941 echo "Adding syncrepl on central master..."
942 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
943 dn: olcDatabase={3}$BACKEND,cn=config
944 changetype: modify
945 add: olcSyncRepl
946 olcSyncRepl: rid=3 provider=$URI2 searchbase="ou=sm1ou1,$BASEDN"
947   binddn="ou=sm1ou1,$BASEDN" bindmethod=simple credentials=$PASSWD
948   type=refreshAndPersist retry="$RETRY" timeout=1
949
950 dn: olcDatabase={5}$BACKEND,cn=config
951 changetype: modify
952 add: olcSyncRepl
953 olcSyncRepl: rid=5 provider=$URI3 searchbase="ou=sm2ou1,$BASEDN"
954   binddn="ou=sm2ou1,$BASEDN" bindmethod=simple credentials=$PASSWD
955   type=refreshAndPersist retry="$RETRY" timeout=1
956
957 EOF
958 RC=$?
959 if test $RC != 0 ; then
960         echo "ldapmodify failed to add syncrepl on central master ($RC)!"
961         test $KILLSERVERS != no && kill -HUP $KILLPIDS
962         exit $RC
963 fi
964 sleep 1
965 echo "Using ldapsearch to check that central master received site2 entries..."
966 RC=32
967 for i in 1 2 3 4 5; do
968         RESULT=`$LDAPSEARCH -H $URI1 \
969                 -s base -b "ou=sm2ou1,$BASEDN" \
970                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
971         if test "x$RESULT$nullOK" = "xOK" ; then
972                 RC=0
973                 break
974         fi
975         echo "Waiting $i seconds for syncrepl to receive changes..."
976         sleep $i
977 done
978 if test $RC != 0 ; then
979         echo "ldapsearch failed ($RC)!"
980         test $KILLSERVERS != no && kill -HUP $KILLPIDS
981         exit $RC
982 fi
983
984 # Test for ITS#6716, modify on central master to ensure that the CSN
985 # order is "sid2 < sid3 < sid1".  When site1 master starts it is likely
986 # to sync with central master before it syncs with site1 master. When
987 # central master syncs with site1 master they will share the sid1 and
988 # sid3 CSNs, the additional sid2 CSN hold by site1 master will be the
989 # oldest. Central master will not receive the changes made on site1
990 # master unless it completely ignores the CSNs presented by central
991 # master.
992 echo "Using ldapmodify to modify central master..."
993 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
994 dn: dc=example,dc=com
995 changetype: modify
996 add: description
997 description: Modify$MNUM
998
999 EOF
1000 RC=$?
1001 if test $RC != 0 ; then
1002         echo "ldapmodify failed ($RC)!"
1003         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1004         exit $RC
1005 fi
1006
1007 if test -z "$SM1_PID" ; then
1008         echo "Restarting site1 master slapd on TCP/IP port $PORT2..."
1009         cd $SM1_DIR
1010         $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
1011         SM1_PID=$!
1012         if test $WAIT != 0 ; then
1013             echo PID $SM1_PID
1014             read foo
1015         fi
1016         KILLPIDS="$KILLPIDS $SM1_PID"
1017         cd $TESTWD
1018         sleep 1
1019 fi
1020 sleep 1
1021 echo "Using ldapsearch to check that site1 master is running..."
1022 for i in 1 2 3 4 5; do
1023         $LDAPSEARCH -s base -b "" -H $URI2 \
1024                 'objectclass=*' > /dev/null 2>&1
1025         RC=$?
1026         test $RC = 0 && break
1027         echo "Waiting $i seconds for slapd to start..."
1028         sleep $i
1029 done
1030 if test $RC != 0 ; then
1031         echo "ldapsearch failed ($RC)!"
1032         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1033         exit $RC
1034 fi
1035
1036 echo "Using ldapsearch to check that central master received site1 entries..."
1037 RC=32
1038 for i in 1 2 3 4 5; do
1039         RESULT=`$LDAPSEARCH -H $URI1 \
1040                 -s base -b "ou=sm1ou1,$BASEDN" \
1041                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
1042         if test "x$RESULT$nullOK" = "xOK" ; then
1043                 RC=0
1044                 break
1045         fi
1046         echo "Waiting $i seconds for syncrepl to receive changes..."
1047         sleep $i
1048 done
1049 if test $RC != 0 ; then
1050         echo "ldapsearch failed ($RC)!"
1051         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1052         exit $RC
1053 fi
1054
1055 echo "Using ldapsearch to check that site1 master received central master update..."
1056 RC=32
1057 for i in 1 2 3 4 5; do
1058         RESULT=`$LDAPSEARCH -H $URI2 \
1059                 -s base -b "$BASEDN" \
1060                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1061         if test "x$RESULT$nullOK" = "xOK" ; then
1062                 RC=0
1063                 break
1064         fi
1065         echo "Waiting $i seconds for syncrepl to receive changes..."
1066         sleep $i
1067 done
1068 if test $RC != 0 ; then
1069         echo "ldapsearch failed ($RC)!"
1070         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1071         exit $RC
1072 fi
1073
1074 echo "Using ldapsearch to check that site2 master received central master update..."
1075 RC=32
1076 for i in 1 2 3 4 5; do
1077         RESULT=`$LDAPSEARCH -H $URI3 \
1078                 -s base -b "$BASEDN" \
1079                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1080         if test "x$RESULT$nullOK" = "xOK" ; then
1081                 RC=0
1082                 break
1083         fi
1084         echo "Waiting $i seconds for syncrepl to receive changes..."
1085         sleep $i
1086 done
1087 if test $RC != 0 ; then
1088         echo "ldapsearch failed ($RC)!"
1089         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1090         exit $RC
1091 fi
1092
1093 # Test done, now some more initialization...
1094
1095 echo "Adding syncrepl consumer on central search..."
1096 $LDAPMODIFY -D cn=config -H $URI4 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
1097 dn: olcDatabase={1}$BACKEND,cn=config
1098 changetype: modify
1099 add: olcSyncRepl
1100 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
1101   binddn="$BASEDN" bindmethod=simple credentials=$PASSWD
1102   type=refreshAndPersist retry="$RETRY" timeout=1
1103
1104 EOF
1105 RC=$?
1106 if test $RC != 0 ; then
1107         echo "ldapmodify failed to add syncrepl on site1 search ($RC)!"
1108         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1109         exit $RC
1110 fi
1111
1112 echo "Adding syncrepl consumer on site1 search..."
1113 $LDAPMODIFY -D cn=config -H $URI5 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
1114 dn: olcDatabase={1}$BACKEND,cn=config
1115 changetype: modify
1116 add: olcSyncRepl
1117 olcSyncRepl: rid=1 provider=$URI2 searchbase="$BASEDN"
1118   binddn="$BASEDN" bindmethod=simple credentials=$PASSWD
1119   type=refreshAndPersist retry="$RETRY" timeout=1
1120
1121 EOF
1122 RC=$?
1123 if test $RC != 0 ; then
1124         echo "ldapmodify failed to add syncrepl on site1 search ($RC)!"
1125         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1126         exit $RC
1127 fi
1128
1129 echo "Adding syncrepl consumer on site2 search..."
1130 $LDAPMODIFY -D cn=config -H $URI6 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
1131 dn: olcDatabase={1}$BACKEND,cn=config
1132 changetype: modify
1133 add: olcSyncRepl
1134 olcSyncRepl: rid=1 provider=$URI3 searchbase="$BASEDN"
1135   binddn="$BASEDN" bindmethod=simple credentials=$PASSWD
1136   type=refreshAndPersist retry="$RETRY" timeout=1
1137
1138 EOF
1139 RC=$?
1140 if test $RC != 0 ; then
1141         echo "ldapmodify failed to add syncrepl on site2 search ($RC)!"
1142         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1143         exit $RC
1144 fi
1145 sleep 1
1146
1147 echo "Using ldapsearch to check that central search received changes..."
1148 RC=32
1149 for i in 1 2 3 4 5; do
1150         RESULT=`$LDAPSEARCH -H $URI4 \
1151                 -s base -b "$BASEDN" \
1152                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
1153         if test "x$RESULT$nullOK" = "xOK" ; then
1154                 RC=0
1155                 break
1156         fi
1157         echo "Waiting $i seconds for syncrepl to receive changes..."
1158         sleep $i
1159 done
1160 if test $RC != 0 ; then
1161         echo "ldapsearch failed ($RC)!"
1162         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1163         exit $RC
1164 fi
1165
1166 echo "Using ldapsearch to check that site1 search received changes..."
1167 RC=32
1168 for i in 1 2 3 4 5; do
1169         RESULT=`$LDAPSEARCH -H $URI5 \
1170                 -s base -b "$BASEDN" \
1171                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
1172         if test "x$RESULT$nullOK" = "xOK" ; then
1173                 RC=0
1174                 break
1175         fi
1176         echo "Waiting $i seconds for syncrepl to receive changes..."
1177         sleep $i
1178 done
1179 if test $RC != 0 ; then
1180         echo "ldapsearch failed ($RC)!"
1181         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1182         exit $RC
1183 fi
1184
1185 echo "Using ldapsearch to check that site2 search received changes..."
1186 RC=32
1187 for i in 1 2 3 4 5; do
1188         RESULT=`$LDAPSEARCH -H $URI6 \
1189                 -s base -b "$BASEDN" \
1190                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
1191         if test "x$RESULT$nullOK" = "xOK" ; then
1192                 RC=0
1193                 break
1194         fi
1195         echo "Waiting $i seconds for syncrepl to receive changes..."
1196         sleep $i
1197 done
1198 if test $RC != 0 ; then
1199         echo "ldapsearch failed ($RC)!"
1200         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1201         exit $RC
1202 fi
1203
1204 # Create a script that will check the contextCSN values of all servers,
1205 # and restart them to re-synchronize if it finds any errors:
1206 cat > $TESTDIR/checkcsn.sh <<'EOF'
1207 #!/bin/sh
1208
1209 CSN_ERRORS=0
1210
1211 CSN1=`$LDAPSEARCH -H $URI1 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1212 CSN2=`$LDAPSEARCH -H $URI2 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1213 CSN3=`$LDAPSEARCH -H $URI3 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1214 CSN4=`$LDAPSEARCH -H $URI4 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1215 CSN5=`$LDAPSEARCH -H $URI5 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1216 CSN6=`$LDAPSEARCH -H $URI6 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1217
1218 if test -z "$CSN1" ; then
1219         echo "ERROR: contextCSN empty on central master"
1220         CSN_ERRORS=`expr $CSN_ERRORS + 1`
1221 fi
1222 nCSN=`echo "$CSN1" | wc -l`
1223 if test "$nCSN" -ne 3 ; then
1224         echo "ERROR: Wrong contextCSN count on central master, should be 3"
1225         CSN_ERRORS=`expr $CSN_ERRORS + 1`
1226         if test -n "$CSN_VERBOSE"; then
1227                 echo "$CSN1"
1228         fi
1229 fi
1230 if  test -z "$CSN2" -o "$CSN1" != "$CSN2" ; then
1231         echo "ERROR: contextCSN mismatch between central master and site1 master"
1232         CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1233         if test -n "$CSN_VERBOSE"; then
1234                 echo "contextCSN on central master:"
1235                 echo "$CSN1"
1236                 echo "contextCSN on site1 master:"
1237                 echo "$CSN2"
1238         fi
1239 fi
1240 if  test -z "$CSN3" -o "$CSN1" != "$CSN3" ; then
1241         echo "ERROR: contextCSN mismatch between central master and site2 master"
1242         CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1243         if test -n "$CSN_VERBOSE"; then
1244                 echo "contextCSN on central master:"
1245                 echo "$CSN1"
1246                 echo "contextCSN on site2 master:"
1247                 echo "$CSN3"
1248         fi
1249 fi
1250 if  test -z "$CSN4" -o "$CSN1" != "$CSN4" ; then
1251         echo "ERROR: contextCSN mismatch between central master and central search"
1252         CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1253         if test -n "$CSN_VERBOSE"; then
1254                 echo "contextCSN on central master:"
1255                 echo "$CSN1"
1256                 echo "contextCSN on central search:"
1257                 echo "$CSN4"
1258         fi
1259 fi
1260 if  test -z "$CSN5" -o "$CSN2" != "$CSN5" ; then
1261         echo "ERROR: contextCSN mismatch between site1 master and site1 search"
1262         CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1263         if test -n "$CSN_VERBOSE"; then
1264                 echo "contextCSN on site1 master:"
1265                 echo "$CSN2"
1266                 echo "contextCSN on site1 search:"
1267                 echo "$CSN5"
1268         fi
1269 fi
1270 if  test -z "$CSN6" -o "$CSN3" != "$CSN6" ; then
1271         echo "ERROR: contextCSN mismatch between site2 master and site2 search:"
1272         CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1273         if test -n "$CSN_VERBOSE"; then
1274                 echo "contextCSN on site2 master:"
1275                 echo "$CSN3"
1276                 echo "contextCSN on site2 search:"
1277                 echo "$CSN6"
1278         fi
1279 fi
1280
1281 if test $CSN_ERRORS != 0 ; then
1282         echo "Stopping all servers to synchronize contextCSN..."
1283         kill -HUP  $KILLPIDS
1284         for pid in $KILLPIDS ; do wait $pid ; done
1285         KILLPIDS=
1286
1287         echo "Restarting site1 master slapd on TCP/IP port $PORT2..."
1288         cd $SM1_DIR
1289         $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
1290         SM1_PID=$!
1291         if test $WAIT != 0 ; then
1292                 echo PID $SM1_PID
1293                 read foo
1294         fi
1295         KILLPIDS="$KILLPIDS $SM1_PID"
1296         cd $TESTWD
1297         sleep 1
1298         echo "Using ldapsearch to check that site1 master is running..."
1299         for i in 1 2 3 4 5; do
1300                 $LDAPSEARCH -s base -b "" -H $URI2 \
1301                         'objectclass=*' > /dev/null 2>&1
1302                 RC=$?
1303                 test $RC = 0 && break
1304                 echo "Waiting $i seconds for slapd to start..."
1305                 sleep $i
1306         done
1307         if test $RC != 0 ; then
1308                 echo "ldapsearch failed ($RC)!"
1309                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1310                 exit $RC
1311         fi
1312
1313         echo "Restarting site2 master slapd on TCP/IP port $PORT3..."
1314         cd $SM2_DIR
1315         $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
1316         SM2_PID=$!
1317         if test $WAIT != 0 ; then
1318                 echo PID $SM2_PID
1319                 read foo
1320         fi
1321         KILLPIDS="$KILLPIDS $SM2_PID "
1322         cd $TESTWD
1323         sleep 1
1324         echo "Using ldapsearch to check that site2 master is running..."
1325         for i in 1 2 3 4 5; do
1326                 $LDAPSEARCH -s base -b "" -H $URI3 \
1327                         'objectclass=*' > /dev/null 2>&1
1328                 RC=$?
1329                 test $RC = 0 && break
1330                 echo "Waiting $i seconds for slapd to start..."
1331                 sleep $i
1332         done
1333         if test $RC != 0 ; then
1334                 echo "ldapsearch failed ($RC)!"
1335                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1336                 exit $RC
1337         fi
1338
1339         echo "Restarting central master slapd on TCP/IP port $PORT1..."
1340         cd $SMC_DIR
1341         $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
1342         SMC_PID=$!
1343         if test $WAIT != 0 ; then
1344                 echo PID $SMC_PID
1345                 read foo
1346         fi
1347         KILLPIDS="$KILLPIDS $SMC_PID"
1348         cd $TESTWD
1349         sleep 1
1350         echo "Using ldapsearch to check that central master slapd is running..."
1351         for i in 1 2 3 4 5; do
1352                 $LDAPSEARCH -s base -b "" -H $URI1 \
1353                         'objectclass=*' > /dev/null 2>&1
1354                 RC=$?
1355                 test $RC = 0 && break
1356                 echo "Waiting $i seconds for slapd to start..."
1357                 sleep $i
1358         done
1359         if test $RC != 0 ; then
1360                 echo "ldapsearch failed ($RC)!"
1361                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1362                 exit $RC
1363         fi
1364
1365         echo "Sleeping 5 seconds to allow contextCSN to synchronize..."
1366         sleep 5
1367
1368         echo "Stopping site1 and site2 master..."
1369         kill -HUP  $SM1_PID $SM2_PID
1370         for pid in $SM1_PID $SM2_PID ; do wait $pid ; done
1371         KILLPIDS=" $SMC_PID"
1372
1373         echo "Restarting site1 master slapd on TCP/IP port $PORT2..."
1374         cd $SM1_DIR
1375         $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
1376         SM1_PID=$!
1377         if test $WAIT != 0 ; then
1378                 echo PID $SM1_PID
1379                 read foo
1380         fi
1381         KILLPIDS="$KILLPIDS $SM1_PID"
1382         cd $TESTWD
1383         sleep 1
1384         echo "Using ldapsearch to check that site1 master is running..."
1385         for i in 1 2 3 4 5; do
1386                 $LDAPSEARCH -s base -b "" -H $URI2 \
1387                         'objectclass=*' > /dev/null 2>&1
1388                 RC=$?
1389                 test $RC = 0 && break
1390                 echo "Waiting $i seconds for slapd to start..."
1391                 sleep $i
1392         done
1393         if test $RC != 0 ; then
1394                 echo "ldapsearch failed ($RC)!"
1395                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1396                 exit $RC
1397         fi
1398
1399         echo "Restarting site2 master slapd on TCP/IP port $PORT3..."
1400         cd $SM2_DIR
1401         $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
1402         SM2_PID=$!
1403         if test $WAIT != 0 ; then
1404                 echo PID $SM2_PID
1405                 read foo
1406         fi
1407         KILLPIDS="$KILLPIDS $SM2_PID"
1408         cd $TESTWD
1409         sleep 1
1410         echo "Using ldapsearch to check that site2 master is running..."
1411         for i in 1 2 3 4 5; do
1412                 $LDAPSEARCH -s base -b "" -H $URI3 \
1413                         'objectclass=*' > /dev/null 2>&1
1414                 RC=$?
1415                 test $RC = 0 && break
1416                 echo "Waiting $i seconds for slapd to start..."
1417                 sleep $i
1418         done
1419         if test $RC != 0 ; then
1420                 echo "ldapsearch failed ($RC)!"
1421                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1422                 exit $RC
1423         fi
1424
1425         echo "Sleeping 5 seconds to allow contextCSN to synchronize..."
1426         sleep 5
1427
1428         echo "Restarting central search slapd on TCP/IP port $PORT4..."
1429         cd $SSC_DIR
1430         $SLAPD -F slapd.d -h $URI4 -d $LVL $TIMING >> $LOG4 2>&1 &
1431         SSC_PID=$!
1432         if test $WAIT != 0 ; then
1433                 echo PID $SSC_PID
1434                 read foo
1435         fi
1436         KILLPIDS="$KILLPIDS $SSC_PID"
1437         cd $TESTWD
1438         sleep 1
1439         echo "Using ldapsearch to check that central search slapd is running..."
1440         for i in 1 2 3 4 5; do
1441                 $LDAPSEARCH -s base -b "" -H $URI4 \
1442                         'objectclass=*' > /dev/null 2>&1
1443                 RC=$?
1444                 test $RC = 0 && break
1445                 echo "Waiting $i seconds for slapd to start..."
1446                 sleep $i
1447         done
1448         if test $RC != 0 ; then
1449                 echo "ldapsearch failed ($RC)!"
1450                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1451                 exit $RC
1452         fi
1453
1454         echo "Restarting site1 search slapd on TCP/IP port $PORT5..."
1455         cd $SS1_DIR
1456         $SLAPD -F slapd.d -h $URI5 -d $LVL $TIMING >> $LOG5 2>&1 &
1457         SS1_PID=$!
1458         if test $WAIT != 0 ; then
1459                 echo PID $SS1_PID
1460                 read foo
1461         fi
1462         KILLPIDS="$KILLPIDS $SS1_PID"
1463         cd $TESTWD
1464         sleep 1
1465         echo "Using ldapsearch to check that site1 search slapd is running..."
1466         for i in 1 2 3 4 5; do
1467                 $LDAPSEARCH -s base -b "" -H $URI5 \
1468                         'objectclass=*' > /dev/null 2>&1
1469                 RC=$?
1470                 test $RC = 0 && break
1471                 echo "Waiting $i seconds for slapd to start..."
1472                 sleep $i
1473         done
1474         if test $RC != 0 ; then
1475                 echo "ldapsearch failed ($RC)!"
1476                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1477                 exit $RC
1478         fi
1479
1480         echo "Restarting site2 search slapd on TCP/IP port $PORT6..."
1481         cd $SS2_DIR
1482         $SLAPD -F slapd.d -h $URI6 -d $LVL $TIMING >> $LOG6 2>&1 &
1483         SS2_PID=$!
1484         if test $WAIT != 0 ; then
1485                 echo PID $SS2_PID
1486                 read foo
1487         fi
1488         KILLPIDS="$KILLPIDS $SS2_PID"
1489         cd $TESTWD
1490         sleep 1
1491         echo "Using ldapsearch to check that site2 search slapd is running..."
1492         for i in 1 2 3 4 5; do
1493                 $LDAPSEARCH -s base -b "" -H $URI6 \
1494                         'objectclass=*' > /dev/null 2>&1
1495                 RC=$?
1496                 test $RC = 0 && break
1497                 echo "Waiting $i seconds for slapd to start..."
1498                 sleep $i
1499         done
1500         if test $RC != 0 ; then
1501                 echo "ldapsearch failed ($RC)!"
1502                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1503                 exit $RC
1504         fi
1505
1506         echo "Sleeping 5 seconds to allow contextCSN to synchronize..."
1507         sleep 5
1508
1509         echo "Checking contextCSN after restart..."
1510         CSN1=`$LDAPSEARCH -H $URI1 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1511         CSN2=`$LDAPSEARCH -H $URI2 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1512         CSN3=`$LDAPSEARCH -H $URI3 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1513         CSN4=`$LDAPSEARCH -H $URI4 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1514         CSN5=`$LDAPSEARCH -H $URI5 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1515         CSN6=`$LDAPSEARCH -H $URI6 -b $BASEDN -s base contextCSN | grep contextCSN | sort`
1516         if test -z "$CSN1" ; then
1517                 echo "ERROR: contextCSN empty on central master"
1518                 CSN_ERRORS=`expr $CSN_ERRORS + 1`
1519         fi
1520
1521         if  test -z "$CSN2" -o "$CSN1" != "$CSN2" ; then
1522                 echo "ERROR: contextCSN mismatch between central master and site1 master"
1523                 CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1524                 if test -n "$CSN_VERBOSE"; then
1525                         echo "contextCSN on central master:"
1526                         echo "$CSN1"
1527                         echo "contextCSN on site1 master:"
1528                         echo "$CSN2"
1529                 fi
1530         fi
1531         if  test -z "$CSN3" -o "$CSN1" != "$CSN3" ; then
1532                 echo "ERROR: contextCSN mismatch between central master and site2 master"
1533                 CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1534                 if test -n "$CSN_VERBOSE"; then
1535                         echo "contextCSN on central master:"
1536                         echo "$CSN1"
1537                         echo "contextCSN on site2 master:"
1538                         echo "$CSN3"
1539                 fi
1540         fi
1541         if  test -z "$CSN4" -o "$CSN1" != "$CSN4" ; then
1542                 echo "ERROR: contextCSN mismatch between central master and central search"
1543                 CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1544                 if test -n "$CSN_VERBOSE"; then
1545                         echo "contextCSN on central master:"
1546                         echo "$CSN1"
1547                         echo "contextCSN on central search:"
1548                         echo "$CSN4"
1549                 fi
1550         fi
1551         if  test -z "$CSN5" -o "$CSN2" != "$CSN5" ; then
1552                 echo "ERROR: contextCSN mismatch between site1 master and site1 search"
1553                 CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1554                 if test -n "$CSN_VERBOSE"; then
1555                         echo "contextCSN on site1 master:"
1556                         echo "$CSN2"
1557                         echo "contextCSN on site1 search:"
1558                         echo "$CSN5"
1559                 fi
1560         fi
1561         if  test -z "$CSN6" -o "$CSN3" != "$CSN6" ; then
1562                 echo "ERROR: contextCSN mismatch between site2 master and site2 search:"
1563                 CSN_ERRORS=`expr $CSN_ERRORS + 1`;
1564                 if test -n "$CSN_VERBOSE"; then
1565                         echo "contextCSN on site2 master:"
1566                         echo "$CSN3"
1567                         echo "contextCSN on site2 search:"
1568                         echo "$CSN6"
1569                 fi
1570         fi
1571 fi
1572
1573 ERRORS=`expr $ERRORS + $CSN_ERRORS`
1574
1575 EOF
1576
1577 test $BACKEND = null && echo : > $TESTDIR/checkcsn.sh
1578
1579 chmod +x $TESTDIR/checkcsn.sh
1580
1581
1582 echo "Checking contextCSN after initial replication..."
1583 . $TESTDIR/checkcsn.sh
1584
1585 # TEST:
1586 # Test that updates to the first backend on central master, which should
1587 # be replicated to all servers actually is so, and that the contextCSN is
1588 # updated everywhere:
1589 echo "Using ldapmodify to modify first backend on central master..."
1590 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1591 dn: ou=ou1,dc=example,dc=com
1592 changetype: modify
1593 add: description
1594 description: Modify$MNUM
1595
1596 EOF
1597 RC=$?
1598 if test $RC != 0 ; then
1599         echo "ldapmodify failed ($RC)!"
1600         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1601         exit $RC
1602 fi
1603 sleep 1
1604
1605 echo "Using ldapsearch to check replication to central search..."
1606 RC=32
1607 for i in 1 2 3 4 5; do
1608         RESULT=`$LDAPSEARCH -H $URI4 \
1609                 -s base -b "ou=ou1,$BASEDN" \
1610                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1611         if test "x$RESULT$nullOK" = "xOK" ; then
1612                 RC=0
1613                 break
1614         fi
1615         echo "Waiting $i seconds for syncrepl to receive changes..."
1616         sleep $i
1617 done
1618 if test $RC != 0 ; then
1619         echo "ldapsearch failed ($RC)!"
1620         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1621         exit $RC
1622 fi
1623
1624 echo "Using ldapsearch to check replication to site1 search..."
1625 RC=32
1626 for i in 1 2 3 4 5; do
1627         RESULT=`$LDAPSEARCH -H $URI5 \
1628                 -s base -b "ou=ou1,$BASEDN" \
1629                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1630         if test "x$RESULT$nullOK" = "xOK" ; then
1631                 RC=0
1632                 break
1633         fi
1634         echo "Waiting $i seconds for syncrepl to receive changes..."
1635         sleep $i
1636 done
1637 if test $RC != 0 ; then
1638         echo "ldapsearch failed ($RC)!"
1639         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1640         exit $RC
1641 fi
1642
1643 echo "Using ldapsearch to check replication to site2 search..."
1644 RC=32
1645 for i in 1 2 3 4 5; do
1646         RESULT=`$LDAPSEARCH -H $URI6 \
1647                 -s base -b "ou=ou1,$BASEDN" \
1648                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1649         if test "x$RESULT$nullOK" = "xOK" ; then
1650                 RC=0
1651                 break
1652         fi
1653         echo "Waiting $i seconds for syncrepl to receive changes..."
1654         sleep $i
1655 done
1656 if test $RC != 0 ; then
1657         echo "ldapsearch failed ($RC)!"
1658         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1659         exit $RC
1660 fi
1661
1662 echo "Checking contextCSN after modify of first backend on central master..."
1663 . $TESTDIR/checkcsn.sh
1664
1665 # TEST:
1666 # Test that updates to the second backend on central master is only
1667 # replicated to those search servers that should receive that backend.
1668 # The contextCSN should still be updated everywhere:
1669 MNUM=`expr $MNUM + 1`
1670 echo "Using ldapmodify to modify second backend on central master..."
1671 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1672 dn: ou=ou2,dc=example,dc=com
1673 changetype: modify
1674 add: description
1675 description: Modify$MNUM
1676
1677 EOF
1678 RC=$?
1679 if test $RC != 0 ; then
1680         echo "ldapmodify failed ($RC)!"
1681         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1682         exit $RC
1683 fi
1684 sleep 1
1685
1686 echo "Using ldapsearch to check replication to site2 search..."
1687 RC=32
1688 for i in 1 2 3 4 5; do
1689         RESULT=`$LDAPSEARCH -H $URI6 \
1690                 -s base -b "ou=ou2,$BASEDN" \
1691                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1692         if test "x$RESULT$nullOK" = "xOK" ; then
1693                 RC=0
1694                 break
1695         fi
1696         echo "Waiting $i seconds for syncrepl to receive changes..."
1697         sleep $i
1698 done
1699 if test $RC != 0 ; then
1700         echo "ldapsearch failed ($RC)!"
1701         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1702         exit $RC
1703 fi
1704
1705 echo "Using ldapsearch to check no replication to site1 master..."
1706 for i in 1 2 3 4 5; do
1707         RESULT=`$LDAPSEARCH -H $URI2 \
1708                 -s base -b "ou=ou2,$BASEDN" \
1709                 "(description=Modify$NMUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1710         if test "x$RESULT" = "xNOK" ; then
1711                 echo "Change was replicated to site1 search!"
1712                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1713                 exit 1
1714         fi
1715         sleep 1
1716 done
1717
1718 echo "Using ldapsearch to check no replication to central search..."
1719 for i in 1 2 3 4 5; do
1720         RESULT=`$LDAPSEARCH -H $URI4 \
1721                 -s base -b "ou=ou2,$BASEDN" \
1722                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1723         if test "x$RESULT" = "xNOK" ; then
1724                 echo "Change was replicated to central search!"
1725                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1726                 exit 1
1727         fi
1728         sleep 1
1729 done
1730
1731 echo "Checking contextCSN after modify of second backend on central master..."
1732 . $TESTDIR/checkcsn.sh
1733
1734 # TEST:
1735 # Test that updates to the first backend on site1 master, which should be
1736 # replicated everywhere except to central and site2 search.  The contextCSN
1737 # should be updated on all servers:
1738 MNUM=`expr $MNUM + 1`
1739 echo "Using ldapmodify to modify first backend on site1 master..."
1740 $LDAPMODIFY -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1741 dn: ou=sm1ou1,dc=example,dc=com
1742 changetype: modify
1743 add: description
1744 description: Modify$MNUM
1745
1746 EOF
1747 RC=$?
1748 if test $RC != 0 ; then
1749         echo "ldapmodify failed ($RC)!"
1750         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1751         exit $RC
1752 fi
1753 sleep 1
1754
1755 echo "Using ldapsearch to check replication to site1 search..."
1756 RC=32
1757 for i in 1 2 3 4 5; do
1758         RESULT=`$LDAPSEARCH -H $URI5 \
1759                 -s base -b "ou=sm1ou1,$BASEDN" \
1760                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1761         if test "x$RESULT$nullOK" = "xOK" ; then
1762                 RC=0
1763                 break
1764         fi
1765         echo "Waiting $i seconds for syncrepl to receive changes..."
1766         sleep $i
1767 done
1768 if test $RC != 0 ; then
1769         echo "ldapsearch failed ($RC)!"
1770         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1771         exit $RC
1772 fi
1773
1774 echo "Using ldapsearch to check replication to site2 master..."
1775 RC=32
1776 for i in 1 2 3 4 5; do
1777         RESULT=`$LDAPSEARCH -H $URI3 \
1778                 -s base -b "ou=sm1ou1,$BASEDN" \
1779                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1780         if test "x$RESULT$nullOK" = "xOK" ; then
1781                 RC=0
1782                 break
1783         fi
1784         echo "Waiting $i seconds for syncrepl to receive changes..."
1785         sleep $i
1786 done
1787 if test $RC != 0 ; then
1788         echo "ldapsearch failed ($RC)!"
1789         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1790         exit $RC
1791 fi
1792
1793 echo "Using ldapsearch to check no replication to site2 search..."
1794 for i in 1 2 3 4 5; do
1795         RESULT=`$LDAPSEARCH -H $URI6 \
1796                 -s base -b "ou=sm1ou2,$BASEDN" \
1797                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1798         if test "x$RESULT" = "xNOK" ; then
1799                 echo "Change was replicated to central search!"
1800                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1801                 exit 1
1802         fi
1803         sleep 1
1804 done
1805
1806 echo "Using ldapsearch to check no replication to central search..."
1807 for i in 1 2 3 4 5; do
1808         RESULT=`$LDAPSEARCH -H $URI4 \
1809                 -s base -b "ou=sm1ou2,$BASEDN" \
1810                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1811         if test "x$RESULT" = "xNOK" ; then
1812                 echo "Change was replicated to central search!"
1813                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1814                 exit 1
1815         fi
1816         sleep 1
1817 done
1818
1819 echo "Checking contextCSN after modify of first backend on site1 master..."
1820 . $TESTDIR/checkcsn.sh
1821
1822
1823 # TEST:
1824 # Test updates to the second backend on site1 master, which should only be
1825 # replicated to site1 search.  The contextCSN should be updated everywhere.
1826 MNUM=`expr $MNUM + 1`
1827 echo "Using ldapmodify to modify second backend on site1 master..."
1828 $LDAPMODIFY -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1829 dn: ou=sm1ou2,dc=example,dc=com
1830 changetype: modify
1831 add: description
1832 description: Modify$MNUM
1833
1834 EOF
1835 RC=$?
1836 if test $RC != 0 ; then
1837         echo "ldapmodify failed ($RC)!"
1838         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1839         exit $RC
1840 fi
1841 sleep 1
1842
1843
1844 echo "Using ldapsearch to check replication to site1 search..."
1845 RC=32
1846 for i in 1 2 3 4 5; do
1847         RESULT=`$LDAPSEARCH -H $URI5 \
1848                 -s base -b "ou=sm1ou2,$BASEDN" \
1849                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1850         if test "x$RESULT$nullOK" = "xOK" ; then
1851                 RC=0
1852                 break
1853         fi
1854         echo "Waiting $i seconds for syncrepl to receive changes..."
1855         sleep $i
1856 done
1857 if test $RC != 0 ; then
1858         echo "ldapsearch failed ($RC)!"
1859         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1860         exit $RC
1861 fi
1862
1863 echo "Using ldapsearch to check no replication to central master..."
1864 for i in 1 2 3 4 5; do
1865         RESULT=`$LDAPSEARCH -H $URI1 \
1866                 -s base -b "ou=sm1ou2,$BASEDN" \
1867                 "(description=Modify$NMUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1868         if test "x$RESULT" = "xNOK" ; then
1869                 echo "Change was replicated to site2 search!"
1870                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1871                 exit 1
1872         fi
1873         sleep 1
1874 done
1875
1876 echo "Checking contextCSN after modify of second backend on site1 master..."
1877 . $TESTDIR/checkcsn.sh
1878
1879
1880 # TEST:
1881 # Test updates to first backend on site2 master, which should be
1882 # replicated to the central servers, but not site1.  The contextCSN
1883 # should be updated everywhere:
1884 MNUM=`expr $MNUM + 1`
1885 echo "Using ldapmodify to modify first backend on site2 master..."
1886 $LDAPMODIFY -D "ou=sm2ou1,$BASEDN" -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1887 dn: ou=sm2ou1,dc=example,dc=com
1888 changetype: modify
1889 add: description
1890 description: Modify$MNUM
1891
1892 EOF
1893 RC=$?
1894 if test $RC != 0 ; then
1895         echo "ldapmodify failed ($RC)!"
1896         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1897         exit $RC
1898 fi
1899 sleep 1
1900
1901 echo "Using ldapsearch to check replication to central master..."
1902 RC=32
1903 for i in 1 2 3 4 5; do
1904         RESULT=`$LDAPSEARCH -H $URI1 \
1905                 -s base -b "ou=sm2ou1,$BASEDN" \
1906                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1907         if test "x$RESULT$nullOK" = "xOK" ; then
1908                 RC=0
1909                 break
1910         fi
1911         echo "Waiting $i seconds for syncrepl to receive changes..."
1912         sleep $i
1913 done
1914 if test $RC != 0 ; then
1915         echo "ldapsearch failed ($RC)!"
1916         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1917         exit $RC
1918 fi
1919
1920 echo "Using ldapsearch to check replication to site2 search..."
1921 RC=32
1922 for i in 1 2 3 4 5; do
1923         RESULT=`$LDAPSEARCH -H $URI6 \
1924                 -s base -b "ou=sm2ou1,$BASEDN" \
1925                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1926         if test "x$RESULT$nullOK" = "xOK" ; then
1927                 RC=0
1928                 break
1929         fi
1930         echo "Waiting $i seconds for syncrepl to receive changes..."
1931         sleep $i
1932 done
1933 if test $RC != 0 ; then
1934         echo "ldapsearch failed ($RC)!"
1935         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1936         exit $RC
1937 fi
1938
1939 echo "Using ldapsearch to check no replication to site1 master..."
1940 for i in 1 2 3 4 5; do
1941         RESULT=`$LDAPSEARCH -H $URI2 \
1942                 -s base -b "ou=sm2ou1,$BASEDN" \
1943                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1944         if test "x$RESULT" = "xNOK" ; then
1945                 echo "Change was replicated to site2 search!"
1946                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1947                 exit 1
1948         fi
1949         sleep 1
1950 done
1951
1952 echo "Using ldapsearch to check no replication to central search..."
1953 for i in 1 2 3 4 5; do
1954         RESULT=`$LDAPSEARCH -H $URI4 \
1955                 -s base -b "ou=sm2ou1,$BASEDN" \
1956                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
1957         if test "x$RESULT" = "xNOK" ; then
1958                 echo "Change was replicated to site2 search!"
1959                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
1960                 exit 1
1961         fi
1962         sleep 1
1963 done
1964
1965 echo "Checking contextCSN after modify of first backend on site2 master..."
1966 . $TESTDIR/checkcsn.sh
1967
1968
1969 # TEST:
1970 # Test updates to the second backend on site2 master, which should only be
1971 # replicated to site2 search.  As always, contextCSN should be updated
1972 # everywhere:
1973 MNUM=`expr $MNUM + 1`
1974 echo "Using ldapmodify to modify second backend on site2 master..."
1975 $LDAPMODIFY -D "ou=sm2ou1,$BASEDN" -H $URI3 -w $PASSWD <<EOF >> $TESTOUT 2>&1
1976 dn: ou=sm2ou2,dc=example,dc=com
1977 changetype: modify
1978 add: description
1979 description: Modify$MNUM
1980
1981 EOF
1982 RC=$?
1983 if test $RC != 0 ; then
1984         echo "ldapmodify failed ($RC)!"
1985         test $KILLSERVERS != no && kill -HUP $KILLPIDS
1986         exit $RC
1987 fi
1988 sleep 1
1989
1990 echo "Using ldapsearch to check replication to site2 search..."
1991 RC=32
1992 for i in 1 2 3 4 5; do
1993         RESULT=`$LDAPSEARCH -H $URI6 \
1994                 -s base -b "ou=sm2ou2,$BASEDN" \
1995                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "OK"}'`
1996         if test "x$RESULT$nullOK" = "xOK" ; then
1997                 RC=0
1998                 break
1999         fi
2000         echo "Waiting $i seconds for syncrepl to receive changes..."
2001         sleep $i
2002 done
2003 if test $RC != 0 ; then
2004         echo "ldapsearch failed ($RC)!"
2005         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2006         exit $RC
2007 fi
2008
2009 echo "Using ldapsearch to check no replication to central master..."
2010 for i in 1 2 3 4 5; do
2011         RESULT=`$LDAPSEARCH -H $URI4 \
2012                 -s base -b "ou=sm2ou2,$BASEDN" \
2013                 "(description=Modify$MNUM)" 2>&1 | awk '/^dn:/ {print "NOK"}'`
2014         if test "x$RESULT" = "xNOK" ; then
2015                 echo "Change was replicated to central search!"
2016                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2017                 exit 1
2018         fi
2019         sleep 1
2020 done
2021
2022 echo "Checking contextCSN after modify of second backend on site2 master..."
2023 . $TESTDIR/checkcsn.sh
2024
2025 # TEST:
2026 # Test that all contextCSN values are updated on the slaves when they
2027 # starts with an empty database.  Start site2 master first, then site2
2028 # search and finally central master so that the site2 search's syncrepl
2029 # connection has been set up when site2 master receives the database:
2030 echo "Stopping central master and site2 servers to test start with empty db..."
2031 kill -HUP  $SMC_PID $SM2_PID $SS2_PID
2032 for pid in $SMC_PID $SM2_PID $SS2_PID; do wait $pid ; done
2033 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
2034 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SM2_PID / /"`;
2035 KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SS2_PID / /"`;
2036 SMC_PID=
2037 SM2_PID=
2038 SS2_PID=
2039 rm -rf $SM2_DIR/db/*
2040 rm -rf $SS2_DIR/db/*
2041
2042 echo "Starting site2 master slapd on TCP/IP port $PORT3..."
2043 cd $SM2_DIR
2044 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
2045 SM2_PID=$!
2046 if test $WAIT != 0 ; then
2047         echo PID $SM2_PID
2048         read foo
2049 fi
2050 KILLPIDS="$KILLPIDS $SM2_PID"
2051 cd $TESTWD
2052 sleep 1
2053 echo "Using ldapsearch to check that site2 master slapd is running..."
2054 for i in 1 2 3 4 5; do
2055         $LDAPSEARCH -s base -b "" -H $URI3 \
2056                 'objectclass=*' > /dev/null 2>&1
2057         RC=$?
2058         test $RC = 0 && break
2059         echo "Waiting $i seconds for slapd to start..."
2060         sleep $i
2061 done
2062 if test $RC != 0 ; then
2063         echo "ldapsearch failed ($RC)!"
2064         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2065         exit $RC
2066 fi
2067
2068 echo "Starting site2 search slapd on TCP/IP port $PORT6..."
2069 cd $SS2_DIR
2070 $SLAPD -F slapd.d -h $URI6 -d $LVL $TIMING >> $LOG6 2>&1 &
2071 SS2_PID=$!
2072 if test $WAIT != 0 ; then
2073         echo PID $SS2_PID
2074         read foo
2075 fi
2076 KILLPIDS="$KILLPIDS $SS2_PID"
2077 cd $TESTWD
2078 sleep 1
2079 echo "Using ldapsearch to check that site2 search slapd is running..."
2080 for i in 1 2 3 4 5; do
2081         $LDAPSEARCH -s base -b "" -H $URI6 \
2082                 'objectclass=*' > /dev/null 2>&1
2083         RC=$?
2084         test $RC = 0 && break
2085         echo "Waiting $i seconds for slapd to start..."
2086         sleep $i
2087 done
2088 if test $RC != 0 ; then
2089         echo "ldapsearch failed ($RC)!"
2090         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2091         exit $RC
2092 fi
2093
2094 echo "Starting central master slapd on TCP/IP port $PORT1..."
2095 cd $SMC_DIR
2096 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
2097 SMC_PID=$!
2098 if test $WAIT != 0 ; then
2099         echo PID $SMC_PID
2100         read foo
2101 fi
2102 KILLPIDS="$KILLPIDS $SMC_PID"
2103 cd $TESTWD
2104 sleep 1
2105 echo "Using ldapsearch to check that central master slapd is running..."
2106 for i in 1 2 3 4 5; do
2107         $LDAPSEARCH -s base -b "" -H $URI1 \
2108                 'objectclass=*' > /dev/null 2>&1
2109         RC=$?
2110         test $RC = 0 && break
2111         echo "Waiting $i seconds for slapd to start..."
2112         sleep $i
2113 done
2114 if test $RC != 0 ; then
2115         echo "ldapsearch failed ($RC)!"
2116         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2117         exit $RC
2118 fi
2119
2120 echo "Using ldapsearch to check that site2 master received base..."
2121 RC=32
2122 for i in 1 2 3 4 5; do
2123         RESULT=`$LDAPSEARCH -H $URI3 \
2124                 -s base -b "$BASEDN" \
2125                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2126         if test "x$RESULT$nullOK" = "xOK" ; then
2127                 RC=0
2128                 break
2129         fi
2130         echo "Waiting $i seconds for syncrepl to receive changes..."
2131         sleep $i
2132 done
2133 if test $RC != 0 ; then
2134         echo "ldapsearch failed ($RC)!"
2135         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2136         exit $RC
2137 fi
2138
2139 echo "Using ldapsearch to check that site2 search received base..."
2140 RC=32
2141 for i in 1 2 3 4 5; do
2142         RESULT=`$LDAPSEARCH -H $URI6 \
2143                 -s base -b "$BASEDN" \
2144                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2145         if test "x$RESULT$nullOK" = "xOK" ; then
2146                 RC=0
2147                 break
2148         fi
2149         echo "Waiting $i seconds for syncrepl to receive changes..."
2150         sleep $i
2151 done
2152 if test $RC != 0 ; then
2153         echo "ldapsearch failed ($RC)!"
2154         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2155         exit $RC
2156 fi
2157
2158 sleep $SLEEP1
2159
2160 echo "Checking contextCSN after site2 servers repopulated..."
2161 . $TESTDIR/checkcsn.sh
2162
2163 if test $ERRORS -ne 0; then
2164         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2165         echo "Found $ERRORS errors"
2166         exit $ERRORS
2167 fi
2168
2169 # TEST:
2170 # Adding syncrepl of the second site1 master backend on central master
2171 # will not initialize the database unless the contextCSN attribute is
2172 # stored in the suffix of the database and not the suffix of the glue
2173 # database:
2174 echo "Adding syncrepl of second site1 master backend on central master..."
2175 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
2176 dn: olcDatabase={4}$BACKEND,cn=config
2177 changetype: modify
2178 add: olcSyncRepl
2179 olcSyncRepl: rid=4 provider=$URI2 searchbase="ou=sm1ou2,$BASEDN"
2180   binddn="ou=sm1ou1,$BASEDN" bindmethod=simple credentials=$PASSWD
2181   type=refreshAndPersist retry="$RETRY" timeout=1
2182 EOF
2183 RC=$?
2184 if test $RC != 0 ; then
2185         echo "ldapmodify failed to add syncrepl on central master ($RC)!"
2186         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2187         exit $RC
2188 fi
2189 sleep 1
2190
2191 echo "Using ldapsearch to check that central master received second site1 backend..."
2192 RC=32
2193 for i in 1 2 3 4 5; do
2194         RESULT=`$LDAPSEARCH -H $URI1 \
2195                 -s base -b "ou=sm1ou2,$BASEDN" \
2196                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2197         if test "x$RESULT$nullOK" = "xOK" ; then
2198                 RC=0
2199                 break
2200         fi
2201         echo "Waiting $i seconds for syncrepl to receive changes..."
2202         sleep $i
2203 done
2204 if test $RC != 0 ; then
2205         echo "ERROR: Second site1 backend not replicated to central master"
2206         ERRORS=`expr $ERRORS + 1`
2207
2208         echo "Restarting central master slapd on TCP/IP port $PORT1..."
2209         kill -HUP $SMC_PID
2210         wait $SMC_PID
2211         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
2212
2213         cd $SMC_DIR
2214         $SLAPD -F slapd.d -h $URI1 -c rid=4,csn=0 -d $LVL $TIMING >> $LOG1 2>&1 &
2215         SMC_PID=$!
2216         if test $WAIT != 0 ; then
2217                 echo PID $SMC_PID
2218                 read foo
2219         fi
2220         KILLPIDS="$KILLPIDS $SMC_PID"
2221         cd $TESTWD
2222         echo "Using ldapsearch to check that central master slapd is running..."
2223         for i in 1 2 3 4 5; do
2224                 $LDAPSEARCH -s base -b "" -H $URI1 \
2225                         'objectclass=*' > /dev/null 2>&1
2226                 RC=$?
2227                 test $RC = 0 && break
2228                 echo "Waiting $i seconds for slapd to start..."
2229                 sleep $i
2230         done
2231         if test $RC != 0 ; then
2232                 echo "ldapsearch failed ($RC)!"
2233                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2234                 exit $RC
2235         fi
2236
2237         echo "Using ldapsearch to check that central master received second site1 backend..."
2238         RC=32
2239         for i in 1 2 3 4 5; do
2240                 RESULT=`$LDAPSEARCH -H $URI1 \
2241                         -s base -b "ou=sm1ou2,$BASEDN" \
2242                         '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2243                 if test "x$RESULT$nullOK" = "xOK" ; then
2244                         RC=0
2245                         break
2246                 fi
2247                 echo "Waiting $i seconds for syncrepl to receive changes..."
2248                 sleep $i
2249         done
2250         if test $RC != 0 ; then
2251                 echo "ldapsearch failed ($RC)!"
2252                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2253                 exit $RC
2254         fi
2255 fi
2256
2257 echo "Using ldapsearch to check that central search received second site1 backend..."
2258 RC=32
2259 for i in 1 2 3 4 5; do
2260         RESULT=`$LDAPSEARCH -H $URI4 \
2261                 -s base -b "ou=sm1ou2,$BASEDN" \
2262                 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2263         if test "x$RESULT$nullOK" = "xOK" ; then
2264                 RC=0
2265                 break
2266         fi
2267         echo "Waiting $i seconds for syncrepl to receive changes..."
2268         sleep $i
2269 done
2270 if test $RC != 0 ; then
2271         echo "ERROR: Second site1 backend not replicated to central search"
2272         ERRORS=`expr $ERRORS + 1`
2273
2274         echo "Restarting central search slapd on TCP/IP port $PORT4..."
2275         kill -HUP $SSC_PID
2276         wait $SSC_PID
2277         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SSC_PID / /"`;
2278
2279         cd $SSC_DIR
2280         $SLAPD -F slapd.d -h $URI4 -c rid=1,csn=0 -d $LVL $TIMING >> $LOG4 2>&1 &
2281         SSC_PID=$!
2282         if test $WAIT != 0 ; then
2283                 echo PID $SSC_PID
2284                 read foo
2285         fi
2286         KILLPIDS="$KILLPIDS $SSC_PID"
2287         cd $TESTWD
2288         echo "Using ldapsearch to check that central search slapd is running..."
2289         for i in 1 2 3 4 5; do
2290                 $LDAPSEARCH -s base -b "" -H $URI4 \
2291                         'objectclass=*' > /dev/null 2>&1
2292                 RC=$?
2293                 test $RC = 0 && break
2294                 echo "Waiting $i seconds for slapd to start..."
2295                 sleep $i
2296         done
2297         if test $RC != 0 ; then
2298                 echo "ldapsearch failed ($RC)!"
2299                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2300                 exit $RC
2301         fi
2302
2303         echo "Using ldapsearch to check that central search received second site1 backend..."
2304         RC=32
2305         for i in 1 2 3 4 5; do
2306                 RESULT=`$LDAPSEARCH -H $URI4 \
2307                         -s base -b "ou=sm1ou2,$BASEDN" \
2308                         '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
2309                 if test "x$RESULT$nullOK" = "xOK" ; then
2310                         RC=0
2311                         break
2312                 fi
2313                 echo "Waiting $i seconds for syncrepl to receive changes..."
2314                 sleep $i
2315         done
2316         if test $RC != 0 ; then
2317                 echo "ldapsearch failed ($RC)!"
2318                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2319                 exit $RC
2320         fi
2321 fi
2322
2323
2324 # TEST:
2325 # Run race tests when more than one backend is replicated from the same
2326 # provider.  This will usually fail long before 100 iterations unless
2327 # syncrepl stores the contextCSN in the suffix of its own database, and
2328 # that syncprov follows these rules before updating its own CSN when it
2329 # detects updates from syncrepl:
2330 # 1) A contextCSN value must have been stored in the suffix of all the
2331 #        syncrepl configured databases within the glued syncprov database.
2332 # 2) Of all contextCSN values stored by syncrepl with the same SID,
2333 #        syncprov must always select the one with the lowest csn value.
2334 test -z "$RACE_TESTS" && RACE_TESTS=10
2335 RACE_NUM=0
2336 RACE_ERROR=0
2337
2338 SUB_DN=ou=sub,ou=sm1ou2,dc=example,dc=com
2339
2340 while test $RACE_ERROR -eq 0 -a $RACE_NUM -lt $RACE_TESTS ; do
2341         RACE_NUM=`expr $RACE_NUM + 1`
2342         echo "Running $RACE_NUM of $RACE_TESTS syncrepl race tests..."
2343
2344         echo "Stopping central master..."
2345         kill -HUP $SMC_PID
2346         wait $SMC_PID
2347         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
2348
2349         MNUM=`expr $MNUM + 1`
2350         echo "Using ldapadd to add entry on site1 master..."
2351         $LDAPADD -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
2352 dn: $SUB_DN
2353 objectClass: top
2354 objectClass: organizationalUnit
2355 ou: sub
2356
2357 EOF
2358         RC=$?
2359         if test $RC != 0 ; then
2360                 echo "ldapadd failed ($RC)!"
2361                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2362                 exit $RC
2363         fi
2364
2365         echo "Starting central master again..."
2366         cd $SMC_DIR
2367         $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
2368         SMC_PID=$!
2369         KILLPIDS="$KILLPIDS $SMC_PID"
2370         cd $TESTWD
2371         echo "Using ldapsearch to check that central master received entry..."
2372         for i in 1 2 3 4 5; do
2373                 $LDAPSEARCH -s base -b "$SUB_DN"  -H $URI1 > /dev/null 2>&1
2374                 RC=$?
2375                 test $RC = 0 && break
2376                 sleep $i
2377         done
2378         if test $RC != 0 ; then
2379                 echo "ERROR: entry not replicated to central master!"
2380                 RACE_ERROR=1
2381                 break
2382         fi
2383
2384         echo "Using ldapsearch to check that central search received entry..."
2385         for i in 1 2 3 4 5; do
2386                 $LDAPSEARCH -s base -b "$SUB_DN"  -H $URI4 > /dev/null 2>&1
2387                 RC=$?
2388                 test $RC = 0 && break
2389                 sleep $i
2390         done
2391         if test $RC != 0 ; then
2392                 echo "ERROR: entry not replicated to central master!"
2393                 RACE_ERROR=1
2394                 break
2395         fi
2396
2397         echo "Stopping central master..."
2398         kill -HUP $SMC_PID
2399         wait $SMC_PID
2400         KILLPIDS=`echo "$KILLPIDS " | sed -e "s/ $SMC_PID / /"`;
2401
2402         echo "Using ldapdelete to delete entry on site1 master..."
2403         $LDAPDELETE -D "ou=sm1ou1,$BASEDN" -H $URI2 -w $PASSWD "$SUB_DN"
2404         RC=$?
2405         if test $RC != 0 ; then
2406                 echo "ldapdelete failed ($RC)!"
2407                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2408                 exit $RC
2409         fi
2410
2411         echo "Starting central master again..."
2412         cd $SMC_DIR
2413         $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
2414         SMC_PID=$!
2415         KILLPIDS="$KILLPIDS $SMC_PID"
2416         cd $TESTWD
2417
2418         echo "Using ldapsearch to check that entry was deleted on central master..."
2419         RC=0
2420         for i in 1 2 3 4 5; do
2421                 $LDAPSEARCH -s base -b "$SUB_DN" -H $URI1 > /dev/null 2>&1
2422                 RC=$?
2423                 if test $RC = $wantNoObj; then break; fi
2424                 sleep $i
2425         done
2426
2427         if test $RC != $wantNoObj; then
2428                 if test $RC != 0; then
2429                         echo "ldapsearch failed ($RC)!"
2430                         test $KILLSERVERS != no && kill -HUP $KILLPIDS
2431                         exit $RC
2432                 fi
2433                 echo "ERROR: Entry not removed on central master!"
2434                 RACE_ERROR=1
2435                 break
2436         fi
2437
2438         echo "Using ldapsearch to check that entry was deleted on central search..."
2439         RC=0
2440         for i in 1 2 3 4 5; do
2441                 $LDAPSEARCH -s base -b "$SUB_DN" -H $URI4 > /dev/null 2>&1
2442                 RC=$?
2443                 if test $RC != 0; then break; fi
2444                 sleep $i
2445         done
2446
2447         if test $RC != $wantNoObj; then
2448                 echo "ERROR: Entry not removed on central search! (RC=$RC)"
2449                 RACE_ERROR=1
2450                 break
2451         fi
2452 done
2453
2454 if test $RACE_ERROR != 0; then
2455         echo "Race error found after $RACE_NUM of $RACE_TESTS iterations"
2456         ERRORS=`expr $ERRORS + $RACE_ERROR`
2457 else
2458         echo "No race errors found after $RACE_TESTS iterations"
2459 fi
2460
2461 test $KILLSERVERS != no && kill -HUP $KILLPIDS
2462
2463 if test $ERRORS -ne 0; then
2464         echo "Found $ERRORS errors"
2465         echo ">>>>>> Exiting with a false success status for now"
2466         exit 0
2467 fi
2468
2469 echo ">>>>> Test succeeded"
2470
2471 exit 0