3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2008 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"
33 CFPROD=$PRODDIR/slapd.d
34 CFPRO2=$PRO2DIR/slapd.d
35 CFCONS=$CONSDIR/slapd.d
38 mkdir -p $PRODDIR $CFPROD $PRODDIR/db $PRODDIR/ou1
39 mkdir -p $PRO2DIR $CFPRO2 $PRO2DIR/db
40 mkdir -p $CONSDIR $CFCONS $CONSDIR/db
46 $SLAPPASSWD -g -n >$CONFIGPWF
48 echo "Initializing producer configurations..."
49 $SLAPADD -F $CFPROD -n 0 <<EOF
51 objectClass: olcGlobal
54 dn: olcDatabase={0}config,cn=config
55 objectClass: olcDatabaseConfig
56 olcDatabase: {0}config
57 olcRootPW:< file://$CONFIGPWF
61 echo "Initializing producer2 configurations..."
62 $SLAPADD -F $CFPRO2 -n 0 <<EOF
64 objectClass: olcGlobal
67 dn: olcDatabase={0}config,cn=config
68 objectClass: olcDatabaseConfig
69 olcDatabase: {0}config
70 olcRootPW:< file://$CONFIGPWF
74 $SLAPADD -F $CFCONS -n 0 <<EOF
76 objectClass: olcGlobal
79 dn: olcDatabase={0}config,cn=config
80 objectClass: olcDatabaseConfig
81 olcDatabase: {0}config
82 olcRootPW:< file://$CONFIGPWF
85 echo "Starting producer slapd on TCP/IP port $PORT1..."
87 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
89 if test $WAIT != 0 ; then
93 KILLPIDS="$KILLPIDS $PID"
96 echo "Using ldapsearch to check that producer slapd is running..."
97 for i in 0 1 2 3 4 5; do
98 $LDAPSEARCH -s base -b "" -H $URI1 \
99 'objectclass=*' > /dev/null 2>&1
101 if test $RC = 0 ; then
104 echo "Waiting 5 seconds for slapd to start..."
107 if test $RC != 0 ; then
108 echo "ldapsearch failed ($RC)!"
109 test $KILLSERVERS != no && kill -HUP $KILLPIDS
113 echo "Starting producer2 slapd on TCP/IP port $PORT2..."
115 $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING > $LOG1 2>&1 &
117 if test $WAIT != 0 ; then
121 KILLPIDS="$KILLPIDS $PID"
124 echo "Using ldapsearch to check that producer slapd is running..."
125 for i in 0 1 2 3 4 5; do
126 $LDAPSEARCH -s base -b "" -H $URI2 \
127 'objectclass=*' > /dev/null 2>&1
129 if test $RC = 0 ; then
132 echo "Waiting 5 seconds for slapd to start..."
135 if test $RC != 0 ; then
136 echo "ldapsearch failed ($RC)!"
137 test $KILLSERVERS != no && kill -HUP $KILLPIDS
141 echo "Starting consumer slapd on TCP/IP port $PORT3..."
143 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING > $LOG2 2>&1 &
145 if test $WAIT != 0 ; then
149 KILLPIDS="$KILLPIDS $PID"
152 echo "Using ldapsearch to check that consumer slapd is running..."
153 for i in 0 1 2 3 4 5; do
154 $LDAPSEARCH -s base -b "" -H $URI3 \
155 'objectclass=*' > /dev/null 2>&1
157 if test $RC = 0 ; then
160 echo "Waiting 5 seconds for slapd to start..."
163 if test $RC != 0 ; then
164 echo "ldapsearch failed ($RC)!"
165 test $KILLSERVERS != no && kill -HUP $KILLPIDS
169 for uri in $URI1 $URI2 $URI3; do
170 echo "Adding schema on $uri..."
171 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
172 include: file://$ABS_SCHEMADIR/core.ldif
174 include: file://$ABS_SCHEMADIR/cosine.ldif
176 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
178 include: file://$ABS_SCHEMADIR/openldap.ldif
180 include: file://$ABS_SCHEMADIR/nis.ldif
183 if test $RC != 0 ; then
184 echo "ldapadd failed for schema config ($RC)!"
185 test $KILLSERVERS != no && kill -HUP $KILLPIDS
189 [ "$BACKENDTYPE" = mod ] || continue
191 echo "Adding backend module on $uri..."
192 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
193 dn: cn=module,cn=config
194 objectClass: olcModuleList
196 olcModulePath: ../../../servers/slapd/back-$BACKEND
197 olcModuleLoad: back_$BACKEND.la
200 if test $RC != 0 ; then
201 echo "ldapadd failed for backend module ($RC)!"
202 test $KILLSERVERS != no && kill -HUP $KILLPIDS
207 echo "Adding databases on producer..."
208 if [ "$SYNCPROV" = syncprovmod ]; then
209 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
210 dn: cn=module,cn=config
211 objectClass: olcModuleList
213 olcModulePath: ../../../servers/slapd/overlays
214 olcModuleLoad: syncprov.la
218 if test $RC != 0 ; then
219 echo "ldapadd failed for moduleLoad ($RC)!"
220 test $KILLSERVERS != no && kill -HUP $KILLPIDS
225 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
226 dn: olcDatabase={1}$BACKEND,cn=config
227 objectClass: olcDatabaseConfig
228 objectClass: olc${BACKEND}Config
229 olcDatabase: {1}$BACKEND
230 olcDbDirectory: $PRODDIR/db
232 olcRootDN: $MANAGERDN
237 if test $RC != 0 ; then
238 echo "ldapadd failed for producer database config1 ($RC)!"
239 test $KILLSERVERS != no && kill -HUP $KILLPIDS
243 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
244 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
245 objectClass: olcOverlayConfig
248 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
249 objectClass: olcOverlayConfig
250 objectClass: olcSyncProvConfig
251 olcOverlay: {1}syncprov
253 dn: olcDatabase={1}$BACKEND,cn=config
254 objectClass: olcDatabaseConfig
255 objectClass: olc${BACKEND}Config
256 olcDatabase: {1}$BACKEND
257 olcDbDirectory: $PRODDIR/ou1
259 olcSuffix: ou=ou1,$BASEDN
260 olcRootDN: $MANAGERDN
264 if test $RC != 0 ; then
265 echo "ldapadd failed for producer database config ($RC)!"
266 test $KILLSERVERS != no && kill -HUP $KILLPIDS
270 echo "Adding databases on producer2..."
271 if [ "$SYNCPROV" = syncprovmod ]; then
272 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
273 dn: cn=module,cn=config
274 objectClass: olcModuleList
276 olcModulePath: ../../../servers/slapd/overlays
277 olcModuleLoad: syncprov.la
281 if test $RC != 0 ; then
282 echo "ldapadd failed for moduleLoad ($RC)!"
283 test $KILLSERVERS != no && kill -HUP $KILLPIDS
288 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
289 dn: olcDatabase={1}$BACKEND,cn=config
290 objectClass: olcDatabaseConfig
291 objectClass: olc${BACKEND}Config
292 olcDatabase: {1}$BACKEND
293 olcDbDirectory: $PRO2DIR/db
295 olcRootDN: $MANAGERDN
298 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
299 objectClass: olcOverlayConfig
300 objectClass: olcSyncProvConfig
301 olcOverlay: {0}syncprov
305 if test $RC != 0 ; then
306 echo "ldapadd failed for producer database config ($RC)!"
307 test $KILLSERVERS != no && kill -HUP $KILLPIDS
311 echo "Adding databases on consumer..."
312 $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
313 dn: olcDatabase={1}$BACKEND,cn=config
314 objectClass: olcDatabaseConfig
315 objectClass: olc${BACKEND}Config
316 olcDatabase: {1}$BACKEND
317 olcDbDirectory: $CONSDIR/db
319 olcRootDN: $MANAGERDN
323 if test $RC != 0 ; then
324 echo "ldapadd failed for consumer database config ($RC)!"
325 test $KILLSERVERS != no && kill -HUP $KILLPIDS
329 echo "Populating producer..."
330 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
331 dn: dc=example,dc=com
333 objectClass: organization
334 objectClass: dcObject
338 dn: ou=ou1,dc=example,dc=com
340 objectClass: organizationalUnit
345 if test $RC != 0 ; then
346 echo "ldapadd failed to populate producer entry ($RC)!"
347 test $KILLSERVERS != no && kill -HUP $KILLPIDS
351 echo "Populating producer2..."
352 $LDAPADD -D "$MANAGERDN" -H $URI2 -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 "Adding syncrepl on producer..."
374 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
375 dn: olcDatabase={1}$BACKEND,cn=config
378 olcSyncRepl: rid=1 provider=$URI2 searchbase="ou=ou1,$BASEDN"
379 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
380 type=refreshAndPersist retry="5 5 300 5" timeout=1
384 if test $RC != 0 ; then
385 echo "ldapmodify failed to add syncrepl consumer ($RC)!"
386 test $KILLSERVERS != no && kill -HUP $KILLPIDS
390 echo "Adding syncrepl consumer on consumer..."
391 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
392 dn: olcDatabase={1}$BACKEND,cn=config
395 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
396 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
397 type=refreshAndPersist retry="5 5 300 5" timeout=1
401 if test $RC != 0 ; then
402 echo "ldapmodify failed to add syncrepl consumer ($RC)!"
403 test $KILLSERVERS != no && kill -HUP $KILLPIDS
407 echo "Using ldapsearch to check that consumer received changes..."
409 for i in 0 1 2 3 4 5; do
410 RESULT=`$LDAPSEARCH -H $URI3 \
411 -s base -b "ou=ou1,$BASEDN" \
412 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
413 if test "x$RESULT" = "xOK" ; then
417 echo "Waiting 5 seconds for syncrepl to receive changes..."
420 if test $RC != 0 ; then
421 echo "ldapsearch failed ($RC)!"
422 test $KILLSERVERS != no && kill -HUP $KILLPIDS
426 echo "Using ldapmodify to modify producer2..."
427 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
428 dn: ou=ou1,dc=example,dc=com
435 if test $RC != 0 ; then
436 echo "ldapmodify failed ($RC)!"
437 test $KILLSERVERS != no && kill -HUP $KILLPIDS
443 echo "Using ldapsearch to check that consumer received changes..."
445 for i in 0 1 2 3 4 5; do
446 RESULT=`$LDAPSEARCH -H $URI3 \
447 -s base -b "ou=ou1,$BASEDN" \
448 '(description=Modify1)' 2>&1 | awk '/^dn:/ {print "OK"}'`
449 if test "x$RESULT" = "xOK" ; then
453 echo "Waiting 5 seconds for syncrepl to receive changes..."
456 if test $RC != 0 ; then
457 echo "ldapsearch failed ($RC)!"
458 test $KILLSERVERS != no && kill -HUP $KILLPIDS
462 type db_stat >/dev/null 2>&1
464 if test $RC != 0 ; then
465 echo "Could not find db_stat ($RC)!"
467 elif db_stat -E -h $PRODDIR/db | egrep -q 'HELD .* len:'; then
468 echo "WARNING: Glue lock bug hit, next modify could deadlock"
471 echo "Glue lock bug not found :-)"
475 echo "Using ldapmodify to modify glue suffix on producer..."
476 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
477 dn: dc=example,dc=com
484 if test $RC != 0 ; then
485 echo "ldapadd failed to modify suffix ($RC)!"
486 test $KILLSERVERS != no && kill -HUP $KILLPIDS
490 test $KILLSERVERS != no && kill -HUP $KILLPIDS
491 test "$lock_bug" = 2 && exit 2
493 echo ">>>>> Test succeeded"