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 echo "running defines.sh"
     17 . $SRCDIR/scripts/defines.sh
     18 
     19 if test $SYNCPROV = syncprovno; then 
     20 	echo "Syncrepl provider overlay not available, test skipped"
     21 	exit 0
     22 fi 
     23 
     24 PRODIR=$TESTDIR/pro
     25 CONDIR=$TESTDIR/con1
     26 DBPRO=$PRODIR/db
     27 DBCON=$CONDIR/db
     28 CFPRO=$PRODIR/slapd.d
     29 CFCON=$CONDIR/slapd.d
     30 
     31 mkdir -p $TESTDIR $PRODIR $CONDIR $DBPRO $DBCON $CFPRO $CFCON
     32 
     33 $SLAPPASSWD -g -n >$CONFIGPWF
     34 
     35 if test x"$SYNCMODE" = x ; then
     36 	SYNCMODE=rp
     37 fi
     38 case "$SYNCMODE" in
     39 	ro)
     40 		SYNCTYPE="type=refreshOnly interval=00:00:00:03"
     41 		;;
     42 	rp)
     43 		SYNCTYPE="type=refreshAndPersist"
     44 		;;
     45 	*)
     46 		echo "unknown sync mode $SYNCMODE"
     47 		exit 1;
     48 		;;
     49 esac
     50 
     51 #
     52 # Test replication of dynamic config:
     53 # - start provider
     54 # - start consumer
     55 # - configure over ldap
     56 # - populate over ldap
     57 # - configure syncrepl over ldap
     58 # - retrieve database over ldap and compare against expected results
     59 #
     60 
     61 echo "Starting provider slapd on TCP/IP port $PORT1..."
     62 . $CONFFILTER $BACKEND < $DYNAMICCONF > $CONFLDIF
     63 $SLAPADD -F $CFPRO -n 0 -l $CONFLDIF
     64 RC=$?
     65 if test $RC != 0 ; then
     66 	echo "slapadd failed ($RC)!"
     67 	exit $RC
     68 fi
     69 
     70 cd $PRODIR
     71 $SLAPD -F ./slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 &
     72 PID=$!
     73 if test $WAIT != 0 ; then
     74     echo PID $PID
     75     read foo
     76 fi
     77 KILLPIDS="$PID"
     78 cd $TESTWD
     79 
     80 sleep 1
     81 
     82 echo "Using ldapsearch to check that provider slapd is running..."
     83 for i in 0 1 2 3 4 5; do
     84 	$LDAPSEARCH -s base -b "" -H $URI1 \
     85 		'objectclass=*' > /dev/null 2>&1
     86 	RC=$?
     87 	if test $RC = 0 ; then
     88 		break
     89 	fi
     90 	echo "Waiting 5 seconds for slapd to start..."
     91 	sleep 5
     92 done
     93 
     94 if test $RC != 0 ; then
     95 	echo "ldapsearch failed ($RC)!"
     96 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     97 	exit $RC
     98 fi
     99 
    100 echo "Inserting syncprov overlay on provider..."
    101 if [ "$SYNCPROV" = syncprovmod ]; then
    102 	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
    103 dn: cn=module,cn=config
    104 objectClass: olcModuleList
    105 cn: module
    106 olcModulePath: $TESTWD/../servers/slapd/overlays
    107 olcModuleLoad: syncprov.la
    108 EOF
    109 	RC=$?
    110 	if test $RC != 0 ; then
    111 		echo "ldapadd failed for moduleLoad ($RC)!"
    112 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    113 		exit $RC
    114 	fi
    115 fi
    116 read CONFIGPW < $CONFIGPWF
    117 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    118 dn: olcDatabase={0}config,cn=config
    119 changetype: modify
    120 add: olcSyncRepl
    121 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
    122   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
    123   retry="3 5 300 5" timeout=3
    124 -
    125 add: olcUpdateRef
    126 olcUpdateRef: $URI1
    127 
    128 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
    129 changetype: add
    130 objectClass: olcOverlayConfig
    131 objectClass: olcSyncProvConfig
    132 olcOverlay: syncprov
    133 EOF
    134 RC=$?
    135 if test $RC != 0 ; then
    136 	echo "ldapmodify failed for syncrepl config ($RC)!"
    137 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    138 	exit $RC
    139 fi
    140 
    141 echo "Starting consumer slapd on TCP/IP port $PORT2..."
    142 $SLAPADD -F $CFCON -n 0 -l $CONFLDIF
    143 RC=$?
    144 if test $RC != 0 ; then
    145 	echo "slapadd failed ($RC)!"
    146 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    147 	exit $RC
    148 fi
    149 
    150 cd $CONDIR
    151 $SLAPD -F ./slapd.d -h $URI2 -d $LVL > $LOG2 2>&1 &
    152 CONSUMERPID=$!
    153 if test $WAIT != 0 ; then
    154     echo CONSUMERPID $CONSUMERPID
    155     read foo
    156 fi
    157 KILLPIDS="$KILLPIDS $CONSUMERPID"
    158 cd $TESTWD
    159 
    160 sleep 1
    161 
    162 echo "Using ldapsearch to check that consumer slapd is running..."
    163 for i in 0 1 2 3 4 5; do
    164 	$LDAPSEARCH -s base -b "" -H $URI2 \
    165 		'objectclass=*' > /dev/null 2>&1
    166 	RC=$?
    167 	if test $RC = 0 ; then
    168 		break
    169 	fi
    170 	echo "Waiting 5 seconds for slapd to start..."
    171 	sleep 5
    172 done
    173 
    174 if test $RC != 0 ; then
    175 	echo "ldapsearch failed ($RC)!"
    176 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    177 	exit $RC
    178 fi
    179 
    180 echo "Configuring syncrepl on consumer..."
    181 $LDAPMODIFY -D cn=config -H $URI2 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    182 dn: olcDatabase={0}config,cn=config
    183 changetype: modify
    184 add: olcSyncRepl
    185 olcSyncRepl: rid=001 provider=$URI1 binddn="cn=config" bindmethod=simple
    186   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
    187   retry="3 5 300 5" timeout=3
    188 -
    189 add: olcUpdateRef
    190 olcUpdateRef: $URI1
    191 EOF
    192 
    193 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    194 sleep $SLEEP1
    195 
    196 echo "Using ldapsearch to check that syncrepl received config changes..."
    197 RC=32
    198 for i in 0 1 2 3 4 5; do
    199 	RESULT=`$LDAPSEARCH -H $URI2 -D cn=config -y $CONFIGPWF \
    200 		-s base -b "olcDatabase={0}config,cn=config" \
    201 		'(olcUpdateRef=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
    202 	if test "x$RESULT" = "xOK" ; then
    203 		RC=0
    204 		break
    205 	fi
    206 	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    207 	sleep $SLEEP1
    208 done
    209 
    210 if test $RC != 0 ; then
    211 	echo "ldapsearch failed ($RC)!"
    212 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    213 	exit $RC
    214 fi
    215 
    216 echo "Adding schema and databases on provider..."
    217 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    218 include: file://$ABS_SCHEMADIR/core.ldif
    219 
    220 include: file://$ABS_SCHEMADIR/cosine.ldif
    221 
    222 include: file://$ABS_SCHEMADIR/inetorgperson.ldif
    223 
    224 include: file://$ABS_SCHEMADIR/openldap.ldif
    225 
    226 include: file://$ABS_SCHEMADIR/nis.ldif
    227 EOF
    228 RC=$?
    229 if test $RC != 0 ; then
    230 	echo "ldapadd failed for schema config ($RC)!"
    231 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    232 	exit $RC
    233 fi
    234 
    235 nullExclude="" nullOK=""
    236 test $BACKEND = null && nullExclude="# " nullOK="OK"
    237 
    238 if [ "$BACKENDTYPE" = mod ]; then
    239 	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    240 dn: cn=module,cn=config
    241 objectClass: olcModuleList
    242 cn: module
    243 olcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
    244 olcModuleLoad: back_$BACKEND.la
    245 EOF
    246 	RC=$?
    247 	if test $RC != 0 ; then
    248 		echo "ldapadd failed for backend config ($RC)!"
    249 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    250 		exit $RC
    251 	fi
    252 fi
    253 
    254 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    255 dn: olcDatabase={1}$BACKEND,cn=config
    256 objectClass: olcDatabaseConfig
    257 ${nullExclude}objectClass: olc${BACKEND}Config
    258 olcDatabase: {1}$BACKEND
    259 olcSuffix: $BASEDN
    260 ${nullExclude}olcDbDirectory: ./db
    261 olcRootDN: $MANAGERDN
    262 olcRootPW: $PASSWD
    263 olcSyncRepl: rid=002 provider=$URI1 binddn="$MANAGERDN" bindmethod=simple
    264   credentials=$PASSWD searchbase="$BASEDN" $SYNCTYPE
    265   retry="3 5 300 5" timeout=3
    266 olcUpdateRef: $URI1
    267 
    268 dn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config
    269 changetype: add
    270 objectClass: olcOverlayConfig
    271 objectClass: olcSyncProvConfig
    272 olcOverlay: syncprov
    273 EOF
    274 RC=$?
    275 if test $RC != 0 ; then
    276 	echo "ldapadd failed for database config ($RC)!"
    277 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    278 	exit $RC
    279 fi
    280 
    281 if test $INDEXDB = indexdb ; then
    282 	$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
    283 dn: olcDatabase={1}$BACKEND,cn=config
    284 changetype: modify
    285 add: olcDbIndex
    286 olcDbIndex: objectClass,entryUUID,entryCSN eq
    287 olcDbIndex: cn,uid pres,eq,sub
    288 EOF
    289 	RC=$?
    290 	if test $RC != 0 ; then
    291 		echo "ldapadd modify for database config ($RC)!"
    292 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    293 		exit $RC
    294 	fi
    295 fi
    296 
    297 echo "Using ldapadd to populate provider..."
    298 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \
    299 	>> $TESTOUT 2>&1
    300 RC=$?
    301 if test $RC != 0 ; then
    302 	echo "ldapadd failed for database config ($RC)!"
    303 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    304 	exit $RC
    305 fi
    306 
    307 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    308 sleep $SLEEP1
    309 
    310 echo "Using ldapsearch to check that syncrepl received database changes..."
    311 RC=32
    312 for i in 0 1 2 3 4 5; do
    313 	RESULT=`$LDAPSEARCH -H $URI2 \
    314 		-s base -b "cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com" \
    315 		'(objectClass=*)' 2>&1 | awk '/^dn:/ {print "OK"}'`
    316 	if test "x$RESULT$nullOK" = "xOK" ; then
    317 		RC=0
    318 		break
    319 	fi
    320 	echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    321 	sleep $SLEEP1
    322 done
    323 
    324 if test $RC != 0 ; then
    325 	echo "ldapsearch failed ($RC)!"
    326 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    327 	exit $RC
    328 fi
    329 
    330 echo "Replacing olcSyncrepl on provider..."
    331 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    332 dn: olcDatabase={0}config,cn=config
    333 changetype: modify
    334 replace: olcSyncRepl
    335 olcSyncRepl: rid=003 provider=$URI1 binddn="cn=config" bindmethod=simple
    336   credentials=$CONFIGPW searchbase="cn=config" type=refreshAndPersist
    337   retry="3 5 300 5" timeout=3
    338 EOF
    339 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..."
    340 sleep $SLEEP1
    341 
    342 echo "Using ldapsearch to read config from the provider..."
    343 $LDAPSEARCH -b cn=config -D cn=config -H $URI1 -y $CONFIGPWF  \
    344 	'objectclass=*' > $PROVIDEROUT 2>&1
    345 RC=$?
    346 
    347 if test $RC != 0 ; then
    348 	echo "ldapsearch failed at provider ($RC)!"
    349 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    350 	exit $RC
    351 fi
    352 
    353 echo "Using ldapsearch to read config from the consumer..."
    354 $LDAPSEARCH -b cn=config -D cn=config -H $URI2 -y $CONFIGPWF \
    355 	'objectclass=*' > $CONSUMEROUT 2>&1
    356 RC=$?
    357 
    358 if test $RC != 0 ; then
    359 	echo "ldapsearch failed at consumer ($RC)!"
    360 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    361 	exit $RC
    362 fi
    363 
    364 echo "Filtering provider results..."
    365 $LDIFFILTER < $PROVIDEROUT > $PROVIDERFLT
    366 echo "Filtering consumer results..."
    367 $LDIFFILTER < $CONSUMEROUT > $CONSUMERFLT
    368 
    369 echo "Comparing retrieved configs from provider and consumer..."
    370 $CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT
    371 
    372 if test $? != 0 ; then
    373 	echo "test failed - provider and consumer configs differ"
    374 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    375 	exit 1
    376 fi
    377 
    378 echo "Using ldapsearch to read all the entries from the provider..."
    379 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI1 -w $PASSWD  \
    380 	'objectclass=*' > $PROVIDEROUT 2>&1
    381 RC=$?
    382 
    383 if test $RC != 0 ; then
    384 	echo "ldapsearch failed at provider ($RC)!"
    385 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    386 	exit $RC
    387 fi
    388 
    389 echo "Using ldapsearch to read all the entries from the consumer..."
    390 $LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI2 -w $PASSWD  \
    391 	'objectclass=*' > $CONSUMEROUT 2>&1
    392 RC=$?
    393 
    394 if test $RC != 0 ; then
    395 	echo "ldapsearch failed at consumer ($RC)!"
    396 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    397 	exit $RC
    398 fi
    399 
    400 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    401 
    402 echo "Filtering provider results..."
    403 $LDIFFILTER < $PROVIDEROUT > $PROVIDERFLT
    404 echo "Filtering consumer results..."
    405 $LDIFFILTER < $CONSUMEROUT > $CONSUMERFLT
    406 
    407 echo "Comparing retrieved entries from provider and consumer..."
    408 $CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT
    409 
    410 if test $? != 0 ; then
    411 	echo "test failed - provider and consumer databases differ"
    412 	exit 1
    413 fi
    414 
    415 echo ">>>>> Test succeeded"
    416 
    417 test $KILLSERVERS != no && wait
    418 
    419 exit 0
    420