1#! /bin/sh
2# $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2021 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
19mkdir -p $TESTDIR $DBDIR1 $DBDIR2
20
21$SLAPPASSWD -g -n >$CONFIGPWF
22echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
23
24echo "Starting an empty slapd on TCP/IP port $PORT2..."
25. $CONFFILTER $BACKEND < $SCHEMACONF > $CONF2
26$SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
27PID=$!
28if test $WAIT != 0 ; then
29    echo PID $PID
30    read foo
31fi
32PID2="$PID"
33KILLPIDS="$PID"
34
35echo "Testing slapd searching..."
36for i in 0 1 2 3 4 5; do
37    $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
38        '(objectclass=*)' > /dev/null 2>&1
39    RC=$?
40    if test $RC = 0 ; then
41        break
42    fi
43    echo "Waiting $SLEEP1 seconds for slapd to start..."
44    sleep $SLEEP1
45done
46if test $RC != 0 ; then
47    echo "ldapsearch failed ($RC)!"
48    test $KILLSERVERS != no && kill -HUP $KILLPIDS
49    exit $RC
50fi
51
52echo "Running slapadd to build slapd database..."
53. $CONFFILTER $BACKEND < $CONFTWO > $CONF3
54$SLAPADD -f $CONF3 -l $LDIFORDERED
55RC=$?
56if test $RC != 0 ; then
57    echo "slapadd failed ($RC)!"
58    exit $RC
59fi
60
61echo "Running slapindex to index slapd database..."
62$SLAPINDEX -f $CONF3
63RC=$?
64if test $RC != 0 ; then
65    echo "warning: slapindex failed ($RC)"
66    echo "  assuming no indexing support"
67fi
68
69echo "Starting second slapd on TCP/IP port $PORT3..."
70$SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 &
71PID=$!
72if test $WAIT != 0 ; then
73    echo PID $PID
74    read foo
75fi
76PID3="$PID"
77KILLPIDS="$KILLPIDS $PID"
78
79sleep $SLEEP0
80
81echo "Testing slapd searching..."
82for i in 0 1 2 3 4 5; do
83    $LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \
84        '(objectclass=*)' > /dev/null 2>&1
85    RC=$?
86    if test $RC = 0 ; then
87        break
88    fi
89    echo "Waiting $SLEEP1 seconds for slapd to start..."
90    sleep $SLEEP1
91done
92if test $RC != 0 ; then
93    echo "ldapsearch failed ($RC)!"
94    test $KILLSERVERS != no && kill -HUP $KILLPIDS
95    exit $RC
96fi
97
98echo "Starting lloadd on TCP/IP port $PORT1..."
99. $CONFFILTER $BACKEND < $LLOADDUNREACHABLECONF > $CONF1.lloadd
100if test $AC_lloadd = lloaddyes; then
101    $LLOADD -f $CONF1.lloadd -h $URI1 -d $LVL > $LOG1 2>&1 &
102else
103    . $CONFFILTER $BACKEND < $SLAPDLLOADCONF > $CONF1.slapd
104    $SLAPD -f $CONF1.slapd -h $URI6 -d $LVL > $LOG1 2>&1 &
105fi
106PID=$!
107if test $WAIT != 0 ; then
108    echo PID $PID
109    read foo
110fi
111KILLPIDS="$KILLPIDS $PID"
112
113echo "Testing slapd searching..."
114for i in 0 1 2 3 4 5; do
115    $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
116        '(objectclass=*)' > /dev/null 2>&1
117    RC=$?
118    if test $RC = 0 ; then
119        break
120    fi
121    echo "Waiting $SLEEP1 seconds for lloadd to start..."
122    sleep $SLEEP1
123done
124
125if test $RC != 0 ; then
126    echo "ldapsearch failed ($RC)!"
127    test $KILLSERVERS != no && kill -HUP $KILLPIDS
128    exit $RC
129fi
130
131echo "Testing exact searching..."
132echo "# Testing exact searching..." > $SEARCHOUT
133$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
134    '(sn=jENSEN)' >> $SEARCHOUT 2>&1
135RC=$?
136if test $RC != 0 ; then
137    echo "ldapsearch failed ($RC)!"
138    test $KILLSERVERS != no && kill -HUP $KILLPIDS
139    exit $RC
140fi
141
142echo "Testing approximate searching..."
143echo "# Testing approximate searching..." >> $SEARCHOUT
144$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
145    '(sn~=jENSEN)' name >> $SEARCHOUT 2>&1
146RC=$?
147if test $RC != 0 ; then
148    echo "ldapsearch failed ($RC)!"
149    test $KILLSERVERS != no && kill -HUP $KILLPIDS
150    exit $RC
151fi
152
153echo "Testing OR searching..."
154echo "# Testing OR searching..." >> $SEARCHOUT
155$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
156    '(|(givenname=Xx*yY*Z)(cn=)(undef=*)(objectclass=groupofnames)(sn=jones)(member=cn=Manager,dc=example,dc=com)(uniqueMember=cn=Manager,dc=example,dc=com))' >> $SEARCHOUT 2>&1
157RC=$?
158if test $RC != 0 ; then
159    echo "ldapsearch failed ($RC)!"
160    test $KILLSERVERS != no && kill -HUP $KILLPIDS
161    exit $RC
162fi
163
164echo "Testing AND matching and ends-with searching..."
165echo "# Testing AND matching and ends-with searching..." >> $SEARCHOUT
166$LDAPSEARCH -S "" -b "ou=groups,$BASEDN" -s one -H $URI1 \
167    '(&(objectclass=groupofnames)(cn=A*)(member=cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com))' >> $SEARCHOUT 2>&1
168RC=$?
169if test $RC != 0 ; then
170    echo "ldapsearch failed ($RC)!"
171    test $KILLSERVERS != no && kill -HUP $KILLPIDS
172    exit $RC
173fi
174
175echo "Testing NOT searching..."
176echo "# Testing NOT searching..." >> $SEARCHOUT
177$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
178    '(!(objectclass=pilotPerson))' >> $SEARCHOUT 2>&1
179RC=$?
180if test $RC != 0 ; then
181    echo "ldapsearch failed ($RC)!"
182    test $KILLSERVERS != no && kill -HUP $KILLPIDS
183    exit $RC
184fi
185
186echo "Testing objectClass/attributeType inheritance ..."
187echo "# Testing objectClass/attributeType inheritance ..." >> $SEARCHOUT
188$LDAPSEARCH -M -a never -S "" -b "$BASEDN" -H $URI1 \
189    '(&(objectClass=inetorgperson)(userid=uham))' \
190    "2.5.4.0" "userid" >> $SEARCHOUT 2>&1
191RC=$?
192if test $RC != 0 ; then
193    echo "ldapsearch failed ($RC)!"
194    test $KILLSERVERS != no && kill -HUP $KILLPIDS
195    exit $RC
196fi
197
198test $KILLSERVERS != no && kill -HUP $KILLPIDS
199
200LDIF=$SEARCHOUTPROVIDER
201
202echo "Filtering ldapsearch results..."
203$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
204echo "Filtering original ldif used to create database..."
205$LDIFFILTER < $LDIF > $LDIFFLT
206echo "Comparing filter output..."
207$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
208
209if test $? != 0 ; then
210    echo "Comparison failed"
211    exit 1
212fi
213
214echo ">>>>> Test succeeded"
215
216test $KILLSERVERS != no && wait
217
218exit 0
219