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"
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:03"
56 SYNCTYPE="type=refreshAndPersist"
59 echo "unknown sync mode $SYNCMODE"
64 echo "Initializing producer configurations..."
65 $SLAPADD -F $CFPROD -n 0 <<EOF
67 objectClass: olcGlobal
71 dn: olcDatabase={0}config,cn=config
72 objectClass: olcDatabaseConfig
73 olcDatabase: {0}config
74 olcRootPW:< file://$CONFIGPWF
78 echo "Initializing producer2 configurations..."
79 $SLAPADD -F $CFPRO2 -n 0 <<EOF
81 objectClass: olcGlobal
84 dn: olcDatabase={0}config,cn=config
85 objectClass: olcDatabaseConfig
86 olcDatabase: {0}config
87 olcRootPW:< file://$CONFIGPWF
91 $SLAPADD -F $CFCONS -n 0 <<EOF
93 objectClass: olcGlobal
96 dn: olcDatabase={0}config,cn=config
97 objectClass: olcDatabaseConfig
98 olcDatabase: {0}config
99 olcRootPW:< file://$CONFIGPWF
102 echo "Starting producer slapd on TCP/IP port $PORT1..."
104 $SLAPD -F slapd.d -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
106 if test $WAIT != 0 ; then
110 KILLPIDS="$KILLPIDS $PID"
113 echo "Using ldapsearch to check that producer slapd is running..."
114 for i in 0 1 2 3 4 5; do
115 $LDAPSEARCH -s base -b "" -H $URI1 \
116 'objectclass=*' > /dev/null 2>&1
118 if test $RC = 0 ; then
121 echo "Waiting 5 seconds for slapd to start..."
124 if test $RC != 0 ; then
125 echo "ldapsearch failed ($RC)!"
126 test $KILLSERVERS != no && kill -HUP $KILLPIDS
130 echo "Starting producer2 slapd on TCP/IP port $PORT2..."
132 $SLAPD -F slapd.d -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
134 if test $WAIT != 0 ; then
138 KILLPIDS="$KILLPIDS $PID"
141 echo "Using ldapsearch to check that producer slapd is running..."
142 for i in 0 1 2 3 4 5; do
143 $LDAPSEARCH -s base -b "" -H $URI2 \
144 'objectclass=*' > /dev/null 2>&1
146 if test $RC = 0 ; then
149 echo "Waiting 5 seconds for slapd to start..."
152 if test $RC != 0 ; then
153 echo "ldapsearch failed ($RC)!"
154 test $KILLSERVERS != no && kill -HUP $KILLPIDS
158 echo "Starting consumer slapd on TCP/IP port $PORT3..."
160 $SLAPD -F slapd.d -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
162 if test $WAIT != 0 ; then
166 KILLPIDS="$KILLPIDS $PID"
169 echo "Using ldapsearch to check that consumer slapd is running..."
170 for i in 0 1 2 3 4 5; do
171 $LDAPSEARCH -s base -b "" -H $URI3 \
172 'objectclass=*' > /dev/null 2>&1
174 if test $RC = 0 ; then
177 echo "Waiting 5 seconds for slapd to start..."
180 if test $RC != 0 ; then
181 echo "ldapsearch failed ($RC)!"
182 test $KILLSERVERS != no && kill -HUP $KILLPIDS
186 for uri in $URI1 $URI2 $URI3; do
187 echo "Adding schema on $uri..."
188 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
189 include: file://$ABS_SCHEMADIR/core.ldif
191 include: file://$ABS_SCHEMADIR/cosine.ldif
193 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
195 include: file://$ABS_SCHEMADIR/openldap.ldif
197 include: file://$ABS_SCHEMADIR/nis.ldif
200 if test $RC != 0 ; then
201 echo "ldapadd failed for schema config ($RC)!"
202 test $KILLSERVERS != no && kill -HUP $KILLPIDS
206 [ "$BACKENDTYPE" = mod ] || continue
208 echo "Adding backend module on $uri..."
209 $LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
210 dn: cn=module,cn=config
211 objectClass: olcModuleList
213 olcModulePath: ../../../servers/slapd/back-$BACKEND
214 olcModuleLoad: back_$BACKEND.la
217 if test $RC != 0 ; then
218 echo "ldapadd failed for backend module ($RC)!"
219 test $KILLSERVERS != no && kill -HUP $KILLPIDS
224 echo "Adding databases on producer..."
225 if [ "$SYNCPROV" = syncprovmod ]; then
226 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
227 dn: cn=module,cn=config
228 objectClass: olcModuleList
230 olcModulePath: ../../../servers/slapd/overlays
231 olcModuleLoad: syncprov.la
235 if test $RC != 0 ; then
236 echo "ldapadd failed for moduleLoad ($RC)!"
237 test $KILLSERVERS != no && kill -HUP $KILLPIDS
242 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
243 dn: olcDatabase={1}$BACKEND,cn=config
244 objectClass: olcDatabaseConfig
245 objectClass: olc${BACKEND}Config
246 olcDatabase: {1}$BACKEND
247 olcDbDirectory: $PRODDIR/db
249 olcRootDN: $MANAGERDN
254 if test $RC != 0 ; then
255 echo "ldapadd failed for producer database config1 ($RC)!"
256 test $KILLSERVERS != no && kill -HUP $KILLPIDS
260 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
261 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
262 objectClass: olcOverlayConfig
265 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
266 objectClass: olcOverlayConfig
267 objectClass: olcSyncProvConfig
268 olcOverlay: {1}syncprov
270 dn: olcDatabase={1}$BACKEND,cn=config
271 objectClass: olcDatabaseConfig
272 objectClass: olc${BACKEND}Config
273 olcDatabase: {1}$BACKEND
274 olcDbDirectory: $PRODDIR/ou1
276 olcSuffix: ou=ou1,$BASEDN
277 olcRootDN: $MANAGERDN
281 if test $RC != 0 ; then
282 echo "ldapadd failed for producer database config ($RC)!"
283 test $KILLSERVERS != no && kill -HUP $KILLPIDS
287 echo "Adding databases on producer2..."
288 if [ "$SYNCPROV" = syncprovmod ]; then
289 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
290 dn: cn=module,cn=config
291 objectClass: olcModuleList
293 olcModulePath: ../../../servers/slapd/overlays
294 olcModuleLoad: syncprov.la
298 if test $RC != 0 ; then
299 echo "ldapadd failed for moduleLoad ($RC)!"
300 test $KILLSERVERS != no && kill -HUP $KILLPIDS
305 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
306 dn: olcDatabase={1}$BACKEND,cn=config
307 objectClass: olcDatabaseConfig
308 objectClass: olc${BACKEND}Config
309 olcDatabase: {1}$BACKEND
310 olcDbDirectory: $PRO2DIR/db
312 olcRootDN: $MANAGERDN
315 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
316 objectClass: olcOverlayConfig
317 objectClass: olcSyncProvConfig
318 olcOverlay: {0}syncprov
322 if test $RC != 0 ; then
323 echo "ldapadd failed for producer database config ($RC)!"
324 test $KILLSERVERS != no && kill -HUP $KILLPIDS
328 echo "Adding databases on consumer..."
329 $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
330 dn: olcDatabase={1}$BACKEND,cn=config
331 objectClass: olcDatabaseConfig
332 objectClass: olc${BACKEND}Config
333 olcDatabase: {1}$BACKEND
334 olcDbDirectory: $CONSDIR/db
336 olcRootDN: $MANAGERDN
340 if test $RC != 0 ; then
341 echo "ldapadd failed for consumer database config ($RC)!"
342 test $KILLSERVERS != no && kill -HUP $KILLPIDS
346 echo "Populating producer..."
347 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
348 dn: dc=example,dc=com
350 objectClass: organization
351 objectClass: dcObject
355 dn: ou=ou1,dc=example,dc=com
357 objectClass: organizationalUnit
362 if test $RC != 0 ; then
363 echo "ldapadd failed to populate producer entry ($RC)!"
364 test $KILLSERVERS != no && kill -HUP $KILLPIDS
368 echo "Populating producer2..."
369 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
370 dn: dc=example,dc=com
372 objectClass: organization
373 objectClass: dcObject
377 dn: ou=ou1,dc=example,dc=com
379 objectClass: organizationalUnit
384 if test $RC != 0 ; then
385 echo "ldapadd failed to populate producer entry ($RC)!"
386 test $KILLSERVERS != no && kill -HUP $KILLPIDS
390 echo "Adding syncrepl on producer..."
391 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
392 dn: olcDatabase={1}$BACKEND,cn=config
395 olcSyncRepl: rid=1 provider=$URI2 searchbase="ou=ou1,$BASEDN"
396 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
397 $SYNCTYPE retry="3 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 "Adding syncrepl consumer on consumer..."
408 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
409 dn: olcDatabase={1}$BACKEND,cn=config
412 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
413 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
414 $SYNCTYPE retry="3 5 300 5" timeout=1
418 if test $RC != 0 ; then
419 echo "ldapmodify failed to add syncrepl consumer ($RC)!"
420 test $KILLSERVERS != no && kill -HUP $KILLPIDS
424 echo "Using ldapsearch to check that consumer received changes..."
426 for i in 0 1 2 3 4 5; do
427 RESULT=`$LDAPSEARCH -H $URI3 \
428 -s base -b "ou=ou1,$BASEDN" \
429 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
430 if test "x$RESULT" = "xOK" ; then
434 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
437 if test $RC != 0 ; then
438 echo "ldapsearch failed ($RC)!"
439 test $KILLSERVERS != no && kill -HUP $KILLPIDS
443 echo "Using ldapmodify to modify producer2..."
444 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
445 dn: ou=ou1,dc=example,dc=com
452 if test $RC != 0 ; then
453 echo "ldapmodify failed ($RC)!"
454 test $KILLSERVERS != no && kill -HUP $KILLPIDS
460 echo "Using ldapsearch to check that consumer received changes..."
462 for i in 0 1 2 3 4 5; do
463 RESULT=`$LDAPSEARCH -H $URI3 \
464 -s base -b "ou=ou1,$BASEDN" \
465 '(description=Modify1)' 2>&1 | awk '/^dn:/ {print "OK"}'`
466 if test "x$RESULT" = "xOK" ; then
470 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
473 if test $RC != 0 ; then
474 echo "ldapsearch failed ($RC)!"
475 test $KILLSERVERS != no && kill -HUP $KILLPIDS
480 for path in `echo "$PATH" | sed -e 's/:/ /g'`; do
481 if test -f "$path/db_stat" && \
482 "$path/db_stat" -E -h $PRODDIR/db > /dev/null 2>&1
484 db_stat="$path/db_stat"
489 if test -z "$db_stat" ; then
490 echo "Could not find a working db_stat in PATH!"
492 elif "$db_stat" -E -h $PRODDIR/db | egrep -q 'HELD .* len:'; then
493 echo "WARNING: Glue lock bug hit, next modify could deadlock"
496 echo "Glue lock bug not found :-)"
500 echo "Using ldapmodify to modify glue suffix on producer..."
501 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
502 dn: dc=example,dc=com
509 if test $RC != 0 ; then
510 echo "ldapadd failed to modify suffix ($RC)!"
511 test $KILLSERVERS != no && kill -HUP $KILLPIDS
515 test $KILLSERVERS != no && kill -HUP $KILLPIDS
516 test "$lock_bug" = 2 && exit 2
518 echo ">>>>> Test succeeded"