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
26if test $BACKLDAP = ldapno ; then 
27	echo "ldap backend not available, test skipped"
28	exit 0
29fi
30
31if test x$TESTLOOPS = x ; then
32	TESTLOOPS=50
33fi
34
35if test x$TESTCHILDREN = x ; then
36	TESTCHILDREN=20
37fi
38
39rm -rf $TESTDIR
40
41mkdir -p $TESTDIR $DBDIR1 $DBDIR2
42
43# NOTE: this could be added to all tests...
44if test "$BACKEND" = "bdb" || test "$BACKEND" = "hdb" ; then
45	if test "x$DB_CONFIG" != "x" ; then \
46		if test -f $DB_CONFIG ; then
47			echo "==> using DB_CONFIG \"$DB_CONFIG\""
48			cp $DB_CONFIG $DBDIR1
49			cp $DB_CONFIG $DBDIR2
50		else
51			echo "==> DB_CONFIG must point to a valid file (ignored)"
52		fi
53	else
54		echo "==> set \"DB_CONFIG\" to the DB_CONFIG file you want to use for the test."
55	fi
56	echo ""
57fi
58
59echo "Starting slapd on TCP/IP port $PORT1..."
60. $CONFFILTER $BACKEND $MONITORDB < $METACONF1 > $CONF1
61$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
62PID=$!
63if test $WAIT != 0 ; then
64    echo PID $PID
65    read foo
66fi
67KILLPIDS="$PID"
68
69sleep 1
70
71echo "Using ldapsearch to check that slapd is running..."
72for i in 0 1 2 3 4 5; do
73	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
74		'objectclass=*' > /dev/null 2>&1
75	RC=$?
76	if test $RC = 0 ; then
77		break
78	fi
79	echo "Waiting 5 seconds for slapd to start..."
80	sleep 5
81done
82if test $RC != 0 ; then
83	echo "ldapsearch failed ($RC)!"
84	test $KILLSERVERS != no && kill -HUP $KILLPIDS
85	exit $RC
86fi
87
88echo "Using ldapadd to populate the database..."
89$LDAPADD -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD < \
90	$LDIFORDERED > $TESTOUT 2>&1
91RC=$?
92if test $RC != 0 ; then
93	echo "ldapadd failed ($RC)!"
94	test $KILLSERVERS != no && kill -HUP $KILLPIDS
95	exit $RC
96fi
97
98echo "Starting slapd on TCP/IP port $PORT2..."
99. $CONFFILTER $BACKEND $MONITORDB < $METACONF2 > $CONF2
100$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
101PID=$!
102if test $WAIT != 0 ; then
103    echo PID $PID
104    read foo
105fi
106KILLPIDS="$KILLPIDS $PID"
107
108sleep 1
109
110echo "Using ldapsearch to check that slapd is running..."
111for i in 0 1 2 3 4 5; do
112	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
113		'objectclass=*' > /dev/null 2>&1
114	RC=$?
115	if test $RC = 0 ; then
116		break
117	fi
118	echo "Waiting 5 seconds for slapd to start..."
119	sleep 5
120done
121if test $RC != 0 ; then
122	echo "ldapsearch failed ($RC)!"
123	test $KILLSERVERS != no && kill -HUP $KILLPIDS
124	exit $RC
125fi
126
127echo "Using ldapadd to populate the database..."
128$LDAPADD -D "$METAMANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD < \
129	$LDIFMETA >> $TESTOUT 2>&1
130RC=$?
131if test $RC != 0 ; then
132	echo "ldapadd failed ($RC)!"
133	test $KILLSERVERS != no && kill -HUP $KILLPIDS
134	exit $RC
135fi
136
137echo "Starting slapd on TCP/IP port $PORT3..."
138. $CONFFILTER $BACKEND $MONITORDB < $METACONF > $CONF3
139$SLAPD -f $CONF3 -h $URI3 -d $LVL $TIMING > $LOG3 2>&1 &
140PID=$!
141if test $WAIT != 0 ; then
142    echo PID $PID
143    read foo
144fi
145KILLPIDS="$KILLPIDS $PID"
146
147sleep 1
148
149echo "Using ldapsearch to check that slapd is running..."
150for i in 0 1 2 3 4 5; do
151	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT3 \
152		'objectclass=*' > /dev/null 2>&1
153	RC=$?
154	if test $RC = 0 ; then
155		break
156	fi
157	echo "Waiting 5 seconds for slapd to start..."
158	sleep 5
159done
160if test $RC != 0 ; then
161	echo "ldapsearch failed ($RC)!"
162	test $KILLSERVERS != no && kill -HUP $KILLPIDS
163	exit $RC
164fi
165
166cat /dev/null > $SEARCHOUT
167
168mkdir -p $TESTDIR/$DATADIR
169METABASEDN="o=Example,c=US"
170for f in $DATADIR/do_* ; do
171	sed -e "s;$BASEDN;$METABASEDN;" $f > $TESTDIR/$f
172done
173
174# add a read that matches only the local database, but selects 
175# also the remote as candidate; this should be removed to compare
176# execution times with test008...
177for f in $TESTDIR/$DATADIR/do_read.* ; do
178	echo "ou=Meta,$METABASEDN" >> $f
179done
180
181# add a read that matches a referral in the local database only, 
182# but selects also the remote as candidate; this should be removed 
183# to compare execution times with test008...
184for f in $TESTDIR/$DATADIR/do_read.* ; do
185	echo "cn=Somewhere,ou=Meta,$METABASEDN" >> $f
186done
187
188# add a bind that resolves to a referral
189for f in $TESTDIR/$DATADIR/do_bind.* ; do
190	echo "cn=Foo,ou=Meta,$METABASEDN" >> $f
191	echo "bar" >> $f
192	echo "" >> $f
193	echo "" >> $f
194done
195
196# fix test data to include back-monitor, if available
197# NOTE: copies do_* files from $TESTDIR/$DATADIR to $TESTDIR
198$MONITORDATA "$MONITORDB" "$TESTDIR/$DATADIR" "$TESTDIR"
199
200BINDDN="cn=Manager,o=Local"
201PASSWD="secret"
202echo "Using tester for concurrent server access..."
203$SLAPDTESTER -P "$PROGDIR" -d "$TESTDIR" -h $LOCALHOST -p $PORT3 \
204	-D "$BINDDN" -w $PASSWD -l $TESTLOOPS -j $TESTCHILDREN \
205	-r 20 -i '!REFERRAL' -i '*INVALID_CREDENTIALS' -SS
206RC=$?
207
208if test $RC != 0 ; then
209	echo "slapd-tester failed ($RC)!"
210	test $KILLSERVERS != no && kill -HUP $KILLPIDS
211	exit $RC
212fi 
213
214echo "Using ldapsearch to retrieve all the entries..."
215$LDAPSEARCH -S "" -b "$METABASEDN" -h $LOCALHOST -p $PORT3 \
216			'objectClass=*' > $SEARCHOUT 2>&1
217RC=$?
218
219test $KILLSERVERS != no && kill -HUP $KILLPIDS
220
221if test $RC != 0 ; then
222	echo "ldapsearch failed ($RC)!"
223	exit $RC
224fi
225
226echo "Filtering ldapsearch results..."
227$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
228echo "Filtering original ldif used to create database..."
229$LDIFFILTER < $METACONCURRENCYOUT > $LDIFFLT
230echo "Comparing filter output..."
231$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
232
233if test $? != 0 ; then
234	echo "comparison failed - slapd-meta search/modification didn't succeed"
235	exit 1
236fi
237
238echo ">>>>> Test succeeded"
239
240test $KILLSERVERS != no && wait
241
242exit 0
243