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 
23
24mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $DBDIR3 $DBDIR4 $DBDIR5 $DBDIR6
25
26#
27# Test replication:
28# - start provider
29# - start consumer
30# - populate over ldap
31# - perform some modifies and deleted
32# - retrieve database over ldap and compare against expected results
33#
34
35echo "Starting provider slapd on TCP/IP port $PORT1..."
36. $CONFFILTER $BACKEND < $SRPROVIDERCONF > $CONF1
37$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
38PID=$!
39if test $WAIT != 0 ; then
40    echo PID $PID
41    read foo
42fi
43KILLPIDS="$PID"
44
45sleep 1
46
47echo "Using ldapsearch to check that provider slapd (pid=$PID) is running..."
48for i in 0 1 2 3 4 5; do
49	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
50		'objectclass=*' > /dev/null 2>&1
51	RC=$?
52	if test $RC = 0 ; then
53		break
54	fi
55	echo "Waiting 5 seconds for slapd to start..."
56	sleep 5
57done
58
59if test $RC != 0 ; then
60	echo "ldapsearch failed ($RC)!"
61	test $KILLSERVERS != no && kill -HUP $KILLPIDS
62	exit $RC
63fi
64
65echo "Using ldapadd to create the context prefix entry in the provider..."
66$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD < \
67	$LDIFORDEREDCP > /dev/null 2>&1
68RC=$?
69if test $RC != 0 ; then
70	echo "ldapadd failed ($RC)!"
71	test $KILLSERVERS != no && kill -HUP $KILLPIDS
72	exit $RC
73fi
74
75echo "Starting R1 consumer slapd on TCP/IP port $PORT2..."
76. $CONFFILTER $BACKEND < $R1SRCONSUMERCONF > $CONF2
77$SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
78CONSUMERPID=$!
79if test $WAIT != 0 ; then
80    echo CONSUMER R1 PID $CONSUMERPID
81    read foo
82fi
83KILLPIDS="$KILLPIDS $CONSUMERPID"
84
85sleep 1
86
87echo "Using ldapsearch to check that R1 consumer slapd (pid=$CONSUMERPID) is running..."
88for i in 0 1 2 3 4 5; do
89	$LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
90		'objectclass=*' > /dev/null 2>&1
91	RC=$?
92	if test $RC = 0 ; then
93		break
94	fi
95	echo "Waiting 5 seconds for R1 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
105echo "Starting R2 consumer slapd on TCP/IP port $PORT3..."
106. $CONFFILTER $BACKEND < $R2SRCONSUMERCONF > $CONF3
107$SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 &
108CONSUMERPID=$!
109if test $WAIT != 0 ; then
110    echo CONSUMER R2 PID $CONSUMERPID
111    read foo
112fi
113KILLPIDS="$KILLPIDS $CONSUMERPID"
114
115sleep 1
116
117echo "Using ldapsearch to check that R2 consumer slapd (pid=$CONSUMERPID) is running..."
118for i in 0 1 2 3 4 5; do
119	$LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \
120		'objectclass=*' > /dev/null 2>&1
121	RC=$?
122	if test $RC = 0 ; then
123		break
124	fi
125	echo "Waiting 5 seconds for R2 consumer slapd to start..."
126	sleep 5
127done
128
129if test $RC != 0 ; then
130	echo "ldapsearch failed ($RC)!"
131	test $KILLSERVERS != no && kill -HUP $KILLPIDS
132	exit $RC
133fi
134
135echo "Starting P1 consumer slapd on TCP/IP port $PORT4..."
136. $CONFFILTER $BACKEND < $P1SRCONSUMERCONF > $CONF4
137$SLAPD -f $CONF4 -h $URI4 -d $LVL > $LOG4 2>&1 &
138CONSUMERPID=$!
139if test $WAIT != 0 ; then
140    echo CONSUMER P1 PID $CONSUMERPID
141    read foo
142fi
143KILLPIDS="$KILLPIDS $CONSUMERPID"
144
145sleep 1
146
147echo "Using ldapsearch to check that P1 consumer slapd (pid=$CONSUMERPID) is running..."
148for i in 0 1 2 3 4 5; do
149	$LDAPSEARCH -s base -b "$MONITOR" -H $URI4 \
150		'objectclass=*' > /dev/null 2>&1
151	RC=$?
152	if test $RC = 0 ; then
153		break
154	fi
155	echo "Waiting 5 seconds for P1 consumer slapd to start..."
156	sleep 5
157done
158
159if test $RC != 0 ; then
160	echo "ldapsearch failed ($RC)!"
161	test $KILLSERVERS != no && kill -HUP $KILLPIDS
162	exit $RC
163fi
164
165echo "Starting P2 consumer slapd on TCP/IP port $PORT5..."
166. $CONFFILTER $BACKEND < $P2SRCONSUMERCONF > $CONF5
167$SLAPD -f $CONF5 -h $URI5 -d $LVL > $LOG5 2>&1 &
168CONSUMERPID=$!
169if test $WAIT != 0 ; then
170    echo CONSUMER P2 PID $CONSUMERPID
171    read foo
172fi
173KILLPIDS="$KILLPIDS $CONSUMERPID"
174
175sleep 1
176
177echo "Using ldapsearch to check that P2 consumer slapd (pid=$CONSUMERPID) is running..."
178for i in 0 1 2 3 4 5; do
179	$LDAPSEARCH -s base -b "$MONITOR" -H $URI5 \
180		'objectclass=*' > /dev/null 2>&1
181	RC=$?
182	if test $RC = 0 ; then
183		break
184	fi
185	echo "Waiting 5 seconds for P2 consumer slapd to start..."
186	sleep 5
187done
188
189if test $RC != 0 ; then
190	echo "ldapsearch failed ($RC)!"
191	test $KILLSERVERS != no && kill -HUP $KILLPIDS
192	exit $RC
193fi
194
195echo "Starting P3 consumer slapd on TCP/IP port $PORT6..."
196. $CONFFILTER $BACKEND < $P3SRCONSUMERCONF > $CONF6
197$SLAPD -f $CONF6 -h $URI6 -d $LVL > $LOG6 2>&1 &
198CONSUMERPID=$!
199if test $WAIT != 0 ; then
200    echo CONSUMER P3 PID $CONSUMERPID
201    read foo
202fi
203KILLPIDS="$KILLPIDS $CONSUMERPID"
204
205sleep 1
206
207echo "Using ldapsearch to check that P3 consumer slapd (pid=$CONSUMERPID) is running..."
208for i in 0 1 2 3 4 5; do
209	$LDAPSEARCH -s base -b "$MONITOR" -H $URI6 \
210		'objectclass=*' > /dev/null 2>&1
211	RC=$?
212	if test $RC = 0 ; then
213		break
214	fi
215	echo "Waiting 5 seconds for P3 consumer slapd to start..."
216	sleep 5
217done
218
219if test $RC != 0 ; then
220	echo "ldapsearch failed ($RC)!"
221	test $KILLSERVERS != no && kill -HUP $KILLPIDS
222	exit $RC
223fi
224
225echo "Using ldapadd to populate the provider directory..."
226$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD < \
227	$LDIFORDEREDNOCP > /dev/null 2>&1
228RC=$?
229if test $RC != 0 ; then
230	echo "ldapadd failed ($RC)!"
231	test $KILLSERVERS != no && kill -HUP $KILLPIDS
232	exit $RC
233fi
234
235echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
236sleep $SLEEP2
237
238echo "Using ldapmodify to modify provider directory..."
239
240#
241# Do some modifications
242#
243
244$LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD > \
245	$TESTOUT 2>&1 << EOMODS
246dn: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
247changetype: modify
248add: drink
249drink: Orange Juice
250-
251delete: sn
252sn: Jones
253-
254add: sn
255sn: Jones
256
257dn: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
258changetype: modify
259replace: drink
260drink: Iced Tea
261drink: Mad Dog 20/20
262
263dn: cn=ITD Staff,ou=Groups,dc=example,dc=com
264changetype: modify
265delete: uniquemember
266uniquemember: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
267uniquemember: cn=Bjorn Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
268-
269add: uniquemember
270uniquemember: cn=Dorothy Stevens, ou=Alumni Association, ou=People, dc=example,dc=com
271uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example,dc=com
272
273dn: cn=All Staff,ou=Groups,dc=example,dc=com
274changetype: modify
275delete: description
276
277dn: cn=Gern Jensen, ou=Information Technology Division, ou=People, dc=example,dc=com
278changetype: add
279objectclass: OpenLDAPperson
280cn: Gern Jensen
281sn: Jensen
282uid: gjensen
283title: Chief Investigator, ITD
284postaladdress: ITD $ 535 W. William St $ Ann Arbor, MI 48103
285seealso: cn=All Staff, ou=Groups, dc=example,dc=com
286drink: Coffee
287homepostaladdress: 844 Brown St. Apt. 4 $ Ann Arbor, MI 48104
288description: Very odd
289facsimiletelephonenumber: +1 313 555 7557
290telephonenumber: +1 313 555 8343
291mail: gjensen@mailgw.example.com
292homephone: +1 313 555 8844
293
294dn: ou=Retired, ou=People, dc=example,dc=com
295changetype: add
296objectclass: organizationalUnit
297ou: Retired
298
299dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
300changetype: add
301objectclass: OpenLDAPperson
302cn: Rosco P. Coltrane
303sn: Coltrane
304uid: rosco
305
306dn: cn=Rosco P. Coltrane, ou=Information Technology Division, ou=People, dc=example,dc=com
307changetype: modrdn
308newrdn: cn=Rosco P. Coltrane
309deleteoldrdn: 1
310newsuperior: ou=Retired, ou=People, dc=example,dc=com
311
312dn: cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example,dc=com
313changetype: delete
314
315dn: dc=testdomain1,dc=example,dc=com
316changetype: modrdn
317newrdn: dc=itsdomain1
318deleteoldrdn: 1
319
320dn: dc=itsdomain1,dc=example,dc=com
321changetype: modify
322replace: description
323description: Example, Inc. ITS test domain
324
325dn: dc=testdomain2,dc=example,dc=com
326changetype: modrdn
327newrdn: dc=itsdomain2
328deleteoldrdn: 1
329
330EOMODS
331
332RC=$?
333if test $RC != 0 ; then
334	echo "ldapmodify failed ($RC)!"
335	test $KILLSERVERS != no && kill -HUP $KILLPIDS
336	exit $RC
337fi
338
339echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
340sleep $SLEEP2
341
342echo "Performing modify alone on provider..."
343$LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD > \
344        $TESTOUT 2>&1 << EOMODS
345dn: dc=itsdomain2,dc=example,dc=com
346changetype: modify
347replace: description
348description: Example, Inc. itsdomain2 test domain
349
350EOMODS
351
352RC=$?   
353if test $RC != 0 ; then
354        echo "ldapmodify failed ($RC)!"
355        test $KILLSERVERS != no && kill -HUP $KILLPIDS
356        exit $RC
357fi      
358
359echo "Waiting $SLEEP2 seconds for syncrepl to receive changes..."
360sleep $SLEEP2 
361
362echo "Using ldapsearch to read all the entries from the provider..."
363$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
364	'(objectClass=*)' '*' entryCSN > $PROVIDEROUT 2>&1
365RC=$?
366
367if test $RC != 0 ; then
368	echo "ldapsearch failed at provider ($RC)!"
369	test $KILLSERVERS != no && kill -HUP $KILLPIDS
370	exit $RC
371fi
372
373echo "Using ldapsearch to read all the entries from the R1 consumer..."
374$LDAPSEARCH -S "" -b "$BASEDN" -H $URI2 \
375	'(objectClass=*)' '*' entryCSN > $SERVER2OUT 2>&1
376RC=$?
377
378if test $RC != 0 ; then
379	echo "ldapsearch failed at R1 consumer ($RC)!"
380	test $KILLSERVERS != no && kill -HUP $KILLPIDS
381	exit $RC
382fi
383
384echo "Using ldapsearch to read all the entries from the R2 consumer..."
385$LDAPSEARCH -S "" -b "$BASEDN" -H $URI3 \
386	'(objectClass=*)' '*' entryCSN > $SERVER3OUT 2>&1
387RC=$?
388
389if test $RC != 0 ; then
390	echo "ldapsearch failed at R2 consumer ($RC)!"
391	test $KILLSERVERS != no && kill -HUP $KILLPIDS
392	exit $RC
393fi
394
395echo "Using ldapsearch to read all the entries from the P1 consumer..."
396$LDAPSEARCH -S "" -b "$BASEDN" -H $URI4 \
397	'(objectClass=*)' '*' entryCSN > $SERVER4OUT 2>&1
398RC=$?
399
400if test $RC != 0 ; then
401	echo "ldapsearch failed at P1 consumer ($RC)!"
402	test $KILLSERVERS != no && kill -HUP $KILLPIDS
403	exit $RC
404fi
405
406echo "Using ldapsearch to read all the entries from the P2 consumer..."
407$LDAPSEARCH -S "" -b "$BASEDN" -H $URI5 \
408	'(objectClass=*)' '*' entryCSN > $SERVER5OUT 2>&1
409RC=$?
410
411if test $RC != 0 ; then
412	echo "ldapsearch failed at P2 consumer ($RC)!"
413	test $KILLSERVERS != no && kill -HUP $KILLPIDS
414	exit $RC
415fi
416
417echo "Using ldapsearch to read all the entries from the P3 consumer..."
418$LDAPSEARCH -S "" -b "$BASEDN" -H $URI6 \
419	'(objectClass=*)' '*' entryCSN > $SERVER6OUT 2>&1
420RC=$?
421
422if test $RC != 0 ; then
423	echo "ldapsearch failed at P3 consumer ($RC)!"
424	test $KILLSERVERS != no && kill -HUP $KILLPIDS
425	exit $RC
426fi
427
428test $KILLSERVERS != no && kill -HUP $KILLPIDS
429
430echo "Filtering provider ldapsearch results..."
431$LDIFFILTER < $PROVIDEROUT > $PROVIDERFLT
432echo "Filtering R1 consumer ldapsearch results..."
433$LDIFFILTER < $SERVER2OUT > $SERVER2FLT
434echo "Filtering R2 consumer ldapsearch results..."
435$LDIFFILTER < $SERVER3OUT > $SERVER3FLT
436echo "Filtering P1 consumer ldapsearch results..."
437$LDIFFILTER < $SERVER4OUT > $SERVER4FLT
438echo "Filtering P2 consumer ldapsearch results..."
439$LDIFFILTER < $SERVER5OUT > $SERVER5FLT
440echo "Filtering P3 consumer ldapsearch results..."
441$LDIFFILTER < $SERVER6OUT > $SERVER6FLT
442
443echo "Comparing retrieved entries from provider and R1 consumer..."
444$CMP $PROVIDERFLT $SERVER2FLT > $CMPOUT
445
446if test $? != 0 ; then
447	echo "test failed - provider and R1 consumer databases differ"
448	exit 1
449fi
450
451echo "Comparing retrieved entries from provider and R2 consumer..."
452$CMP $PROVIDERFLT $SERVER3FLT > $CMPOUT
453
454if test $? != 0 ; then
455	echo "test failed - provider and R2 consumer databases differ"
456	exit 1
457fi
458
459echo "Comparing retrieved entries from provider and P1 consumer..."
460$CMP $PROVIDERFLT $SERVER4FLT > $CMPOUT
461
462if test $? != 0 ; then
463	echo "test failed - provider and P1 consumer databases differ"
464	exit 1
465fi
466
467echo "Comparing retrieved entries from provider and P2 consumer..."
468$CMP $PROVIDERFLT $SERVER5FLT > $CMPOUT
469
470if test $? != 0 ; then
471	echo "test failed - provider and P2 consumer databases differ"
472	exit 1
473fi
474
475echo "Comparing retrieved entries from provider and P3 consumer..."
476$CMP $PROVIDERFLT $SERVER6FLT > $CMPOUT
477
478if test $? != 0 ; then
479	echo "test failed - provider and P3 consumer databases differ"
480	exit 1
481fi
482
483echo ">>>>> Test succeeded"
484
485test $KILLSERVERS != no && wait
486
487exit 0
488