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