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