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