]> git.sur5r.net Git - openldap/blob - tests/scripts/relay
490c9cedc3f1fba1e47856256f3bcdaa9c7ebd79
[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 < $RWMCONF > $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
152 dn: ou=Referrals,$BASEDN
153 changetype: add
154 objectclass: referral
155 objectclass: extensibleObject
156 ou: Referrals
157 ref: ldap://localhost.localdomain/ou=Referrals,$BASEDN
158 description: Just added as ldap://localhost.localdomain:389/ou=Referrals,$BASEDN
159
160 dn: ou=Referrals,$BASEDN
161 changetype: modify
162 replace: ref
163 ref: ldap://localhost:9010/ou=Referrals,$BASEDN
164 -
165 add: description
166 description: ...and modified as ldap://localhost:9010/ou=Referrals,$BASEDN
167 -
168 EOMODS
169
170 RC=$?
171 if test $RC != 0 ; then
172         echo "Modify failed ($RC)!"
173         test $KILLSERVERS != no && kill -HUP $KILLPIDS
174         exit $RC
175 fi
176
177 BASEDN="o=Example,c=US"
178 echo "Modifying database \"$BASEDN\"..."
179 $LDAPMODIFY -v -D "cn=Manager,$BASEDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \
180         -M >> $TESTOUT 2>&1 << EOMODS
181 dn: cn=Added Group,ou=Groups,$BASEDN
182 changetype: add
183 objectClass: groupOfNames
184 objectClass: uidObject
185 cn: Added Group
186 member: cn=Added Group,ou=Groups,$BASEDN
187 uid: added
188
189 dn: cn=Another Added Group,ou=Groups,$BASEDN
190 changetype: add
191 objectClass: groupOfNames
192 cn: Another Added Group
193 member: cn=Added Group,ou=Groups,$BASEDN
194 member: cn=Another Added Group,ou=Groups,$BASEDN
195
196 dn: cn=Another Added Group,ou=Groups,$BASEDN
197 changetype: modify
198 add: objectClass
199 objectClass: uidObject
200 -
201 add: uid
202 uid: added
203 -
204
205 dn: cn=Added Group,ou=Groups,$BASEDN
206 changetype: modify
207 delete: objectClass
208 objectClass: uidObject
209 -
210 delete: uid
211 -
212 EOMODS
213
214 RC=$?
215 if test $RC != 0 ; then
216         echo "Modify failed ($RC)!"
217         test $KILLSERVERS != no && kill -HUP $KILLPIDS
218         exit $RC
219 fi
220
221 echo "Searching base=\"$BASEDN\"..."
222 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
223 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
224 RC=$?
225 if test $RC != 0 ; then
226         echo "Search failed ($RC)!"
227         test $KILLSERVERS != no && kill -HUP $KILLPIDS
228         exit $RC
229 fi
230
231 BASEDN="o=Esempio,c=IT"
232 echo "Searching base=\"$BASEDN\"..."
233 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
234 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
235 RC=$?
236 if test $RC != 0 ; then
237         echo "Search failed ($RC)!"
238         test $KILLSERVERS != no && kill -HUP $KILLPIDS
239         exit $RC
240 fi
241
242 FILTER="(objectClass=referral)"
243 echo "Searching filter=\"$FILTER\""
244 echo "  attrs=\"'*' ref\""
245 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
246 echo "#         attrs=\"'*' ref\"" >> $SEARCHOUT
247
248 BASEDN="dc=example,dc=com"
249 echo "  base=\"$BASEDN\"..."
250 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
251 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -M "$FILTER" "*" ref \
252         >> $SEARCHOUT 2>&1
253 RC=$?
254 if test $RC != 0 ; then
255         echo "Search failed ($RC)!"
256         test $KILLSERVERS != no && kill -HUP $KILLPIDS
257         exit $RC
258 fi
259
260 BASEDN="o=Example,c=US"
261 echo "  base=\"$BASEDN\"..."
262 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
263 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -M "$FILTER" "*" ref \
264         >> $SEARCHOUT 2>&1
265 RC=$?
266 if test $RC != 0 ; then
267         echo "Search failed ($RC)!"
268         test $KILLSERVERS != no && kill -HUP $KILLPIDS
269         exit $RC
270 fi
271
272 BASEDN="o=Esempio,c=IT"
273 echo "  base=\"$BASEDN\"..."
274 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
275 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -M "$FILTER" "*" ref \
276         >> $SEARCHOUT 2>&1
277 RC=$?
278 if test $RC != 0 ; then
279         echo "Search failed ($RC)!"
280         test $KILLSERVERS != no && kill -HUP $KILLPIDS
281         exit $RC
282 fi
283
284 BASEDN="o=Example,c=US"
285 FILTER="(seeAlso=cn=all staff,ou=Groups,$BASEDN)"
286 echo "Searching filter=\"$FILTER\""
287 echo "  attrs=\"seeAlso\""
288 echo "  base=\"$BASEDN\"..."
289 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
290 echo "#         attrs=\"seeAlso\"" >> $SEARCHOUT
291 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
292 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" seeAlso \
293         >> $SEARCHOUT 2>&1
294 RC=$?
295 if test $RC != 0 ; then
296         echo "Search failed ($RC)!"
297         test $KILLSERVERS != no && kill -HUP $KILLPIDS
298         exit $RC
299 fi
300
301 BASEDN="o=Example,c=US"
302 FILTER="(member=cn=Another Added Group,ou=Groups,$BASEDN)"
303 echo "Searching filter=\"$FILTER\""
304 echo "  attrs=\"member\""
305 echo "  base=\"$BASEDN\"..."
306 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
307 echo "#         attrs=\"seeAlso\"" >> $SEARCHOUT
308 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
309 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" member \
310         >> $SEARCHOUT 2>&1
311 RC=$?
312 if test $RC != 0 ; then
313         echo "Search failed ($RC)!"
314         test $KILLSERVERS != no && kill -HUP $KILLPIDS
315         exit $RC
316 fi
317
318 echo "Filtering ldapsearch results..."
319 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
320 echo "Filtering original ldif used to create database..."
321 . $LDIFFILTER < $RELAYOUT > $LDIFFLT
322 echo "Comparing filter output..."
323 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
324         
325 if test $? != 0 ; then
326         echo "comparison failed - relay search/modification didn't succeed"
327         test $KILLSERVERS != no && kill -HUP $KILLPIDS
328         exit 1
329 fi
330
331 BASEDN="o=Example,c=US"
332 echo "Changing password to database \"$BASEDN\"..."
333 $LDAPPASSWD -h $LOCALHOST -p $PORT1 -D "cn=Manager,$BASEDN" -w $PASSWD \
334         -s $PASSWD "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
335         >> $TESTOUT 2>&1
336 RC=$?
337 if test $RC != 0 ; then
338         echo "Passwd ExOp failed ($RC)!"
339         test $KILLSERVERS != no && kill -HUP $KILLPIDS
340         exit $RC
341 fi
342
343 BASEDN="o=Beispiel,c=DE"
344 echo "Binding with newly changed password to database \"$BASEDN\"..."
345 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
346         -D "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
347         -w $PASSWD >> $TESTOUT 2>&1
348 RC=$?
349 if test $RC != 0 ; then
350         echo "WhoAmI failed ($RC)!"
351         test $KILLSERVERS != no && kill -HUP $KILLPIDS
352         exit $RC
353 fi
354
355 BASEDN="o=Esempio,c=IT"
356 echo "Comparing to database \"$BASEDN\"..."
357 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 \
358         "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
359         "seeAlso:cn=All Staff,ou=Groups,$BASEDN" >> $TESTOUT 2>&1
360 RC=$?
361 if test $RC != 6 ; then
362         echo "Compare failed ($RC)!"
363         test $KILLSERVERS != no && kill -HUP $KILLPIDS
364         exit $RC
365 fi
366
367 test $KILLSERVERS != no && kill -HUP $KILLPIDS
368