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