1*e670fd5cSchristos#! /bin/sh 2*e670fd5cSchristos# $OpenLDAP$ 3*e670fd5cSchristos## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4*e670fd5cSchristos## 5*e670fd5cSchristos## Copyright 1998-2021 The OpenLDAP Foundation. 6*e670fd5cSchristos## All rights reserved. 7*e670fd5cSchristos## 8*e670fd5cSchristos## Redistribution and use in source and binary forms, with or without 9*e670fd5cSchristos## modification, are permitted only as authorized by the OpenLDAP 10*e670fd5cSchristos## Public License. 11*e670fd5cSchristos## 12*e670fd5cSchristos## A copy of this license is available in the file LICENSE in the 13*e670fd5cSchristos## top-level directory of the distribution or, alternatively, at 14*e670fd5cSchristos## <http://www.OpenLDAP.org/license.html>. 15*e670fd5cSchristos 16*e670fd5cSchristosecho "running defines.sh" 17*e670fd5cSchristos. $SRCDIR/scripts/defines.sh 18*e670fd5cSchristos 19*e670fd5cSchristosif test $SYNCPROV = syncprovno; then 20*e670fd5cSchristos echo "Syncrepl provider overlay not available, test skipped" 21*e670fd5cSchristos exit 0 22*e670fd5cSchristosfi 23*e670fd5cSchristos 24*e670fd5cSchristosMPR=${MPR-4} 25*e670fd5cSchristos 26*e670fd5cSchristosif [ $MPR -gt 9 ]; then 27*e670fd5cSchristosMPR=9 28*e670fd5cSchristosfi 29*e670fd5cSchristos 30*e670fd5cSchristosXDIR=$TESTDIR/srv 31*e670fd5cSchristosTMP=$TESTDIR/tmp 32*e670fd5cSchristos 33*e670fd5cSchristosmkdir -p $TESTDIR 34*e670fd5cSchristos 35*e670fd5cSchristos$SLAPPASSWD -g -n >$CONFIGPWF 36*e670fd5cSchristos 37*e670fd5cSchristosif test x"$SYNCMODE" = x ; then 38*e670fd5cSchristos SYNCMODE=rp 39*e670fd5cSchristosfi 40*e670fd5cSchristoscase "$SYNCMODE" in 41*e670fd5cSchristos ro) 42*e670fd5cSchristos SYNCTYPE="type=refreshOnly interval=00:00:00:03" 43*e670fd5cSchristos ;; 44*e670fd5cSchristos rp) 45*e670fd5cSchristos SYNCTYPE="type=refreshAndPersist" 46*e670fd5cSchristos ;; 47*e670fd5cSchristos *) 48*e670fd5cSchristos echo "unknown sync mode $SYNCMODE" 49*e670fd5cSchristos exit 1; 50*e670fd5cSchristos ;; 51*e670fd5cSchristosesac 52*e670fd5cSchristos 53*e670fd5cSchristos# 54*e670fd5cSchristos# Test replication of dynamic config: 55*e670fd5cSchristos# - start servers 56*e670fd5cSchristos# - configure over ldap 57*e670fd5cSchristos# - populate over ldap 58*e670fd5cSchristos# - configure syncrepl over ldap 59*e670fd5cSchristos# - retrieve database over ldap and compare against expected results 60*e670fd5cSchristos# 61*e670fd5cSchristos 62*e670fd5cSchristosecho "Initializing server configurations..." 63*e670fd5cSchristosn=1 64*e670fd5cSchristoswhile [ $n -le $MPR ]; do 65*e670fd5cSchristos 66*e670fd5cSchristosDBDIR=${XDIR}$n/db 67*e670fd5cSchristosCFDIR=${XDIR}$n/slapd.d 68*e670fd5cSchristos 69*e670fd5cSchristosmkdir -p ${XDIR}$n $DBDIR $CFDIR 70*e670fd5cSchristos 71*e670fd5cSchristos$SLAPADD -F $CFDIR -n 0 <<EOF 72*e670fd5cSchristosdn: cn=config 73*e670fd5cSchristosobjectClass: olcGlobal 74*e670fd5cSchristoscn: config 75*e670fd5cSchristosolcServerID: $n 76*e670fd5cSchristos 77*e670fd5cSchristosdn: olcDatabase={0}config,cn=config 78*e670fd5cSchristosobjectClass: olcDatabaseConfig 79*e670fd5cSchristosolcDatabase: {0}config 80*e670fd5cSchristosolcRootPW:< file://$CONFIGPWF 81*e670fd5cSchristosEOF 82*e670fd5cSchristos 83*e670fd5cSchristosn=`expr $n + 1` 84*e670fd5cSchristosdone 85*e670fd5cSchristos 86*e670fd5cSchristosecho "Starting server 1 on TCP/IP port $PORT1..." 87*e670fd5cSchristoscd ${XDIR}1 88*e670fd5cSchristos$SLAPD -F slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 & 89*e670fd5cSchristosPID=$! 90*e670fd5cSchristosif test $WAIT != 0 ; then 91*e670fd5cSchristos echo PID $PID 92*e670fd5cSchristos read foo 93*e670fd5cSchristosfi 94*e670fd5cSchristosKILLPIDS="$PID" 95*e670fd5cSchristoscd $TESTWD 96*e670fd5cSchristos 97*e670fd5cSchristossleep 1 98*e670fd5cSchristos 99*e670fd5cSchristosecho "Using ldapsearch to check that server 1 is running..." 100*e670fd5cSchristosfor i in 0 1 2 3 4 5; do 101*e670fd5cSchristos $LDAPSEARCH -s base -b "" -H $URI1 \ 102*e670fd5cSchristos 'objectclass=*' > /dev/null 2>&1 103*e670fd5cSchristos RC=$? 104*e670fd5cSchristos if test $RC = 0 ; then 105*e670fd5cSchristos break 106*e670fd5cSchristos fi 107*e670fd5cSchristos echo "Waiting 5 seconds for slapd to start..." 108*e670fd5cSchristos sleep 5 109*e670fd5cSchristosdone 110*e670fd5cSchristos 111*e670fd5cSchristosif test $RC != 0 ; then 112*e670fd5cSchristos echo "ldapsearch failed ($RC)!" 113*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 114*e670fd5cSchristos exit $RC 115*e670fd5cSchristosfi 116*e670fd5cSchristos 117*e670fd5cSchristosecho "Inserting syncprov overlay on server 1..." 118*e670fd5cSchristosecho "" > $TMP 119*e670fd5cSchristosif [ "$SYNCPROV" = syncprovmod ]; then 120*e670fd5cSchristoscat <<EOF >> $TMP 121*e670fd5cSchristosdn: cn=module,cn=config 122*e670fd5cSchristoschangetype: add 123*e670fd5cSchristosobjectClass: olcModuleList 124*e670fd5cSchristoscn: module 125*e670fd5cSchristosolcModulePath: $TESTWD/../servers/slapd/overlays 126*e670fd5cSchristosolcModuleLoad: syncprov.la 127*e670fd5cSchristos 128*e670fd5cSchristosEOF 129*e670fd5cSchristosfi 130*e670fd5cSchristos# 131*e670fd5cSchristos# Note that we configure a timeout here; it's possible for both 132*e670fd5cSchristos# servers to attempt to bind to each other while a modify to 133*e670fd5cSchristos# cn=config is in progress. When the modify pauses the thread pool 134*e670fd5cSchristos# neither server will progress. The timeout will drop the syncrepl 135*e670fd5cSchristos# attempt and allow the modifies to complete. 136*e670fd5cSchristos# 137*e670fd5cSchristosread CONFIGPW < $CONFIGPWF 138*e670fd5cSchristosecho "dn: cn=config" >> $TMP 139*e670fd5cSchristosecho "changetype: modify" >> $TMP 140*e670fd5cSchristosecho "replace: olcServerID" >> $TMP 141*e670fd5cSchristosn=1 142*e670fd5cSchristoswhile [ $n -le $MPR ]; do 143*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 144*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 145*e670fd5cSchristosecho "olcServerID: $n $URI" >> $TMP 146*e670fd5cSchristosn=`expr $n + 1` 147*e670fd5cSchristosdone 148*e670fd5cSchristos 149*e670fd5cSchristoscat <<EOF >> $TMP 150*e670fd5cSchristos 151*e670fd5cSchristosdn: olcOverlay=syncprov,olcDatabase={0}config,cn=config 152*e670fd5cSchristoschangetype: add 153*e670fd5cSchristosobjectClass: olcOverlayConfig 154*e670fd5cSchristosobjectClass: olcSyncProvConfig 155*e670fd5cSchristosolcOverlay: syncprov 156*e670fd5cSchristos 157*e670fd5cSchristosdn: olcDatabase={0}config,cn=config 158*e670fd5cSchristoschangetype: modify 159*e670fd5cSchristosadd: olcSyncRepl 160*e670fd5cSchristosEOF 161*e670fd5cSchristos 162*e670fd5cSchristosn=1 163*e670fd5cSchristoswhile [ $n -le $MPR ]; do 164*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 165*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 166*e670fd5cSchristosecho "olcSyncRepl: rid=00$n provider=$URI binddn=\"cn=config\" bindmethod=simple" >> $TMP 167*e670fd5cSchristosecho " credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP 168*e670fd5cSchristosecho " retry=\"3 10 300 5\" timeout=3" >> $TMP 169*e670fd5cSchristosn=`expr $n + 1` 170*e670fd5cSchristosdone 171*e670fd5cSchristosecho "-" >> $TMP 172*e670fd5cSchristosecho "add: olcMultiProvider" >> $TMP 173*e670fd5cSchristosecho "olcMultiProvider: TRUE" >> $TMP 174*e670fd5cSchristos$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >> $TESTOUT 2>&1 175*e670fd5cSchristosRC=$? 176*e670fd5cSchristosif test $RC != 0 ; then 177*e670fd5cSchristos echo "ldapmodify failed for syncrepl config ($RC)!" 178*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 179*e670fd5cSchristos exit $RC 180*e670fd5cSchristosfi 181*e670fd5cSchristos 182*e670fd5cSchristosn=2 183*e670fd5cSchristoswhile [ $n -le $MPR ]; do 184*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 185*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 186*e670fd5cSchristosLOG=$TESTDIR/slapd.$n.log 187*e670fd5cSchristosecho "Starting server $n on TCP/IP port $PORT..." 188*e670fd5cSchristoscd ${XDIR}$n 189*e670fd5cSchristos$SLAPD -F ./slapd.d -h $URI -d $LVL > $LOG 2>&1 & 190*e670fd5cSchristosCONSUMERPID=$! 191*e670fd5cSchristosif test $WAIT != 0 ; then 192*e670fd5cSchristos echo CONSUMERPID $CONSUMERPID 193*e670fd5cSchristos read foo 194*e670fd5cSchristosfi 195*e670fd5cSchristosKILLPIDS="$KILLPIDS $CONSUMERPID" 196*e670fd5cSchristoscd $TESTWD 197*e670fd5cSchristos 198*e670fd5cSchristossleep 1 199*e670fd5cSchristos 200*e670fd5cSchristosecho "Using ldapsearch to check that server $n is running..." 201*e670fd5cSchristosfor i in 0 1 2 3 4 5; do 202*e670fd5cSchristos $LDAPSEARCH -s base -b "" -H $URI \ 203*e670fd5cSchristos 'objectclass=*' > /dev/null 2>&1 204*e670fd5cSchristos RC=$? 205*e670fd5cSchristos if test $RC = 0 ; then 206*e670fd5cSchristos break 207*e670fd5cSchristos fi 208*e670fd5cSchristos echo "Waiting 5 seconds for slapd to start..." 209*e670fd5cSchristos sleep 5 210*e670fd5cSchristosdone 211*e670fd5cSchristos 212*e670fd5cSchristosif test $RC != 0 ; then 213*e670fd5cSchristos echo "ldapsearch failed ($RC)!" 214*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 215*e670fd5cSchristos exit $RC 216*e670fd5cSchristosfi 217*e670fd5cSchristos 218*e670fd5cSchristosecho "Configuring syncrepl on server $n..." 219*e670fd5cSchristoscat <<EOF > $TMP 220*e670fd5cSchristosdn: olcDatabase={0}config,cn=config 221*e670fd5cSchristoschangetype: modify 222*e670fd5cSchristosadd: olcSyncRepl 223*e670fd5cSchristosEOF 224*e670fd5cSchristosj=1 225*e670fd5cSchristoswhile [ $j -le $MPR ]; do 226*e670fd5cSchristosP2=`expr $BASEPORT + $j` 227*e670fd5cSchristosU2="ldap://${LOCALHOST}:$P2/" 228*e670fd5cSchristosecho "olcSyncRepl: rid=00$j provider=$U2 binddn=\"cn=config\" bindmethod=simple" >> $TMP 229*e670fd5cSchristosecho " credentials=$CONFIGPW searchbase=\"cn=config\" type=refreshAndPersist" >> $TMP 230*e670fd5cSchristosecho " retry=\"3 10 300 5\" timeout=3" >> $TMP 231*e670fd5cSchristosj=`expr $j + 1` 232*e670fd5cSchristosdone 233*e670fd5cSchristoscat <<EOF >> $TMP 234*e670fd5cSchristos- 235*e670fd5cSchristosadd: olcMultiProvider 236*e670fd5cSchristosolcMultiProvider: TRUE 237*e670fd5cSchristosEOF 238*e670fd5cSchristos$LDAPMODIFY -D cn=config -H $URI -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1 239*e670fd5cSchristosn=`expr $n + 1` 240*e670fd5cSchristosdone 241*e670fd5cSchristos 242*e670fd5cSchristosecho "Adding schema and databases on server 1..." 243*e670fd5cSchristos$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1 244*e670fd5cSchristosinclude: file://$ABS_SCHEMADIR/core.ldif 245*e670fd5cSchristos 246*e670fd5cSchristosinclude: file://$ABS_SCHEMADIR/cosine.ldif 247*e670fd5cSchristos 248*e670fd5cSchristosinclude: file://$ABS_SCHEMADIR/inetorgperson.ldif 249*e670fd5cSchristos 250*e670fd5cSchristosinclude: file://$ABS_SCHEMADIR/openldap.ldif 251*e670fd5cSchristos 252*e670fd5cSchristosinclude: file://$ABS_SCHEMADIR/nis.ldif 253*e670fd5cSchristosEOF 254*e670fd5cSchristosRC=$? 255*e670fd5cSchristosif test $RC != 0 ; then 256*e670fd5cSchristos echo "ldapadd failed for schema config ($RC)!" 257*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 258*e670fd5cSchristos exit $RC 259*e670fd5cSchristosfi 260*e670fd5cSchristos 261*e670fd5cSchristosnullExclude="" 262*e670fd5cSchristostest $BACKEND = null && nullExclude="# " 263*e670fd5cSchristos 264*e670fd5cSchristosecho "" > $TMP 265*e670fd5cSchristosif [ "$BACKENDTYPE" = mod ]; then 266*e670fd5cSchristoscat <<EOF >> $TMP 267*e670fd5cSchristosdn: cn=module,cn=config 268*e670fd5cSchristosobjectClass: olcModuleList 269*e670fd5cSchristoscn: module 270*e670fd5cSchristosolcModulePath: $TESTWD/../servers/slapd/back-$BACKEND 271*e670fd5cSchristosolcModuleLoad: back_$BACKEND.la 272*e670fd5cSchristos 273*e670fd5cSchristosEOF 274*e670fd5cSchristosfi 275*e670fd5cSchristos 276*e670fd5cSchristoscat <<EOF >> $TMP 277*e670fd5cSchristosdn: olcDatabase={1}$BACKEND,cn=config 278*e670fd5cSchristosobjectClass: olcDatabaseConfig 279*e670fd5cSchristos${nullExclude}objectClass: olc${BACKEND}Config 280*e670fd5cSchristosolcDatabase: {1}$BACKEND 281*e670fd5cSchristosolcSuffix: $BASEDN 282*e670fd5cSchristos${nullExclude}olcDbDirectory: ./db 283*e670fd5cSchristosolcRootDN: $MANAGERDN 284*e670fd5cSchristosolcRootPW: $PASSWD 285*e670fd5cSchristosEOF 286*e670fd5cSchristos 287*e670fd5cSchristosn=1 288*e670fd5cSchristoswhile [ $n -le $MPR ]; do 289*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 290*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 291*e670fd5cSchristos 292*e670fd5cSchristosecho "olcSyncRepl: rid=01$n provider=$URI binddn=\"$MANAGERDN\" bindmethod=simple" >> $TMP 293*e670fd5cSchristosecho " credentials=$PASSWD searchbase=\"$BASEDN\" $SYNCTYPE" >> $TMP 294*e670fd5cSchristosecho " retry=\"3 10 300 5\" timeout=3" >> $TMP 295*e670fd5cSchristosn=`expr $n + 1` 296*e670fd5cSchristosdone 297*e670fd5cSchristos 298*e670fd5cSchristoscat <<EOF >> $TMP 299*e670fd5cSchristosolcMultiProvider: TRUE 300*e670fd5cSchristos 301*e670fd5cSchristosdn: olcOverlay=syncprov,olcDatabase={1}${BACKEND},cn=config 302*e670fd5cSchristosobjectClass: olcOverlayConfig 303*e670fd5cSchristosobjectClass: olcSyncProvConfig 304*e670fd5cSchristosolcOverlay: syncprov 305*e670fd5cSchristosEOF 306*e670fd5cSchristos$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF < $TMP >>$TESTOUT 2>&1 307*e670fd5cSchristosRC=$? 308*e670fd5cSchristosif test $RC != 0 ; then 309*e670fd5cSchristos echo "ldapadd failed for database config ($RC)!" 310*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 311*e670fd5cSchristos exit $RC 312*e670fd5cSchristosfi 313*e670fd5cSchristos 314*e670fd5cSchristosif test $INDEXDB = indexdb ; then 315*e670fd5cSchristos $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1 316*e670fd5cSchristosdn: olcDatabase={1}$BACKEND,cn=config 317*e670fd5cSchristoschangetype: modify 318*e670fd5cSchristosadd: olcDbIndex 319*e670fd5cSchristosolcDbIndex: objectClass,entryUUID,entryCSN eq 320*e670fd5cSchristosolcDbIndex: cn,uid pres,eq,sub 321*e670fd5cSchristosEOF 322*e670fd5cSchristos RC=$? 323*e670fd5cSchristos if test $RC != 0 ; then 324*e670fd5cSchristos echo "ldapadd modify for database config ($RC)!" 325*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 326*e670fd5cSchristos exit $RC 327*e670fd5cSchristos fi 328*e670fd5cSchristosfi 329*e670fd5cSchristos 330*e670fd5cSchristosecho "Using ldapadd to populate server 1..." 331*e670fd5cSchristos$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD -f $LDIFORDERED \ 332*e670fd5cSchristos >> $TESTOUT 2>&1 333*e670fd5cSchristosRC=$? 334*e670fd5cSchristosif test $RC != 0 ; then 335*e670fd5cSchristos echo "ldapadd failed for server 1 database ($RC)!" 336*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 337*e670fd5cSchristos exit $RC 338*e670fd5cSchristosfi 339*e670fd5cSchristos 340*e670fd5cSchristosecho "Waiting $SLEEP2 seconds for syncrepl to receive changes..." 341*e670fd5cSchristossleep $SLEEP2 342*e670fd5cSchristos 343*e670fd5cSchristosn=1 344*e670fd5cSchristoswhile [ $n -le $MPR ]; do 345*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 346*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 347*e670fd5cSchristos 348*e670fd5cSchristosecho "Using ldapsearch to read config from server $n..." 349*e670fd5cSchristos$LDAPSEARCH -b cn=config -D cn=config -H $URI -y $CONFIGPWF \ 350*e670fd5cSchristos 'objectclass=*' > $TESTDIR/server$n.out 2>&1 351*e670fd5cSchristosRC=$? 352*e670fd5cSchristos 353*e670fd5cSchristosif test $RC != 0 ; then 354*e670fd5cSchristos echo "ldapsearch failed at server $n ($RC)!" 355*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 356*e670fd5cSchristos exit $RC 357*e670fd5cSchristosfi 358*e670fd5cSchristos 359*e670fd5cSchristos$LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt 360*e670fd5cSchristos 361*e670fd5cSchristosn=`expr $n + 1` 362*e670fd5cSchristosdone 363*e670fd5cSchristos 364*e670fd5cSchristosn=2 365*e670fd5cSchristoswhile [ $n -le $MPR ]; do 366*e670fd5cSchristosecho "Comparing retrieved configs from server 1 and server $n..." 367*e670fd5cSchristos$CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT 368*e670fd5cSchristos 369*e670fd5cSchristosif test $? != 0 ; then 370*e670fd5cSchristos echo "test failed - server 1 and server $n configs differ" 371*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 372*e670fd5cSchristos exit 1 373*e670fd5cSchristosfi 374*e670fd5cSchristosn=`expr $n + 1` 375*e670fd5cSchristosdone 376*e670fd5cSchristos 377*e670fd5cSchristosn=1 378*e670fd5cSchristoswhile [ $n -le $MPR ]; do 379*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 380*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 381*e670fd5cSchristos 382*e670fd5cSchristosecho "Using ldapsearch to read all the entries from server $n..." 383*e670fd5cSchristos$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \ 384*e670fd5cSchristos 'objectclass=*' > $TESTDIR/server$n.out 2>&1 385*e670fd5cSchristosRC=$? 386*e670fd5cSchristos 387*e670fd5cSchristosif test $RC != 0 ; then 388*e670fd5cSchristos echo "ldapsearch failed at server $n ($RC)!" 389*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 390*e670fd5cSchristos exit $RC 391*e670fd5cSchristosfi 392*e670fd5cSchristos$LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt 393*e670fd5cSchristosn=`expr $n + 1` 394*e670fd5cSchristosdone 395*e670fd5cSchristos 396*e670fd5cSchristosn=2 397*e670fd5cSchristoswhile [ $n -le $MPR ]; do 398*e670fd5cSchristosecho "Comparing retrieved entries from server 1 and server $n..." 399*e670fd5cSchristos$CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT 400*e670fd5cSchristos 401*e670fd5cSchristosif test $? != 0 ; then 402*e670fd5cSchristos echo "test failed - server 1 and server $n databases differ" 403*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 404*e670fd5cSchristos exit 1 405*e670fd5cSchristosfi 406*e670fd5cSchristosn=`expr $n + 1` 407*e670fd5cSchristosdone 408*e670fd5cSchristos 409*e670fd5cSchristosecho "Using ldapadd to populate server 2..." 410*e670fd5cSchristos$LDAPADD -D "$MANAGERDN" -H $URI2 -w $PASSWD -f $LDIFADD1 \ 411*e670fd5cSchristos >> $TESTOUT 2>&1 412*e670fd5cSchristosRC=$? 413*e670fd5cSchristosif test $RC != 0 ; then 414*e670fd5cSchristos echo "ldapadd failed for server 2 database ($RC)!" 415*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 416*e670fd5cSchristos exit $RC 417*e670fd5cSchristosfi 418*e670fd5cSchristos 419*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 420*e670fd5cSchristossleep $SLEEP1 421*e670fd5cSchristos 422*e670fd5cSchristosn=1 423*e670fd5cSchristoswhile [ $n -le $MPR ]; do 424*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 425*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 426*e670fd5cSchristos 427*e670fd5cSchristosecho "Using ldapsearch to read all the entries from server $n..." 428*e670fd5cSchristos$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \ 429*e670fd5cSchristos 'objectclass=*' > $TESTDIR/server$n.out 2>&1 430*e670fd5cSchristosRC=$? 431*e670fd5cSchristos 432*e670fd5cSchristosif test $RC != 0 ; then 433*e670fd5cSchristos echo "ldapsearch failed at server $n ($RC)!" 434*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 435*e670fd5cSchristos exit $RC 436*e670fd5cSchristosfi 437*e670fd5cSchristos$LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt 438*e670fd5cSchristosn=`expr $n + 1` 439*e670fd5cSchristosdone 440*e670fd5cSchristos 441*e670fd5cSchristosn=2 442*e670fd5cSchristoswhile [ $n -le $MPR ]; do 443*e670fd5cSchristosecho "Comparing retrieved entries from server 1 and server $n..." 444*e670fd5cSchristos$CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT 445*e670fd5cSchristos 446*e670fd5cSchristosif test $? != 0 ; then 447*e670fd5cSchristos echo "test failed - server 1 and server $n databases differ" 448*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 449*e670fd5cSchristos exit 1 450*e670fd5cSchristosfi 451*e670fd5cSchristosn=`expr $n + 1` 452*e670fd5cSchristosdone 453*e670fd5cSchristos 454*e670fd5cSchristosecho "Using ldapadd to populate server 3..." 455*e670fd5cSchristos$LDAPADD -D "$MANAGERDN" -H $URI3 -w $PASSWD \ 456*e670fd5cSchristos << EOMODS >> $TESTOUT 2>&1 457*e670fd5cSchristosdn: cn=Server 3 Test,dc=example,dc=com 458*e670fd5cSchristoschangetype: add 459*e670fd5cSchristosobjectClass: device 460*e670fd5cSchristoscn: Server 3 Test 461*e670fd5cSchristosEOMODS 462*e670fd5cSchristosRC=$? 463*e670fd5cSchristosif test $RC != 0 ; then 464*e670fd5cSchristos echo "ldapadd failed for server 3 database ($RC)!" 465*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 466*e670fd5cSchristos exit $RC 467*e670fd5cSchristosfi 468*e670fd5cSchristos 469*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 470*e670fd5cSchristossleep $SLEEP1 471*e670fd5cSchristos 472*e670fd5cSchristosn=1 473*e670fd5cSchristoswhile [ $n -le $MPR ]; do 474*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 475*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 476*e670fd5cSchristos 477*e670fd5cSchristosecho "Using ldapsearch to read all the entries from server $n..." 478*e670fd5cSchristos$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \ 479*e670fd5cSchristos 'objectclass=*' > $TESTDIR/server$n.out 2>&1 480*e670fd5cSchristosRC=$? 481*e670fd5cSchristos 482*e670fd5cSchristosif test $RC != 0 ; then 483*e670fd5cSchristos echo "ldapsearch failed at server $n ($RC)!" 484*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 485*e670fd5cSchristos exit $RC 486*e670fd5cSchristosfi 487*e670fd5cSchristos$LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt 488*e670fd5cSchristosn=`expr $n + 1` 489*e670fd5cSchristosdone 490*e670fd5cSchristos 491*e670fd5cSchristosn=2 492*e670fd5cSchristoswhile [ $n -le $MPR ]; do 493*e670fd5cSchristosecho "Comparing retrieved entries from server 1 and server $n..." 494*e670fd5cSchristos$CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT 495*e670fd5cSchristos 496*e670fd5cSchristosif test $? != 0 ; then 497*e670fd5cSchristos echo "test failed - server 1 and server $n databases differ" 498*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 499*e670fd5cSchristos exit 1 500*e670fd5cSchristosfi 501*e670fd5cSchristosn=`expr $n + 1` 502*e670fd5cSchristosdone 503*e670fd5cSchristos 504*e670fd5cSchristosecho "Using ldapmodify to add to server 1 entries that will be deleted..." 505*e670fd5cSchristos$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 506*e670fd5cSchristos >> $TESTOUT 2>&1 << EOADDS 507*e670fd5cSchristosdn: cn=To be deleted by server 1,dc=example,dc=com 508*e670fd5cSchristoschangetype: add 509*e670fd5cSchristosobjectClass: device 510*e670fd5cSchristos# no distinguished values, will be added by DSA 511*e670fd5cSchristos 512*e670fd5cSchristosdn: cn=To be deleted by server 2,dc=example,dc=com 513*e670fd5cSchristoschangetype: add 514*e670fd5cSchristosobjectClass: device 515*e670fd5cSchristos# no distinguished values, will be added by DSA 516*e670fd5cSchristos 517*e670fd5cSchristosdn: cn=To be deleted by server 3,dc=example,dc=com 518*e670fd5cSchristoschangetype: add 519*e670fd5cSchristosobjectClass: device 520*e670fd5cSchristos# no distinguished values, will be added by DSA 521*e670fd5cSchristos 522*e670fd5cSchristosdn: cn=To be deleted by server 1,dc=example,dc=com 523*e670fd5cSchristoschangetype: delete 524*e670fd5cSchristosEOADDS 525*e670fd5cSchristosRC=$? 526*e670fd5cSchristosif test $RC != 0 ; then 527*e670fd5cSchristos echo "ldapmodify failed for server 1 database ($RC)!" 528*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 529*e670fd5cSchristos exit $RC 530*e670fd5cSchristosfi 531*e670fd5cSchristos 532*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 533*e670fd5cSchristossleep $SLEEP1 534*e670fd5cSchristos 535*e670fd5cSchristosn=1 536*e670fd5cSchristoswhile [ $n -le $MPR ]; do 537*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 538*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 539*e670fd5cSchristos 540*e670fd5cSchristosecho "Using ldapsearch to read all the entries from server $n..." 541*e670fd5cSchristos$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \ 542*e670fd5cSchristos 'objectclass=*' > $TESTDIR/server$n.out 2>&1 543*e670fd5cSchristosRC=$? 544*e670fd5cSchristos 545*e670fd5cSchristosif test $RC != 0 ; then 546*e670fd5cSchristos echo "ldapsearch failed at server $n ($RC)!" 547*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 548*e670fd5cSchristos exit $RC 549*e670fd5cSchristosfi 550*e670fd5cSchristos$LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt 551*e670fd5cSchristosn=`expr $n + 1` 552*e670fd5cSchristosdone 553*e670fd5cSchristos 554*e670fd5cSchristosn=2 555*e670fd5cSchristoswhile [ $n -le $MPR ]; do 556*e670fd5cSchristosecho "Comparing retrieved entries from server 1 and server $n..." 557*e670fd5cSchristos$CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT 558*e670fd5cSchristos 559*e670fd5cSchristosif test $? != 0 ; then 560*e670fd5cSchristos echo "test failed - server 1 and server $n databases differ" 561*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 562*e670fd5cSchristos exit 1 563*e670fd5cSchristosfi 564*e670fd5cSchristosn=`expr $n + 1` 565*e670fd5cSchristosdone 566*e670fd5cSchristos 567*e670fd5cSchristosecho "Using ldapmodify to delete entries from server 2..." 568*e670fd5cSchristos$LDAPMODIFY -D "$MANAGERDN" -H $URI2 -w $PASSWD \ 569*e670fd5cSchristos >> $TESTOUT 2>&1 << EOADDS 570*e670fd5cSchristosdn: cn=To be deleted by server 2,dc=example,dc=com 571*e670fd5cSchristoschangetype: delete 572*e670fd5cSchristosEOADDS 573*e670fd5cSchristosRC=$? 574*e670fd5cSchristosif test $RC != 0 ; then 575*e670fd5cSchristos echo "ldapmodify failed for server 2 database ($RC)!" 576*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 577*e670fd5cSchristos exit $RC 578*e670fd5cSchristosfi 579*e670fd5cSchristos 580*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 581*e670fd5cSchristossleep $SLEEP1 582*e670fd5cSchristos 583*e670fd5cSchristosecho "Using ldapmodify to delete entries from server 3..." 584*e670fd5cSchristos$LDAPMODIFY -D "$MANAGERDN" -H $URI3 -w $PASSWD \ 585*e670fd5cSchristos >> $TESTOUT 2>&1 << EOADDS 586*e670fd5cSchristosdn: cn=To be deleted by server 3,dc=example,dc=com 587*e670fd5cSchristoschangetype: delete 588*e670fd5cSchristosEOADDS 589*e670fd5cSchristosRC=$? 590*e670fd5cSchristosif test $RC != 0 ; then 591*e670fd5cSchristos echo "ldapmodify failed for server 3 database ($RC)!" 592*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 593*e670fd5cSchristos exit $RC 594*e670fd5cSchristosfi 595*e670fd5cSchristos 596*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 597*e670fd5cSchristossleep $SLEEP1 598*e670fd5cSchristos 599*e670fd5cSchristosn=1 600*e670fd5cSchristoswhile [ $n -le $MPR ]; do 601*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 602*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 603*e670fd5cSchristos 604*e670fd5cSchristosecho "Using ldapsearch to read all the entries from server $n..." 605*e670fd5cSchristos$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \ 606*e670fd5cSchristos 'objectclass=*' > $TESTDIR/server$n.out 2>&1 607*e670fd5cSchristosRC=$? 608*e670fd5cSchristos 609*e670fd5cSchristosif test $RC != 0 ; then 610*e670fd5cSchristos echo "ldapsearch failed at server $n ($RC)!" 611*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 612*e670fd5cSchristos exit $RC 613*e670fd5cSchristosfi 614*e670fd5cSchristos$LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt 615*e670fd5cSchristosn=`expr $n + 1` 616*e670fd5cSchristosdone 617*e670fd5cSchristos 618*e670fd5cSchristosn=2 619*e670fd5cSchristoswhile [ $n -le $MPR ]; do 620*e670fd5cSchristosecho "Comparing retrieved entries from server 1 and server $n..." 621*e670fd5cSchristos$CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT 622*e670fd5cSchristos 623*e670fd5cSchristosif test $? != 0 ; then 624*e670fd5cSchristos echo "test failed - server 1 and server $n databases differ" 625*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 626*e670fd5cSchristos exit 1 627*e670fd5cSchristosfi 628*e670fd5cSchristosn=`expr $n + 1` 629*e670fd5cSchristosdone 630*e670fd5cSchristos 631*e670fd5cSchristos# kill! 632*e670fd5cSchristos# test $KILLSERVERS != no && kill -HUP $KILLPIDS 633*e670fd5cSchristoskill -HUP $KILLPIDS 634*e670fd5cSchristos 635*e670fd5cSchristos# kill! 636*e670fd5cSchristos# test $KILLSERVERS != no && wait 637*e670fd5cSchristoswait 638*e670fd5cSchristos 639*e670fd5cSchristosecho "Restarting servers..." 640*e670fd5cSchristosKILLPIDS="" 641*e670fd5cSchristos 642*e670fd5cSchristosecho "Starting server 1 on TCP/IP port $PORT1..." 643*e670fd5cSchristosecho "======================= RESTART =======================" >> $LOG1 644*e670fd5cSchristoscd ${XDIR}1 645*e670fd5cSchristos$SLAPD -F slapd.d -h $URI1 -d $LVL >> $LOG1 2>&1 & 646*e670fd5cSchristosPID=$! 647*e670fd5cSchristosif test $WAIT != 0 ; then 648*e670fd5cSchristos echo PID $PID 649*e670fd5cSchristos read foo 650*e670fd5cSchristosfi 651*e670fd5cSchristosKILLPIDS="$PID" 652*e670fd5cSchristoscd $TESTWD 653*e670fd5cSchristos 654*e670fd5cSchristossleep 1 655*e670fd5cSchristos 656*e670fd5cSchristosecho "Using ldapsearch to check that server 1 is running..." 657*e670fd5cSchristosfor i in 0 1 2 3 4 5; do 658*e670fd5cSchristos $LDAPSEARCH -s base -b "" -H $URI1 \ 659*e670fd5cSchristos 'objectclass=*' > /dev/null 2>&1 660*e670fd5cSchristos RC=$? 661*e670fd5cSchristos if test $RC = 0 ; then 662*e670fd5cSchristos break 663*e670fd5cSchristos fi 664*e670fd5cSchristos echo "Waiting 5 seconds for slapd to start..." 665*e670fd5cSchristos sleep 5 666*e670fd5cSchristosdone 667*e670fd5cSchristos 668*e670fd5cSchristosif test $RC != 0 ; then 669*e670fd5cSchristos echo "ldapsearch failed ($RC)!" 670*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 671*e670fd5cSchristos exit $RC 672*e670fd5cSchristosfi 673*e670fd5cSchristos 674*e670fd5cSchristosn=2 675*e670fd5cSchristoswhile [ $n -le $MPR ]; do 676*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 677*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 678*e670fd5cSchristosLOG=$TESTDIR/slapd.$n.log 679*e670fd5cSchristosecho "Starting server $n on TCP/IP port $PORT..." 680*e670fd5cSchristoscd ${XDIR}$n 681*e670fd5cSchristosecho "======================= RESTART =======================" >> $LOG 682*e670fd5cSchristos$SLAPD -F ./slapd.d -h $URI -d $LVL >> $LOG 2>&1 & 683*e670fd5cSchristosPID=$! 684*e670fd5cSchristosif test $WAIT != 0 ; then 685*e670fd5cSchristos echo PID $PID 686*e670fd5cSchristos read foo 687*e670fd5cSchristosfi 688*e670fd5cSchristosKILLPIDS="$KILLPIDS $PID" 689*e670fd5cSchristoscd $TESTWD 690*e670fd5cSchristosn=`expr $n + 1` 691*e670fd5cSchristosdone 692*e670fd5cSchristos 693*e670fd5cSchristosn=2 694*e670fd5cSchristoswhile [ $n -le $MPR ]; do 695*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 696*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 697*e670fd5cSchristosecho "Using ldapsearch to check that server $n is running..." 698*e670fd5cSchristosfor i in 0 1 2 3 4 5; do 699*e670fd5cSchristos $LDAPSEARCH -s base -b "" -H $URI \ 700*e670fd5cSchristos 'objectclass=*' > /dev/null 2>&1 701*e670fd5cSchristos RC=$? 702*e670fd5cSchristos if test $RC = 0 ; then 703*e670fd5cSchristos break 704*e670fd5cSchristos fi 705*e670fd5cSchristos echo "Waiting 5 seconds for slapd to start..." 706*e670fd5cSchristos sleep 5 707*e670fd5cSchristosdone 708*e670fd5cSchristos 709*e670fd5cSchristosif test $RC != 0 ; then 710*e670fd5cSchristos echo "ldapsearch failed ($RC)!" 711*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 712*e670fd5cSchristos exit $RC 713*e670fd5cSchristosfi 714*e670fd5cSchristosn=`expr $n + 1` 715*e670fd5cSchristosdone 716*e670fd5cSchristos 717*e670fd5cSchristos# Insert modifications and more tests here. 718*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for servers to resync..." 719*e670fd5cSchristossleep $SLEEP1 720*e670fd5cSchristos 721*e670fd5cSchristosecho "Using ldapmodify to add/modify/delete entries from server 1..." 722*e670fd5cSchristosfor i in 1 2 3 4 5 6 7 8 9 10; do 723*e670fd5cSchristosecho " iteration $i" 724*e670fd5cSchristos$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 725*e670fd5cSchristos >> $TESTOUT 2>&1 << EOMODS 726*e670fd5cSchristosdn: cn=Add-Mod-Del,dc=example,dc=com 727*e670fd5cSchristoschangetype: add 728*e670fd5cSchristoscn: Add-Mod-Del 729*e670fd5cSchristosobjectclass: organizationalRole 730*e670fd5cSchristos 731*e670fd5cSchristosdn: cn=Add-Mod-Del,dc=example,dc=com 732*e670fd5cSchristoschangetype: modify 733*e670fd5cSchristosreplace: description 734*e670fd5cSchristosdescription: guinea pig 735*e670fd5cSchristos- 736*e670fd5cSchristos 737*e670fd5cSchristosdn: cn=Add-Mod-Del,dc=example,dc=com 738*e670fd5cSchristoschangetype: delete 739*e670fd5cSchristosEOMODS 740*e670fd5cSchristosRC=$? 741*e670fd5cSchristosif test $RC != 0 ; then 742*e670fd5cSchristos echo "ldapmodify failed for server 1 database ($RC)!" 743*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 744*e670fd5cSchristos exit $RC 745*e670fd5cSchristosfi 746*e670fd5cSchristosdone 747*e670fd5cSchristos 748*e670fd5cSchristosecho "Waiting $SLEEP1 seconds for servers to resync..." 749*e670fd5cSchristossleep $SLEEP1 750*e670fd5cSchristos 751*e670fd5cSchristosn=1 752*e670fd5cSchristoswhile [ $n -le $MPR ]; do 753*e670fd5cSchristosPORT=`expr $BASEPORT + $n` 754*e670fd5cSchristosURI="ldap://${LOCALHOST}:$PORT/" 755*e670fd5cSchristos 756*e670fd5cSchristosecho "Using ldapsearch to read all the entries from server $n..." 757*e670fd5cSchristos$LDAPSEARCH -S "" -b "$BASEDN" -D "$MANAGERDN" -H $URI -w $PASSWD \ 758*e670fd5cSchristos 'objectclass=*' > $TESTDIR/server$n.out 2>&1 759*e670fd5cSchristosRC=$? 760*e670fd5cSchristos 761*e670fd5cSchristosif test $RC != 0 ; then 762*e670fd5cSchristos echo "ldapsearch failed at server $n ($RC)!" 763*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 764*e670fd5cSchristos exit $RC 765*e670fd5cSchristosfi 766*e670fd5cSchristos$LDIFFILTER < $TESTDIR/server$n.out > $TESTDIR/server$n.flt 767*e670fd5cSchristosn=`expr $n + 1` 768*e670fd5cSchristosdone 769*e670fd5cSchristos 770*e670fd5cSchristosn=2 771*e670fd5cSchristoswhile [ $n -le $MPR ]; do 772*e670fd5cSchristosecho "Comparing retrieved entries from server 1 and server $n..." 773*e670fd5cSchristos$CMP $PROVIDERFLT $TESTDIR/server$n.flt > $CMPOUT 774*e670fd5cSchristos 775*e670fd5cSchristosif test $? != 0 ; then 776*e670fd5cSchristos echo "test failed - server 1 and server $n databases differ" 777*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 778*e670fd5cSchristos exit 1 779*e670fd5cSchristosfi 780*e670fd5cSchristosn=`expr $n + 1` 781*e670fd5cSchristosdone 782*e670fd5cSchristos 783*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS 784*e670fd5cSchristos 785*e670fd5cSchristosecho ">>>>> Test succeeded" 786*e670fd5cSchristos 787*e670fd5cSchristostest $KILLSERVERS != no && wait 788*e670fd5cSchristos 789*e670fd5cSchristosexit 0 790