3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2007 The OpenLDAP Foundation.
6 ## All rights reserved.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 if test $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 mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $DBDIR3
40 # - populate over ldap
41 # - perform some modifies and deleted
42 # - attempt to modify the slave (referral or chain)
43 # - retrieve database over ldap and compare against expected results
46 echo "Starting master slapd on TCP/IP port $PORT1..."
47 . $CONFFILTER $BACKEND $MONITORDB < $PLSRMASTERCONF > $CONF1
48 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
50 if test $WAIT != 0 ; then
51 echo MASTERPID $MASTERPID
58 echo "Using ldapsearch to check that master slapd is running..."
59 for i in 0 1 2 3 4 5; do
60 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
61 '(objectClass=*)' > /dev/null 2>&1
63 if test $RC = 0 ; then
66 echo "Waiting 5 seconds for slapd to start..."
70 if test $RC != 0 ; then
71 echo "ldapsearch failed ($RC)!"
72 test $KILLSERVERS != no && kill -HUP $KILLPIDS
76 echo "Using ldapadd to create the context prefix entry in the master..."
77 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
78 $LDIFORDEREDCP > /dev/null 2>&1
80 if test $RC != 0 ; then
81 echo "ldapadd failed ($RC)!"
82 test $KILLSERVERS != no && kill -HUP $KILLPIDS
86 echo "Starting P1 slave slapd on TCP/IP port $PORT2..."
87 . $CONFFILTER $BACKEND $MONITORDB < $RSLAVECONF > $CONF2
88 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
90 if test $WAIT != 0 ; then
91 echo P1SLAVEPID $P1SLAVEPID
94 KILLPIDS="$MASTERPID $P1SLAVEPID"
98 echo "Using ldapsearch to check that P1 slave slapd is running..."
99 for i in 0 1 2 3 4 5; do
100 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
101 '(objectClass=*)' > /dev/null 2>&1
103 if test $RC = 0 ; then
106 echo "Waiting 5 seconds for slapd to start..."
110 if test $RC != 0 ; then
111 echo "ldapsearch failed ($RC)!"
112 test $KILLSERVERS != no && kill -HUP $KILLPIDS
116 echo "Starting R1 slave slapd on TCP/IP port $PORT3..."
117 . $CONFFILTER $BACKEND $MONITORDB < $RSLAVECONF | sed -e 's;\.2\.;.3.;' > $CONF3
118 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
120 if test $WAIT != 0 ; then
121 echo R1SLAVEPID $R1SLAVEPID
124 KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
128 echo "Using ldapsearch to check that R1 slave slapd is running..."
129 for i in 0 1 2 3 4 5; do
130 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
131 '(objectClass=*)' > /dev/null 2>&1
133 if test $RC = 0; then
136 echo "Waiting 5 seconds for slapd to start..."
140 if test $RC != 0 ; then
141 echo "ldapsearch failed ($RC)!"
142 test $KILLSERVERS != no && kill -HUP $KILLPIDS
147 echo "$CHECK > Using ldapadd to populate the master directory..."
148 $LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
149 $LDIFORDEREDNOCP > /dev/null 2>&1
151 if test $RC != 0 ; then
152 echo "ldapadd failed ($RC)!"
153 test $KILLSERVERS != no && kill -HUP $KILLPIDS
158 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
161 #echo "Using ldapsearch to read all the entries from the master..."
162 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
163 '(objectClass=*)' > "${MASTEROUT}.1" 2>&1
166 if test $RC != 0 ; then
167 echo "ldapsearch failed at master ($RC)!"
168 test $KILLSERVERS != no && kill -HUP $KILLPIDS
172 #echo "Using ldapsearch to read all the entries from the P1 slave..."
173 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
174 '(objectClass=*)' > "${SLAVEOUT}.1" 2>&1
177 if test $RC != 0 ; then
178 echo "ldapsearch failed at P1 slave ($RC)!"
179 test $KILLSERVERS != no && kill -HUP $KILLPIDS
183 #echo "Filtering master results..."
184 . $LDIFFILTER < "${MASTEROUT}.1" > $MASTERFLT
185 #echo "Filtering slave results..."
186 . $LDIFFILTER < "${SLAVEOUT}.1" > $SLAVEFLT
188 echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
189 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
191 if test $? != 0 ; then
192 echo "test failed - master and P1 slave databases differ"
193 test $KILLSERVERS != no && kill -HUP $KILLPIDS
197 #echo "Using ldapsearch to read all the entries from the R1 slave..."
198 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
199 '(objectClass=*)' > "${SLAVEOUT}.1" 2>&1
202 if test $RC != 0 ; then
203 echo "ldapsearch failed at R1 slave ($RC)!"
204 test $KILLSERVERS != no && kill -HUP $KILLPIDS
208 #echo "Filtering slave results..."
209 . $LDIFFILTER < "${SLAVEOUT}.1" > $SLAVEFLT
211 echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
212 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
214 if test $? != 0 ; then
215 echo "test failed - master and R1 slave databases differ"
216 test $KILLSERVERS != no && kill -HUP $KILLPIDS
220 CHECK=`expr $CHECK + 1`
222 echo "$CHECK > Stopping the provider, sleeping $SLEEP seconds and restarting it..."
223 kill -HUP "$MASTERPID"
227 echo "======================= RESTART =======================" >> $LOG1
228 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 &
230 if test $WAIT != 0 ; then
231 echo MASTERPID $MASTERPID
234 KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
238 echo "Using ldapsearch to check that master slapd is running..."
239 for i in 0 1 2 3 4 5; do
240 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
241 '(objectClass=*)' > /dev/null 2>&1
243 if test $RC = 0 ; then
246 echo "Waiting 5 seconds for slapd to start..."
250 if test $RC != 0 ; then
251 echo "ldapsearch failed ($RC)!"
252 test $KILLSERVERS != no && kill -HUP $KILLPIDS
256 echo "Using ldapmodify to modify master directory..."
259 # Do some modifications
262 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
263 $TESTOUT 2>&1 << EOMODS
264 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
275 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
280 dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
283 uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
284 uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
287 uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
288 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
290 dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc
296 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
298 objectclass: OpenLDAPperson
302 title: Chief Investigator, ITD
303 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
304 seealso: cn=All Staff, ou=Groups, dc=example,dc=com
306 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
307 description: Very odd
308 facsimiletelephonenumber: +1 313 555 7557
309 telephonenumber: +1 313 555 8343
310 mail: gjensen@mailgw.example.com
311 homephone: +1 313 555 8844
313 dn: ou=Retired, ou=People, dc=example,dc=com
315 objectclass: organizationalUnit
318 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
320 objectclass: OpenLDAPperson
321 cn: Rosco P. Coltrane
324 description: Fat tycoon
326 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
328 newrdn: cn=Rosco P. Coltrane
330 newsuperior: ou=Retired, ou=People, dc=example,dc=com
332 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
337 if test $RC != 0 ; then
338 echo "ldapmodify failed ($RC)!"
339 test $KILLSERVERS != no && kill -HUP $KILLPIDS
344 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
347 #echo "Using ldapsearch to read all the entries from the master..."
348 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
349 '(objectClass=*)' > "${MASTEROUT}.2" 2>&1
352 if test $RC != 0 ; then
353 echo "ldapsearch failed at master ($RC)!"
354 test $KILLSERVERS != no && kill -HUP $KILLPIDS
358 #echo "Using ldapsearch to read all the entries from the P1 slave..."
359 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
360 '(objectClass=*)' > "${SLAVEOUT}.2" 2>&1
363 if test $RC != 0 ; then
364 echo "ldapsearch failed at P1 slave ($RC)!"
365 test $KILLSERVERS != no && kill -HUP $KILLPIDS
369 #echo "Filtering master results..."
370 . $LDIFFILTER < "${MASTEROUT}.2" > $MASTERFLT
371 #echo "Filtering P1 slave results..."
372 . $LDIFFILTER < "${SLAVEOUT}.2" > $SLAVEFLT
374 echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
375 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
377 if test $? != 0 ; then
378 echo "test failed - master and P1 slave databases differ"
379 test $KILLSERVERS != no && kill -HUP $KILLPIDS
383 #echo "Using ldapsearch to read all the entries from the R1 slave..."
384 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
385 '(objectClass=*)' > "${SLAVEOUT}.2" 2>&1
388 if test $RC != 0 ; then
389 echo "ldapsearch failed at R1 slave ($RC)!"
390 test $KILLSERVERS != no && kill -HUP $KILLPIDS
394 #echo "Filtering slave results..."
395 . $LDIFFILTER < "${SLAVEOUT}.2" > $SLAVEFLT
397 echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
398 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
400 if test $? != 0 ; then
401 echo "test failed - master and R1 slave databases differ"
402 test $KILLSERVERS != no && kill -HUP $KILLPIDS
406 CHECK=`expr $CHECK + 1`
407 echo "$CHECK > Stopping slaves to test recovery..."
408 kill -HUP $P1SLAVEPID $R1SLAVEPID
412 echo "Modifying more entries on the master..."
413 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
414 $TESTOUT 2>&1 << EOMODS
415 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
418 description: r1 slave is down...
420 dn: cn=James T. Kirk, ou=Retired, ou=People, dc=example,dc=com
422 objectclass: OpenLDAPperson
427 dn: cn=Tiberius J. Hooker, ou=Retired, ou=People, dc=example,dc=com
429 objectclass: OpenLDAPperson
432 cn: Tiberius J. Hooker
436 echo "Restarting P1 slave..."
437 echo "======================= RESTART =======================" >> $LOG3
438 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 &
440 if test $WAIT != 0 ; then
441 echo P1SLAVEPID $P1SLAVEPID
445 echo "Restarting R1 slave..."
446 echo "======================= RESTART =======================" >> $LOG3
447 $SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING >> $LOG3 2>&1 &
449 if test $WAIT != 0 ; then
450 echo R1SLAVEPID $R1SLAVEPID
453 KILLPIDS="$MASTERPID $P1SLAVEPID $R1SLAVEPID"
456 echo "Waiting $SLEEP seconds for syncrepl to receive changes..."
459 #echo "Using ldapsearch to read all the entries from the master..."
460 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
461 '(objectClass=*)' > "${MASTEROUT}.3" 2>&1
464 if test $RC != 0 ; then
465 echo "ldapsearch failed at master ($RC)!"
466 test $KILLSERVERS != no && kill -HUP $KILLPIDS
470 #echo "Using ldapsearch to read all the entries from the P1 slave..."
471 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
472 '(objectClass=*)' > "${SLAVEOUT}.3" 2>&1
475 if test $RC != 0 ; then
476 echo "ldapsearch failed at slave ($RC)!"
477 test $KILLSERVERS != no && kill -HUP $KILLPIDS
481 #echo "Filtering master results..."
482 . $LDIFFILTER < "${MASTEROUT}.3" > $MASTERFLT
483 #echo "Filtering slave results..."
484 . $LDIFFILTER < "${SLAVEOUT}.3" > $SLAVEFLT
486 echo "$CHECK < Comparing retrieved entries from master and P1 slave..."
487 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
489 if test $? != 0 ; then
490 echo "test failed - master and slave databases differ"
491 test $KILLSERVERS != no && kill -HUP $KILLPIDS
495 #echo "Using ldapsearch to read all the entries from the R1 slave..."
496 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT3 \
497 '(objectClass=*)' > "${SLAVEOUT}.3" 2>&1
500 if test $RC != 0 ; then
501 echo "ldapsearch failed at slave ($RC)!"
502 test $KILLSERVERS != no && kill -HUP $KILLPIDS
506 #echo "Filtering slave results..."
507 . $LDIFFILTER < "${SLAVEOUT}.3" > $SLAVEFLT
509 echo "$CHECK < Comparing retrieved entries from master and R1 slave..."
510 $CMP $MASTERFLT $SLAVEFLT > $CMPOUT
512 if test $? != 0 ; then
513 echo "test failed - master and slave databases differ"
514 test $KILLSERVERS != no && kill -HUP $KILLPIDS
518 CHECK=`expr $CHECK + 1`
519 echo "$CHECK > Try updating the P1 slave slapd..."
520 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
521 $TESTOUT 2>&1 << EOMODS
522 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
525 description: This write must fail because directed to a shadow context,
526 description: unless the chain overlay is configured appropriately ;)
531 if test $RC != 0 ; then
532 echo "ldapmodify failed ($RC)!"
533 test $KILLSERVERS != no && kill -HUP $KILLPIDS
538 echo "Waiting $SLEEP 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