1#! /bin/sh 2# $OpenLDAP$ 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 1998-2021 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 16echo "running defines.sh" 17. $SRCDIR/scripts/defines.sh 18 19if test $BACKLDAP = ldapno; then 20 echo "LDAP backend not available, test skipped" 21 exit 0 22fi 23 24if test $SYNCPROV = syncprovno; then 25 echo "Syncrepl provider overlay not available, test skipped" 26 exit 0 27fi 28 29mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $DBDIR3 30 31# 32# Test replication: 33# - start provider 34# - start consumer 35# - populate over ldap 36# - perform some modifies and deleted 37# - attempt to modify the consumer (referral or chain) 38# - retrieve database over ldap and compare against expected results 39# 40 41echo "Starting provider slapd on TCP/IP port $PORT1..." 42. $CONFFILTER $BACKEND < $PLSRPROVIDERCONF > $CONF1 43$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 & 44PROVIDERPID=$! 45if test $WAIT != 0 ; then 46 echo PROVIDERPID $PROVIDERPID 47 read foo 48fi 49KILLPIDS="$PROVIDERPID" 50 51sleep 1 52 53echo "Using ldapsearch to check that provider slapd is running..." 54for i in 0 1 2 3 4 5; do 55 $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ 56 '(objectClass=*)' > /dev/null 2>&1 57 RC=$? 58 if test $RC = 0 ; then 59 break 60 fi 61 echo "Waiting 5 seconds for slapd to start..." 62 sleep 5 63done 64 65if test $RC != 0 ; then 66 echo "ldapsearch failed ($RC)!" 67 test $KILLSERVERS != no && kill -HUP $KILLPIDS 68 exit $RC 69fi 70 71echo "Using ldapadd to create the context prefix entry in the provider..." 72$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD < \ 73 $LDIFORDEREDCP > /dev/null 2>&1 74RC=$? 75if test $RC != 0 ; then 76 echo "ldapadd failed ($RC)!" 77 test $KILLSERVERS != no && kill -HUP $KILLPIDS 78 exit $RC 79fi 80 81echo "Starting P1 consumer slapd on TCP/IP port $PORT2..." 82. $CONFFILTER $BACKEND < $RCONSUMERCONF > $CONF2 83$SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 & 84P1CONSUMERPID=$! 85if test $WAIT != 0 ; then 86 echo P1CONSUMERPID $P1CONSUMERPID 87 read foo 88fi 89KILLPIDS="$PROVIDERPID $P1CONSUMERPID" 90 91sleep 1 92 93echo "Using ldapsearch to check that P1 consumer slapd is running..." 94for i in 0 1 2 3 4 5; do 95 $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \ 96 '(objectClass=*)' > /dev/null 2>&1 97 RC=$? 98 if test $RC = 0 ; then 99 break 100 fi 101 echo "Waiting 5 seconds for slapd to start..." 102 sleep 5 103done 104 105if test $RC != 0 ; then 106 echo "ldapsearch failed ($RC)!" 107 test $KILLSERVERS != no && kill -HUP $KILLPIDS 108 exit $RC 109fi 110 111echo "Starting R1 consumer slapd on TCP/IP port $PORT3..." 112. $CONFFILTER $BACKEND < $RCONSUMERCONF | sed -e 's;\.2\.\([^/]*\)$;.3.\1;' > $CONF3 113$SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 & 114R1CONSUMERPID=$! 115if test $WAIT != 0 ; then 116 echo R1CONSUMERPID $R1CONSUMERPID 117 read foo 118fi 119KILLPIDS="$PROVIDERPID $P1CONSUMERPID $R1CONSUMERPID" 120 121sleep 1 122 123echo "Using ldapsearch to check that R1 consumer slapd is running..." 124for i in 0 1 2 3 4 5; do 125 $LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \ 126 '(objectClass=*)' > /dev/null 2>&1 127 RC=$? 128 if test $RC = 0; then 129 break 130 fi 131 echo "Waiting 5 seconds for slapd to start..." 132 sleep 5 133done 134 135if test $RC != 0 ; then 136 echo "ldapsearch failed ($RC)!" 137 test $KILLSERVERS != no && kill -HUP $KILLPIDS 138 exit $RC 139fi 140 141CHECK=1 142echo "$CHECK > Using ldapadd to populate the provider directory..." 143$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD < \ 144 $LDIFORDEREDNOCP > /dev/null 2>&1 145RC=$? 146if test $RC != 0 ; then 147 echo "ldapadd failed ($RC)!" 148 test $KILLSERVERS != no && kill -HUP $KILLPIDS 149 exit $RC 150fi 151 152echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 153sleep $SLEEP1 154 155#echo "Using ldapsearch to read all the entries from the provider..." 156$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 157 '(objectClass=*)' > "${PROVIDEROUT}.1" 2>&1 158RC=$? 159 160if test $RC != 0 ; then 161 echo "ldapsearch failed at provider ($RC)!" 162 test $KILLSERVERS != no && kill -HUP $KILLPIDS 163 exit $RC 164fi 165 166#echo "Using ldapsearch to read all the entries from the P1 consumer..." 167$LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 \ 168 '(objectClass=*)' > "${CONSUMEROUT}.1" 2>&1 169RC=$? 170 171if test $RC != 0 ; then 172 echo "ldapsearch failed at P1 consumer ($RC)!" 173 test $KILLSERVERS != no && kill -HUP $KILLPIDS 174 exit $RC 175fi 176 177#echo "Filtering provider results..." 178$LDIFFILTER < "${PROVIDEROUT}.1" > $PROVIDERFLT 179#echo "Filtering consumer results..." 180$LDIFFILTER < "${CONSUMEROUT}.1" > $CONSUMERFLT 181 182echo "$CHECK < Comparing retrieved entries from provider and P1 consumer..." 183$CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT 184 185if test $? != 0 ; then 186 echo "test failed - provider and P1 consumer databases differ" 187 test $KILLSERVERS != no && kill -HUP $KILLPIDS 188 exit 1 189fi 190 191#echo "Using ldapsearch to read all the entries from the R1 consumer..." 192$LDAPSEARCH -S "" -b "$BASEDN" -H $URI3 \ 193 '(objectClass=*)' > "${CONSUMEROUT}.1" 2>&1 194RC=$? 195 196if test $RC != 0 ; then 197 echo "ldapsearch failed at R1 consumer ($RC)!" 198 test $KILLSERVERS != no && kill -HUP $KILLPIDS 199 exit $RC 200fi 201 202#echo "Filtering consumer results..." 203$LDIFFILTER < "${CONSUMEROUT}.1" > $CONSUMERFLT 204 205echo "$CHECK < Comparing retrieved entries from provider and R1 consumer..." 206$CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT 207 208if test $? != 0 ; then 209 echo "test failed - provider and R1 consumer databases differ" 210 test $KILLSERVERS != no && kill -HUP $KILLPIDS 211 exit 1 212fi 213 214CHECK=`expr $CHECK + 1` 215echo "$CHECK > Stopping the provider, sleeping $SLEEP2 seconds and restarting it..." 216kill -HUP "$PROVIDERPID" 217wait $PROVIDERPID 218sleep $SLEEP2 219 220echo "======================= RESTART =======================" >> $LOG1 221$SLAPD -f $CONF1 -h $URI1 -d $LVL >> $LOG1 2>&1 & 222PROVIDERPID=$! 223if test $WAIT != 0 ; then 224 echo PROVIDERPID $PROVIDERPID 225 read foo 226fi 227KILLPIDS="$PROVIDERPID $P1CONSUMERPID $R1CONSUMERPID" 228 229sleep 1 230 231echo "Using ldapsearch to check that provider slapd is running..." 232for i in 0 1 2 3 4 5; do 233 $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ 234 '(objectClass=*)' > /dev/null 2>&1 235 RC=$? 236 if test $RC = 0 ; then 237 break 238 fi 239 echo "Waiting 5 seconds for slapd to start..." 240 sleep 5 241done 242 243if test $RC != 0 ; then 244 echo "ldapsearch failed ($RC)!" 245 test $KILLSERVERS != no && kill -HUP $KILLPIDS 246 exit $RC 247fi 248 249echo "Using ldapmodify to modify provider directory..." 250 251# 252# Do some modifications 253# 254 255$LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD > \ 256 $TESTOUT 2>&1 << EOMODS 257dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 258changetype: modify 259add: drink 260drink: Orange Juice 261- 262delete: sn 263sn: Jones 264- 265add: sn 266sn: Jones 267 268dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 269changetype: modify 270replace: drink 271drink: Iced Tea 272 273dn: cn=ITD Staff,ou=Groups,dc=example,dc=com 274changetype: modify 275delete: uniquemember 276uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 277uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 278- 279add: uniquemember 280uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com 281uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 282 283dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc 284 =com 285changetype: modify 286delete: cn 287cn: Biiff Jensen 288 289dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 290changetype: add 291objectclass: OpenLDAPperson 292cn: Gern Jensen 293sn: Jensen 294uid: gjensen 295title: Chief Investigator, ITD 296postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103 297seealso: cn=All Staff, ou=Groups, dc=example,dc=com 298drink: Coffee 299homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104 300description: Very odd 301facsimiletelephonenumber: +1 313 555 7557 302telephonenumber: +1 313 555 8343 303mail: gjensen@mailgw.example.com 304homephone: +1 313 555 8844 305 306dn: ou=Retired, ou=People, dc=example,dc=com 307changetype: add 308objectclass: organizationalUnit 309ou: Retired 310 311dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 312changetype: add 313objectclass: OpenLDAPperson 314cn: Rosco P. Coltrane 315sn: Coltrane 316uid: rosco 317description: Fat tycoon 318 319dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 320changetype: modrdn 321newrdn: cn=Rosco P. Coltrane 322deleteoldrdn: 1 323newsuperior: ou=Retired, ou=People, dc=example,dc=com 324 325dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 326changetype: delete 327EOMODS 328 329RC=$? 330if test $RC != 0 ; then 331 echo "ldapmodify failed ($RC)!" 332 test $KILLSERVERS != no && kill -HUP $KILLPIDS 333 exit $RC 334fi 335 336echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 337sleep $SLEEP1 338 339#echo "Using ldapsearch to read all the entries from the provider..." 340$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 341 '(objectClass=*)' > "${PROVIDEROUT}.2" 2>&1 342RC=$? 343 344if test $RC != 0 ; then 345 echo "ldapsearch failed at provider ($RC)!" 346 test $KILLSERVERS != no && kill -HUP $KILLPIDS 347 exit $RC 348fi 349 350#echo "Using ldapsearch to read all the entries from the P1 consumer..." 351$LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 \ 352 '(objectClass=*)' > "${CONSUMEROUT}.2" 2>&1 353RC=$? 354 355if test $RC != 0 ; then 356 echo "ldapsearch failed at P1 consumer ($RC)!" 357 test $KILLSERVERS != no && kill -HUP $KILLPIDS 358 exit $RC 359fi 360 361#echo "Filtering provider results..." 362$LDIFFILTER < "${PROVIDEROUT}.2" > $PROVIDERFLT 363#echo "Filtering P1 consumer results..." 364$LDIFFILTER < "${CONSUMEROUT}.2" > $CONSUMERFLT 365 366echo "$CHECK < Comparing retrieved entries from provider and P1 consumer..." 367$CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT 368 369if test $? != 0 ; then 370 echo "test failed - provider and P1 consumer databases differ" 371 test $KILLSERVERS != no && kill -HUP $KILLPIDS 372 exit 1 373fi 374 375#echo "Using ldapsearch to read all the entries from the R1 consumer..." 376$LDAPSEARCH -S "" -b "$BASEDN" -H $URI3 \ 377 '(objectClass=*)' > "${CONSUMEROUT}.2" 2>&1 378RC=$? 379 380if test $RC != 0 ; then 381 echo "ldapsearch failed at R1 consumer ($RC)!" 382 test $KILLSERVERS != no && kill -HUP $KILLPIDS 383 exit $RC 384fi 385 386#echo "Filtering consumer results..." 387$LDIFFILTER < "${CONSUMEROUT}.2" > $CONSUMERFLT 388 389echo "$CHECK < Comparing retrieved entries from provider and R1 consumer..." 390$CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT 391 392if test $? != 0 ; then 393 echo "test failed - provider and R1 consumer databases differ" 394 test $KILLSERVERS != no && kill -HUP $KILLPIDS 395 exit 1 396fi 397 398CHECK=`expr $CHECK + 1` 399echo "$CHECK > Stopping consumer to test recovery..." 400kill -HUP $P1CONSUMERPID $R1CONSUMERPID 401wait $P1CONSUMERPID 402wait $R1CONSUMERPID 403 404echo "Modifying more entries on the provider..." 405$LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD >> \ 406 $TESTOUT 2>&1 << EOMODS 407dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 408changetype: modify 409add: description 410description: r1 consumer is down... 411 412dn: cn=James T. Kirk, ou=Retired, ou=People, dc=example,dc=com 413changetype: add 414objectclass: OpenLDAPperson 415sn: Kirk 416uid: jtk 417cn: James T. Kirk 418 419dn: cn=Tiberius J. Hooker, ou=Retired, ou=People, dc=example,dc=com 420changetype: add 421objectclass: OpenLDAPperson 422sn: Hooker 423uid: tjh 424cn: Tiberius J. Hooker 425 426EOMODS 427 428echo "Restarting P1 consumer..." 429echo "======================= RESTART =======================" >> $LOG3 430$SLAPD -f $CONF2 -h $URI2 -d $LVL >> $LOG2 2>&1 & 431P1CONSUMERPID=$! 432if test $WAIT != 0 ; then 433 echo P1CONSUMERPID $P1CONSUMERPID 434 read foo 435fi 436 437echo "Restarting R1 consumer..." 438echo "======================= RESTART =======================" >> $LOG3 439$SLAPD -f $CONF3 -h $URI3 -d $LVL >> $LOG3 2>&1 & 440R1CONSUMERPID=$! 441if test $WAIT != 0 ; then 442 echo R1CONSUMERPID $R1CONSUMERPID 443 read foo 444fi 445KILLPIDS="$PROVIDERPID $P1CONSUMERPID $R1CONSUMERPID" 446 447echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..." 448sleep $SLEEP2 449 450#echo "Using ldapsearch to read all the entries from the provider..." 451$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 452 '(objectClass=*)' > "${PROVIDEROUT}.3" 2>&1 453RC=$? 454 455if test $RC != 0 ; then 456 echo "ldapsearch failed at provider ($RC)!" 457 test $KILLSERVERS != no && kill -HUP $KILLPIDS 458 exit $RC 459fi 460 461#echo "Using ldapsearch to read all the entries from the P1 consumer..." 462$LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 \ 463 '(objectClass=*)' > "${CONSUMEROUT}.3" 2>&1 464RC=$? 465 466if test $RC != 0 ; then 467 echo "ldapsearch failed at consumer ($RC)!" 468 test $KILLSERVERS != no && kill -HUP $KILLPIDS 469 exit $RC 470fi 471 472#echo "Filtering provider results..." 473$LDIFFILTER < "${PROVIDEROUT}.3" > $PROVIDERFLT 474#echo "Filtering consumer results..." 475$LDIFFILTER < "${CONSUMEROUT}.3" > $CONSUMERFLT 476 477echo "$CHECK < Comparing retrieved entries from provider and P1 consumer..." 478$CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT 479 480if test $? != 0 ; then 481 echo "test failed - provider and consumer databases differ" 482 test $KILLSERVERS != no && kill -HUP $KILLPIDS 483 exit 1 484fi 485 486#echo "Using ldapsearch to read all the entries from the R1 consumer..." 487$LDAPSEARCH -S "" -b "$BASEDN" -H $URI3 \ 488 '(objectClass=*)' > "${CONSUMEROUT}.3" 2>&1 489RC=$? 490 491if test $RC != 0 ; then 492 echo "ldapsearch failed at consumer ($RC)!" 493 test $KILLSERVERS != no && kill -HUP $KILLPIDS 494 exit $RC 495fi 496 497#echo "Filtering consumer results..." 498$LDIFFILTER < "${CONSUMEROUT}.3" > $CONSUMERFLT 499 500echo "$CHECK < Comparing retrieved entries from provider and R1 consumer..." 501$CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT 502 503if test $? != 0 ; then 504 echo "test failed - provider and consumer databases differ" 505 test $KILLSERVERS != no && kill -HUP $KILLPIDS 506 exit 1 507fi 508 509CHECK=`expr $CHECK + 1` 510echo "$CHECK > Try updating the P1 consumer slapd..." 511$LDAPMODIFY -v -D "$MANAGERDN" -H $URI2 -w $PASSWD > \ 512 $TESTOUT 2>&1 << EOMODS 513dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com 514changetype: modify 515add: description 516description: This write must fail because directed to a shadow context, 517description: unless the chain overlay is configured appropriately ;) 518 519EOMODS 520 521RC=$? 522if test $RC != 0 ; then 523 echo "ldapmodify failed ($RC)!" 524 test $KILLSERVERS != no && kill -HUP $KILLPIDS 525 exit $RC 526fi 527 528echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 529sleep $SLEEP1 530 531#echo "Using ldapsearch to read all the entries from the provider..." 532$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 533 '(objectClass=*)' > "${PROVIDEROUT}.4" 2>&1 534RC=$? 535 536if test $RC != 0 ; then 537 echo "ldapsearch failed at provider ($RC)!" 538 test $KILLSERVERS != no && kill -HUP $KILLPIDS 539 exit $RC 540fi 541 542#echo "Using ldapsearch to read all the entries from the P1 consumer..." 543$LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 \ 544'(objectClass=*)' > "${CONSUMEROUT}.4" 2>&1 545RC=$? 546 547if test $RC != 0 ; then 548 echo "ldapsearch failed at consumer ($RC)!" 549 test $KILLSERVERS != no && kill -HUP $KILLPIDS 550 exit $RC 551fi 552 553#echo "Filtering provider results..." 554$LDIFFILTER < "${PROVIDEROUT}.4" > $PROVIDERFLT 555#echo "Filtering consumer results..." 556$LDIFFILTER < "${CONSUMEROUT}.4" > $CONSUMERFLT 557 558echo "$CHECK < Comparing retrieved entries from provider and P1 consumer..." 559$CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT 560 561if test $? != 0 ; then 562 echo "test failed - provider and P1 consumer databases differ" 563 test $KILLSERVERS != no && kill -HUP $KILLPIDS 564 exit 1 565fi 566 567#echo "Using ldapsearch to read all the entries from the R1 consumer..." 568$LDAPSEARCH -S "" -b "$BASEDN" -H $URI3 \ 569'(objectClass=*)' > "${CONSUMEROUT}.4" 2>&1 570RC=$? 571 572if test $RC != 0 ; then 573 echo "ldapsearch failed at consumer ($RC)!" 574 test $KILLSERVERS != no && kill -HUP $KILLPIDS 575 exit $RC 576fi 577 578#echo "Filtering consumer results..." 579$LDIFFILTER < "${CONSUMEROUT}.4" > $CONSUMERFLT 580 581echo "$CHECK < Comparing retrieved entries from provider and R1 consumer..." 582$CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT 583 584if test $? != 0 ; then 585 echo "test failed - provider and R1 consumer databases differ" 586 test $KILLSERVERS != no && kill -HUP $KILLPIDS 587 exit 1 588fi 589 590test $KILLSERVERS != no && kill -HUP $KILLPIDS 591 592echo ">>>>> Test succeeded" 593 594test $KILLSERVERS != no && wait 595 596exit 0 597