3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2009 The OpenLDAP Foundation.
6 ## All rights reserved.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
12 ## A copy of this license is available in the file LICENSE in the
13 ## top-level directory of the distribution or, alternatively, at
14 ## <http://www.OpenLDAP.org/license.html>.
16 # This script tests a bug where syncprov used on a glue database
17 # with a subordinate syncrepl consumer database looses a read-lock
18 # on the glue suffix entry when a modification is received on the
19 # syncrepl consumer. The bug is only triggered when there is an
20 # active syncrepl consumers of the glue suffix entry.
22 echo "running defines.sh"
23 . $SRCDIR/scripts/defines.sh
25 if test $SYNCPROV = syncprovno; then
26 echo "Syncrepl provider overlay not available, test skipped"
30 if test $BACKEND = null; then
31 echo "$BACKEND backend does not support cn=config, test skipped"
38 CFPROD=$PRODDIR/slapd.d
39 CFPRO2=$PRO2DIR/slapd.d
40 CFCONS=$CONSDIR/slapd.d
43 mkdir -p $PRODDIR $CFPROD $PRODDIR/db $PRODDIR/ou1
44 mkdir -p $PRO2DIR $CFPRO2 $PRO2DIR/db
45 mkdir -p $CONSDIR $CFCONS $CONSDIR/db
51 $SLAPPASSWD -g -n >$CONFIGPWF
53 if test x"$SYNCMODE" = x ; then
58 SYNCTYPE="type=refreshOnly interval=00:00:00:03"
61 SYNCTYPE="type=refreshAndPersist"
64 echo "unknown sync mode $SYNCMODE"
69 echo "Initializing producer configurations..."
70 $SLAPADD -F $CFPROD -n 0 <<EOF
72 objectClass: olcGlobal
76 dn: olcDatabase={0}config,cn=config
77 objectClass: olcDatabaseConfig
78 olcDatabase: {0}config
79 olcRootPW:< file://$CONFIGPWF
83 echo "Initializing producer2 configurations..."
84 $SLAPADD -F $CFPRO2 -n 0 <<EOF
86 objectClass: olcGlobal
89 dn: olcDatabase={0}config,cn=config
90 objectClass: olcDatabaseConfig
91 olcDatabase: {0}config
92 olcRootPW:< file://$CONFIGPWF
96 $SLAPADD -F $CFCONS -n 0 <<EOF
98 objectClass: olcGlobal
101 dn: olcDatabase={0}config,cn=config
102 objectClass: olcDatabaseConfig
103 olcDatabase: {0}config
104 olcRootPW:< file://$CONFIGPWF
107 echo "Starting producer slapd on TCP/IP port $PORT1..."
109 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
111 if test $WAIT != 0 ; then
115 KILLPIDS="$KILLPIDS $PID"
118 echo "Using ldapsearch to check that producer slapd is running..."
119 for i in 0 1 2 3 4 5; do
120 $LDAPSEARCH -s base -b "" -H $URI1 \
121 'objectclass=*' > /dev/null 2>&1
123 if test $RC = 0 ; then
126 echo "Waiting 5 seconds for slapd to start..."
129 if test $RC != 0 ; then
130 echo "ldapsearch failed ($RC)!"
131 test $KILLSERVERS != no && kill -HUP $KILLPIDS
135 echo "Starting producer2 slapd on TCP/IP port $PORT2..."
137 $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
139 if test $WAIT != 0 ; then
143 KILLPIDS="$KILLPIDS $PID"
146 echo "Using ldapsearch to check that producer slapd is running..."
147 for i in 0 1 2 3 4 5; do
148 $LDAPSEARCH -s base -b "" -H $URI2 \
149 'objectclass=*' > /dev/null 2>&1
151 if test $RC = 0 ; then
154 echo "Waiting 5 seconds for slapd to start..."
157 if test $RC != 0 ; then
158 echo "ldapsearch failed ($RC)!"
159 test $KILLSERVERS != no && kill -HUP $KILLPIDS
163 echo "Starting consumer slapd on TCP/IP port $PORT3..."
165 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
167 if test $WAIT != 0 ; then
171 KILLPIDS="$KILLPIDS $PID"
174 echo "Using ldapsearch to check that consumer slapd is running..."
175 for i in 0 1 2 3 4 5; do
176 $LDAPSEARCH -s base -b "" -H $URI3 \
177 'objectclass=*' > /dev/null 2>&1
179 if test $RC = 0 ; then
182 echo "Waiting 5 seconds for slapd to start..."
185 if test $RC != 0 ; then
186 echo "ldapsearch failed ($RC)!"
187 test $KILLSERVERS != no && kill -HUP $KILLPIDS
191 for uri in $URI1 $URI2 $URI3; do
192 echo "Adding schema on $uri..."
193 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
194 include: file://$ABS_SCHEMADIR/core.ldif
196 include: file://$ABS_SCHEMADIR/cosine.ldif
198 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
200 include: file://$ABS_SCHEMADIR/openldap.ldif
202 include: file://$ABS_SCHEMADIR/nis.ldif
205 if test $RC != 0 ; then
206 echo "ldapadd failed for schema config ($RC)!"
207 test $KILLSERVERS != no && kill -HUP $KILLPIDS
211 [ "$BACKENDTYPE" = mod ] || continue
213 echo "Adding backend module on $uri..."
214 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
215 dn: cn=module,cn=config
216 objectClass: olcModuleList
218 olcModulePath: ../../../servers/slapd/back-$BACKEND
219 olcModuleLoad: back_$BACKEND.la
222 if test $RC != 0 ; then
223 echo "ldapadd failed for backend module ($RC)!"
224 test $KILLSERVERS != no && kill -HUP $KILLPIDS
229 echo "Adding databases on producer..."
230 if [ "$SYNCPROV" = syncprovmod ]; then
231 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
232 dn: cn=module,cn=config
233 objectClass: olcModuleList
235 olcModulePath: ../../../servers/slapd/overlays
236 olcModuleLoad: syncprov.la
240 if test $RC != 0 ; then
241 echo "ldapadd failed for moduleLoad ($RC)!"
242 test $KILLSERVERS != no && kill -HUP $KILLPIDS
247 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
248 dn: olcDatabase={1}$BACKEND,cn=config
249 objectClass: olcDatabaseConfig
250 objectClass: olc${BACKEND}Config
251 olcDatabase: {1}$BACKEND
252 olcDbDirectory: $PRODDIR/db
254 olcRootDN: $MANAGERDN
259 if test $RC != 0 ; then
260 echo "ldapadd failed for producer database config1 ($RC)!"
261 test $KILLSERVERS != no && kill -HUP $KILLPIDS
265 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
266 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
267 objectClass: olcOverlayConfig
270 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
271 objectClass: olcOverlayConfig
272 objectClass: olcSyncProvConfig
273 olcOverlay: {1}syncprov
275 dn: olcDatabase={1}$BACKEND,cn=config
276 objectClass: olcDatabaseConfig
277 objectClass: olc${BACKEND}Config
278 olcDatabase: {1}$BACKEND
279 olcDbDirectory: $PRODDIR/ou1
281 olcSuffix: ou=ou1,$BASEDN
282 olcRootDN: $MANAGERDN
286 if test $RC != 0 ; then
287 echo "ldapadd failed for producer database config ($RC)!"
288 test $KILLSERVERS != no && kill -HUP $KILLPIDS
292 echo "Adding databases on producer2..."
293 if [ "$SYNCPROV" = syncprovmod ]; then
294 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
295 dn: cn=module,cn=config
296 objectClass: olcModuleList
298 olcModulePath: ../../../servers/slapd/overlays
299 olcModuleLoad: syncprov.la
303 if test $RC != 0 ; then
304 echo "ldapadd failed for moduleLoad ($RC)!"
305 test $KILLSERVERS != no && kill -HUP $KILLPIDS
310 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
311 dn: olcDatabase={1}$BACKEND,cn=config
312 objectClass: olcDatabaseConfig
313 objectClass: olc${BACKEND}Config
314 olcDatabase: {1}$BACKEND
315 olcDbDirectory: $PRO2DIR/db
317 olcRootDN: $MANAGERDN
320 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
321 objectClass: olcOverlayConfig
322 objectClass: olcSyncProvConfig
323 olcOverlay: {0}syncprov
327 if test $RC != 0 ; then
328 echo "ldapadd failed for producer database config ($RC)!"
329 test $KILLSERVERS != no && kill -HUP $KILLPIDS
333 echo "Adding databases on consumer..."
334 $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
335 dn: olcDatabase={1}$BACKEND,cn=config
336 objectClass: olcDatabaseConfig
337 objectClass: olc${BACKEND}Config
338 olcDatabase: {1}$BACKEND
339 olcDbDirectory: $CONSDIR/db
341 olcRootDN: $MANAGERDN
345 if test $RC != 0 ; then
346 echo "ldapadd failed for consumer database config ($RC)!"
347 test $KILLSERVERS != no && kill -HUP $KILLPIDS
351 echo "Populating producer..."
352 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
353 dn: dc=example,dc=com
355 objectClass: organization
356 objectClass: dcObject
360 dn: ou=ou1,dc=example,dc=com
362 objectClass: organizationalUnit
367 if test $RC != 0 ; then
368 echo "ldapadd failed to populate producer entry ($RC)!"
369 test $KILLSERVERS != no && kill -HUP $KILLPIDS
373 echo "Populating producer2..."
374 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
375 dn: dc=example,dc=com
377 objectClass: organization
378 objectClass: dcObject
382 dn: ou=ou1,dc=example,dc=com
384 objectClass: organizationalUnit
389 if test $RC != 0 ; then
390 echo "ldapadd failed to populate producer entry ($RC)!"
391 test $KILLSERVERS != no && kill -HUP $KILLPIDS
395 echo "Adding syncrepl on producer..."
396 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
397 dn: olcDatabase={1}$BACKEND,cn=config
400 olcSyncRepl: rid=1 provider=$URI2 searchbase="ou=ou1,$BASEDN"
401 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
402 $SYNCTYPE retry="3 5 300 5" timeout=1
406 if test $RC != 0 ; then
407 echo "ldapmodify failed to add syncrepl consumer ($RC)!"
408 test $KILLSERVERS != no && kill -HUP $KILLPIDS
412 echo "Adding syncrepl consumer on consumer..."
413 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
414 dn: olcDatabase={1}$BACKEND,cn=config
417 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
418 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
419 $SYNCTYPE retry="3 5 300 5" timeout=1
423 if test $RC != 0 ; then
424 echo "ldapmodify failed to add syncrepl consumer ($RC)!"
425 test $KILLSERVERS != no && kill -HUP $KILLPIDS
429 echo "Using ldapsearch to check that consumer received changes..."
431 for i in 0 1 2 3 4 5; do
432 RESULT=`$LDAPSEARCH -H $URI3 \
433 -s base -b "ou=ou1,$BASEDN" \
434 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
435 if test "x$RESULT" = "xOK" ; then
439 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
442 if test $RC != 0 ; then
443 echo "ldapsearch failed ($RC)!"
444 test $KILLSERVERS != no && kill -HUP $KILLPIDS
448 echo "Using ldapmodify to modify producer2..."
449 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
450 dn: ou=ou1,dc=example,dc=com
457 if test $RC != 0 ; then
458 echo "ldapmodify failed ($RC)!"
459 test $KILLSERVERS != no && kill -HUP $KILLPIDS
465 echo "Using ldapsearch to check that consumer received changes..."
467 for i in 0 1 2 3 4 5; do
468 RESULT=`$LDAPSEARCH -H $URI3 \
469 -s base -b "ou=ou1,$BASEDN" \
470 '(description=Modify1)' 2>&1 | awk '/^dn:/ {print "OK"}'`
471 if test "x$RESULT" = "xOK" ; then
475 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
478 if test $RC != 0 ; then
479 echo "ldapsearch failed ($RC)!"
480 test $KILLSERVERS != no && kill -HUP $KILLPIDS
485 for path in `echo "$PATH" | sed -e 's/:/ /g'`; do
486 if test -f "$path/db_stat" && \
487 "$path/db_stat" -E -h $PRODDIR/db > /dev/null 2>&1
489 db_stat="$path/db_stat"
494 if test -z "$db_stat" ; then
495 echo "Could not find a working db_stat in PATH!"
497 elif "$db_stat" -E -h $PRODDIR/db | egrep -q 'HELD .* len:'; then
498 echo "WARNING: Glue lock bug hit, next modify could deadlock"
501 echo "Glue lock bug not found :-)"
505 echo "Using ldapmodify to modify glue suffix on producer..."
506 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
507 dn: dc=example,dc=com
514 if test $RC != 0 ; then
515 echo "ldapadd failed to modify suffix ($RC)!"
516 test $KILLSERVERS != no && kill -HUP $KILLPIDS
520 test $KILLSERVERS != no && kill -HUP $KILLPIDS
521 test "$lock_bug" = 2 && exit 2
523 echo ">>>>> Test succeeded"