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