1#! /bin/sh 2# $OpenLDAP$ 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 1998-2017 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,bdb=a,hdb=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 $MONITORDB < $DSRMASTERCONF > $CONF1 49$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $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 $LOCALHOST -p $PORT1 \ 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 $LOCALHOST -p $PORT1 -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 $MONITORDB < $DSRSLAVECONF > $CONF2 89$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 & 90SLAVEPID=$! 91if test $WAIT != 0 ; then 92 echo SLAVEPID $SLAVEPID 93 read foo 94fi 95KILLPIDS="$KILLPIDS $SLAVEPID" 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 $LOCALHOST -p $PORT2 \ 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 $LOCALHOST -p $PORT1 -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 $TIMING >> $LOG1 2>&1 & 135PID=$! 136if test $WAIT != 0 ; then 137 echo PID $PID 138 read foo 139fi 140KILLPIDS="$PID $SLAVEPID" 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 $LOCALHOST -p $PORT1 \ 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 $LOCALHOST -p $PORT1 -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 181dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 182changetype: modify 183replace: drink 184drink: Iced Tea 185 186dn: cn=ITD Staff,ou=Groups,dc=example,dc=com 187changetype: modify 188delete: uniquemember 189uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 190uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 191- 192add: uniquemember 193uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com 194uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 195 196dn: cn=All Staff,ou=Groups,dc=example,dc=com 197changetype: modify 198delete: description 199 200dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 201changetype: add 202objectclass: OpenLDAPperson 203cn: Gern Jensen 204sn: Jensen 205uid: gjensen 206title: Chief Investigator, ITD 207postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103 208seealso: cn=All Staff, ou=Groups, dc=example,dc=com 209drink: Coffee 210homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104 211description: Very odd 212facsimiletelephonenumber: +1 313 555 7557 213telephonenumber: +1 313 555 8343 214mail: gjensen@mailgw.example.com 215homephone: +1 313 555 8844 216 217dn: ou=Retired, ou=People, dc=example,dc=com 218changetype: add 219objectclass: organizationalUnit 220ou: Retired 221 222dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 223changetype: add 224objectclass: OpenLDAPperson 225cn: Rosco P. Coltrane 226sn: Coltrane 227uid: rosco 228description: Fat tycoon 229 230dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 231changetype: modrdn 232newrdn: cn=Rosco P. Coltrane 233deleteoldrdn: 1 234newsuperior: ou=Retired, ou=People, dc=example,dc=com 235 236dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 237changetype: delete 238 239EOMODS 240RC=$? 241if test $RC != 0 ; then 242 echo "ldapmodify failed ($RC)!" 243 test $KILLSERVERS != no && kill -HUP $KILLPIDS 244 exit $RC 245fi 246 247echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 248sleep $SLEEP1 249 250echo "Using ldapsearch to read all the entries from the provider..." 251$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 252 'objectclass=*' \* + > $MASTEROUT 2>&1 253RC=$? 254 255if test $RC != 0 ; then 256 echo "ldapsearch failed at provider ($RC)!" 257 test $KILLSERVERS != no && kill -HUP $KILLPIDS 258 exit $RC 259fi 260 261echo "Using ldapsearch to read all the entries from the consumer..." 262$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ 263 'objectclass=*' \* + > $SLAVEOUT 2>&1 264RC=$? 265 266if test $RC != 0 ; then 267 echo "ldapsearch failed at consumer ($RC)!" 268 test $KILLSERVERS != no && kill -HUP $KILLPIDS 269 exit $RC 270fi 271 272echo "Filtering provider results..." 273$LDIFFILTER -b $BACKEND -s $SPEC < $MASTEROUT | grep -iv "^auditcontext:" > $MASTERFLT 274echo "Filtering consumer results..." 275$LDIFFILTER -b $BACKEND -s $SPEC < $SLAVEOUT | grep -iv "^auditcontext:" > $SLAVEFLT 276 277echo "Comparing retrieved entries from provider and consumer..." 278$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 279 280if test $? != 0 ; then 281 echo "test failed - provider and consumer databases differ" 282 test $KILLSERVERS != no && kill -HUP $KILLPIDS 283 exit 1 284fi 285 286echo "Stopping consumer to test recovery..." 287kill -HUP $SLAVEPID 288sleep 10 289 290echo "Modifying more entries on the provider..." 291$LDAPMODIFY -v -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \ 292 $TESTOUT 2>&1 << EOMODS 293dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com 294changetype: delete 295 296dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 297changetype: modify 298add: drink 299drink: Mad Dog 20/20 300 301dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com 302changetype: add 303objectclass: OpenLDAPperson 304sn: Coltrane 305uid: rosco 306cn: Rosco P. Coltrane 307 308dn: cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com 309changetype: modify 310replace: drink 311drink: Red Wine 312- 313replace: drink 314 315dn: cn=All Staff,ou=Groups,dc=example,dc=com 316changetype: modrdn 317newrdn: cn=Some Staff 318deleteoldrdn: 1 319 320EOMODS 321 322echo "Restarting consumer..." 323echo "RESTART" >> $LOG2 324$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING >> $LOG2 2>&1 & 325SLAVEPID=$! 326if test $WAIT != 0 ; then 327 echo SLAVEPID $SLAVEPID 328 read foo 329fi 330KILLPIDS="$PID $SLAVEPID" 331 332echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 333sleep $SLEEP1 334 335if test ! $BACKLDAP = "ldapno" ; then 336 echo "Try updating the consumer slapd..." 337 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \ 338 $TESTOUT 2>&1 << EOMODS 339dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com 340changetype: modify 341add: description 342description: This write must fail because directed to a shadow context, 343description: unless the chain overlay is configured appropriately ;) 344 345EOMODS 346 347 RC=$? 348 if test $RC != 0 ; then 349 echo "ldapmodify failed ($RC)!" 350 test $KILLSERVERS != no && kill -HUP $KILLPIDS 351 exit $RC 352 fi 353 354 echo "Waiting $SLEEP1 seconds for syncrepl to receive changes..." 355 sleep $SLEEP1 356fi 357 358echo "Using ldapsearch to read all the entries from the provider..." 359$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 360 'objectclass=*' \* + > $MASTEROUT 2>&1 361RC=$? 362 363if test $RC != 0 ; then 364 echo "ldapsearch failed at provider ($RC)!" 365 test $KILLSERVERS != no && kill -HUP $KILLPIDS 366 exit $RC 367fi 368 369echo "Using ldapsearch to read all the entries from the consumer..." 370$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \ 371 'objectclass=*' \* + > $SLAVEOUT 2>&1 372RC=$? 373 374if test $RC != 0 ; then 375 echo "ldapsearch failed at consumer ($RC)!" 376 test $KILLSERVERS != no && kill -HUP $KILLPIDS 377 exit $RC 378fi 379 380test $KILLSERVERS != no && kill -HUP $KILLPIDS 381 382echo "Filtering provider results..." 383$LDIFFILTER -b $BACKEND -s $SPEC < $MASTEROUT | grep -iv "^auditcontext:" > $MASTERFLT 384echo "Filtering consumer results..." 385$LDIFFILTER -b $BACKEND -s $SPEC < $SLAVEOUT | grep -iv "^auditcontext:" > $SLAVEFLT 386 387echo "Comparing retrieved entries from provider and consumer..." 388$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 389 390if test $? != 0 ; then 391 echo "test failed - provider and consumer databases differ" 392 exit 1 393fi 394 395echo ">>>>> Test succeeded" 396 397test $KILLSERVERS != no && wait 398 399exit 0 400