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