1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/data/regressions/its4326/its4326,v 1.2.2.5 2010/04/13 20:23:57 kurt Exp
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2010 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 $BACKLDAP = "ldapno" ; then
20	echo "LDAP backend not available, test skipped"
21	exit 0
22fi
23
24mkdir -p $TESTDIR $DBDIR1 $DBDIR2
25
26ITS=4326
27ITSDIR=$DATADIR/regressions/its$ITS
28
29echo "Running slapadd to build slapd database..."
30. $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
31$SLAPADD -f $CONF1 -l $LDIFORDERED
32RC=$?
33if test $RC != 0 ; then
34	echo "slapadd failed ($RC)!"
35	exit $RC
36fi
37
38echo "Starting slapd on TCP/IP port $PORT1..."
39$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
40SERVERPID=$!
41if test $WAIT != 0 ; then
42    echo SERVERPID $SERVERPID
43    read foo
44fi
45KILLPIDS="$SERVERPID"
46
47sleep 1
48
49echo "Using ldapsearch to check that slapd is running..."
50for i in 0 1 2 3 4 5; do
51	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
52		'objectclass=*' > /dev/null 2>&1
53	RC=$?
54	if test $RC = 0 ; then
55		break
56	fi
57	echo "Waiting 5 seconds for slapd to start..."
58	sleep 5
59done
60
61if test $RC != 0 ; then
62	echo "ldapsearch failed ($RC)!"
63	test $KILLSERVERS != no && kill -HUP $KILLPIDS
64	exit $RC
65fi
66
67echo "Starting proxy slapd on TCP/IP port $PORT2..."
68. $CONFFILTER $BACKEND $MONITORDB < $ITSDIR/slapd.conf > $CONF2
69$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
70PROXYPID=$!
71if test $WAIT != 0 ; then
72    echo PROXYPID $PROXYPID
73    read foo
74fi
75KILLPIDS="$KILLPIDS $PROXYPID"
76
77sleep 1
78
79echo "Using ldapsearch to check that proxy slapd is running..."
80for i in 0 1 2 3 4 5; do
81	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
82		'objectclass=*' > /dev/null 2>&1
83	RC=$?
84	if test $RC = 0 ; then
85		break
86	fi
87	echo "Waiting 5 seconds for slapd to start..."
88	sleep 5
89done
90
91if test $RC != 0 ; then
92	echo "ldapsearch failed ($RC)!"
93	test $KILLSERVERS != no && kill -HUP $KILLPIDS
94	exit $RC
95fi
96
97echo "Searching the proxy..."
98$LDAPSEARCH -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
99	'(objectClass=*)' > /dev/null 2>&1
100RC=$?
101if test $RC != 0 ; then
102	echo "ldapsearch failed ($RC)!"
103	test $KILLSERVERS != no && kill -HUP $KILLPIDS
104	exit $RC
105fi
106
107echo "Re-searching the proxy..."
108$LDAPSEARCH -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
109	'(objectClass=*)' > /dev/null 2>&1
110RC=$?
111if test $RC != 0 ; then
112	echo "ldapsearch failed ($RC)!"
113	test $KILLSERVERS != no && kill -HUP $KILLPIDS
114	exit $RC
115fi
116
117SLEEP=2
118echo "Stopping the server and sleeping $SLEEP seconds..."
119kill -HUP "$SERVERPID"
120wait $SERVERPID
121sleep $SLEEP
122KILLPIDS="$PROXYPID"
123
124echo "Searching the proxy..."
125$LDAPSEARCH -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
126	'(objectClass=*)' > /dev/null 2>&1
127RC=$?
128case $RC in
1290)
130	echo "ldapsearch should have failed ($RC)!"
131	test $KILLSERVERS != no && kill -HUP $KILLPIDS
132	exit $RC
133	;;
13452)
135	echo "ldapsearch failed ($RC)"
136	;;
137*)
138	echo "ldapsearch failed ($RC)!"
139	test $KILLSERVERS != no && kill -HUP $KILLPIDS
140	exit $RC
141	;;
142esac
143
144echo "Re-searching the proxy..."
145$LDAPSEARCH -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
146	'(objectClass=*)' > /dev/null 2>&1
147RC=$?
148case $RC in
1490)
150	echo "ldapsearch should have failed ($RC)!"
151	test $KILLSERVERS != no && kill -HUP $KILLPIDS
152	exit $RC
153	;;
15452)
155	echo "ldapsearch failed ($RC)"
156	;;
157*)
158	echo "ldapsearch failed ($RC)!"
159	test $KILLSERVERS != no && kill -HUP $KILLPIDS
160	exit $RC
161	;;
162esac
163
164echo "Restarting slapd on TCP/IP port $PORT1..."
165$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
166SERVERPID=$!
167if test $WAIT != 0 ; then
168    echo SERVERPID $SERVERPID
169    read foo
170fi
171KILLPIDS="$SERVERPID $PROXYPID"
172
173sleep 1
174
175echo "Using ldapsearch to check that slapd is running..."
176for i in 0 1 2 3 4 5; do
177	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
178		'objectclass=*' > /dev/null 2>&1
179	RC=$?
180	if test $RC = 0 ; then
181		break
182	fi
183	echo "Waiting 5 seconds for slapd to start..."
184	sleep 5
185done
186
187if test $RC != 0 ; then
188	echo "ldapsearch failed ($RC)!"
189	test $KILLSERVERS != no && kill -HUP $KILLPIDS
190	exit $RC
191fi
192
193echo "Searching the proxy..."
194$LDAPSEARCH -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
195	'(objectClass=*)' > /dev/null 2>&1
196RC=$?
197if test $RC != 0 ; then
198	echo "ldapsearch failed ($RC)!"
199	test $KILLSERVERS != no && kill -HUP $KILLPIDS
200	exit $RC
201fi
202
203echo "Re-searching the proxy..."
204$LDAPSEARCH -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
205	'(objectClass=*)' > /dev/null 2>&1
206RC=$?
207if test $RC != 0 ; then
208	echo "ldapsearch failed ($RC)!"
209	test $KILLSERVERS != no && kill -HUP $KILLPIDS
210	exit $RC
211fi
212
213test $KILLSERVERS != no && kill -HUP $KILLPIDS
214
215echo ">>>>> Test succeeded"
216
217test $KILLSERVERS != no && wait
218
219exit 0
220