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