]> git.sur5r.net Git - openldap/blob - tests/scripts/relay
74b282c36187de46b7ee1f4675e299b26a14353c
[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 "Testing virtual naming context mapping with $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 echo "searching base=\"$BASEDN\"..."
178 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
179 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
180 RC=$?
181 if test $RC != 0 ; then
182         echo "Search failed ($RC)!"
183         test $KILLSERVERS != no && kill -HUP $KILLPIDS
184         exit $RC
185 fi
186
187 BASEDN="o=Esempio,c=IT"
188 echo "searching base=\"$BASEDN\"..."
189 echo "# searching base=\"$BASEDN\"..." >> $SEARCHOUT
190 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" >> $SEARCHOUT 2>&1
191 RC=$?
192 if test $RC != 0 ; then
193         echo "Search failed ($RC)!"
194         test $KILLSERVERS != no && kill -HUP $KILLPIDS
195         exit $RC
196 fi
197
198 FILTER="(objectClass=referral)"
199 echo "searching filter=\"$FILTER\""
200 echo "  attrs=\"'*' ref\""
201 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
202 echo "#         attrs=\"'*' ref\"" >> $SEARCHOUT
203
204 BASEDN="dc=example,dc=com"
205 echo "  base=\"$BASEDN\"..."
206 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
207 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -M "$FILTER" "*" ref \
208         >> $SEARCHOUT 2>&1
209 RC=$?
210 if test $RC != 0 ; then
211         echo "Search failed ($RC)!"
212         test $KILLSERVERS != no && kill -HUP $KILLPIDS
213         exit $RC
214 fi
215
216 BASEDN="o=Example,c=US"
217 echo "  base=\"$BASEDN\"..."
218 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
219 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -M "$FILTER" "*" ref \
220         >> $SEARCHOUT 2>&1
221 RC=$?
222 if test $RC != 0 ; then
223         echo "Search failed ($RC)!"
224         test $KILLSERVERS != no && kill -HUP $KILLPIDS
225         exit $RC
226 fi
227
228 BASEDN="o=Esempio,c=IT"
229 echo "  base=\"$BASEDN\"..."
230 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
231 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -M "$FILTER" "*" ref \
232         >> $SEARCHOUT 2>&1
233 RC=$?
234 if test $RC != 0 ; then
235         echo "Search failed ($RC)!"
236         test $KILLSERVERS != no && kill -HUP $KILLPIDS
237         exit $RC
238 fi
239
240 BASEDN="o=Example,c=US"
241 FILTER="(seeAlso=cn=all staff,ou=Groups,$BASEDN)"
242 echo "searching filter=\"$FILTER\""
243 echo "  attrs=\"seeAlso\""
244 echo "  base=\"$BASEDN\"..."
245 echo "# searching filter=\"$FILTER\"" >> $SEARCHOUT
246 echo "#         attrs=\"seeAlso\"" >> $SEARCHOUT
247 echo "#         base=\"$BASEDN\"..." >> $SEARCHOUT
248 $LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" "$FILTER" seeAlso \
249         >> $SEARCHOUT 2>&1
250 RC=$?
251 if test $RC != 0 ; then
252         echo "Search failed ($RC)!"
253         test $KILLSERVERS != no && kill -HUP $KILLPIDS
254         exit $RC
255 fi
256
257 echo "Filtering ldapsearch results..."
258 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
259 echo "Filtering original ldif used to create database..."
260 . $LDIFFILTER < $RELAYOUT > $LDIFFLT
261 echo "Comparing filter output..."
262 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
263         
264 if test $? != 0 ; then
265         echo "comparison failed - relay search/modification didn't succeed"
266         test $KILLSERVERS != no && kill -HUP $KILLPIDS
267         exit 1
268 fi
269
270 BASEDN="o=Example,c=US"
271 echo "changing password to database \"$BASEDN\"..."
272 $LDAPPASSWD -h $LOCALHOST -p $PORT1 -D "cn=Manager,$BASEDN" -w $PASSWD \
273         -s $PASSWD "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
274         >> $TESTOUT 2>&1
275 RC=$?
276 if test $RC != 0 ; then
277         echo "Passwd ExOp failed ($RC)!"
278         test $KILLSERVERS != no && kill -HUP $KILLPIDS
279         exit $RC
280 fi
281
282 BASEDN="o=Beispiel,c=DE"
283 echo "binding with newly changed password to database \"$BASEDN\"..."
284 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
285         -D "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
286         -w $PASSWD >> $TESTOUT 2>&1
287 RC=$?
288 if test $RC != 0 ; then
289         echo "WhoAmI failed ($RC)!"
290         test $KILLSERVERS != no && kill -HUP $KILLPIDS
291         exit $RC
292 fi
293
294 BASEDN="o=Esempio,c=IT"
295 echo "comparing to database \"$BASEDN\"..."
296 $LDAPCOMPARE -h $LOCALHOST -p $PORT1 \
297         "cn=Added User,ou=Alumni Association,ou=People,$BASEDN" \
298         "seeAlso:cn=All Staff,ou=Groups,$BASEDN" >> $TESTOUT 2>&1
299 RC=$?
300 if test $RC != 6 ; then
301         echo "Compare failed ($RC)!"
302         test $KILLSERVERS != no && kill -HUP $KILLPIDS
303         exit $RC
304 fi
305
306 test $KILLSERVERS != no && kill -HUP $KILLPIDS
307