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
55 dn: olcDatabase={0}config,cn=config
56 objectClass: olcDatabaseConfig
57 olcDatabase: {0}config
58 olcRootPW:< file://$CONFIGPWF
62 echo "Initializing producer2 configurations..."
63 $SLAPADD -F $CFPRO2 -n 0 <<EOF
65 objectClass: olcGlobal
68 dn: olcDatabase={0}config,cn=config
69 objectClass: olcDatabaseConfig
70 olcDatabase: {0}config
71 olcRootPW:< file://$CONFIGPWF
75 $SLAPADD -F $CFCONS -n 0 <<EOF
77 objectClass: olcGlobal
80 dn: olcDatabase={0}config,cn=config
81 objectClass: olcDatabaseConfig
82 olcDatabase: {0}config
83 olcRootPW:< file://$CONFIGPWF
86 echo "Starting producer slapd on TCP/IP port $PORT1..."
88 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
90 if test $WAIT != 0 ; then
94 KILLPIDS="$KILLPIDS $PID"
97 echo "Using ldapsearch to check that producer slapd is running..."
98 for i in 0 1 2 3 4 5; do
99 $LDAPSEARCH -s base -b "" -H $URI1 \
100 'objectclass=*' > /dev/null 2>&1
102 if test $RC = 0 ; then
105 echo "Waiting 5 seconds for slapd to start..."
108 if test $RC != 0 ; then
109 echo "ldapsearch failed ($RC)!"
110 test $KILLSERVERS != no && kill -HUP $KILLPIDS
114 echo "Starting producer2 slapd on TCP/IP port $PORT2..."
116 $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
118 if test $WAIT != 0 ; then
122 KILLPIDS="$KILLPIDS $PID"
125 echo "Using ldapsearch to check that producer slapd is running..."
126 for i in 0 1 2 3 4 5; do
127 $LDAPSEARCH -s base -b "" -H $URI2 \
128 'objectclass=*' > /dev/null 2>&1
130 if test $RC = 0 ; then
133 echo "Waiting 5 seconds for slapd to start..."
136 if test $RC != 0 ; then
137 echo "ldapsearch failed ($RC)!"
138 test $KILLSERVERS != no && kill -HUP $KILLPIDS
142 echo "Starting consumer slapd on TCP/IP port $PORT3..."
144 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
146 if test $WAIT != 0 ; then
150 KILLPIDS="$KILLPIDS $PID"
153 echo "Using ldapsearch to check that consumer slapd is running..."
154 for i in 0 1 2 3 4 5; do
155 $LDAPSEARCH -s base -b "" -H $URI3 \
156 'objectclass=*' > /dev/null 2>&1
158 if test $RC = 0 ; then
161 echo "Waiting 5 seconds for slapd to start..."
164 if test $RC != 0 ; then
165 echo "ldapsearch failed ($RC)!"
166 test $KILLSERVERS != no && kill -HUP $KILLPIDS
170 for uri in $URI1 $URI2 $URI3; do
171 echo "Adding schema on $uri..."
172 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
173 include: file://$ABS_SCHEMADIR/core.ldif
175 include: file://$ABS_SCHEMADIR/cosine.ldif
177 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
179 include: file://$ABS_SCHEMADIR/openldap.ldif
181 include: file://$ABS_SCHEMADIR/nis.ldif
184 if test $RC != 0 ; then
185 echo "ldapadd failed for schema config ($RC)!"
186 test $KILLSERVERS != no && kill -HUP $KILLPIDS
190 [ "$BACKENDTYPE" = mod ] || continue
192 echo "Adding backend module on $uri..."
193 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
194 dn: cn=module,cn=config
195 objectClass: olcModuleList
197 olcModulePath: ../../../servers/slapd/back-$BACKEND
198 olcModuleLoad: back_$BACKEND.la
201 if test $RC != 0 ; then
202 echo "ldapadd failed for backend module ($RC)!"
203 test $KILLSERVERS != no && kill -HUP $KILLPIDS
208 echo "Adding databases on producer..."
209 if [ "$SYNCPROV" = syncprovmod ]; then
210 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
211 dn: cn=module,cn=config
212 objectClass: olcModuleList
214 olcModulePath: ../../../servers/slapd/overlays
215 olcModuleLoad: syncprov.la
219 if test $RC != 0 ; then
220 echo "ldapadd failed for moduleLoad ($RC)!"
221 test $KILLSERVERS != no && kill -HUP $KILLPIDS
226 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
227 dn: olcDatabase={1}$BACKEND,cn=config
228 objectClass: olcDatabaseConfig
229 objectClass: olc${BACKEND}Config
230 olcDatabase: {1}$BACKEND
231 olcDbDirectory: $PRODDIR/db
233 olcRootDN: $MANAGERDN
238 if test $RC != 0 ; then
239 echo "ldapadd failed for producer database config1 ($RC)!"
240 test $KILLSERVERS != no && kill -HUP $KILLPIDS
244 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
245 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
246 objectClass: olcOverlayConfig
249 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
250 objectClass: olcOverlayConfig
251 objectClass: olcSyncProvConfig
252 olcOverlay: {1}syncprov
254 dn: olcDatabase={1}$BACKEND,cn=config
255 objectClass: olcDatabaseConfig
256 objectClass: olc${BACKEND}Config
257 olcDatabase: {1}$BACKEND
258 olcDbDirectory: $PRODDIR/ou1
260 olcSuffix: ou=ou1,$BASEDN
261 olcRootDN: $MANAGERDN
265 if test $RC != 0 ; then
266 echo "ldapadd failed for producer database config ($RC)!"
267 test $KILLSERVERS != no && kill -HUP $KILLPIDS
271 echo "Adding databases on producer2..."
272 if [ "$SYNCPROV" = syncprovmod ]; then
273 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
274 dn: cn=module,cn=config
275 objectClass: olcModuleList
277 olcModulePath: ../../../servers/slapd/overlays
278 olcModuleLoad: syncprov.la
282 if test $RC != 0 ; then
283 echo "ldapadd failed for moduleLoad ($RC)!"
284 test $KILLSERVERS != no && kill -HUP $KILLPIDS
289 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
290 dn: olcDatabase={1}$BACKEND,cn=config
291 objectClass: olcDatabaseConfig
292 objectClass: olc${BACKEND}Config
293 olcDatabase: {1}$BACKEND
294 olcDbDirectory: $PRO2DIR/db
296 olcRootDN: $MANAGERDN
299 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
300 objectClass: olcOverlayConfig
301 objectClass: olcSyncProvConfig
302 olcOverlay: {0}syncprov
306 if test $RC != 0 ; then
307 echo "ldapadd failed for producer database config ($RC)!"
308 test $KILLSERVERS != no && kill -HUP $KILLPIDS
312 echo "Adding databases on consumer..."
313 $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
314 dn: olcDatabase={1}$BACKEND,cn=config
315 objectClass: olcDatabaseConfig
316 objectClass: olc${BACKEND}Config
317 olcDatabase: {1}$BACKEND
318 olcDbDirectory: $CONSDIR/db
320 olcRootDN: $MANAGERDN
324 if test $RC != 0 ; then
325 echo "ldapadd failed for consumer database config ($RC)!"
326 test $KILLSERVERS != no && kill -HUP $KILLPIDS
330 echo "Populating producer..."
331 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
332 dn: dc=example,dc=com
334 objectClass: organization
335 objectClass: dcObject
339 dn: ou=ou1,dc=example,dc=com
341 objectClass: organizationalUnit
346 if test $RC != 0 ; then
347 echo "ldapadd failed to populate producer entry ($RC)!"
348 test $KILLSERVERS != no && kill -HUP $KILLPIDS
352 echo "Populating producer2..."
353 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
354 dn: dc=example,dc=com
356 objectClass: organization
357 objectClass: dcObject
361 dn: ou=ou1,dc=example,dc=com
363 objectClass: organizationalUnit
368 if test $RC != 0 ; then
369 echo "ldapadd failed to populate producer entry ($RC)!"
370 test $KILLSERVERS != no && kill -HUP $KILLPIDS
374 echo "Adding syncrepl on producer..."
375 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
376 dn: olcDatabase={1}$BACKEND,cn=config
379 olcSyncRepl: rid=1 provider=$URI2 searchbase="ou=ou1,$BASEDN"
380 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
381 type=refreshAndPersist retry="5 5 300 5" timeout=1
385 if test $RC != 0 ; then
386 echo "ldapmodify failed to add syncrepl consumer ($RC)!"
387 test $KILLSERVERS != no && kill -HUP $KILLPIDS
391 echo "Adding syncrepl consumer on consumer..."
392 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
393 dn: olcDatabase={1}$BACKEND,cn=config
396 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
397 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
398 type=refreshAndPersist 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 "Using ldapsearch to check that consumer received changes..."
410 for i in 0 1 2 3 4 5; do
411 RESULT=`$LDAPSEARCH -H $URI3 \
412 -s base -b "ou=ou1,$BASEDN" \
413 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
414 if test "x$RESULT" = "xOK" ; then
418 echo "Waiting 5 seconds for syncrepl to receive changes..."
421 if test $RC != 0 ; then
422 echo "ldapsearch failed ($RC)!"
423 test $KILLSERVERS != no && kill -HUP $KILLPIDS
427 echo "Using ldapmodify to modify producer2..."
428 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
429 dn: ou=ou1,dc=example,dc=com
436 if test $RC != 0 ; then
437 echo "ldapmodify failed ($RC)!"
438 test $KILLSERVERS != no && kill -HUP $KILLPIDS
444 echo "Using ldapsearch to check that consumer received changes..."
446 for i in 0 1 2 3 4 5; do
447 RESULT=`$LDAPSEARCH -H $URI3 \
448 -s base -b "ou=ou1,$BASEDN" \
449 '(description=Modify1)' 2>&1 | awk '/^dn:/ {print "OK"}'`
450 if test "x$RESULT" = "xOK" ; then
454 echo "Waiting 5 seconds for syncrepl to receive changes..."
457 if test $RC != 0 ; then
458 echo "ldapsearch failed ($RC)!"
459 test $KILLSERVERS != no && kill -HUP $KILLPIDS
463 type db_stat >/dev/null 2>&1
465 if test $RC != 0 ; then
466 echo "Could not find db_stat ($RC)!"
468 elif db_stat -E -h $PRODDIR/db | egrep -q 'HELD .* len:'; then
469 echo "WARNING: Glue lock bug hit, next modify could deadlock"
472 echo "Glue lock bug not found :-)"
476 echo "Using ldapmodify to modify glue suffix on producer..."
477 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
478 dn: dc=example,dc=com
485 if test $RC != 0 ; then
486 echo "ldapadd failed to modify suffix ($RC)!"
487 test $KILLSERVERS != no && kill -HUP $KILLPIDS
491 test $KILLSERVERS != no && kill -HUP $KILLPIDS
492 test "$lock_bug" = 2 && exit 2
494 echo ">>>>> Test succeeded"