3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2017 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 $BACKLDAP = ldapno; then
20 echo "LDAP backend not available, test skipped"
24 if test $SYNCPROV = syncprovno; then
25 echo "Syncrepl provider overlay not available, test skipped"
29 if test $MONITORDB = no; then
30 echo "Monitor backend not available, test skipped"
34 if test $THREADS = threadsno ; then
35 echo "Need threads support, test skipped"
39 mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $DBDIR3
45 # - populate over ldap
46 # - perform some modifies and deleted
47 # - attempt to modify the slave (referral or chain)
48 # - retrieve database over ldap and compare against expected results
51 echo "Starting master slapd on TCP/IP port $PORT1..."
52 . $CONFFILTER $BACKEND $MONITORDB < $PLSRMASTERCONF > $CONF1
53 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
55 if test $WAIT != 0 ; then
56 echo MASTERPID $MASTERPID
63 echo "Using ldapsearch to check that master slapd is running..."
64 for i in 0 1 2 3 4 5; do
65 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
66 '(objectClass=*)' > /dev/null 2>&1
68 if test $RC = 0 ; then
71 echo "Waiting 5 seconds for slapd to start..."
75 if test $RC != 0 ; then
76 echo "ldapsearch failed ($RC)!"
77 test $KILLSERVERS != no && kill -HUP $KILLPIDS
81 echo "Using ldapadd to create the context prefix entry in the master..."
82 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
83 $LDIFORDEREDCP > /dev/null 2>&1
85 if test $RC != 0 ; then
86 echo "ldapadd failed ($RC)!"
87 test $KILLSERVERS != no && kill -HUP $KILLPIDS
91 echo "Starting P1 slave slapd on TCP/IP port $PORT2..."
92 . $CONFFILTER $BACKEND $MONITORDB < $RSLAVECONF > $CONF2
93 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
95 if test $WAIT != 0 ; then
96 echo P1SLAVEPID $P1SLAVEPID
99 KILLPIDS="$MASTERPID $P1SLAVEPID"
103 echo "Using ldapsearch to check that P1 slave slapd is running..."
104 for i in 0 1 2 3 4 5; do
105 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
106 '(objectClass=*)' > /dev/null 2>&1
108 if test $RC = 0 ; then
111 echo "Waiting 5 seconds for slapd to start..."
115 if test $RC != 0 ; then
116 echo "ldapsearch failed ($RC)!"
117 test $KILLSERVERS != no && kill -HUP $KILLPIDS
121 echo "Starting R1 slave slapd on TCP/IP port $PORT3..."
122 . $CONFFILTER $BACKEND $MONITORDB < $RSLAVECONF | sed -e 's;\.2\.\([^/]*\)$;.3.\1;' > $CONF3
123 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
125 if test $WAIT != 0 ; then
126 echo R1SLAVEPID $R1SLAVEPID
129 KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
133 echo "Using ldapsearch to check that R1 slave slapd is running..."
134 for i in 0 1 2 3 4 5; do
135 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
136 '(objectClass=*)' > /dev/null 2>&1
138 if test $RC = 0; then
141 echo "Waiting 5 seconds for slapd to start..."
145 if test $RC != 0 ; then
146 echo "ldapsearch failed ($RC)!"
147 test $KILLSERVERS != no && kill -HUP $KILLPIDS
152 echo "$CHECK > Using ldapadd to populate the master directory..."
153 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
154 $LDIFORDEREDNOCP > /dev/null 2>&1
156 if test $RC != 0 ; then
157 echo "ldapadd failed ($RC)!"
158 test $KILLSERVERS != no && kill -HUP $KILLPIDS
162 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
165 #echo "Using ldapsearch to read all the entries from the master..."
166 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
167 '(objectClass=*)' > "${MASTEROUT}.1" 2>&1
170 if test $RC != 0 ; then
171 echo "ldapsearch failed at master ($RC)!"
172 test $KILLSERVERS != no && kill -HUP $KILLPIDS
176 #echo "Using ldapsearch to read all the entries from the P1 slave..."
177 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
178 '(objectClass=*)' > "${SLAVEOUT}.1" 2>&1
181 if test $RC != 0 ; then
182 echo "ldapsearch failed at P1 slave ($RC)!"
183 test $KILLSERVERS != no && kill -HUP $KILLPIDS
187 #echo "Filtering master results..."
188 $LDIFFILTER < "${MASTEROUT}.1" > $MASTERFLT
189 #echo "Filtering slave results..."
190 $LDIFFILTER < "${SLAVEOUT}.1" > $SLAVEFLT
192 echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
193 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
195 if test $? != 0 ; then
196 echo "test failed - master and P1 slave databases differ"
197 test $KILLSERVERS != no && kill -HUP $KILLPIDS
201 #echo "Using ldapsearch to read all the entries from the R1 slave..."
202 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
203 '(objectClass=*)' > "${SLAVEOUT}.1" 2>&1
206 if test $RC != 0 ; then
207 echo "ldapsearch failed at R1 slave ($RC)!"
208 test $KILLSERVERS != no && kill -HUP $KILLPIDS
212 #echo "Filtering slave results..."
213 $LDIFFILTER < "${SLAVEOUT}.1" > $SLAVEFLT
215 echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
216 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
218 if test $? != 0 ; then
219 echo "test failed - master and R1 slave databases differ"
220 test $KILLSERVERS != no && kill -HUP $KILLPIDS
224 CHECK=`expr $CHECK + 1`
225 echo "$CHECK > Stopping the provider, sleeping $SLEEP2 seconds and restarting it..."
226 kill -HUP "$MASTERPID"
230 echo "======================= RESTART =======================" >> $LOG1
231 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
233 if test $WAIT != 0 ; then
234 echo MASTERPID $MASTERPID
237 KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
241 echo "Using ldapsearch to check that master slapd is running..."
242 for i in 0 1 2 3 4 5; do
243 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
244 '(objectClass=*)' > /dev/null 2>&1
246 if test $RC = 0 ; then
249 echo "Waiting 5 seconds for slapd to start..."
253 if test $RC != 0 ; then
254 echo "ldapsearch failed ($RC)!"
255 test $KILLSERVERS != no && kill -HUP $KILLPIDS
259 echo "Using ldapmodify to modify master directory..."
262 # Do some modifications
265 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
266 $TESTOUT 2>&1 << EOMODS
267 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
278 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
283 dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
286 uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
287 uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
290 uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
291 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
293 dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc
299 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
301 objectclass: OpenLDAPperson
305 title: Chief Investigator, ITD
306 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
307 seealso: cn=All Staff, ou=Groups, dc=example,dc=com
309 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
310 description: Very odd
311 facsimiletelephonenumber: +1 313 555 7557
312 telephonenumber: +1 313 555 8343
313 mail: gjensen@mailgw.example.com
314 homephone: +1 313 555 8844
316 dn: ou=Retired, ou=People, dc=example,dc=com
318 objectclass: organizationalUnit
321 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
323 objectclass: OpenLDAPperson
324 cn: Rosco P. Coltrane
327 description: Fat tycoon
329 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
331 newrdn: cn=Rosco P. Coltrane
333 newsuperior: ou=Retired, ou=People, dc=example,dc=com
335 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
340 if test $RC != 0 ; then
341 echo "ldapmodify failed ($RC)!"
342 test $KILLSERVERS != no && kill -HUP $KILLPIDS
346 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
349 #echo "Using ldapsearch to read all the entries from the master..."
350 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
351 '(objectClass=*)' > "${MASTEROUT}.2" 2>&1
354 if test $RC != 0 ; then
355 echo "ldapsearch failed at master ($RC)!"
356 test $KILLSERVERS != no && kill -HUP $KILLPIDS
360 #echo "Using ldapsearch to read all the entries from the P1 slave..."
361 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
362 '(objectClass=*)' > "${SLAVEOUT}.2" 2>&1
365 if test $RC != 0 ; then
366 echo "ldapsearch failed at P1 slave ($RC)!"
367 test $KILLSERVERS != no && kill -HUP $KILLPIDS
371 #echo "Filtering master results..."
372 $LDIFFILTER < "${MASTEROUT}.2" > $MASTERFLT
373 #echo "Filtering P1 slave results..."
374 $LDIFFILTER < "${SLAVEOUT}.2" > $SLAVEFLT
376 echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
377 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
379 if test $? != 0 ; then
380 echo "test failed - master and P1 slave databases differ"
381 test $KILLSERVERS != no && kill -HUP $KILLPIDS
385 #echo "Using ldapsearch to read all the entries from the R1 slave..."
386 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
387 '(objectClass=*)' > "${SLAVEOUT}.2" 2>&1
390 if test $RC != 0 ; then
391 echo "ldapsearch failed at R1 slave ($RC)!"
392 test $KILLSERVERS != no && kill -HUP $KILLPIDS
396 #echo "Filtering slave results..."
397 $LDIFFILTER < "${SLAVEOUT}.2" > $SLAVEFLT
399 echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
400 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
402 if test $? != 0 ; then
403 echo "test failed - master and R1 slave databases differ"
404 test $KILLSERVERS != no && kill -HUP $KILLPIDS
408 CHECK=`expr $CHECK + 1`
409 echo "$CHECK > Stopping slaves to test recovery..."
410 kill -HUP $P1SLAVEPID $R1SLAVEPID
414 echo "Modifying more entries on the master..."
415 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
416 $TESTOUT 2>&1 << EOMODS
417 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
420 description: r1 slave is down...
422 dn: cn=James T. Kirk, ou=Retired, ou=People, dc=example,dc=com
424 objectclass: OpenLDAPperson
429 dn: cn=Tiberius J. Hooker, ou=Retired, ou=People, dc=example,dc=com
431 objectclass: OpenLDAPperson
434 cn: Tiberius J. Hooker
438 echo "Restarting P1 slave..."
439 echo "======================= RESTART =======================" >> $LOG3
440 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
442 if test $WAIT != 0 ; then
443 echo P1SLAVEPID $P1SLAVEPID
447 echo "Restarting R1 slave..."
448 echo "======================= RESTART =======================" >> $LOG3
449 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
451 if test $WAIT != 0 ; then
452 echo R1SLAVEPID $R1SLAVEPID
455 KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
457 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
460 #echo "Using ldapsearch to read all the entries from the master..."
461 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
462 '(objectClass=*)' > "${MASTEROUT}.3" 2>&1
465 if test $RC != 0 ; then
466 echo "ldapsearch failed at master ($RC)!"
467 test $KILLSERVERS != no && kill -HUP $KILLPIDS
471 #echo "Using ldapsearch to read all the entries from the P1 slave..."
472 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
473 '(objectClass=*)' > "${SLAVEOUT}.3" 2>&1
476 if test $RC != 0 ; then
477 echo "ldapsearch failed at slave ($RC)!"
478 test $KILLSERVERS != no && kill -HUP $KILLPIDS
482 #echo "Filtering master results..."
483 $LDIFFILTER < "${MASTEROUT}.3" > $MASTERFLT
484 #echo "Filtering slave results..."
485 $LDIFFILTER < "${SLAVEOUT}.3" > $SLAVEFLT
487 echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
488 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
490 if test $? != 0 ; then
491 echo "test failed - master and slave databases differ"
492 test $KILLSERVERS != no && kill -HUP $KILLPIDS
496 #echo "Using ldapsearch to read all the entries from the R1 slave..."
497 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
498 '(objectClass=*)' > "${SLAVEOUT}.3" 2>&1
501 if test $RC != 0 ; then
502 echo "ldapsearch failed at slave ($RC)!"
503 test $KILLSERVERS != no && kill -HUP $KILLPIDS
507 #echo "Filtering slave results..."
508 $LDIFFILTER < "${SLAVEOUT}.3" > $SLAVEFLT
510 echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
511 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
513 if test $? != 0 ; then
514 echo "test failed - master and slave databases differ"
515 test $KILLSERVERS != no && kill -HUP $KILLPIDS
519 CHECK=`expr $CHECK + 1`
520 echo "$CHECK > Try updating the P1 slave slapd..."
521 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
522 $TESTOUT 2>&1 << EOMODS
523 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
526 description: This write must fail because directed to a shadow context,
527 description: unless the chain overlay is configured appropriately ;)
532 if test $RC != 0 ; then
533 echo "ldapmodify failed ($RC)!"
534 test $KILLSERVERS != no && kill -HUP $KILLPIDS
538 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
541 #echo "Using ldapsearch to read all the entries from the master..."
542 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
543 '(objectClass=*)' > "${MASTEROUT}.4" 2>&1
546 if test $RC != 0 ; then
547 echo "ldapsearch failed at master ($RC)!"
548 test $KILLSERVERS != no && kill -HUP $KILLPIDS
552 #echo "Using ldapsearch to read all the entries from the P1 slave..."
553 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
554 '(objectClass=*)' > "${SLAVEOUT}.4" 2>&1
557 if test $RC != 0 ; then
558 echo "ldapsearch failed at slave ($RC)!"
559 test $KILLSERVERS != no && kill -HUP $KILLPIDS
563 #echo "Filtering master results..."
564 $LDIFFILTER < "${MASTEROUT}.4" > $MASTERFLT
565 #echo "Filtering slave results..."
566 $LDIFFILTER < "${SLAVEOUT}.4" > $SLAVEFLT
568 echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
569 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
571 if test $? != 0 ; then
572 echo "test failed - master and P1 slave databases differ"
573 test $KILLSERVERS != no && kill -HUP $KILLPIDS
577 #echo "Using ldapsearch to read all the entries from the R1 slave..."
578 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
579 '(objectClass=*)' > "${SLAVEOUT}.4" 2>&1
582 if test $RC != 0 ; then
583 echo "ldapsearch failed at slave ($RC)!"
584 test $KILLSERVERS != no && kill -HUP $KILLPIDS
588 #echo "Filtering slave results..."
589 $LDIFFILTER < "${SLAVEOUT}.4" > $SLAVEFLT
591 echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
592 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
594 if test $? != 0 ; then
595 echo "test failed - master and R1 slave databases differ"
596 test $KILLSERVERS != no && kill -HUP $KILLPIDS
600 test $KILLSERVERS != no && kill -HUP $KILLPIDS
602 echo ">>>>> Test succeeded"
604 test $KILLSERVERS != no && wait