Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / tests / scripts / test032-chain
blob12d4dfef45ee8ab360efee092711fe8051cf2a18
1 #! /bin/sh
2 # $OpenLDAP: pkg/ldap/tests/scripts/test032-chain,v 1.11.2.3 2008/02/11 23:26:51 kurt Exp $
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2008 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.
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>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 if test $BACKLDAP = "ldapno" ; then
20 echo "LDAP backend not available, test skipped"
21 exit 0
22 fi
24 rm -rf $TESTDIR
26 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
28 echo "Running slapadd to build slapd database..."
29 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF1 > $ADDCONF
30 . $CONFFILTER < $LDIFCHAIN1 > $SEARCHOUT
31 $SLAPADD -f $ADDCONF -l $SEARCHOUT
32 RC=$?
33 if test $RC != 0 ; then
34 echo "slapadd 1 failed ($RC)!"
35 exit $RC
38 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF2 > $ADDCONF
39 . $CONFFILTER < $LDIFCHAIN2 > $SEARCHOUT
40 $SLAPADD -f $ADDCONF -l $SEARCHOUT
41 RC=$?
42 if test $RC != 0 ; then
43 echo "slapadd 2 failed ($RC)!"
44 exit $RC
47 echo "Starting first slapd on TCP/IP port $PORT1..."
48 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF1 > $CONF1
49 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
50 PID1=$!
51 if test $WAIT != 0 ; then
52 echo PID $PID1
53 read foo
55 KILLPIDS="$PID1"
57 echo "Starting second slapd on TCP/IP port $PORT2..."
58 . $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF2 > $CONF2
59 $SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 &
60 PID2=$!
61 if test $WAIT != 0 ; then
62 echo PID $PID2
63 read foo
66 KILLPIDS="$KILLPIDS $PID2"
68 sleep 1
70 echo "Using ldapsearch to check that first slapd is running..."
71 for i in 0 1 2 3 4 5; do
72 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
73 'objectclass=*' > /dev/null 2>&1
74 RC=$?
75 if test $RC = 0 ; then
76 break
78 echo "Waiting 5 seconds for slapd to start..."
79 sleep 5
80 done
82 if test $RC != 0 ; then
83 echo "ldapsearch failed ($RC)!"
84 test $KILLSERVERS != no && kill -HUP $KILLPIDS
85 exit $RC
88 echo "Using ldapsearch to check that second slapd is running..."
89 for i in 0 1 2 3 4 5; do
90 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \
91 'objectclass=*' > /dev/null 2>&1
92 RC=$?
93 if test $RC = 0 ; then
94 break
96 echo "Waiting 5 seconds for slapd to start..."
97 sleep 5
98 done
100 if test $RC != 0 ; then
101 echo "ldapsearch failed ($RC)!"
102 test $KILLSERVERS != no && kill -HUP $KILLPIDS
103 exit $RC
106 for P in $PORT1 $PORT2 ; do
107 echo "Testing ldapsearch as anonymous for \"$BASEDN\" on port $P..."
108 $LDAPSEARCH -h $LOCALHOST -p $P -b "$BASEDN" -S "" \
109 > $SEARCHOUT 2>&1
111 RC=$?
112 if test $RC != 0 ; then
113 echo "ldapsearch failed ($RC)!"
114 test $KILLSERVERS != no && kill -HUP $KILLPIDS
115 exit $RC
118 echo "Filtering ldapsearch results..."
119 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
120 echo "Filtering original ldif used to create database..."
121 . $LDIFFILTER < $CHAINOUT > $LDIFFLT
122 echo "Comparing filter output..."
123 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
125 if test $? != 0 ; then
126 echo "comparison failed - chained search didn't succeed"
127 test $KILLSERVERS != no && kill -HUP $KILLPIDS
128 exit 1
131 echo "Reading the referral entry "ou=Other,$BASEDN" as anonymous on port $P..."
132 $LDAPSEARCH -h $LOCALHOST -p $P -b "ou=Other,$BASEDN" -S "" \
133 > $SEARCHOUT 2>&1
135 RC=$?
136 if test $RC != 0 ; then
137 echo "ldapsearch failed ($RC)!"
138 test $KILLSERVERS != no && kill -HUP $KILLPIDS
139 exit $RC
142 echo "Filtering ldapsearch results..."
143 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
144 echo "Filtering original ldif used to create database..."
145 . $LDIFFILTER < $CHAINREFOUT > $LDIFFLT
146 echo "Comparing filter output..."
147 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
149 if test $? != 0 ; then
150 echo "comparison failed - chained search didn't succeed"
151 test $KILLSERVERS != no && kill -HUP $KILLPIDS
152 exit 1
155 DN="cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN"
156 echo "Comparing \"$DN\" on port $P..."
157 $LDAPCOMPARE -h $LOCALHOST -p $P "$DN" "cn:Mark Elliot" \
158 > $TESTOUT 2>&1
160 RC=$?
161 if test $RC != 6 ; then
162 echo "ldapcompare failed ($RC)!"
163 test $KILLSERVERS != no && kill -HUP $KILLPIDS
164 exit $RC
167 DN="ou=Other,$BASEDN"
168 echo "Comparing \"$DN\" on port $P with manageDSAit control..."
169 $LDAPCOMPARE -h $LOCALHOST -p $P -M "$DN" "ou:Other" \
170 > $TESTOUT 2>&1
172 RC=$?
173 if test $RC != 6 ; then
174 echo "ldapcompare failed ($RC)!"
175 test $KILLSERVERS != no && kill -HUP $KILLPIDS
176 exit $RC
178 done
181 # Testing writes to first server
183 echo "Writing to first server with scope on second server..."
184 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \
185 $TESTOUT 2>&1 << EOMODS
186 dn: cn=New Group,ou=Groups,dc=example,dc=com
187 changetype: add
188 objectClass: groupOfNames
189 cn: New Group
190 member:
192 dn: cn=New Group,ou=Groups,dc=example,dc=com
193 changetype: modify
194 add: description
195 description: testing chain overlay writes...
197 replace: member
198 member: cn=New Group,ou=Groups,dc=example,dc=com
199 member: cn=Manager,dc=example,dc=com
201 add: owner
202 owner: cn=Manager,dc=example,dc=com
205 dn: cn=New Group,ou=Groups,dc=example,dc=com
206 changetype: modrdn
207 newrdn: cn=Renamed Group
208 deleteoldrdn: 1
210 dn: cn=All Staff,ou=Groups,dc=example,dc=com
211 changetype: delete
212 EOMODS
214 RC=$?
215 if test $RC != 0 ; then
216 echo "ldapmodify failed ($RC)!"
217 test $KILLSERVERS != no && kill -HUP $KILLPIDS
218 exit $RC
222 # Testing writes to second server
224 echo "Writing to second server with scope on first server..."
225 $LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \
226 $TESTOUT 2>&1 << EOMODS
227 dn: cn=New User,ou=People,dc=example,dc=com
228 changetype: add
229 objectClass: person
230 cn: New User
231 sn: User
232 seeAlso: cn=New Group,ou=Groups,dc=example,dc=com
234 dn: cn=New User,ou=People,dc=example,dc=com
235 changetype: modify
236 add: description
237 description: testing chain overlay writes...
239 replace: seeAlso
240 seeAlso: cn=Renamed Group,ou=Groups,dc=example,dc=com
243 dn: cn=New User,ou=People,dc=example,dc=com
244 changetype: modrdn
245 newrdn: cn=Renamed User
246 deleteoldrdn: 1
248 dn: cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com
249 changetype: delete
250 EOMODS
252 RC=$?
253 if test $RC != 0 ; then
254 echo "ldapmodify failed ($RC)!"
255 test $KILLSERVERS != no && kill -HUP $KILLPIDS
256 exit $RC
259 for P in $PORT1 $PORT2 ; do
260 echo "Testing ldapsearch as anonymous for \"$BASEDN\" on port $P..."
261 $LDAPSEARCH -h $LOCALHOST -p $P -b "$BASEDN" -S "" \
262 > $SEARCHOUT 2>&1
264 RC=$?
265 if test $RC != 0 ; then
266 echo "ldapsearch failed ($RC)!"
267 test $KILLSERVERS != no && kill -HUP $KILLPIDS
268 exit $RC
271 echo "Filtering ldapsearch results..."
272 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
273 echo "Filtering original ldif used to create database..."
274 . $LDIFFILTER < $CHAINMODOUT > $LDIFFLT
275 echo "Comparing filter output..."
276 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
278 if test $? != 0 ; then
279 echo "comparison failed - chained search didn't succeed"
280 test $KILLSERVERS != no && kill -HUP $KILLPIDS
281 exit 1
283 done
285 NEWPW=newsecret
286 echo "Using ldappasswd on second server with scope on first server..."
287 $LDAPPASSWD -h $LOCALHOST -p $PORT2 \
288 -w secret -s $NEWPW \
289 -D "$MANAGERDN" "$BJORNSDN" >> $TESTOUT 2>&1
290 RC=$?
291 if test $RC != 0 ; then
292 echo "ldappasswd failed ($RC)!"
293 test $KILLSERVERS != no && kill -HUP $KILLPIDS
294 exit $RC
297 echo "Binding with newly changed password on first server..."
298 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 \
299 -D "$BJORNSDN" -w $NEWPW
300 RC=$?
301 if test $RC != 0 ; then
302 echo "ldapwhoami failed ($RC)!"
303 test $KILLSERVERS != no && kill -HUP $KILLPIDS
304 exit $RC
307 test $KILLSERVERS != no && kill -HUP $KILLPIDS
309 echo ">>>>> Test succeeded"
311 test $KILLSERVERS != no && wait
313 exit 0