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 "Using $RELAY backend..."
17echo ""
18
19echo "Starting slapd on TCP/IP port $PORT1..."
20echo "======== Starting slapd with $RELAY backend ========" >> $LOG1
21. $CONFFILTER $BACKEND < $RELAYCONF > $CONF1
22$SLAPD -f $CONF1 -h $URI1 -d $LVL >> $LOG1 2>&1 &
23PID=$!
24if test $WAIT != 0 ; then
25    echo PID $PID
26    read foo
27fi
28KILLPIDS="$PID"
29
30sleep 1
31
32echo "Using ldapsearch to check that slapd is running..."
33for i in 0 1 2 3 4 5; do
34          $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
35                    'objectclass=*' > /dev/null 2>&1
36          RC=$?
37          if test $RC = 0 ; then
38                    break
39          fi
40          echo "Waiting 5 seconds for slapd to start..."
41          sleep 5
42done
43if test $RC != 0 ; then
44          echo "ldapsearch failed ($RC)!"
45          test $KILLSERVERS != no && kill -HUP $KILLPIDS
46          exit $RC
47fi
48
49echo "Using ldapadd to populate the database..."
50$LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD < \
51          $LDIFORDERED > $TESTOUT 2>&1
52RC=$?
53if test $RC != 0 ; then
54          echo "ldapadd failed ($RC)!"
55          test $KILLSERVERS != no && kill -HUP $KILLPIDS
56          exit $RC
57fi
58
59cat /dev/null > $SEARCHOUT
60
61BASEDN="dc=example,dc=com"
62echo "Searching base=\"$BASEDN\"..."
63echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
64$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" >> $SEARCHOUT 2>&1
65RC=$?
66if test $RC != 0 ; then
67          echo "Search failed ($RC)!"
68          test $KILLSERVERS != no && kill -HUP $KILLPIDS
69          exit $RC
70fi
71
72BASEDN="o=Example,c=US"
73echo "Searching base=\"$BASEDN\"..."
74echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
75$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" >> $SEARCHOUT 2>&1
76RC=$?
77if test $RC != 0 ; then
78          echo "Search failed ($RC)!"
79          test $KILLSERVERS != no && kill -HUP $KILLPIDS
80          exit $RC
81fi
82
83BASEDN="o=Esempio,c=IT"
84echo "Searching base=\"$BASEDN\"..."
85echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
86$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" >> $SEARCHOUT 2>&1
87RC=$?
88if test $RC != 0 ; then
89          echo "Search failed ($RC)!"
90          test $KILLSERVERS != no && kill -HUP $KILLPIDS
91          exit $RC
92fi
93
94BASEDN="o=Beispiel,c=DE"
95echo "Searching base=\"$BASEDN\"..."
96echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
97$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" >> $SEARCHOUT 2>&1
98RC=$?
99if test $RC != 0 ; then
100          echo "Search failed ($RC)!"
101          test $KILLSERVERS != no && kill -HUP $KILLPIDS
102          exit $RC
103fi
104
105#
106# Do some modifications
107#
108
109BASEDN="o=Beispiel,c=DE"
110echo "Modifying database \"$BASEDN\"..."
111$LDAPMODIFY -v -D "cn=Manager,$BASEDN" -H $URI1 -w $PASSWD \
112          -M >> $TESTOUT 2>&1 << EOMODS
113dn: cn=Added User,ou=Alumni Association,ou=People,$BASEDN
114changetype: add
115objectClass: OpenLDAPperson
116cn: Added User
117sn: User
118uid: auser
119seealso: cn=All Staff,ou=Groups,$BASEDN
120homephone: +49 1234567890
121drink: Beer
122mail: auser@mail.alumni.example.com
123telephonenumber: +49 1234-567-890
124description: Just added in o=Beispiel,c=DE naming context
125
126dn: cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN
127changetype: modify
128add: seeAlso
129seeAlso: cn=Ursula Hampster,ou=Alumni Association,ou=People,$BASEDN
130-
131add: description
132description: Just added self to seeAlso in $BASEDN virtual naming context
133-
134
135dn: cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN
136changetype: delete
137
138dn: cn=John Doe,ou=Information Technology Division,ou=People,$BASEDN
139changetype: modrdn
140newrdn: cn=John P. Doe
141deleteoldrdn: 1
142
143dn: cn=Jane Doe,ou=Alumni Association,ou=People,$BASEDN
144changetype: modrdn
145newrdn: cn=Jane Q. Doe
146deleteoldrdn: 1
147newsuperior: ou=Information Technology Division,ou=People,$BASEDN
148
149dn: cn=Jane Q. Doe,ou=Information Technology Division,ou=People,$BASEDN
150changetype: modify
151add: cn
152cn: Jane Qissapaolo Doe
153-
154# This operation (delete of DN-valued attribute) triggered ITS#3498
155delete: seeAlso
156-
157
158dn: cn=Jane Q. Doe,ou=Information Technology Division,ou=People,$BASEDN
159changetype: modify
160add: seeAlso
161seeAlso: cn=All Staff,ou=Groups,$BASEDN
162-
163
164dn: ou=Referrals,$BASEDN
165changetype: add
166objectclass: referral
167objectclass: extensibleObject
168ou: Referrals
169ref: ldap://localhost.localdomain/ou=Referrals,$BASEDN
170description: Just added as ldap://localhost.localdomain:389/ou=Referrals,$BASEDN
171
172dn: ou=Referrals,$BASEDN
173changetype: modify
174replace: ref
175ref: ldap://localhost:9012/ou=Referrals,$BASEDN
176-
177add: description
178description: ...and modified as ldap://localhost:9012/ou=Referrals,$BASEDN
179-
180EOMODS
181
182RC=$?
183if test $RC != 0 ; then
184          echo "Modify failed ($RC)!"
185          test $KILLSERVERS != no && kill -HUP $KILLPIDS
186          exit $RC
187fi
188
189BASEDN="o=Example,c=US"
190echo "Modifying database \"$BASEDN\"..."
191$LDAPMODIFY -v -D "cn=Manager,$BASEDN" -H $URI1 -w $PASSWD \
192          -M >> $TESTOUT 2>&1 << EOMODS
193# These operations (updates with objectClass mapping) triggered ITS#3499
194dn: cn=Added Group,ou=Groups,$BASEDN
195changetype: add
196objectClass: groupOfNames
197objectClass: uidObject
198cn: Added Group
199member: cn=Added Group,ou=Groups,$BASEDN
200uid: added
201
202dn: cn=Another Added Group,ou=Groups,$BASEDN
203changetype: add
204objectClass: groupOfNames
205cn: Another Added Group
206member: cn=Added Group,ou=Groups,$BASEDN
207member: cn=Another Added Group,ou=Groups,$BASEDN
208
209dn: cn=Another Added Group,ou=Groups,$BASEDN
210changetype: modify
211add: objectClass
212objectClass: uidObject
213-
214add: uid
215uid: added
216-
217
218dn: cn=Added Group,ou=Groups,$BASEDN
219changetype: modify
220delete: objectClass
221objectClass: uidObject
222-
223delete: uid
224-
225EOMODS
226
227RC=$?
228if test $RC != 0 ; then
229          echo "Modify failed ($RC)!"
230          test $KILLSERVERS != no && kill -HUP $KILLPIDS
231          exit $RC
232fi
233
234echo "Searching base=\"$BASEDN\"..."
235echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
236$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" >> $SEARCHOUT 2>&1
237RC=$?
238if test $RC != 0 ; then
239          echo "Search failed ($RC)!"
240          test $KILLSERVERS != no && kill -HUP $KILLPIDS
241          exit $RC
242fi
243
244BASEDN="o=Esempio,c=IT"
245echo "Searching base=\"$BASEDN\"..."
246echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
247$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" >> $SEARCHOUT 2>&1
248RC=$?
249if test $RC != 0 ; then
250          echo "Search failed ($RC)!"
251          test $KILLSERVERS != no && kill -HUP $KILLPIDS
252          exit $RC
253fi
254
255FILTER="(objectClass=referral)"
256echo "Searching filter=\"$FILTER\""
257echo "    attrs=\"'*' ref\""
258echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
259echo "#   attrs=\"'*' ref\"" >> $SEARCHOUT
260
261BASEDN="dc=example,dc=com"
262echo "    base=\"$BASEDN\"..."
263echo "#   base=\"$BASEDN\"..." >> $SEARCHOUT
264$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" -M "$FILTER" '*' ref \
265          >> $SEARCHOUT 2>&1
266RC=$?
267if test $RC != 0 ; then
268          echo "Search failed ($RC)!"
269          test $KILLSERVERS != no && kill -HUP $KILLPIDS
270          exit $RC
271fi
272
273BASEDN="o=Example,c=US"
274echo "    base=\"$BASEDN\"..."
275echo "#   base=\"$BASEDN\"..." >> $SEARCHOUT
276$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" -M "$FILTER" '*' ref \
277          >> $SEARCHOUT 2>&1
278RC=$?
279if test $RC != 0 ; then
280          echo "Search failed ($RC)!"
281          test $KILLSERVERS != no && kill -HUP $KILLPIDS
282          exit $RC
283fi
284
285BASEDN="o=Esempio,c=IT"
286echo "    base=\"$BASEDN\"..."
287echo "#   base=\"$BASEDN\"..." >> $SEARCHOUT
288$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" -M "$FILTER" '*' ref \
289          >> $SEARCHOUT 2>&1
290RC=$?
291if test $RC != 0 ; then
292          echo "Search failed ($RC)!"
293          test $KILLSERVERS != no && kill -HUP $KILLPIDS
294          exit $RC
295fi
296
297BASEDN="o=Example,c=US"
298FILTER="(seeAlso=cn=all staff,ou=Groups,$BASEDN)"
299echo "Searching filter=\"$FILTER\""
300echo "    attrs=\"seeAlso\""
301echo "    base=\"$BASEDN\"..."
302echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
303echo "#   attrs=\"seeAlso\"" >> $SEARCHOUT
304echo "#   base=\"$BASEDN\"..." >> $SEARCHOUT
305$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" "$FILTER" seeAlso \
306          >> $SEARCHOUT 2>&1
307RC=$?
308if test $RC != 0 ; then
309          echo "Search failed ($RC)!"
310          test $KILLSERVERS != no && kill -HUP $KILLPIDS
311          exit $RC
312fi
313
314FILTER="(uid=example)"
315echo "Searching filter=\"$FILTER\""
316echo "    attrs=\"uid\""
317echo "    base=\"$BASEDN\"..."
318echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
319echo "#   attrs=\"uid\"" >> $SEARCHOUT
320echo "#   base=\"$BASEDN\"..." >> $SEARCHOUT
321$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" "$FILTER" uid \
322          >> $SEARCHOUT 2>&1
323RC=$?
324if test $RC != 0 ; then
325          echo "Search failed ($RC)!"
326          test $KILLSERVERS != no && kill -HUP $KILLPIDS
327          exit $RC
328fi
329
330FILTER="(member=cn=Another Added Group,ou=Groups,$BASEDN)"
331echo "Searching filter=\"$FILTER\""
332echo "    attrs=\"member\""
333echo "    base=\"$BASEDN\"..."
334echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
335echo "#   attrs=\"member\"" >> $SEARCHOUT
336echo "#   base=\"$BASEDN\"..." >> $SEARCHOUT
337$LDAPSEARCH -S '' -H $URI1 -b "$BASEDN" "$FILTER" member \
338          >> $SEARCHOUT 2>&1
339RC=$?
340if test $RC != 0 ; then
341          echo "Search failed ($RC)!"
342          test $KILLSERVERS != no && kill -HUP $KILLPIDS
343          exit $RC
344fi
345
346echo "Filtering ldapsearch results..."
347$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
348echo "Filtering original ldif used to create database..."
349$LDIFFILTER < $RELAYOUT > $LDIFFLT
350echo "Comparing filter output..."
351$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
352
353if test $? != 0 ; then
354          echo "comparison failed - relay search/modification didn't succeed"
355          test $KILLSERVERS != no && kill -HUP $KILLPIDS
356          exit 1
357fi
358
359BASEDN="o=Example,c=US"
360echo "Changing password to database \"$BASEDN\"..."
361$LDAPPASSWD -H $URI1 -D "cn=Manager,$BASEDN" -w $PASSWD \
362          -s $PASSWD "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
363          >> $TESTOUT 2>&1
364RC=$?
365if test $RC != 0 ; then
366          echo "Passwd ExOp failed ($RC)!"
367          test $KILLSERVERS != no && kill -HUP $KILLPIDS
368          exit $RC
369fi
370
371BASEDN="o=Beispiel,c=DE"
372echo "Binding with newly changed password to database \"$BASEDN\"..."
373$LDAPWHOAMI -H $URI1 \
374          -D "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
375          -w $PASSWD >> $TESTOUT 2>&1
376RC=$?
377if test $RC != 0 ; then
378          echo "WhoAmI failed ($RC)!"
379          test $KILLSERVERS != no && kill -HUP $KILLPIDS
380          exit $RC
381fi
382
383BASEDN="o=Esempio,c=IT"
384echo "Comparing to database \"$BASEDN\"..."
385$LDAPCOMPARE -H $URI1 \
386          "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
387          "seeAlso:cn=All Staff,ou=Groups,$BASEDN" >> $TESTOUT 2>&1
388RC=$?
389if test $RC != 6 && test $RC,$BACKEND != 5,null ; then
390          echo "Compare failed ($RC)!"
391          test $KILLSERVERS != no && kill -HUP $KILLPIDS
392          exit 1
393fi
394
395test $KILLSERVERS != no && kill -HUP $KILLPIDS
396