]> git.sur5r.net Git - openldap/blob - tests/scripts/test032-chain
Regenerated with new OL_ARG_ENABLE
[openldap] / tests / scripts / test032-chain
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 "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $BACKLDAP = "ldapno" ; then 
20         echo "LDAP backend not available, test skipped"
21         exit 0
22 fi 
23
24 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
25
26 echo "Running slapadd to build slapd database..."
27 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF1 > $ADDCONF
28 . $CONFFILTER < $LDIFCHAIN1 > $SEARCHOUT
29 $SLAPADD -f $ADDCONF -l $SEARCHOUT
30 RC=$?
31 if test $RC != 0 ; then
32         echo "slapadd 1 failed ($RC)!"
33         exit $RC
34 fi
35
36 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF2 > $ADDCONF
37 . $CONFFILTER < $LDIFCHAIN2 > $SEARCHOUT
38 $SLAPADD -f $ADDCONF -l $SEARCHOUT
39 RC=$?
40 if test $RC != 0 ; then
41         echo "slapadd 2 failed ($RC)!"
42         exit $RC
43 fi
44
45 echo "Starting first slapd on TCP/IP port $PORT1..."
46 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF1 > $CONF1
47 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
48 PID1=$!
49 if test $WAIT != 0 ; then
50     echo PID $PID1
51     read foo
52 fi
53
54 echo "Starting second slapd on TCP/IP port $PORT2..."
55 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF2 > $CONF2
56 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
57 PID2=$!
58 if test $WAIT != 0 ; then
59     echo PID $PID2
60     read foo
61 fi
62
63 KILLPIDS="$PID1 $PID2"
64
65 echo "Using ldapsearch to check that first slapd is running..."
66 for i in 0 1 2 3 4 5; do
67         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
68                 'objectclass=*' > /dev/null 2>&1
69         RC=$?
70         if test $RC = 0 ; then
71                 break
72         fi
73         echo "Waiting 5 seconds for slapd to start..."
74         sleep 5
75 done
76
77 echo "Using ldapsearch to check that second slapd is running..."
78 for i in 0 1 2 3 4 5; do
79         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
80                 'objectclass=*' > /dev/null 2>&1
81         RC=$?
82         if test $RC = 0 ; then
83                 break
84         fi
85         echo "Waiting 5 seconds for slapd to start..."
86         sleep 5
87 done
88
89 for P in $PORT1 $PORT2 ; do
90         echo "Testing ldapsearch as anonymous for \"$BASEDN\" on port $P..."
91         $LDAPSEARCH -h $LOCALHOST -p $P -b "$BASEDN" -S "" \
92                  > $SEARCHOUT 2>&1
93
94         RC=$?
95         if test $RC != 0 ; then
96                 echo "ldapsearch failed ($RC)!"
97                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
98                 exit $RC
99         fi
100
101         echo "Filtering ldapsearch results..."
102         . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
103         echo "Filtering original ldif used to create database..."
104         . $LDIFFILTER < $CHAINOUT > $LDIFFLT
105         echo "Comparing filter output..."
106         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
107         
108         if test $? != 0 ; then
109                 echo "comparison failed - chained search didn't succeed"
110                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
111                 exit 1
112         fi
113
114         echo "Reading the referral entry "ou=Other,$BASEDN" as anonymous on port $P..."
115         $LDAPSEARCH -h $LOCALHOST -p $P -b "ou=Other,$BASEDN" -S "" \
116                  > $SEARCHOUT 2>&1
117
118         RC=$?
119         if test $RC != 0 ; then
120                 echo "ldapsearch failed ($RC)!"
121                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
122                 exit $RC
123         fi
124
125         echo "Filtering ldapsearch results..."
126         . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
127         echo "Filtering original ldif used to create database..."
128         . $LDIFFILTER < $CHAINREFOUT > $LDIFFLT
129         echo "Comparing filter output..."
130         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
131                 
132         if test $? != 0 ; then
133                 echo "comparison failed - chained search didn't succeed"
134                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
135                 exit 1
136         fi
137
138         DN="cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN"
139         echo "Comparing \"$DN\" on port $P..."
140         $LDAPCOMPARE -h $LOCALHOST -p $P "$DN" "cn:Mark Elliot"
141                  > $TESTOUT 2>&1
142
143         RC=$?
144         if test $RC != 0 ; then
145                 echo "ldapcompare failed ($RC)!"
146                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
147                 exit $RC
148         fi
149
150         DN="ou=Other,$BASEDN"
151         echo "Comparing \"$DN\" on port $P with manageDSAit control..."
152         $LDAPCOMPARE -h $LOCALHOST -p $P -M "$DN" "ou:Other"
153                  > $TESTOUT 2>&1
154
155         RC=$?
156         if test $RC != 0 ; then
157                 echo "ldapcompare failed ($RC)!"
158                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
159                 exit $RC
160         fi
161 done
162
163 #
164 # Testing writes to first server
165 #
166 echo "Writing to first server with scope on second server..."
167 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
168         $TESTOUT 2>&1 << EOMODS
169 dn: cn=New Group,ou=Groups,dc=example,dc=com
170 changetype: add
171 objectClass: groupOfNames
172 cn: New Group
173 member:
174
175 dn: cn=New Group,ou=Groups,dc=example,dc=com
176 changetype: modify
177 add: description
178 description: testing chain overlay writes...
179 -
180 replace: member
181 member: cn=New Group,ou=Groups,dc=example,dc=com
182 member: cn=Manager,dc=example,dc=com
183 -
184 add: owner
185 owner: cn=Manager,dc=example,dc=com
186 -
187
188 dn: cn=New Group,ou=Groups,dc=example,dc=com
189 changetype: modrdn
190 newrdn: cn=Renamed Group
191 deleteoldrdn: 1
192
193 dn: cn=All Staff,ou=Groups,dc=example,dc=com
194 changetype: delete
195 EOMODS
196
197 RC=$?
198 if test $RC != 0 ; then
199         echo "ldapmodify failed ($RC)!"
200         test $KILLSERVERS != no && kill -HUP $KILLPIDS
201         exit $RC
202 fi
203
204 #
205 # Testing writes to second server
206 #
207 echo "Writing to second server with scope on first server..."
208 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
209         $TESTOUT 2>&1 << EOMODS
210 dn: cn=New User,ou=People,dc=example,dc=com
211 changetype: add
212 objectClass: person
213 cn: New User
214 sn: User
215 seeAlso: cn=New Group,ou=Groups,dc=example,dc=com
216
217 dn: cn=New User,ou=People,dc=example,dc=com
218 changetype: modify
219 add: description
220 description: testing chain overlay writes...
221 -
222 replace: seeAlso
223 seeAlso: cn=Renamed Group,ou=Groups,dc=example,dc=com
224 -
225
226 dn: cn=New User,ou=People,dc=example,dc=com
227 changetype: modrdn
228 newrdn: cn=Renamed User
229 deleteoldrdn: 1
230
231 dn: cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com
232 changetype: delete
233 EOMODS
234
235 RC=$?
236 if test $RC != 0 ; then
237         echo "ldapmodify failed ($RC)!"
238         test $KILLSERVERS != no && kill -HUP $KILLPIDS
239         exit $RC
240 fi
241
242 for P in $PORT1 $PORT2 ; do
243         echo "Testing ldapsearch as anonymous for \"$BASEDN\" on port $P..."
244         $LDAPSEARCH -h $LOCALHOST -p $P -b "$BASEDN" -S "" \
245                  > $SEARCHOUT 2>&1
246
247         RC=$?
248         if test $RC != 0 ; then
249                 echo "ldapsearch failed ($RC)!"
250                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
251                 exit $RC
252         fi
253
254         echo "Filtering ldapsearch results..."
255         . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
256         echo "Filtering original ldif used to create database..."
257         . $LDIFFILTER < $CHAINMODOUT > $LDIFFLT
258         echo "Comparing filter output..."
259         $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
260         
261         if test $? != 0 ; then
262                 echo "comparison failed - chained search didn't succeed"
263                 test $KILLSERVERS != no && kill -HUP $KILLPIDS
264                 exit 1
265         fi
266 done
267
268 NEWPW=newsecret
269 echo "Using ldappasswd on second server with scope on first server..."
270 $LDAPPASSWD -h $LOCALHOST -p $PORT2 \
271         -w secret -s $NEWPW \
272         -D "$MANAGERDN" "$BJORNSDN" >> $TESTOUT 2>&1
273 RC=$?
274 if test $RC != 0 ; then
275         echo "ldappasswd failed ($RC)!"
276         test $KILLSERVERS != no && kill -HUP $KILLPIDS
277         exit $RC
278 fi
279
280 echo "Binding with newly changed password on first server..."
281 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
282         -D "$BJORNSDN" -w $NEWPW
283 RC=$?
284 if test $RC != 0 ; then
285         echo "ldapwhoami failed ($RC)!"
286         test $KILLSERVERS != no && kill -HUP $KILLPIDS
287         exit $RC
288 fi
289
290 test $KILLSERVERS != no && kill -HUP $KILLPIDS
291
292 echo ">>>>> Test succeeded"
293 exit 0
294