1#! /bin/sh 2# $OpenLDAP: pkg/ldap/tests/scripts/test018-syncreplication-persist,v 1.38.2.3 2008/02/11 23:26:51 kurt Exp $ 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 1998-2008 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 16if test "$BACKEND" != "bdb" && test "$BACKEND" != "hdb" ; then 17 echo "Test does not support $BACKEND" 18 exit 0 19fi 20 21echo "running defines.sh" 22. $SRCDIR/scripts/defines.sh 23 24if test $SYNCPROV = syncprovno; then 25 echo "Syncrepl provider overlay not available, test skipped" 26 exit 0 27fi 28 29mkdir -p $TESTDIR $DBDIR1 $DBDIR4 30 31# 32# Test replication: 33# - start producer 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 producer slapd on TCP/IP port $PORT1..." 42. $CONFFILTER $BACKEND $MONITORDB < $SRMASTERCONF > $CONF1 43$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 & 44PID=$! 45if test $WAIT != 0 ; then 46 echo PID $PID 47 read foo 48fi 49KILLPIDS="$PID" 50 51sleep 1 52 53echo "Using ldapsearch to check that producer slapd is running..." 54for i in 0 1 2 3 4 5; do 55 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \ 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 producer..." 72$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -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 consumer slapd on TCP/IP port $PORT4..." 82. $CONFFILTER $BACKEND $MONITORDB < $P1SRSLAVECONF > $CONF4 83$SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING > $LOG4 2>&1 & 84SLAVEPID=$! 85if test $WAIT != 0 ; then 86 echo SLAVEPID $SLAVEPID 87 read foo 88fi 89KILLPIDS="$KILLPIDS $SLAVEPID" 90 91sleep 1 92 93echo "Using ldapsearch to check that consumer slapd is running..." 94for i in 0 1 2 3 4 5; do 95 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT4 \ 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 "Using ldapadd to populate the producer directory..." 112$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \ 113 $LDIFORDEREDNOCP > /dev/null 2>&1 114RC=$? 115if test $RC != 0 ; then 116 echo "ldapadd failed ($RC)!" 117 test $KILLSERVERS != no && kill -HUP $KILLPIDS 118 exit $RC 119fi 120 121echo "Waiting 15 seconds for syncrepl to receive changes..." 122sleep 15 123 124echo "Stopping the provider, sleeping 10 seconds and restarting it..." 125kill -HUP "$PID" 126wait $PID 127sleep 10 128echo "RESTART" >> $LOG1 129$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING >> $LOG1 2>&1 & 130PID=$! 131if test $WAIT != 0 ; then 132 echo PID $PID 133 read foo 134fi 135KILLPIDS="$PID $SLAVEPID" 136 137sleep 1 138 139echo "Using ldapsearch to check that producer slapd is running..." 140for i in 0 1 2 3 4 5; do 141 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \ 142 'objectclass=*' > /dev/null 2>&1 143 RC=$? 144 if test $RC = 0 ; then 145 break 146 fi 147 echo "Waiting 5 seconds for slapd to start..." 148 sleep 5 149done 150 151if test $RC != 0 ; then 152 echo "ldapsearch failed ($RC)!" 153 test $KILLSERVERS != no && kill -HUP $KILLPIDS 154 exit $RC 155fi 156 157echo "Using ldapmodify to modify producer directory..." 158 159# 160# Do some modifications 161# 162 163$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \ 164 $TESTOUT 2>&1 << EOMODS 165dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 166changetype: modify 167add: drink 168drink: Orange Juice 169- 170delete: sn 171sn: Jones 172- 173add: sn 174sn: Jones 175 176dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 177changetype: modify 178replace: drink 179drink: Iced Tea 180 181dn: cn=ITD Staff,ou=Groups,dc=example,dc=com 182changetype: modify 183delete: uniquemember 184uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 185uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 186- 187add: uniquemember 188uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com 189uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com 190 191dn: cn=All Staff,ou=Groups,dc=example,dc=com 192changetype: modify 193delete: description 194 195dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 196changetype: add 197objectclass: OpenLDAPperson 198cn: Gern Jensen 199sn: Jensen 200uid: gjensen 201title: Chief Investigator, ITD 202postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103 203seealso: cn=All Staff, ou=Groups, dc=example,dc=com 204drink: Coffee 205homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104 206description: Very odd 207facsimiletelephonenumber: +1 313 555 7557 208telephonenumber: +1 313 555 8343 209mail: gjensen@mailgw.example.com 210homephone: +1 313 555 8844 211 212dn: ou=Retired, ou=People, dc=example,dc=com 213changetype: add 214objectclass: organizationalUnit 215ou: Retired 216 217dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 218changetype: add 219objectclass: OpenLDAPperson 220cn: Rosco P. Coltrane 221sn: Coltrane 222uid: rosco 223description: Fat tycoon 224 225dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com 226changetype: modrdn 227newrdn: cn=Rosco P. Coltrane 228deleteoldrdn: 1 229newsuperior: ou=Retired, ou=People, dc=example,dc=com 230 231dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com 232changetype: delete 233 234EOMODS 235 236RC=$? 237if test $RC != 0 ; then 238 echo "ldapmodify failed ($RC)!" 239 test $KILLSERVERS != no && kill -HUP $KILLPIDS 240 exit $RC 241fi 242 243echo "Using ldappasswd to change some passwords..." 244$LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \ 245 'cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \ 246 > $TESTOUT 2>&1 247RC=$? 248if test $RC != 0 ; then 249 echo "ldapmodify failed ($RC)!" 250 test $KILLSERVERS != no && kill -HUP $KILLPIDS 251 exit $RC 252fi 253 254echo "Waiting 15 seconds for syncrepl to receive changes..." 255sleep 15 256 257echo "Stopping consumer to test recovery..." 258kill -HUP $SLAVEPID 259wait $SLAVEPID 260 261echo "Modifying more entries on the producer..." 262$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \ 263 $TESTOUT 2>&1 << EOMODS 264dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com 265changetype: delete 266 267dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com 268changetype: modify 269add: drink 270drink: Mad Dog 20/20 271 272dn: cn=Rosco P. Coltrane, ou=Retired, ou=People, dc=example,dc=com 273changetype: add 274objectclass: OpenLDAPperson 275sn: Coltrane 276uid: rosco 277cn: Rosco P. Coltrane 278 279EOMODS 280 281echo "Restarting consumer..." 282echo "RESTART" >> $LOG4 283$SLAPD -f $CONF4 -h $URI4 -d $LVL $TIMING >> $LOG4 2>&1 & 284SLAVEPID=$! 285if test $WAIT != 0 ; then 286 echo SLAVEPID $SLAVEPID 287 read foo 288fi 289KILLPIDS="$PID $SLAVEPID" 290 291echo "Waiting 25 seconds for syncrepl to receive changes..." 292sleep 25 293 294if test ! $BACKLDAP = "ldapno" ; then 295 echo "Try updating the consumer slapd..." 296 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD > \ 297 $TESTOUT 2>&1 << EOMODS 298dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com 299changetype: modify 300add: description 301description: This write must fail because directed to a shadow context, 302description: unless the chain overlay is configured appropriately ;) 303 304EOMODS 305 306 RC=$? 307 if test $RC != 0 ; then 308 echo "ldapmodify failed ($RC)!" 309 test $KILLSERVERS != no && kill -HUP $KILLPIDS 310 exit $RC 311 fi 312 313 # ITS#4964 314 echo "Trying to change some passwords on the consumer..." 315 $LDAPPASSWD -D "$MANAGERDN" -h $LOCALHOST -p $PORT4 -w $PASSWD \ 316 'cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com' \ 317 > $TESTOUT 2>&1 318 RC=$? 319 if test $RC != 0 ; then 320 echo "ldapmodify failed ($RC)!" 321 test $KILLSERVERS != no && kill -HUP $KILLPIDS 322 exit $RC 323 fi 324 325 echo "Waiting 15 seconds for syncrepl to receive changes..." 326 sleep 15 327fi 328 329OPATTRS="entryUUID creatorsName createTimestamp modifiersName modifyTimestamp" 330 331echo "Using ldapsearch to read all the entries from the producer..." 332$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 333 '(objectclass=*)' '*' $OPATTRS > $MASTEROUT 2>&1 334RC=$? 335 336if test $RC != 0 ; then 337 echo "ldapsearch failed at producer ($RC)!" 338 test $KILLSERVERS != no && kill -HUP $KILLPIDS 339 exit $RC 340fi 341 342echo "Using ldapsearch to read all the entries from the consumer..." 343$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT4 \ 344 '(objectclass=*)' '*' $OPATTRS > $SLAVEOUT 2>&1 345RC=$? 346 347if test $RC != 0 ; then 348 echo "ldapsearch failed at consumer ($RC)!" 349 test $KILLSERVERS != no && kill -HUP $KILLPIDS 350 exit $RC 351fi 352 353test $KILLSERVERS != no && kill -HUP $KILLPIDS 354 355echo "Filtering producer results..." 356. $LDIFFILTER < $MASTEROUT > $MASTERFLT 357echo "Filtering consumer results..." 358. $LDIFFILTER < $SLAVEOUT > $SLAVEFLT 359 360echo "Comparing retrieved entries from producer and consumer..." 361$CMP $MASTERFLT $SLAVEFLT > $CMPOUT 362 363if test $? != 0 ; then 364 echo "test failed - producer and consumer databases differ" 365 exit 1 366fi 367 368echo ">>>>> Test succeeded" 369 370test $KILLSERVERS != no && wait 371 372exit 0 373