1#! /bin/sh
2# $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 2004-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 $REFINT = refintno; then 
20	echo "Referential Integrity overlay not available, test skipped"
21	exit 0
22fi 
23
24mkdir -p $TESTDIR $DBDIR1
25
26echo "Running slapadd to build slapd database..."
27. $CONFFILTER $BACKEND < $REFINTCONF > $CONF1
28$SLAPADD -f $CONF1 -l $LDIFREFINT
29RC=$?
30if test $RC != 0 ; then
31	echo "slapadd failed ($RC)!"
32	exit $RC
33fi
34
35echo "Starting slapd on TCP/IP port $PORT1..."
36$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
37PID=$!
38if test $WAIT != 0 ; then
39    echo PID $PID
40    read foo
41fi
42KILLPIDS="$PID"
43
44sleep 1
45
46echo "Testing slapd referential integrity operations..."
47for i in 0 1 2 3 4 5; do
48	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
49		'objectclass=*' > /dev/null 2>&1
50	RC=$?
51	if test $RC = 0 ; then
52		break
53	fi
54	echo "Waiting 5 seconds for slapd to start..."
55	sleep 5
56done
57
58if test $RC != 0 ; then
59	echo "ldapsearch failed ($RC)!"
60	test $KILLSERVERS != no && kill -HUP $KILLPIDS
61	exit $RC
62fi
63
64echo "Searching unmodified database..."
65
66$LDAPSEARCH -S "" -b "o=refint" -H $URI1 > $SEARCHOUT 2>&1
67RC=$?
68if test $RC != 0 ; then
69	echo "ldapsearch failed ($RC)!"
70	test $KILLSERVERS != no && kill -HUP $KILLPIDS
71	exit $RC
72fi
73
74$EGREP_CMD "(manager|secretary):" $SEARCHOUT | sed "s/george/foster/g" | \
75	sort > $TESTOUT 2>&1
76
77echo "Testing modrdn..."
78$LDAPMODRDN -D "$REFINTDN" -r -H $URI1 -w $PASSWD > \
79	/dev/null 2>&1 'uid=george,ou=users,o=refint' 'uid=foster'
80#$LDAPMODRDN -D "$REFINTDN" -r -H $URI1 -w $PASSWD  \
81#	'uid=george,ou=users,o=refint' 'uid=foster'
82
83RC=$?
84if test $RC != 0 ; then
85	echo "ldapmodrdn failed ($RC)!"
86	test $KILLSERVERS != no && kill -HUP $KILLPIDS
87	exit $RC
88fi
89
90sleep 1;
91
92echo "Using ldapsearch to check dependents new rdn..."
93
94$LDAPSEARCH -S "" -b "o=refint" -H $URI1 > $SEARCHOUT 2>&1
95
96RC=$?
97	if test $RC != 0 ; then
98	echo "ldapsearch failed ($RC)!"
99	test $KILLSERVERS != no && kill -HUP $KILLPIDS
100	exit $RC
101fi
102
103$EGREP_CMD "(manager|secretary):" $SEARCHOUT | sort > $SEARCHFLT 2>&1
104
105echo "Comparing ldapsearch results against original..."
106$CMP $TESTOUT $SEARCHFLT > $CMPOUT
107
108if test $? != 0 ; then
109	echo "comparison failed - modify operations did not complete correctly"
110	test $KILLSERVERS != no && kill -HUP $KILLPIDS
111	exit 1
112fi
113
114echo "Testing delete..."
115$LDAPMODIFY -v -D "$REFINTDN" -H $URI1 -w $PASSWD > \
116	$TESTOUT 2>&1 << EDEL
117version: 1
118dn: uid=foster,ou=users,o=refint
119changetype: delete
120EDEL
121
122RC=$?
123if test $RC != 0 ; then
124	echo "ldapmodify failed ($RC)!"
125	test $KILLSERVERS != no && kill -HUP $KILLPIDS
126	exit $RC
127fi
128
129sleep 1;
130
131echo "Using ldapsearch to verify dependents have been deleted..."
132$LDAPSEARCH -S "" -b "o=refint" -H $URI1 > $SEARCHOUT 2>&1
133
134RC=$?
135if test $RC != 0 ; then
136	echo "ldapsearch failed ($RC)!"
137	test $KILLSERVERS != no && kill -HUP $KILLPIDS
138	exit $RC
139fi
140
141$EGREP_CMD "(manager|secretary):" $SEARCHOUT > $SEARCHFLT 2>&1
142
143RC=`grep -c foster $SEARCHFLT`
144if test $RC != 0 ; then
145	echo "dependent modify failed - dependents were not deleted"
146	test $KILLSERVERS != no && kill -HUP $KILLPIDS
147	exit 1
148fi
149
150echo "Additional test records..."
151
152$LDAPADD -D "$REFINTDN" -H $URI1 -w $PASSWD > \
153	$TESTOUT 2>&1 << ETEST
154dn: uid=special,ou=users,o=refint
155objectClass: inetOrgPerson
156objectClass: extensibleObject
157uid: special
158sn: special
159cn: special
160businessCategory: nothing
161carLicense: FOO
162departmentNumber: 933
163displayName: special
164employeeNumber: 41491
165employeeType: vendor
166givenName: special
167member: uid=alice,ou=users,o=refint
168ETEST
169
170RC=$?
171if test $RC != 0 ; then
172	echo "ldapadd failed ($RC)!"
173	test $KILLSERVERS != no && kill -HUP $KILLPIDS
174	exit $RC
175fi
176
177echo "Testing delete when referential attribute is a MUST..."
178$LDAPMODIFY -v -D "$REFINTDN" -H $URI1 -w $PASSWD > \
179	$TESTOUT 2>&1 << EDEL
180version: 1
181dn: uid=alice,ou=users,o=refint
182changetype: delete
183EDEL
184
185RC=$?
186if test $RC != 0 ; then
187	echo "ldapmodify failed ($RC)!"
188	test $KILLSERVERS != no && kill -HUP $KILLPIDS
189	exit $RC
190fi
191
192$LDAPMODIFY -v -D "$REFINTDN" -H $URI1 -w $PASSWD > \
193	$TESTOUT 2>&1 << EDEL
194version: 1
195dn: cn=group,o=refint
196changetype: add
197objectClass: groupOfNames
198cn: group
199member: uid=bill,ou=users,o=refint
200member: uid=bob,ou=users,o=refint
201member: uid=dave,ou=users,o=refint
202member: uid=jorge,ou=users,o=refint
203member: uid=theman,ou=users,o=refint
204member: uid=richard,ou=users,o=refint
205EDEL
206
207RC=$?
208if test $RC != 0 ; then
209	echo "ldapmodify failed ($RC)!"
210	test $KILLSERVERS != no && kill -HUP $KILLPIDS
211	exit $RC
212fi
213
214sleep 1;
215
216$LDAPSEARCH -S "" -b "o=refint" -H $URI1 \
217	manager member secretary > $SEARCHOUT 2>&1
218RC=$?
219if test $RC != 0 ; then
220	echo "ldapsearch failed ($RC)!"
221	test $KILLSERVERS != no && kill -HUP $KILLPIDS
222	exit $RC
223fi
224
225$EGREP_CMD "(manager|member|secretary):" $SEARCHOUT \
226	| sed "s/ou=users/ou=people/g" | \
227	sort > $TESTOUT 2>&1
228
229echo "testing subtree rename"
230$LDAPMODRDN -D "$REFINTDN" -r -H $URI1 -w $PASSWD > \
231	/dev/null 2>&1 'ou=users,o=refint' 'ou=people'
232RC=$?
233if test $RC != 0 ; then
234	echo "ldapmodrdn failed ($RC)!"
235	test $KILLSERVERS != no && kill -HUP $KILLPIDS
236	exit $RC
237fi
238
239sleep 1;
240
241echo "Using ldapsearch to check dependents new rdn..."
242
243$LDAPSEARCH -S "" -b "o=refint" -H $URI1 \
244	manager member secretary > $SEARCHOUT 2>&1
245
246RC=$?
247if test $RC != 0 ; then
248	echo "ldapsearch failed ($RC)!"
249	test $KILLSERVERS != no && kill -HUP $KILLPIDS
250	exit $RC
251fi
252
253$EGREP_CMD "(manager|member|secretary):" $SEARCHOUT \
254	| sort > $SEARCHFLT 2>&1
255
256echo "Comparing ldapsearch results against original..."
257$CMP $TESTOUT $SEARCHFLT > $CMPOUT
258
259if test $? != 0 ; then
260	echo "comparison failed - subtree rename operations did not complete correctly"
261	test $KILLSERVERS != no && kill -HUP $KILLPIDS
262	exit 1
263fi
264
265test $KILLSERVERS != no && kill -HUP $KILLPIDS
266
267echo ">>>>> Test succeeded"
268
269test $KILLSERVERS != no && wait
270
271exit 0
272