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 mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $DBDIR3 $DBDIR4 $DBDIR5 $DBDIR6
     25 
     26 #
     27 # Test replication:
     28 # - start provider
     29 # - start consumer
     30 # - populate over ldap
     31 # - perform some modifies and deleted
     32 # - retrieve database over ldap and compare against expected results
     33 #
     34 
     35 echo "Starting provider slapd on TCP/IP port $PORT1..."
     36 . $CONFFILTER $BACKEND < $SRPROVIDERCONF > $CONF1
     37 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
     38 PID=$!
     39 if test $WAIT != 0 ; then
     40     echo PID $PID
     41     read foo
     42 fi
     43 KILLPIDS="$PID"
     44 
     45 sleep 1
     46 
     47 echo "Using ldapsearch to check that provider slapd (pid=$PID) is running..."
     48 for i in 0 1 2 3 4 5; do
     49 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
     50 		'objectclass=*' > /dev/null 2>&1
     51 	RC=$?
     52 	if test $RC = 0 ; then
     53 		break
     54 	fi
     55 	echo "Waiting 5 seconds for slapd to start..."
     56 	sleep 5
     57 done
     58 
     59 if test $RC != 0 ; then
     60 	echo "ldapsearch failed ($RC)!"
     61 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     62 	exit $RC
     63 fi
     64 
     65 echo "Using ldapadd to create the context prefix entry in the provider..."
     66 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD < \
     67 	$LDIFORDEREDCP > /dev/null 2>&1
     68 RC=$?
     69 if test $RC != 0 ; then
     70 	echo "ldapadd failed ($RC)!"
     71 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     72 	exit $RC
     73 fi
     74 
     75 echo "Starting R1 consumer slapd on TCP/IP port $PORT2..."
     76 . $CONFFILTER $BACKEND < $R1SRCONSUMERCONF > $CONF2
     77 $SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
     78 CONSUMERPID=$!
     79 if test $WAIT != 0 ; then
     80     echo CONSUMER R1 PID $CONSUMERPID
     81     read foo
     82 fi
     83 KILLPIDS="$KILLPIDS $CONSUMERPID"
     84 
     85 sleep 1
     86 
     87 echo "Using ldapsearch to check that R1 consumer slapd (pid=$CONSUMERPID) is running..."
     88 for i in 0 1 2 3 4 5; do
     89 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
     90 		'objectclass=*' > /dev/null 2>&1
     91 	RC=$?
     92 	if test $RC = 0 ; then
     93 		break
     94 	fi
     95 	echo "Waiting 5 seconds for R1 slapd to start..."
     96 	sleep 5
     97 done
     98 
     99 if test $RC != 0 ; then
    100 	echo "ldapsearch failed ($RC)!"
    101 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    102 	exit $RC
    103 fi
    104 
    105 echo "Starting R2 consumer slapd on TCP/IP port $PORT3..."
    106 . $CONFFILTER $BACKEND < $R2SRCONSUMERCONF > $CONF3
    107 $SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 &
    108 CONSUMERPID=$!
    109 if test $WAIT != 0 ; then
    110     echo CONSUMER R2 PID $CONSUMERPID
    111     read foo
    112 fi
    113 KILLPIDS="$KILLPIDS $CONSUMERPID"
    114 
    115 sleep 1
    116 
    117 echo "Using ldapsearch to check that R2 consumer slapd (pid=$CONSUMERPID) is running..."
    118 for i in 0 1 2 3 4 5; do
    119 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \
    120 		'objectclass=*' > /dev/null 2>&1
    121 	RC=$?
    122 	if test $RC = 0 ; then
    123 		break
    124 	fi
    125 	echo "Waiting 5 seconds for R2 consumer slapd to start..."
    126 	sleep 5
    127 done
    128 
    129 if test $RC != 0 ; then
    130 	echo "ldapsearch failed ($RC)!"
    131 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    132 	exit $RC
    133 fi
    134 
    135 echo "Starting P1 consumer slapd on TCP/IP port $PORT4..."
    136 . $CONFFILTER $BACKEND < $P1SRCONSUMERCONF > $CONF4
    137 $SLAPD -f $CONF4 -h $URI4 -d $LVL > $LOG4 2>&1 &
    138 CONSUMERPID=$!
    139 if test $WAIT != 0 ; then
    140     echo CONSUMER P1 PID $CONSUMERPID
    141     read foo
    142 fi
    143 KILLPIDS="$KILLPIDS $CONSUMERPID"
    144 
    145 sleep 1
    146 
    147 echo "Using ldapsearch to check that P1 consumer slapd (pid=$CONSUMERPID) is running..."
    148 for i in 0 1 2 3 4 5; do
    149 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI4 \
    150 		'objectclass=*' > /dev/null 2>&1
    151 	RC=$?
    152 	if test $RC = 0 ; then
    153 		break
    154 	fi
    155 	echo "Waiting 5 seconds for P1 consumer slapd to start..."
    156 	sleep 5
    157 done
    158 
    159 if test $RC != 0 ; then
    160 	echo "ldapsearch failed ($RC)!"
    161 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    162 	exit $RC
    163 fi
    164 
    165 echo "Starting P2 consumer slapd on TCP/IP port $PORT5..."
    166 . $CONFFILTER $BACKEND < $P2SRCONSUMERCONF > $CONF5
    167 $SLAPD -f $CONF5 -h $URI5 -d $LVL > $LOG5 2>&1 &
    168 CONSUMERPID=$!
    169 if test $WAIT != 0 ; then
    170     echo CONSUMER P2 PID $CONSUMERPID
    171     read foo
    172 fi
    173 KILLPIDS="$KILLPIDS $CONSUMERPID"
    174 
    175 sleep 1
    176 
    177 echo "Using ldapsearch to check that P2 consumer slapd (pid=$CONSUMERPID) is running..."
    178 for i in 0 1 2 3 4 5; do
    179 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI5 \
    180 		'objectclass=*' > /dev/null 2>&1
    181 	RC=$?
    182 	if test $RC = 0 ; then
    183 		break
    184 	fi
    185 	echo "Waiting 5 seconds for P2 consumer slapd to start..."
    186 	sleep 5
    187 done
    188 
    189 if test $RC != 0 ; then
    190 	echo "ldapsearch failed ($RC)!"
    191 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    192 	exit $RC
    193 fi
    194 
    195 echo "Starting P3 consumer slapd on TCP/IP port $PORT6..."
    196 . $CONFFILTER $BACKEND < $P3SRCONSUMERCONF > $CONF6
    197 $SLAPD -f $CONF6 -h $URI6 -d $LVL > $LOG6 2>&1 &
    198 CONSUMERPID=$!
    199 if test $WAIT != 0 ; then
    200     echo CONSUMER P3 PID $CONSUMERPID
    201     read foo
    202 fi
    203 KILLPIDS="$KILLPIDS $CONSUMERPID"
    204 
    205 sleep 1
    206 
    207 echo "Using ldapsearch to check that P3 consumer slapd (pid=$CONSUMERPID) is running..."
    208 for i in 0 1 2 3 4 5; do
    209 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI6 \
    210 		'objectclass=*' > /dev/null 2>&1
    211 	RC=$?
    212 	if test $RC = 0 ; then
    213 		break
    214 	fi
    215 	echo "Waiting 5 seconds for P3 consumer slapd to start..."
    216 	sleep 5
    217 done
    218 
    219 if test $RC != 0 ; then
    220 	echo "ldapsearch failed ($RC)!"
    221 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    222 	exit $RC
    223 fi
    224 
    225 echo "Using ldapadd to populate the provider directory..."
    226 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD < \
    227 	$LDIFORDEREDNOCP > /dev/null 2>&1
    228 RC=$?
    229 if test $RC != 0 ; then
    230 	echo "ldapadd failed ($RC)!"
    231 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    232 	exit $RC
    233 fi
    234 
    235 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
    236 sleep $SLEEP2
    237 
    238 echo "Using ldapmodify to modify provider directory..."
    239 
    240 #
    241 # Do some modifications
    242 #
    243 
    244 $LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD > \
    245 	$TESTOUT 2>&1 << EOMODS
    246 dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
    247 changetype: modify
    248 add: drink
    249 drink: Orange Juice
    250 -
    251 delete: sn
    252 sn: Jones
    253 -
    254 add: sn
    255 sn: Jones
    256 
    257 dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
    258 changetype: modify
    259 replace: drink
    260 drink: Iced Tea
    261 drink: Mad Dog 20/20
    262 
    263 dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
    264 changetype: modify
    265 delete: uniquemember
    266 uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
    267 uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
    268 -
    269 add: uniquemember
    270 uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
    271 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
    272 
    273 dn: cn=All Staff,ou=Groups,dc=example,dc=com
    274 changetype: modify
    275 delete: description
    276 
    277 dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
    278 changetype: add
    279 objectclass: OpenLDAPperson
    280 cn: Gern Jensen
    281 sn: Jensen
    282 uid: gjensen
    283 title: Chief Investigator, ITD
    284 postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
    285 seealso: cn=All Staff, ou=Groups, dc=example,dc=com
    286 drink: Coffee
    287 homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
    288 description: Very odd
    289 facsimiletelephonenumber: +1 313 555 7557
    290 telephonenumber: +1 313 555 8343
    291 mail: gjensen@mailgw.example.com
    292 homephone: +1 313 555 8844
    293 
    294 dn: ou=Retired, ou=People, dc=example,dc=com
    295 changetype: add
    296 objectclass: organizationalUnit
    297 ou: Retired
    298 
    299 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
    300 changetype: add
    301 objectclass: OpenLDAPperson
    302 cn: Rosco P. Coltrane
    303 sn: Coltrane
    304 uid: rosco
    305 
    306 dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
    307 changetype: modrdn
    308 newrdn: cn=Rosco P. Coltrane
    309 deleteoldrdn: 1
    310 newsuperior: ou=Retired, ou=People, dc=example,dc=com
    311 
    312 dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
    313 changetype: delete
    314 
    315 dn: dc=testdomain1,dc=example,dc=com
    316 changetype: modrdn
    317 newrdn: dc=itsdomain1
    318 deleteoldrdn: 1
    319 
    320 dn: dc=itsdomain1,dc=example,dc=com
    321 changetype: modify
    322 replace: description
    323 description: Example, Inc. ITS test domain
    324 
    325 dn: dc=testdomain2,dc=example,dc=com
    326 changetype: modrdn
    327 newrdn: dc=itsdomain2
    328 deleteoldrdn: 1
    329 
    330 EOMODS
    331 
    332 RC=$?
    333 if test $RC != 0 ; then
    334 	echo "ldapmodify failed ($RC)!"
    335 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    336 	exit $RC
    337 fi
    338 
    339 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
    340 sleep $SLEEP2
    341 
    342 echo "Performing modify alone on provider..."
    343 $LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD > \
    344         $TESTOUT 2>&1 << EOMODS
    345 dn: dc=itsdomain2,dc=example,dc=com
    346 changetype: modify
    347 replace: description
    348 description: Example, Inc. itsdomain2 test domain
    349 
    350 EOMODS
    351 
    352 RC=$?   
    353 if test $RC != 0 ; then
    354         echo "ldapmodify failed ($RC)!"
    355         test $KILLSERVERS != no && kill -HUP $KILLPIDS
    356         exit $RC
    357 fi      
    358 
    359 echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
    360 sleep $SLEEP2 
    361 
    362 echo "Using ldapsearch to read all the entries from the provider..."
    363 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
    364 	'(objectClass=*)' '*' entryCSN > $PROVIDEROUT 2>&1
    365 RC=$?
    366 
    367 if test $RC != 0 ; then
    368 	echo "ldapsearch failed at provider ($RC)!"
    369 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    370 	exit $RC
    371 fi
    372 
    373 echo "Using ldapsearch to read all the entries from the R1 consumer..."
    374 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 \
    375 	'(objectClass=*)' '*' entryCSN > $SERVER2OUT 2>&1
    376 RC=$?
    377 
    378 if test $RC != 0 ; then
    379 	echo "ldapsearch failed at R1 consumer ($RC)!"
    380 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    381 	exit $RC
    382 fi
    383 
    384 echo "Using ldapsearch to read all the entries from the R2 consumer..."
    385 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI3 \
    386 	'(objectClass=*)' '*' entryCSN > $SERVER3OUT 2>&1
    387 RC=$?
    388 
    389 if test $RC != 0 ; then
    390 	echo "ldapsearch failed at R2 consumer ($RC)!"
    391 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    392 	exit $RC
    393 fi
    394 
    395 echo "Using ldapsearch to read all the entries from the P1 consumer..."
    396 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI4 \
    397 	'(objectClass=*)' '*' entryCSN > $SERVER4OUT 2>&1
    398 RC=$?
    399 
    400 if test $RC != 0 ; then
    401 	echo "ldapsearch failed at P1 consumer ($RC)!"
    402 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    403 	exit $RC
    404 fi
    405 
    406 echo "Using ldapsearch to read all the entries from the P2 consumer..."
    407 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI5 \
    408 	'(objectClass=*)' '*' entryCSN > $SERVER5OUT 2>&1
    409 RC=$?
    410 
    411 if test $RC != 0 ; then
    412 	echo "ldapsearch failed at P2 consumer ($RC)!"
    413 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    414 	exit $RC
    415 fi
    416 
    417 echo "Using ldapsearch to read all the entries from the P3 consumer..."
    418 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI6 \
    419 	'(objectClass=*)' '*' entryCSN > $SERVER6OUT 2>&1
    420 RC=$?
    421 
    422 if test $RC != 0 ; then
    423 	echo "ldapsearch failed at P3 consumer ($RC)!"
    424 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    425 	exit $RC
    426 fi
    427 
    428 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    429 
    430 echo "Filtering provider ldapsearch results..."
    431 $LDIFFILTER < $PROVIDEROUT > $PROVIDERFLT
    432 echo "Filtering R1 consumer ldapsearch results..."
    433 $LDIFFILTER < $SERVER2OUT > $SERVER2FLT
    434 echo "Filtering R2 consumer ldapsearch results..."
    435 $LDIFFILTER < $SERVER3OUT > $SERVER3FLT
    436 echo "Filtering P1 consumer ldapsearch results..."
    437 $LDIFFILTER < $SERVER4OUT > $SERVER4FLT
    438 echo "Filtering P2 consumer ldapsearch results..."
    439 $LDIFFILTER < $SERVER5OUT > $SERVER5FLT
    440 echo "Filtering P3 consumer ldapsearch results..."
    441 $LDIFFILTER < $SERVER6OUT > $SERVER6FLT
    442 
    443 echo "Comparing retrieved entries from provider and R1 consumer..."
    444 $CMP $PROVIDERFLT $SERVER2FLT > $CMPOUT
    445 
    446 if test $? != 0 ; then
    447 	echo "test failed - provider and R1 consumer databases differ"
    448 	exit 1
    449 fi
    450 
    451 echo "Comparing retrieved entries from provider and R2 consumer..."
    452 $CMP $PROVIDERFLT $SERVER3FLT > $CMPOUT
    453 
    454 if test $? != 0 ; then
    455 	echo "test failed - provider and R2 consumer databases differ"
    456 	exit 1
    457 fi
    458 
    459 echo "Comparing retrieved entries from provider and P1 consumer..."
    460 $CMP $PROVIDERFLT $SERVER4FLT > $CMPOUT
    461 
    462 if test $? != 0 ; then
    463 	echo "test failed - provider and P1 consumer databases differ"
    464 	exit 1
    465 fi
    466 
    467 echo "Comparing retrieved entries from provider and P2 consumer..."
    468 $CMP $PROVIDERFLT $SERVER5FLT > $CMPOUT
    469 
    470 if test $? != 0 ; then
    471 	echo "test failed - provider and P2 consumer databases differ"
    472 	exit 1
    473 fi
    474 
    475 echo "Comparing retrieved entries from provider and P3 consumer..."
    476 $CMP $PROVIDERFLT $SERVER6FLT > $CMPOUT
    477 
    478 if test $? != 0 ; then
    479 	echo "test failed - provider and P3 consumer databases differ"
    480 	exit 1
    481 fi
    482 
    483 echo ">>>>> Test succeeded"
    484 
    485 test $KILLSERVERS != no && wait
    486 
    487 exit 0
    488