1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test009-referral,v 1.38.2.7 2010/04/19 19:14:33 quanah 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
19#
20# Test default referral
21#
22
23mkdir -p $TESTDIR $DBDIR1 $DBDIR2
24
25echo "Running slapadd to build slapd database..."
26. $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
27$SLAPADD -f $CONF1 -l $LDIFORDERED
28RC=$?
29if test $RC != 0 ; then
30	echo "slapadd failed ($RC)!"
31	exit $RC
32fi
33
34echo "Starting master slapd on TCP/IP port $PORT1..."
35$SLAPD -n master -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
36PID=$!
37if test $WAIT != 0 ; then
38    echo PID $PID
39    read foo
40fi
41
42echo "Starting slave slapd on TCP/IP port $PORT2..."
43. $CONFFILTER $BACKEND $MONITORDB < $REFSLAVECONF > $CONF2
44$SLAPD -n slave -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
45SLAVEPID=$!
46if test $WAIT != 0 ; then
47    echo SLAVEPID $SLAVEPID
48    read foo
49fi
50
51KILLPIDS="$PID $SLAVEPID"
52
53sleep 1
54
55echo "Testing for master slapd..."
56for i in 0 1 2 3 4 5; do
57	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
58		'objectclass=*' > /dev/null 2>&1
59	RC=$?
60	if test $RC = 0 ; then
61		break
62	fi
63	echo "Waiting 5 seconds for master slapd to start..."
64	sleep 5
65done
66
67if test $RC != 0 ; then
68	echo "ldapsearch failed ($RC)!"
69	test $KILLSERVERS != no && kill -HUP $KILLPIDS
70	exit $RC
71fi
72
73echo "Testing for slave slapd..."
74for i in 0 1 2 3 4 5; do
75	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
76		'objectclass=*' > /dev/null 2>&1
77	RC=$?
78	if test $RC = 0 ; then
79		break
80	fi
81	echo "Waiting 5 seconds for slave slapd to start..."
82	sleep 5
83done
84
85cat /dev/null > $SEARCHOUT
86
87echo "Testing exact searching..."
88$LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
89	'sn=jensen' >> $SEARCHOUT 2>&1
90RC=$?
91if test $RC != 0 ; then
92	echo "ldapsearch failed ($RC)!"
93	test $KILLSERVERS != no && kill -HUP $KILLPIDS
94	exit $RC
95fi
96
97echo "Testing approximate searching..."
98$LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
99	'(sn=jENSEN)' name >> $SEARCHOUT 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 "Testing OR searching..."
108$LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
109	'(|(objectclass=groupofnames)(objectClass=groupofuniquenames)(sn=jones))' >> $SEARCHOUT 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
117echo "Testing AND matching and ends-with searching..."
118$LDAPSEARCH -C -S "" -b "ou=groups,$BASEDN" -s one -h $LOCALHOST -p $PORT2 \
119	'(&(objectclass=groupofnames)(cn=A*))' >> $SEARCHOUT 2>&1
120RC=$?
121if test $RC != 0 ; then
122	echo "ldapsearch failed ($RC)!"
123	test $KILLSERVERS != no && kill -HUP $KILLPIDS
124	exit $RC
125fi
126
127echo "Testing NOT searching..."
128$LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
129	'(!(objectclass=pilotPerson))' >> $SEARCHOUT 2>&1
130RC=$?
131if test $RC != 0 ; then
132	echo "ldapsearch failed ($RC)!"
133	test $KILLSERVERS != no && kill -HUP $KILLPIDS
134	exit $RC
135fi
136
137echo "Testing objectClass/attributeType inheritance ..."
138$LDAPSEARCH -M -a never -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
139	'(&(objectClass=inetorgperson)(userid=uham))' \
140	"2.5.4.0" "userid" >> $SEARCHOUT 2>&1
141RC=$?
142if test $RC != 0 ; then
143	echo "ldapsearch failed ($RC)!"
144	test $KILLSERVERS != no && kill -HUP $KILLPIDS
145	exit $RC
146fi
147
148echo "Testing dontUseCopy control..."
149$LDAPSEARCH -C -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT2 \
150	-E \!dontUseCopy \
151	'sn=jensen' >> $SEARCHOUT
152RC=$?
153if test $RC = 10 ; then
154	echo "ldapsearch failed as expected ($RC)"
155else
156	echo "ldapsearch did not error as expected ($RC)!"
157	test $KILLSERVERS != no && kill -HUP $KILLPIDS
158	exit $RC
159fi
160
161test $KILLSERVERS != no && kill -HUP $KILLPIDS
162
163LDIF=$SEARCHOUTMASTER
164
165echo "Filtering ldapsearch results..."
166$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
167echo "Filtering original ldif used to create database..."
168$LDIFFILTER < $LDIF > $LDIFFLT
169echo "Comparing filter output..."
170$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
171
172if test $? != 0 ; then
173	echo "Comparison failed"
174	exit 1
175fi
176
177echo ">>>>> Test succeeded"
178
179test $KILLSERVERS != no && wait
180
181exit 0
182