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 if test x"$SYNCMODE" = x ; then
53 SYNCTYPE="type=refreshOnly interval=00:00:00:10"
56 SYNCTYPE="type=refreshAndPersist"
59 echo "unknown sync mode $SYNCMODE"
65 echo "Initializing producer configurations..."
66 $SLAPADD -F $CFPROD -n 0 <<EOF
68 objectClass: olcGlobal
72 dn: olcDatabase={0}config,cn=config
73 objectClass: olcDatabaseConfig
74 olcDatabase: {0}config
75 olcRootPW:< file://$CONFIGPWF
79 echo "Initializing producer2 configurations..."
80 $SLAPADD -F $CFPRO2 -n 0 <<EOF
82 objectClass: olcGlobal
85 dn: olcDatabase={0}config,cn=config
86 objectClass: olcDatabaseConfig
87 olcDatabase: {0}config
88 olcRootPW:< file://$CONFIGPWF
92 $SLAPADD -F $CFCONS -n 0 <<EOF
94 objectClass: olcGlobal
97 dn: olcDatabase={0}config,cn=config
98 objectClass: olcDatabaseConfig
99 olcDatabase: {0}config
100 olcRootPW:< file://$CONFIGPWF
103 echo "Starting producer slapd on TCP/IP port $PORT1..."
105 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
107 if test $WAIT != 0 ; then
111 KILLPIDS="$KILLPIDS $PID"
114 echo "Using ldapsearch to check that producer slapd is running..."
115 for i in 0 1 2 3 4 5; do
116 $LDAPSEARCH -s base -b "" -H $URI1 \
117 'objectclass=*' > /dev/null 2>&1
119 if test $RC = 0 ; then
122 echo "Waiting 5 seconds for slapd to start..."
125 if test $RC != 0 ; then
126 echo "ldapsearch failed ($RC)!"
127 test $KILLSERVERS != no && kill -HUP $KILLPIDS
131 echo "Starting producer2 slapd on TCP/IP port $PORT2..."
133 $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
135 if test $WAIT != 0 ; then
139 KILLPIDS="$KILLPIDS $PID"
142 echo "Using ldapsearch to check that producer slapd is running..."
143 for i in 0 1 2 3 4 5; do
144 $LDAPSEARCH -s base -b "" -H $URI2 \
145 'objectclass=*' > /dev/null 2>&1
147 if test $RC = 0 ; then
150 echo "Waiting 5 seconds for slapd to start..."
153 if test $RC != 0 ; then
154 echo "ldapsearch failed ($RC)!"
155 test $KILLSERVERS != no && kill -HUP $KILLPIDS
159 echo "Starting consumer slapd on TCP/IP port $PORT3..."
161 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
163 if test $WAIT != 0 ; then
167 KILLPIDS="$KILLPIDS $PID"
170 echo "Using ldapsearch to check that consumer slapd is running..."
171 for i in 0 1 2 3 4 5; do
172 $LDAPSEARCH -s base -b "" -H $URI3 \
173 'objectclass=*' > /dev/null 2>&1
175 if test $RC = 0 ; then
178 echo "Waiting 5 seconds for slapd to start..."
181 if test $RC != 0 ; then
182 echo "ldapsearch failed ($RC)!"
183 test $KILLSERVERS != no && kill -HUP $KILLPIDS
187 for uri in $URI1 $URI2 $URI3; do
188 echo "Adding schema on $uri..."
189 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
190 include: file://$ABS_SCHEMADIR/core.ldif
192 include: file://$ABS_SCHEMADIR/cosine.ldif
194 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
196 include: file://$ABS_SCHEMADIR/openldap.ldif
198 include: file://$ABS_SCHEMADIR/nis.ldif
201 if test $RC != 0 ; then
202 echo "ldapadd failed for schema config ($RC)!"
203 test $KILLSERVERS != no && kill -HUP $KILLPIDS
207 [ "$BACKENDTYPE" = mod ] || continue
209 echo "Adding backend module on $uri..."
210 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
211 dn: cn=module,cn=config
212 objectClass: olcModuleList
214 olcModulePath: ../../../servers/slapd/back-$BACKEND
215 olcModuleLoad: back_$BACKEND.la
218 if test $RC != 0 ; then
219 echo "ldapadd failed for backend module ($RC)!"
220 test $KILLSERVERS != no && kill -HUP $KILLPIDS
225 echo "Adding databases on producer..."
226 if [ "$SYNCPROV" = syncprovmod ]; then
227 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
228 dn: cn=module,cn=config
229 objectClass: olcModuleList
231 olcModulePath: ../../../servers/slapd/overlays
232 olcModuleLoad: syncprov.la
236 if test $RC != 0 ; then
237 echo "ldapadd failed for moduleLoad ($RC)!"
238 test $KILLSERVERS != no && kill -HUP $KILLPIDS
243 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
244 dn: olcDatabase={1}$BACKEND,cn=config
245 objectClass: olcDatabaseConfig
246 objectClass: olc${BACKEND}Config
247 olcDatabase: {1}$BACKEND
248 olcDbDirectory: $PRODDIR/db
250 olcRootDN: $MANAGERDN
255 if test $RC != 0 ; then
256 echo "ldapadd failed for producer database config1 ($RC)!"
257 test $KILLSERVERS != no && kill -HUP $KILLPIDS
261 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
262 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
263 objectClass: olcOverlayConfig
266 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
267 objectClass: olcOverlayConfig
268 objectClass: olcSyncProvConfig
269 olcOverlay: {1}syncprov
271 dn: olcDatabase={1}$BACKEND,cn=config
272 objectClass: olcDatabaseConfig
273 objectClass: olc${BACKEND}Config
274 olcDatabase: {1}$BACKEND
275 olcDbDirectory: $PRODDIR/ou1
277 olcSuffix: ou=ou1,$BASEDN
278 olcRootDN: $MANAGERDN
282 if test $RC != 0 ; then
283 echo "ldapadd failed for producer database config ($RC)!"
284 test $KILLSERVERS != no && kill -HUP $KILLPIDS
288 echo "Adding databases on producer2..."
289 if [ "$SYNCPROV" = syncprovmod ]; then
290 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
291 dn: cn=module,cn=config
292 objectClass: olcModuleList
294 olcModulePath: ../../../servers/slapd/overlays
295 olcModuleLoad: syncprov.la
299 if test $RC != 0 ; then
300 echo "ldapadd failed for moduleLoad ($RC)!"
301 test $KILLSERVERS != no && kill -HUP $KILLPIDS
306 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
307 dn: olcDatabase={1}$BACKEND,cn=config
308 objectClass: olcDatabaseConfig
309 objectClass: olc${BACKEND}Config
310 olcDatabase: {1}$BACKEND
311 olcDbDirectory: $PRO2DIR/db
313 olcRootDN: $MANAGERDN
316 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
317 objectClass: olcOverlayConfig
318 objectClass: olcSyncProvConfig
319 olcOverlay: {0}syncprov
323 if test $RC != 0 ; then
324 echo "ldapadd failed for producer database config ($RC)!"
325 test $KILLSERVERS != no && kill -HUP $KILLPIDS
329 echo "Adding databases on consumer..."
330 $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
331 dn: olcDatabase={1}$BACKEND,cn=config
332 objectClass: olcDatabaseConfig
333 objectClass: olc${BACKEND}Config
334 olcDatabase: {1}$BACKEND
335 olcDbDirectory: $CONSDIR/db
337 olcRootDN: $MANAGERDN
341 if test $RC != 0 ; then
342 echo "ldapadd failed for consumer database config ($RC)!"
343 test $KILLSERVERS != no && kill -HUP $KILLPIDS
347 echo "Populating producer..."
348 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
349 dn: dc=example,dc=com
351 objectClass: organization
352 objectClass: dcObject
356 dn: ou=ou1,dc=example,dc=com
358 objectClass: organizationalUnit
363 if test $RC != 0 ; then
364 echo "ldapadd failed to populate producer entry ($RC)!"
365 test $KILLSERVERS != no && kill -HUP $KILLPIDS
369 echo "Populating producer2..."
370 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
371 dn: dc=example,dc=com
373 objectClass: organization
374 objectClass: dcObject
378 dn: ou=ou1,dc=example,dc=com
380 objectClass: organizationalUnit
385 if test $RC != 0 ; then
386 echo "ldapadd failed to populate producer entry ($RC)!"
387 test $KILLSERVERS != no && kill -HUP $KILLPIDS
391 echo "Adding syncrepl on producer..."
392 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
393 dn: olcDatabase={1}$BACKEND,cn=config
396 olcSyncRepl: rid=1 provider=$URI2 searchbase="ou=ou1,$BASEDN"
397 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
398 $SYNCTYPE retry="5 5 300 5" timeout=1
402 if test $RC != 0 ; then
403 echo "ldapmodify failed to add syncrepl consumer ($RC)!"
404 test $KILLSERVERS != no && kill -HUP $KILLPIDS
408 echo "Adding syncrepl consumer on consumer..."
409 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
410 dn: olcDatabase={1}$BACKEND,cn=config
413 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
414 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
415 $SYNCTYPE retry="5 5 300 5" timeout=1
419 if test $RC != 0 ; then
420 echo "ldapmodify failed to add syncrepl consumer ($RC)!"
421 test $KILLSERVERS != no && kill -HUP $KILLPIDS
425 echo "Using ldapsearch to check that consumer received changes..."
427 for i in 0 1 2 3 4 5; do
428 RESULT=`$LDAPSEARCH -H $URI3 \
429 -s base -b "ou=ou1,$BASEDN" \
430 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
431 if test "x$RESULT" = "xOK" ; then
435 echo "Waiting 5 seconds for syncrepl to receive changes..."
438 if test $RC != 0 ; then
439 echo "ldapsearch failed ($RC)!"
440 test $KILLSERVERS != no && kill -HUP $KILLPIDS
444 echo "Using ldapmodify to modify producer2..."
445 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
446 dn: ou=ou1,dc=example,dc=com
453 if test $RC != 0 ; then
454 echo "ldapmodify failed ($RC)!"
455 test $KILLSERVERS != no && kill -HUP $KILLPIDS
461 echo "Using ldapsearch to check that consumer received changes..."
463 for i in 0 1 2 3 4 5; do
464 RESULT=`$LDAPSEARCH -H $URI3 \
465 -s base -b "ou=ou1,$BASEDN" \
466 '(description=Modify1)' 2>&1 | awk '/^dn:/ {print "OK"}'`
467 if test "x$RESULT" = "xOK" ; then
471 echo "Waiting 5 seconds for syncrepl to receive changes..."
474 if test $RC != 0 ; then
475 echo "ldapsearch failed ($RC)!"
476 test $KILLSERVERS != no && kill -HUP $KILLPIDS
480 type db_stat >/dev/null 2>&1
482 if test $RC != 0 ; then
483 echo "Could not find db_stat ($RC)!"
485 elif db_stat -E -h $PRODDIR/db | egrep -q 'HELD .* len:'; then
486 echo "WARNING: Glue lock bug hit, next modify could deadlock"
489 echo "Glue lock bug not found :-)"
493 echo "Using ldapmodify to modify glue suffix on producer..."
494 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
495 dn: dc=example,dc=com
502 if test $RC != 0 ; then
503 echo "ldapadd failed to modify suffix ($RC)!"
504 test $KILLSERVERS != no && kill -HUP $KILLPIDS
508 test $KILLSERVERS != no && kill -HUP $KILLPIDS
509 test "$lock_bug" = 2 && exit 2
511 echo ">>>>> Test succeeded"