1#! /bin/sh
2# $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-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
19echo ""
20
21if test $BACKMETA = metano ; then 
22	echo "meta backend not available, test skipped"
23	exit 0
24fi
25
26# to be removed some time...
27if test "x$TEST_META" = "xno" ; then
28	echo '### Test disabled by "TEST_META=no"; unset TEST_META to re-enable'
29	echo ""
30	exit 0
31else
32	echo "### this test is experimental; in case of problems,"
33	echo "### set \"TEST_META=no\" to disable, and report thru"
34	echo "### the Issue Tracking System <http://www.openldap.org/its/>"
35	echo ""
36fi
37
38if test x$TESTLOOPS = x ; then
39	TESTLOOPS=50
40fi
41
42rm -rf $TESTDIR
43
44mkdir -p $TESTDIR $DBDIR1 $DBDIR2
45
46ITS=4448
47ITSDIR=$DATADIR/regressions/its$ITS
48ITSCONF=$ITSDIR/slapd-meta.conf
49
50# NOTE: this could be added to all tests...
51if test "$BACKEND" = "bdb" || test "$BACKEND" = "hdb" ; then
52	if test "x$DB_CONFIG" != "x" ; then \
53		if test -f $DB_CONFIG ; then
54			echo "==> using DB_CONFIG \"$DB_CONFIG\""
55			cp $DB_CONFIG $DBDIR1
56			cp $DB_CONFIG $DBDIR2
57		else
58			echo "==> DB_CONFIG must point to a valid file (ignored)"
59		fi
60	else
61		echo "==> set \"DB_CONFIG\" to the DB_CONFIG file you want to use for the test."
62	fi
63	echo ""
64fi
65
66echo "Starting slapd on TCP/IP port $PORT1..."
67. $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
68$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
69PID=$!
70if test $WAIT != 0 ; then
71    echo PID $PID
72    read foo
73fi
74KILLPIDS="$PID"
75
76sleep 1
77
78echo "Using ldapsearch to check that slapd is running..."
79for i in 0 1 2 3 4 5; do
80	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
81		'objectclass=*' > /dev/null 2>&1
82	RC=$?
83	if test $RC = 0 ; then
84		break
85	fi
86	echo "Waiting 5 seconds for slapd to start..."
87	sleep 5
88done
89if test $RC != 0 ; then
90	echo "ldapsearch failed ($RC)!"
91	test $KILLSERVERS != no && kill -HUP $KILLPIDS
92	exit $RC
93fi
94
95echo "Using ldapadd to populate the database..."
96$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
97	$LDIFORDERED > $TESTOUT 2>&1
98RC=$?
99if test $RC != 0 ; then
100	echo "ldapadd failed ($RC)!"
101	test $KILLSERVERS != no && kill -HUP $KILLPIDS
102	exit $RC
103fi
104
105echo "Using ldapadd to add the referral..."
106$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD << EOMODS \
107	> $TESTOUT 2>&1
108dn: cn=Meta,dc=example,dc=com
109objectClass: referral
110objectClass: extensibleObject
111cn: Meta
112ref: ${URI2}ou=Meta,dc=example,dc=com
113EOMODS
114
115RC=$?
116if test $RC != 0 ; then
117	echo "ldapadd failed ($RC)!"
118	test $KILLSERVERS != no && kill -HUP $KILLPIDS
119	exit $RC
120fi
121
122echo "Starting slapd on TCP/IP port $PORT2..."
123. $CONFFILTER $BACKEND $MONITORDB < $METACONF2 > $CONF2
124$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
125PID=$!
126if test $WAIT != 0 ; then
127    echo PID $PID
128    read foo
129fi
130KILLPIDS="$KILLPIDS $PID"
131
132sleep 1
133
134echo "Using ldapsearch to check that slapd is running..."
135for i in 0 1 2 3 4 5; do
136	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
137		'objectclass=*' > /dev/null 2>&1
138	RC=$?
139	if test $RC = 0 ; then
140		break
141	fi
142	echo "Waiting 5 seconds for slapd to start..."
143	sleep 5
144done
145if test $RC != 0 ; then
146	echo "ldapsearch failed ($RC)!"
147	test $KILLSERVERS != no && kill -HUP $KILLPIDS
148	exit $RC
149fi
150
151echo "Using ldapadd to populate the database..."
152$LDAPADD -D "$METAMANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD < \
153	$LDIFMETA >> $TESTOUT 2>&1
154RC=$?
155if test $RC != 0 ; then
156	echo "ldapadd failed ($RC)!"
157	test $KILLSERVERS != no && kill -HUP $KILLPIDS
158	exit $RC
159fi
160
161echo "Starting slapd on TCP/IP port $PORT3..."
162. $CONFFILTER $BACKEND $MONITORDB < $ITSCONF > $CONF3
163$SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
164PID=$!
165if test $WAIT != 0 ; then
166    echo PID $PID
167    read foo
168fi
169KILLPIDS="$KILLPIDS $PID"
170
171sleep 1
172
173echo "Using ldapsearch to check that slapd is running..."
174for i in 0 1 2 3 4 5; do
175	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
176		'objectclass=*' > /dev/null 2>&1
177	RC=$?
178	if test $RC = 0 ; then
179		break
180	fi
181	echo "Waiting 5 seconds for slapd to start..."
182	sleep 5
183done
184if test $RC != 0 ; then
185	echo "ldapsearch failed ($RC)!"
186	test $KILLSERVERS != no && kill -HUP $KILLPIDS
187	exit $RC
188fi
189
190cat /dev/null > $SEARCHOUT
191
192mkdir -p $TESTDIR/$DATADIR
193METABASEDN="o=Example,c=US"
194#for f in $DATADIR/do_* ; do
195#	sed -e "s;$BASEDN;$METABASEDN;" $f > $TESTDIR/$f
196#done
197
198# add a read that matches only the local database, but selects 
199# also the remote as candidate; this should be removed to compare
200# execution times with test008...
201#for f in $TESTDIR/$DATADIR/do_read.* ; do
202#	echo "ou=Meta,$METABASEDN" >> $f
203#done
204
205# add a read that matches a referral in the local database only, 
206# but selects also the remote as candidate; this should be removed 
207# to compare execution times with test008...
208#for f in $TESTDIR/$DATADIR/do_read.* ; do
209#	echo "cn=Somewhere,ou=Meta,$METABASEDN" >> $f
210#done
211
212# add a bind that resolves to a referral
213#for f in $TESTDIR/$DATADIR/do_bind.* ; do
214#	echo "cn=Foo,ou=Meta,$METABASEDN" >> $f
215#	echo "bar" >> $f
216#	echo "" >> $f
217#	echo "" >> $f
218#done
219
220echo \
221"$METABASEDN
222(cn=John Belushi)
223$METABASEDN
224(cn=Meta)
225$METABASEDN
226(cn=Foo Bar)
227$METABASEDN
228(cn=Dan Aykroyd)
229$METABASEDN
230(cn=John Belushi)
231$METABASEDN
232(cn=Meta)
233$METABASEDN
234(cn=Foo Bar)
235$METABASEDN
236(cn=Dan Aykroyd)
237$METABASEDN
238(cn=John Belushi)
239$METABASEDN
240(cn=Meta)
241$METABASEDN
242(cn=Foo Bar)
243$METABASEDN
244(cn=Dan Aykroyd)
245$METABASEDN
246(cn=John Belushi)
247$METABASEDN
248(cn=Meta)
249$METABASEDN
250(cn=Foo Bar)
251$METABASEDN
252(cn=Dan Aykroyd)
253$METABASEDN
254(cn=John Belushi)
255$METABASEDN
256(cn=Meta)
257$METABASEDN
258(cn=Foo Bar)
259$METABASEDN
260(cn=Dan Aykroyd)
261$METABASEDN
262(cn=John Belushi)
263$METABASEDN
264(cn=Meta)
265$METABASEDN
266(cn=Foo Bar)
267$METABASEDN
268(cn=Dan Aykroyd)
269$METABASEDN
270(cn=John Belushi)
271$METABASEDN
272(cn=Meta)
273$METABASEDN
274(cn=Foo Bar)
275$METABASEDN
276(cn=Dan Aykroyd)
277$METABASEDN
278(cn=John Belushi)
279$METABASEDN
280(cn=Meta)
281$METABASEDN
282(cn=Foo Bar)
283$METABASEDN
284(cn=Dan Aykroyd)" \
285> $TESTDIR/$DATADIR/do_search.0
286
287echo "Using tester for concurrent server access..."
288$SLAPDTESTER -P "$PROGDIR" -d "$TESTDIR/$DATADIR" -h $LOCALHOST -p $PORT3 \
289	-D "cn=Manager,$METABASEDN" -w $PASSWD -l $TESTLOOPS -r 20 -FF
290RC=$?
291
292if test $RC != 0 ; then
293	echo "slapd-tester failed ($RC)!"
294	test $KILLSERVERS != no && kill -HUP $KILLPIDS
295	exit $RC
296fi 
297
298echo "Using ldapsearch to retrieve all the entries..."
299$LDAPSEARCH -S "" -b "$METABASEDN" -h $LOCALHOST -p $PORT3 \
300			'(objectClass=*)' > $SEARCHOUT 2>&1
301RC=$?
302
303test $KILLSERVERS != no && kill -HUP $KILLPIDS
304
305if test $RC != 0 ; then
306	echo "ldapsearch failed ($RC)!"
307	exit $RC
308fi
309
310echo "Filtering ldapsearch results..."
311$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
312echo "Filtering original ldif used to create database..."
313$LDIFFILTER < $METACONCURRENCYOUT > $LDIFFLT
314echo "Comparing filter output..."
315$BCMP $SEARCHFLT $LDIFFLT > $CMPOUT
316
317if test $? != 0 ; then
318	echo "comparison failed - slapd-meta search/modification didn't succeed"
319	exit 1
320fi
321
322echo ">>>>> Test succeeded"
323
324test $KILLSERVERS != no && wait
325
326exit 0
327