Home | History | Annotate | Line # | Download | only in scripts
      1 #! /bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 1998-2024 The OpenLDAP Foundation.
      6 ## All rights reserved.
      7 ##
      8 ## Redistribution and use in source and binary forms, with or without
      9 ## modification, are permitted only as authorized by the OpenLDAP
     10 ## Public License.
     11 ##
     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>.
     15 
     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.
     21 
     22 echo "running defines.sh"
     23 . $SRCDIR/scripts/defines.sh
     24 
     25 if test $SYNCPROV = syncprovno; then 
     26 	echo "Syncrepl provider overlay not available, test skipped"
     27 	exit 0
     28 fi 
     29 
     30 PRODDIR=$TESTDIR/prod
     31 PRO2DIR=$TESTDIR/pro2
     32 CONSDIR=$TESTDIR/cons
     33 CFPROD=$PRODDIR/slapd.d
     34 CFPRO2=$PRO2DIR/slapd.d
     35 CFCONS=$CONSDIR/slapd.d
     36 
     37 mkdir -p $TESTDIR
     38 mkdir -p $PRODDIR $CFPROD $PRODDIR/db $PRODDIR/ou1
     39 mkdir -p $PRO2DIR $CFPRO2 $PRO2DIR/db
     40 mkdir -p $CONSDIR $CFCONS $CONSDIR/db 
     41 
     42 cd $TESTDIR
     43 
     44 KILLPIDS=
     45 
     46 $SLAPPASSWD -g -n >$CONFIGPWF
     47 
     48 if test x"$SYNCMODE" = x ; then
     49 	SYNCMODE=rp
     50 fi
     51 case "$SYNCMODE" in
     52 	ro)
     53 		SYNCTYPE="type=refreshOnly interval=00:00:00:03"
     54 		;;
     55 	rp)
     56 		SYNCTYPE="type=refreshAndPersist"
     57 		;;
     58 	*)
     59 		echo "unknown sync mode $SYNCMODE"
     60 		exit 1;
     61 		;;
     62 esac
     63 
     64 echo "Initializing provider configurations..."
     65 $SLAPADD -F $CFPROD -n 0 <<EOF
     66 dn: cn=config
     67 objectClass: olcGlobal
     68 cn: config
     69 olcServerID: 1
     70 
     71 dn: olcDatabase={0}config,cn=config
     72 objectClass: olcDatabaseConfig
     73 olcDatabase: {0}config
     74 olcRootPW:< file://$CONFIGPWF
     75 
     76 EOF
     77 RC=$?
     78 if test $RC != 0 ; then
     79 	echo "slapadd failed ($RC)!"
     80 	exit $RC
     81 fi
     82 
     83 echo "Initializing provider2 configurations..."
     84 $SLAPADD -F $CFPRO2 -n 0 <<EOF
     85 dn: cn=config
     86 objectClass: olcGlobal
     87 cn: config
     88 
     89 dn: olcDatabase={0}config,cn=config
     90 objectClass: olcDatabaseConfig
     91 olcDatabase: {0}config
     92 olcRootPW:< file://$CONFIGPWF
     93 
     94 EOF
     95 RC=$?
     96 if test $RC != 0 ; then
     97 	echo "slapadd failed ($RC)!"
     98 	exit $RC
     99 fi
    100 
    101 $SLAPADD -F $CFCONS -n 0 <<EOF
    102 dn: cn=config
    103 objectClass: olcGlobal
    104 cn: config
    105 
    106 dn: olcDatabase={0}config,cn=config
    107 objectClass: olcDatabaseConfig
    108 olcDatabase: {0}config
    109 olcRootPW:< file://$CONFIGPWF
    110 EOF
    111 RC=$?
    112 if test $RC != 0 ; then
    113 	echo "slapadd failed ($RC)!"
    114 	exit $RC
    115 fi
    116 
    117 echo "Starting provider slapd on TCP/IP port $PORT1..."
    118 cd $PRODDIR
    119 $SLAPD -F slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 &
    120 PID=$!
    121 if test $WAIT != 0 ; then
    122     echo PID $PID
    123     read foo
    124 fi
    125 KILLPIDS="$KILLPIDS $PID"
    126 cd $TESTWD
    127 sleep 1
    128 echo "Using ldapsearch to check that provider slapd is running..."
    129 for i in 0 1 2 3 4 5; do
    130 	$LDAPSEARCH -s base -b "" -H $URI1 \
    131 		'objectclass=*' > /dev/null 2>&1
    132 	RC=$?
    133 	if test $RC = 0 ; then
    134 		break
    135 	fi
    136 	echo "Waiting 5 seconds for slapd to start..."
    137 	sleep 5
    138 done
    139 if test $RC != 0 ; then
    140 	echo "ldapsearch failed ($RC)!"
    141 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    142 	exit $RC
    143 fi
    144 
    145 echo "Starting provider2 slapd on TCP/IP port $PORT2..."
    146 cd $PRO2DIR
    147 $SLAPD -F slapd.d -h $URI2 -d $LVL > $LOG2 2>&1 &
    148 PID=$!
    149 if test $WAIT != 0 ; then
    150     echo PID $PID
    151     read foo
    152 fi
    153 KILLPIDS="$KILLPIDS $PID"
    154 cd $TESTWD
    155 sleep 1
    156 echo "Using ldapsearch to check that provider slapd is running..."
    157 for i in 0 1 2 3 4 5; do
    158 	$LDAPSEARCH -s base -b "" -H $URI2 \
    159 		'objectclass=*' > /dev/null 2>&1
    160 	RC=$?
    161 	if test $RC = 0 ; then
    162 		break
    163 	fi
    164 	echo "Waiting 5 seconds for slapd to start..."
    165 	sleep 5
    166 done
    167 if test $RC != 0 ; then
    168 	echo "ldapsearch failed ($RC)!"
    169 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    170 	exit $RC
    171 fi
    172 
    173 echo "Starting consumer slapd on TCP/IP port $PORT3..."
    174 cd $CONSDIR
    175 $SLAPD -F slapd.d -h $URI3 -d $LVL > $LOG3 2>&1 &
    176 PID=$!
    177 if test $WAIT != 0 ; then
    178     echo PID $PID
    179     read foo
    180 fi
    181 KILLPIDS="$KILLPIDS $PID"
    182 cd $TESTWD
    183 sleep 1
    184 echo "Using ldapsearch to check that consumer slapd is running..."
    185 for i in 0 1 2 3 4 5; do
    186 	$LDAPSEARCH -s base -b "" -H $URI3 \
    187 		'objectclass=*' > /dev/null 2>&1
    188 	RC=$?
    189 	if test $RC = 0 ; then
    190 		break
    191 	fi
    192 	echo "Waiting 5 seconds for slapd to start..."
    193 	sleep 5
    194 done
    195 if test $RC != 0 ; then
    196 	echo "ldapsearch failed ($RC)!"
    197 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    198 	exit $RC
    199 fi
    200 
    201 for uri in $URI1 $URI2 $URI3; do
    202 	echo "Adding schema on $uri..."
    203 	$LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
    204 include: file://$ABS_SCHEMADIR/core.ldif
    205 
    206 include: file://$ABS_SCHEMADIR/cosine.ldif
    207 
    208 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
    209 
    210 include: file://$ABS_SCHEMADIR/openldap.ldif
    211 
    212 include: file://$ABS_SCHEMADIR/nis.ldif
    213 EOF
    214 	RC=$?
    215 	if test $RC != 0 ; then
    216 		echo "ldapadd failed for schema config ($RC)!"
    217 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    218 		exit $RC
    219 	fi
    220 
    221 	[ "$BACKENDTYPE" = mod ] || continue
    222 
    223 	echo "Adding backend module on $uri..."
    224 	$LDAPADD -D cn=config -H $uri -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    225 dn: cn=module,cn=config
    226 objectClass: olcModuleList
    227 cn: module
    228 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
    229 olcModuleLoad: back_$BACKEND.la
    230 EOF
    231 	RC=$?
    232 	if test $RC != 0 ; then
    233 		echo "ldapadd failed for backend module ($RC)!"
    234 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    235 		exit $RC
    236 	fi
    237 done
    238 
    239 echo "Adding databases on provider..."
    240 if [ "$SYNCPROV" = syncprovmod ]; then
    241 	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    242 dn: cn=module,cn=config
    243 objectClass: olcModuleList
    244 cn: module
    245 olcModulePath: $TESTWD/../servers/slapd/overlays
    246 olcModuleLoad: syncprov.la
    247 
    248 EOF
    249 	RC=$?
    250 	if test $RC != 0 ; then
    251 		echo "ldapadd failed for moduleLoad ($RC)!"
    252 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    253 		exit $RC
    254 	fi
    255 fi
    256 
    257 nullExclude="" nullOK=""
    258 test $BACKEND = null && nullExclude="# " nullOK="OK"
    259 
    260 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    261 dn: olcDatabase={1}$BACKEND,cn=config
    262 objectClass: olcDatabaseConfig
    263 ${nullExclude}objectClass: olc${BACKEND}Config
    264 olcDatabase: {1}$BACKEND
    265 ${nullExclude}olcDbDirectory: $PRODDIR/db
    266 olcSuffix: $BASEDN
    267 olcRootDN: $MANAGERDN
    268 olcRootPW: $PASSWD
    269 
    270 EOF
    271 RC=$?
    272 if test $RC != 0 ; then
    273 	echo "ldapadd failed for provider database config1 ($RC)!"
    274 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    275 	exit $RC
    276 fi
    277 
    278 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    279 dn: olcOverlay={0}glue,olcDatabase={1}$BACKEND,cn=config
    280 objectClass: olcOverlayConfig
    281 olcOverlay: {0}glue
    282 
    283 dn: olcOverlay={1}syncprov,olcDatabase={1}$BACKEND,cn=config
    284 objectClass: olcOverlayConfig
    285 objectClass: olcSyncProvConfig
    286 olcOverlay: {1}syncprov
    287 
    288 dn: olcDatabase={1}$BACKEND,cn=config
    289 objectClass: olcDatabaseConfig
    290 ${nullExclude}objectClass: olc${BACKEND}Config
    291 olcDatabase: {1}$BACKEND
    292 ${nullExclude}olcDbDirectory: $PRODDIR/ou1
    293 olcSubordinate: TRUE
    294 olcSuffix: ou=ou1,$BASEDN
    295 olcRootDN: $MANAGERDN
    296 
    297 EOF
    298 RC=$?
    299 if test $RC != 0 ; then
    300 	echo "ldapadd failed for provider database config ($RC)!"
    301 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    302 	exit $RC
    303 fi
    304 
    305 echo "Adding databases on provider2..."
    306 if [ "$SYNCPROV" = syncprovmod ]; then
    307 	$LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    308 dn: cn=module,cn=config
    309 objectClass: olcModuleList
    310 cn: module
    311 olcModulePath: $TESTWD/../servers/slapd/overlays
    312 olcModuleLoad: syncprov.la
    313 
    314 EOF
    315 	RC=$?
    316 	if test $RC != 0 ; then
    317 		echo "ldapadd failed for moduleLoad ($RC)!"
    318 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    319 		exit $RC
    320 	fi
    321 fi
    322 
    323 $LDAPADD -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    324 dn: olcDatabase={1}$BACKEND,cn=config
    325 objectClass: olcDatabaseConfig
    326 ${nullExclude}objectClass: olc${BACKEND}Config
    327 olcDatabase: {1}$BACKEND
    328 ${nullExclude}olcDbDirectory: $PRO2DIR/db
    329 olcSuffix: $BASEDN
    330 olcRootDN: $MANAGERDN
    331 olcRootPW: $PASSWD
    332 
    333 dn: olcOverlay={0}syncprov,olcDatabase={1}$BACKEND,cn=config
    334 objectClass: olcOverlayConfig
    335 objectClass: olcSyncProvConfig
    336 olcOverlay: {0}syncprov
    337 
    338 EOF
    339 RC=$?
    340 if test $RC != 0 ; then
    341 	echo "ldapadd failed for provider database config ($RC)!"
    342 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    343 	exit $RC
    344 fi
    345 
    346 echo "Adding databases on consumer..."
    347 $LDAPADD -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    348 dn: olcDatabase={1}$BACKEND,cn=config
    349 objectClass: olcDatabaseConfig
    350 ${nullExclude}objectClass: olc${BACKEND}Config
    351 olcDatabase: {1}$BACKEND
    352 ${nullExclude}olcDbDirectory: $CONSDIR/db
    353 olcSuffix: $BASEDN
    354 olcRootDN: $MANAGERDN
    355 
    356 EOF
    357 RC=$?
    358 if test $RC != 0 ; then
    359 	echo "ldapadd failed for consumer database config ($RC)!"
    360 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    361 	exit $RC
    362 fi
    363 
    364 echo "Populating provider..."
    365 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
    366 dn: dc=example,dc=com
    367 objectClass: top
    368 objectClass: organization
    369 objectClass: dcObject
    370 dc: example
    371 o: Example, Inc
    372 
    373 dn: ou=ou1,dc=example,dc=com
    374 objectClass: top
    375 objectClass: organizationalUnit
    376 ou: ou1
    377 
    378 EOF
    379 RC=$?
    380 if test $RC != 0 ; then
    381 	echo "ldapadd failed to populate provider entry ($RC)!"
    382 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    383 	exit $RC
    384 fi
    385 
    386 echo "Populating provider2..."
    387 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
    388 dn: dc=example,dc=com
    389 objectClass: top
    390 objectClass: organization
    391 objectClass: dcObject
    392 dc: example
    393 o: Example, Inc
    394 
    395 dn: ou=ou1,dc=example,dc=com
    396 objectClass: top
    397 objectClass: organizationalUnit
    398 ou: ou1
    399 
    400 EOF
    401 RC=$?
    402 if test $RC != 0 ; then
    403 	echo "ldapadd failed to populate provider entry ($RC)!"
    404 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    405 	exit $RC
    406 fi
    407 
    408 echo "Adding syncrepl on provider..."
    409 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    410 dn: olcDatabase={1}$BACKEND,cn=config
    411 changetype: modify
    412 add: olcSyncRepl
    413 olcSyncRepl: rid=1 provider=$URI2 searchbase="ou=ou1,$BASEDN"
    414   binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
    415   $SYNCTYPE retry="3 5 300 5" timeout=1
    416 
    417 EOF
    418 RC=$?
    419 if test $RC != 0 ; then
    420 	echo "ldapmodify failed to add syncrepl consumer ($RC)!"
    421 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    422 	exit $RC
    423 fi
    424 
    425 echo "Adding syncrepl consumer on consumer..."
    426 $LDAPMODIFY -D cn=config -H $URI3 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    427 dn: olcDatabase={1}$BACKEND,cn=config
    428 changetype: modify
    429 add: olcSyncRepl
    430 olcSyncRepl: rid=1 provider=$URI1 searchbase="$BASEDN"
    431   binddn="$MANAGERDN" bindmethod=simple credentials=$PASSWD
    432   $SYNCTYPE retry="3 5 300 5" timeout=1
    433 
    434 EOF
    435 RC=$?
    436 if test $RC != 0 ; then
    437 	echo "ldapmodify failed to add syncrepl consumer ($RC)!"
    438 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    439 	exit $RC
    440 fi
    441 
    442 echo "Using ldapsearch to check that consumer received changes..."
    443 RC=32
    444 for i in 0 1 2 3 4 5; do
    445 	RESULT=`$LDAPSEARCH -H $URI3 \
    446 		-s base -b "ou=ou1,$BASEDN" \
    447 		'(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
    448 	if test "x$RESULT$nullOK" = "xOK" ; then
    449 		RC=0
    450 		break
    451 	fi
    452 	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    453 	sleep $SLEEP1
    454 done
    455 if test $RC != 0 ; then
    456 	echo "ldapsearch failed ($RC)!"
    457 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    458 	exit $RC
    459 fi
    460 
    461 echo "Using ldapmodify to modify provider2..."
    462 $LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD <<EOF >> $TESTOUT 2>&1
    463 dn: ou=ou1,dc=example,dc=com
    464 changetype: modify
    465 add: description
    466 description: Modify1
    467 
    468 EOF
    469 RC=$?
    470 if test $RC != 0 ; then
    471 	echo "ldapmodify failed ($RC)!"
    472 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    473 	exit $RC
    474 fi
    475 
    476 sleep 1
    477 
    478 echo "Using ldapsearch to check that consumer received changes..."
    479 RC=32
    480 for i in 0 1 2 3 4 5; do
    481 	RESULT=`$LDAPSEARCH -H $URI3 \
    482 		-s base -b "ou=ou1,$BASEDN" \
    483 		'(description=Modify1)' 2>&1 | awk '/^dn:/ {print "OK"}'`
    484 	if test "x$RESULT$nullOK" = "xOK" ; then
    485 		RC=0
    486 		break
    487 	fi
    488 	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    489 	sleep $SLEEP1
    490 done
    491 if test $RC != 0 ; then
    492 	echo "ldapsearch failed ($RC)!"
    493 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    494 	exit $RC
    495 fi
    496 
    497 echo "Using ldapmodify to modify glue suffix on provider..."
    498 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD <<EOF >> $TESTOUT 2>&1
    499 dn: dc=example,dc=com
    500 changetype: modify
    501 add: description
    502 description: Test1
    503 
    504 EOF
    505 RC=$?
    506 if test $RC != 0 ; then
    507 	echo "ldapadd failed to modify suffix ($RC)!"
    508 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    509 	exit $RC
    510 fi
    511 
    512 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    513 test "$lock_bug" = 2	&& exit 2
    514 
    515 echo ">>>>> Test succeeded"
    516 
    517 exit 0
    518