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 $SYNCPROV = syncprovno; then 20 echo "Syncrepl provider overlay not available, test skipped" 21 exit 0 22fi 23if test $ACCESSLOG = accesslogno; then 24 echo "Accesslog overlay not available, test skipped" 25 exit 0 26fi 27if 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 31fi 32 33mkdir -p $TESTDIR $DBDIR1A $DBDIR1B $DBDIR2 34 35SPEC="mdb=a" 36 37# 38# Test replication: 39# - start provider 40# - start consumer 41# - populate over ldap 42# - perform some modifies and deleted 43# - attempt to modify the consumer (referral or chain) 44# - retrieve database over ldap and compare against expected results 45# 46 47echo "Starting provider slapd on TCP/IP port $PORT1..." 48. $CONFFILTER $BACKEND < $DSRPROVIDERCONF > $CONF1 49$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 & 50PID=$! 51if test $WAIT != 0 ; then 52 echo PID $PID 53 read foo 54fi 55KILLPIDS="$PID" 56 57sleep 1 58 59echo "Using ldapsearch to check that provider slapd is running..." 60for i in 0 1 2 3 4 5; do 61 $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ 62 'objectclass=*' > /dev/null 2>&1 63 RC=$? 64 if test $RC = 0 ; then 65 break 66 fi 67 echo "Waiting 5 seconds for slapd to start..." 68 sleep 5 69done 70 71if test $RC != 0 ; then 72 echo "ldapsearch failed ($RC)!" 73 test $KILLSERVERS != no && kill -HUP $KILLPIDS 74 exit $RC 75fi 76 77echo "Using ldapadd to create the context prefix entries in the provider..." 78$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD < \ 79 $LDIFORDEREDCP > /dev/null 2>&1 80RC=$? 81if test $RC != 0 ; then 82 echo "ldapadd failed ($RC)!" 83 test $KILLSERVERS != no && kill -HUP $KILLPIDS 84 exit $RC 85fi 86 87echo "Starting consumer slapd on TCP/IP port $PORT2..." 88. $CONFFILTER $BACKEND < $DSRCONSUMERCONF > $CONF2 89$SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 & 90CONSUMERPID=$! 91if test $WAIT != 0 ; then 92 echo CONSUMERPID $CONSUMERPID 93 read foo 94fi 95KILLPIDS="$KILLPIDS $CONSUMERPID" 96 97sleep 1 98 99echo "Using ldapsearch to check that consumer slapd is running..." 100for i in 0 1 2 3 4 5; do 101 $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \ 102 'objectclass=*' > /dev/null 2>&1 103 RC=$? 104 if test $RC = 0 ; then 105 break 106 fi 107 echo "Waiting 5 seconds for slapd to start..." 108 sleep 5 109done 110 111if test $RC != 0 ; then 112 echo "ldapsearch failed ($RC)!" 113 test $KILLSERVERS != no && kill -HUP $KILLPIDS 114 exit $RC 115fi 116 117echo "Using ldapadd to populate the provider directory..." 118$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD < \ 119 $LDIFORDEREDNOCP > /dev/null 2>&1 120RC=$? 121if test $RC != 0 ; then 122 echo "ldapadd failed ($RC)!" 123 test $KILLSERVERS != no && kill -HUP $KILLPIDS 124 exit $RC 125fi 126 127echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 128sleep $SLEEP1 129 130echo "Stopping the provider, sleeping 10 seconds and restarting it..." 131kill -HUP "$PID" 132sleep 10 133echo "RESTART" >> $LOG1 134$SLAPD -f $CONF1 -h $URI1 -d $LVL >> $LOG1 2>&1 & 135PID=$! 136if test $WAIT != 0 ; then 137 echo PID $PID 138 read foo 139fi 140KILLPIDS="$PID $CONSUMERPID" 141 142sleep 1 143 144echo "Using ldapsearch to check that provider slapd is running..." 145for i in 0 1 2 3 4 5; do 146 $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ 147 'objectclass=*' > /dev/null 2>&1 148 RC=$? 149 if test $RC = 0 ; then 150 break 151 fi 152 echo "Waiting 5 seconds for slapd to start..." 153 sleep 5 154done 155 156if test $RC != 0 ; then 157 echo "ldapsearch failed ($RC)!" 158 test $KILLSERVERS != no && kill -HUP $KILLPIDS 159 exit $RC 160fi 161 162echo "Using ldapmodify to modify provider directory..." 163 164# 165# Do some modifications 166# 167 168$LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD > \ 169 $TESTOUT 2>&1 << EOMODS 170dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 171changetype: modify 172add: drink 173drink: Orange Juice 174- 175delete: sn 176sn: Jones 177- 178add: sn 179sn: Jones 180- 181add: displayName 182displayName: The one 183 184dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 185changetype: modify 186add: displayName 187displayName: James the First 188- 189delete: displayName 190displayName: The one 191 192dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 193changetype: modify 194replace: drink 195drink: Iced Tea 196 197dn: cn=ITD Staff,ou=Groups,dc=example,dc=com 198changetype: modify 199delete: uniquemember 200uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 201uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 202- 203add: uniquemember 204uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com 205uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 206 207dn: cn=All Staff,ou=Groups,dc=example,dc=com 208changetype: modify 209delete: description 210 211dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 212changetype: add 213objectclass: OpenLDAPperson 214cn: Gern Jensen 215sn: Jensen 216uid: gjensen 217title: Chief Investigator, ITD 218postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103 219seealso: cn=All Staff, ou=Groups, dc=example,dc=com 220drink: Coffee 221homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104 222description: Very odd 223facsimiletelephonenumber: +1 313 555 7557 224telephonenumber: +1 313 555 8343 225mail: gjensen@mailgw.example.com 226homephone: +1 313 555 8844 227 228dn: ou=Retired, ou=People, dc=example,dc=com 229changetype: add 230objectclass: organizationalUnit 231ou: Retired 232 233dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 234changetype: add 235objectclass: OpenLDAPperson 236cn: Rosco P. Coltrane 237sn: Coltrane 238uid: rosco 239description: Fat tycoon 240 241dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 242changetype: modrdn 243newrdn: cn=Rosco P. Coltrane 244deleteoldrdn: 1 245newsuperior: ou=Retired, ou=People, dc=example,dc=com 246 247dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 248changetype: delete 249 250EOMODS 251RC=$? 252if test $RC != 0 ; then 253 echo "ldapmodify failed ($RC)!" 254 test $KILLSERVERS != no && kill -HUP $KILLPIDS 255 exit $RC 256fi 257 258echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 259sleep $SLEEP1 260 261echo "Using ldapsearch to read all the entries from the provider..." 262$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 263 'objectclass=*' \* + > $PROVIDEROUT 2>&1 264RC=$? 265 266if test $RC != 0 ; then 267 echo "ldapsearch failed at provider ($RC)!" 268 test $KILLSERVERS != no && kill -HUP $KILLPIDS 269 exit $RC 270fi 271 272echo "Using ldapsearch to read all the entries from the consumer..." 273$LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 \ 274 'objectclass=*' \* + > $CONSUMEROUT 2>&1 275RC=$? 276 277if test $RC != 0 ; then 278 echo "ldapsearch failed at consumer ($RC)!" 279 test $KILLSERVERS != no && kill -HUP $KILLPIDS 280 exit $RC 281fi 282 283echo "Filtering provider results..." 284$LDIFFILTER -b $BACKEND -s $SPEC < $PROVIDEROUT | grep -iv "^auditcontext:" > $PROVIDERFLT 285echo "Filtering consumer results..." 286$LDIFFILTER -b $BACKEND -s $SPEC < $CONSUMEROUT | grep -iv "^auditcontext:" > $CONSUMERFLT 287 288echo "Comparing retrieved entries from provider and consumer..." 289$CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT 290 291if test $? != 0 ; then 292 echo "test failed - provider and consumer databases differ" 293 test $KILLSERVERS != no && kill -HUP $KILLPIDS 294 exit 1 295fi 296 297echo "Stopping consumer to test recovery..." 298kill -HUP $CONSUMERPID 299sleep 10 300 301echo "Modifying more entries on the provider..." 302$LDAPMODIFY -v -D "$BJORNSDN" -H $URI1 -w bjorn >> \ 303 $TESTOUT 2>&1 << EOMODS 304dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com 305changetype: delete 306 307dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 308changetype: modify 309add: drink 310drink: Mad Dog 20/20 311 312dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com 313changetype: add 314objectclass: OpenLDAPperson 315sn: Coltrane 316uid: rosco 317cn: Rosco P. Coltrane 318 319dn: cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com 320changetype: modify 321replace: drink 322drink: Red Wine 323- 324replace: drink 325 326dn: cn=All Staff,ou=Groups,dc=example,dc=com 327changetype: modrdn 328newrdn: cn=Some Staff 329deleteoldrdn: 1 330 331EOMODS 332 333echo "Restarting consumer..." 334echo "RESTART" >> $LOG2 335$SLAPD -f $CONF2 -h $URI2 -d $LVL >> $LOG2 2>&1 & 336CONSUMERPID=$! 337if test $WAIT != 0 ; then 338 echo CONSUMERPID $CONSUMERPID 339 read foo 340fi 341KILLPIDS="$PID $CONSUMERPID" 342 343echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 344sleep $SLEEP1 345 346if test ! $BACKLDAP = "ldapno" ; then 347 echo "Try updating the consumer slapd..." 348 $LDAPMODIFY -v -D "$MANAGERDN" -H $URI2 -w $PASSWD > \ 349 $TESTOUT 2>&1 << EOMODS 350dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com 351changetype: modify 352add: description 353description: This write must fail because directed to a shadow context, 354description: unless the chain overlay is configured appropriately ;) 355 356EOMODS 357 358 RC=$? 359 if test $RC != 0 ; then 360 echo "ldapmodify failed ($RC)!" 361 test $KILLSERVERS != no && kill -HUP $KILLPIDS 362 exit $RC 363 fi 364 365 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 366 sleep $SLEEP1 367fi 368 369echo "Using ldapsearch to read all the entries from the provider..." 370$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 371 'objectclass=*' \* + > $PROVIDEROUT 2>&1 372RC=$? 373 374if test $RC != 0 ; then 375 echo "ldapsearch failed at provider ($RC)!" 376 test $KILLSERVERS != no && kill -HUP $KILLPIDS 377 exit $RC 378fi 379 380echo "Using ldapsearch to read all the entries from the consumer..." 381$LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 \ 382 'objectclass=*' \* + > $CONSUMEROUT 2>&1 383RC=$? 384 385if test $RC != 0 ; then 386 echo "ldapsearch failed at consumer ($RC)!" 387 test $KILLSERVERS != no && kill -HUP $KILLPIDS 388 exit $RC 389fi 390 391test $KILLSERVERS != no && kill -HUP $KILLPIDS 392 393echo "Filtering provider results..." 394$LDIFFILTER -b $BACKEND -s $SPEC < $PROVIDEROUT | grep -iv "^auditcontext:" > $PROVIDERFLT 395echo "Filtering consumer results..." 396$LDIFFILTER -b $BACKEND -s $SPEC < $CONSUMEROUT | grep -iv "^auditcontext:" > $CONSUMERFLT 397 398echo "Comparing retrieved entries from provider and consumer..." 399$CMP $PROVIDERFLT $CONSUMERFLT > $CMPOUT 400 401if test $? != 0 ; then 402 echo "test failed - provider and consumer databases differ" 403 exit 1 404fi 405 406echo ">>>>> Test succeeded" 407 408test $KILLSERVERS != no && wait 409 410exit 0 411