3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 ## Copyright 1998-2013 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 provider 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 provider2 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 provider 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 provider 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 provider2 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 provider 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: $TESTWD/../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 provider..."
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: $TESTWD/../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 nullExclude="" nullOK=""
243 test $BACKEND = null && nullExclude="# " nullOK="OK"
245 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
246 dn: olcDatabase={1}$BACKEND,cn=config
247 objectClass: olcDatabaseConfig
248 ${nullExclude}objectClass: olc${BACKEND}Config
249 olcDatabase: {1}$BACKEND
250 ${nullExclude}olcDbDirectory: $PRODDIR/db
252 olcRootDN: $MANAGERDN
257 if test $RC != 0 ; then
258 echo "ldapadd failed for provider database config1 ($RC)!"
259 test $KILLSERVERS != no && kill -HUP $KILLPIDS
263 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
264 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
265 objectClass: olcOverlayConfig
268 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
269 objectClass: olcOverlayConfig
270 objectClass: olcSyncProvConfig
271 olcOverlay: {1}syncprov
273 dn: olcDatabase={1}$BACKEND,cn=config
274 objectClass: olcDatabaseConfig
275 ${nullExclude}objectClass: olc${BACKEND}Config
276 olcDatabase: {1}$BACKEND
277 ${nullExclude}olcDbDirectory: $PRODDIR/ou1
279 olcSuffix: ou=ou1,$BASEDN
280 olcRootDN: $MANAGERDN
284 if test $RC != 0 ; then
285 echo "ldapadd failed for provider database config ($RC)!"
286 test $KILLSERVERS != no && kill -HUP $KILLPIDS
290 echo "Adding databases on provider2..."
291 if [ "$SYNCPROV" = syncprovmod ]; then
292 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
293 dn: cn=module,cn=config
294 objectClass: olcModuleList
296 olcModulePath: $TESTWD/../servers/slapd/overlays
297 olcModuleLoad: syncprov.la
301 if test $RC != 0 ; then
302 echo "ldapadd failed for moduleLoad ($RC)!"
303 test $KILLSERVERS != no && kill -HUP $KILLPIDS
308 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
309 dn: olcDatabase={1}$BACKEND,cn=config
310 objectClass: olcDatabaseConfig
311 ${nullExclude}objectClass: olc${BACKEND}Config
312 olcDatabase: {1}$BACKEND
313 ${nullExclude}olcDbDirectory: $PRO2DIR/db
315 olcRootDN: $MANAGERDN
318 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
319 objectClass: olcOverlayConfig
320 objectClass: olcSyncProvConfig
321 olcOverlay: {0}syncprov
325 if test $RC != 0 ; then
326 echo "ldapadd failed for provider database config ($RC)!"
327 test $KILLSERVERS != no && kill -HUP $KILLPIDS
331 echo "Adding databases on consumer..."
332 $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
333 dn: olcDatabase={1}$BACKEND,cn=config
334 objectClass: olcDatabaseConfig
335 ${nullExclude}objectClass: olc${BACKEND}Config
336 olcDatabase: {1}$BACKEND
337 ${nullExclude}olcDbDirectory: $CONSDIR/db
339 olcRootDN: $MANAGERDN
343 if test $RC != 0 ; then
344 echo "ldapadd failed for consumer database config ($RC)!"
345 test $KILLSERVERS != no && kill -HUP $KILLPIDS
349 echo "Populating provider..."
350 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
351 dn: dc=example,dc=com
353 objectClass: organization
354 objectClass: dcObject
358 dn: ou=ou1,dc=example,dc=com
360 objectClass: organizationalUnit
365 if test $RC != 0 ; then
366 echo "ldapadd failed to populate provider entry ($RC)!"
367 test $KILLSERVERS != no && kill -HUP $KILLPIDS
371 echo "Populating provider2..."
372 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
373 dn: dc=example,dc=com
375 objectClass: organization
376 objectClass: dcObject
380 dn: ou=ou1,dc=example,dc=com
382 objectClass: organizationalUnit
387 if test $RC != 0 ; then
388 echo "ldapadd failed to populate provider entry ($RC)!"
389 test $KILLSERVERS != no && kill -HUP $KILLPIDS
393 echo "Adding syncrepl on provider..."
394 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
395 dn: olcDatabase={1}$BACKEND,cn=config
398 olcSyncRepl: rid=1 provider=$URI2 searchbase="ou=ou1,$BASEDN"
399 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
400 $SYNCTYPE retry="3 5 300 5" timeout=1
404 if test $RC != 0 ; then
405 echo "ldapmodify failed to add syncrepl consumer ($RC)!"
406 test $KILLSERVERS != no && kill -HUP $KILLPIDS
410 echo "Adding syncrepl consumer on consumer..."
411 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
412 dn: olcDatabase={1}$BACKEND,cn=config
415 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
416 binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
417 $SYNCTYPE retry="3 5 300 5" timeout=1
421 if test $RC != 0 ; then
422 echo "ldapmodify failed to add syncrepl consumer ($RC)!"
423 test $KILLSERVERS != no && kill -HUP $KILLPIDS
427 echo "Using ldapsearch to check that consumer received changes..."
429 for i in 0 1 2 3 4 5; do
430 RESULT=`$LDAPSEARCH -H $URI3 \
431 -s base -b "ou=ou1,$BASEDN" \
432 '(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
433 if test "x$RESULT$nullOK" = "xOK" ; then
437 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
440 if test $RC != 0 ; then
441 echo "ldapsearch failed ($RC)!"
442 test $KILLSERVERS != no && kill -HUP $KILLPIDS
446 echo "Using ldapmodify to modify provider2..."
447 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
448 dn: ou=ou1,dc=example,dc=com
455 if test $RC != 0 ; then
456 echo "ldapmodify failed ($RC)!"
457 test $KILLSERVERS != no && kill -HUP $KILLPIDS
463 echo "Using ldapsearch to check that consumer received changes..."
465 for i in 0 1 2 3 4 5; do
466 RESULT=`$LDAPSEARCH -H $URI3 \
467 -s base -b "ou=ou1,$BASEDN" \
468 '(description=Modify1)' 2>&1 | awk '/^dn:/ {print "OK"}'`
469 if test "x$RESULT$nullOK" = "xOK" ; then
473 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
476 if test $RC != 0 ; then
477 echo "ldapsearch failed ($RC)!"
478 test $KILLSERVERS != no && kill -HUP $KILLPIDS
482 case $BACKEND in bdb | hdb)
484 for path in `echo "$PATH" | sed -e 's/:/ /g'`; do
485 if test -f "$path/db_stat" && \
486 "$path/db_stat" -E -h $PRODDIR/db > /dev/null 2>&1
488 db_stat="$path/db_stat"
493 if test -z "$db_stat" ; then
494 echo "Could not find a working db_stat in PATH!"
496 elif "$db_stat" -E -h $PRODDIR/db | egrep -q 'HELD .* len:'; then
497 echo "WARNING: Glue lock bug hit, next modify could deadlock"
500 echo "Glue lock bug not found :-)"
505 echo "Using ldapmodify to modify glue suffix on provider..."
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"