1#! /bin/sh
2# $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 2004-2011 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 $MONITORDB < $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 $TIMING > $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 $LOCALHOST -p $PORT1 \
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 $LOCALHOST -p $PORT1 > $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 $LOCALHOST -p $PORT1 -w $PASSWD > \
79	/dev/null 2>&1 'uid=george,ou=users,o=refint' 'uid=foster'
80#$LDAPMODRDN -D "$REFINTDN" -r -h $LOCALHOST -p $PORT1 -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 $LOCALHOST -p $PORT1 > $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 $LOCALHOST -p $PORT1 -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 $LOCALHOST -p $PORT1 > $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 $LOCALHOST -p $PORT1 -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 $LOCALHOST -p $PORT1 -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
192if test $BACKEND != "bdb" ; then
193	$LDAPMODIFY -v -D "$REFINTDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
194		$TESTOUT 2>&1 << EDEL
195version: 1
196dn: cn=group,o=refint
197changetype: add
198objectClass: groupOfNames
199cn: group
200member: uid=bill,ou=users,o=refint
201member: uid=bob,ou=users,o=refint
202member: uid=dave,ou=users,o=refint
203member: uid=jorge,ou=users,o=refint
204member: uid=theman,ou=users,o=refint
205member: uid=richard,ou=users,o=refint
206EDEL
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	sleep 1;
216
217	$LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 \
218		manager member secretary > $SEARCHOUT 2>&1
219	RC=$?
220	if test $RC != 0 ; then
221		echo "ldapsearch failed ($RC)!"
222		test $KILLSERVERS != no && kill -HUP $KILLPIDS
223		exit $RC
224	fi
225
226	$EGREP_CMD "(manager|member|secretary):" $SEARCHOUT \
227		| sed "s/ou=users/ou=people/g" | \
228		sort > $TESTOUT 2>&1
229
230	echo "testing subtree rename"
231	$LDAPMODRDN -D "$REFINTDN" -r -h $LOCALHOST -p $PORT1 -w $PASSWD > \
232		/dev/null 2>&1 'ou=users,o=refint' 'ou=people'
233	RC=$?
234	if test $RC != 0 ; then
235		echo "ldapmodrdn failed ($RC)!"
236		test $KILLSERVERS != no && kill -HUP $KILLPIDS
237		exit $RC
238	fi
239
240	sleep 1;
241
242	echo "Using ldapsearch to check dependents new rdn..."
243
244	$LDAPSEARCH -S "" -b "o=refint" -h $LOCALHOST -p $PORT1 \
245		manager member secretary > $SEARCHOUT 2>&1
246
247	RC=$?
248	if test $RC != 0 ; then
249		echo "ldapsearch failed ($RC)!"
250		test $KILLSERVERS != no && kill -HUP $KILLPIDS
251		exit $RC
252	fi
253
254	$EGREP_CMD "(manager|member|secretary):" $SEARCHOUT \
255		| sort > $SEARCHFLT 2>&1
256
257	echo "Comparing ldapsearch results against original..."
258	$CMP $TESTOUT $SEARCHFLT > $CMPOUT
259
260	if test $? != 0 ; then
261		echo "comparison failed - subtree rename operations did not complete correctly"
262		test $KILLSERVERS != no && kill -HUP $KILLPIDS
263		exit 1
264	fi
265fi
266
267test $KILLSERVERS != no && kill -HUP $KILLPIDS
268
269echo ">>>>> Test succeeded"
270
271test $KILLSERVERS != no && wait
272
273exit 0
274