xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test076-authid-rewrite (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1*e670fd5cSchristos#! /bin/sh
2*e670fd5cSchristos# $OpenLDAP$
3*e670fd5cSchristos## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4*e670fd5cSchristos##
5*e670fd5cSchristos## Copyright 1998-2021 The OpenLDAP Foundation.
6*e670fd5cSchristos## All rights reserved.
7*e670fd5cSchristos##
8*e670fd5cSchristos## Redistribution and use in source and binary forms, with or without
9*e670fd5cSchristos## modification, are permitted only as authorized by the OpenLDAP
10*e670fd5cSchristos## Public License.
11*e670fd5cSchristos##
12*e670fd5cSchristos## A copy of this license is available in the file LICENSE in the
13*e670fd5cSchristos## top-level directory of the distribution or, alternatively, at
14*e670fd5cSchristos## <http://www.OpenLDAP.org/license.html>.
15*e670fd5cSchristos
16*e670fd5cSchristosecho "running defines.sh"
17*e670fd5cSchristos. $SRCDIR/scripts/defines.sh
18*e670fd5cSchristos
19*e670fd5cSchristosif test $WITH_SASL = no; then
20*e670fd5cSchristos	echo "SASL authentication not available, test skipped"
21*e670fd5cSchristos	exit 0
22*e670fd5cSchristosfi
23*e670fd5cSchristos
24*e670fd5cSchristosCONFDIR=$TESTDIR/slapd.d
25*e670fd5cSchristosMECH=DIGEST-MD5
26*e670fd5cSchristos
27*e670fd5cSchristosmkdir -p $TESTDIR $CONFDIR $DBDIR1
28*e670fd5cSchristos
29*e670fd5cSchristos$SLAPPASSWD -g -n >$CONFIGPWF
30*e670fd5cSchristos
31*e670fd5cSchristosecho "Starting slapd on TCP/IP port $PORT1... $PWD"
32*e670fd5cSchristos. $CONFFILTER $BACKEND < $DYNAMICCONF > $CONFLDIF
33*e670fd5cSchristos$SLAPADD -F $CONFDIR -n 0 -l $CONFLDIF
34*e670fd5cSchristoscd $TESTDIR
35*e670fd5cSchristos$SLAPD -F ./slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 &
36*e670fd5cSchristosPID=$!
37*e670fd5cSchristosif test $WAIT != 0 ; then
38*e670fd5cSchristos    echo PID $PID
39*e670fd5cSchristos    read foo
40*e670fd5cSchristosfi
41*e670fd5cSchristosKILLPIDS="$PID"
42*e670fd5cSchristoscd $TESTWD
43*e670fd5cSchristos
44*e670fd5cSchristossleep 1
45*e670fd5cSchristos
46*e670fd5cSchristosecho "Using ldapsearch to check that slapd is running..."
47*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
48*e670fd5cSchristos	$LDAPSEARCH -s base -b "" -H $URI1 \
49*e670fd5cSchristos		'objectclass=*' > /dev/null 2>&1
50*e670fd5cSchristos	RC=$?
51*e670fd5cSchristos	if test $RC = 0 ; then
52*e670fd5cSchristos		break
53*e670fd5cSchristos	fi
54*e670fd5cSchristos	echo "Waiting 5 seconds for slapd to start..."
55*e670fd5cSchristos	sleep 5
56*e670fd5cSchristosdone
57*e670fd5cSchristos
58*e670fd5cSchristosif test $RC != 0 ; then
59*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
60*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
61*e670fd5cSchristos	exit $RC
62*e670fd5cSchristosfi
63*e670fd5cSchristos
64*e670fd5cSchristosecho "Checking whether $MECH is supported..."
65*e670fd5cSchristos$LDAPSEARCH -s base -b "" -H $URI1 \
66*e670fd5cSchristos	'objectClass=*' supportedSASLMechanisms > $SEARCHOUT 2>&1
67*e670fd5cSchristosRC=$?
68*e670fd5cSchristosif test $RC != 0 ; then
69*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
70*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
71*e670fd5cSchristos	exit $RC
72*e670fd5cSchristosfi
73*e670fd5cSchristos
74*e670fd5cSchristosgrep "supportedSASLMechanisms: $MECH" $SEARCHOUT > $TESTOUT
75*e670fd5cSchristosRC=$?
76*e670fd5cSchristosif test $RC != 0 ; then
77*e670fd5cSchristos	echo "SASL mechanism $MECH is not available, test skipped"
78*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
79*e670fd5cSchristos	exit 0
80*e670fd5cSchristosfi
81*e670fd5cSchristos
82*e670fd5cSchristosecho "Adding schema and database..."
83*e670fd5cSchristos$LDAPADD -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
84*e670fd5cSchristosinclude: file://$ABS_SCHEMADIR/core.ldif
85*e670fd5cSchristos
86*e670fd5cSchristosinclude: file://$ABS_SCHEMADIR/cosine.ldif
87*e670fd5cSchristos
88*e670fd5cSchristosinclude: file://$ABS_SCHEMADIR/inetorgperson.ldif
89*e670fd5cSchristos
90*e670fd5cSchristosinclude: file://$ABS_SCHEMADIR/openldap.ldif
91*e670fd5cSchristos
92*e670fd5cSchristosinclude: file://$ABS_SCHEMADIR/nis.ldif
93*e670fd5cSchristosEOF
94*e670fd5cSchristosRC=$?
95*e670fd5cSchristosif test $RC != 0 ; then
96*e670fd5cSchristos	echo "ldapadd failed for schema config ($RC)!"
97*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
98*e670fd5cSchristos	exit $RC
99*e670fd5cSchristosfi
100*e670fd5cSchristos
101*e670fd5cSchristosif [ "$BACKENDTYPE" = mod ]; then
102*e670fd5cSchristos	$LDAPADD -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
103*e670fd5cSchristosdn: cn=module,cn=config
104*e670fd5cSchristosobjectClass: olcModuleList
105*e670fd5cSchristoscn: module
106*e670fd5cSchristosolcModulePath: $TESTWD/../servers/slapd/back-$BACKEND
107*e670fd5cSchristosolcModuleLoad: back_$BACKEND.la
108*e670fd5cSchristosEOF
109*e670fd5cSchristos	RC=$?
110*e670fd5cSchristos	if test $RC != 0 ; then
111*e670fd5cSchristos		echo "ldapadd failed for backend config ($RC)!"
112*e670fd5cSchristos		test $KILLSERVERS != no && kill -HUP $KILLPIDS
113*e670fd5cSchristos		exit $RC
114*e670fd5cSchristos	fi
115*e670fd5cSchristosfi
116*e670fd5cSchristos
117*e670fd5cSchristos$LDAPADD -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
118*e670fd5cSchristosdn: olcDatabase={1}$BACKEND,cn=config
119*e670fd5cSchristosobjectClass: olcDatabaseConfig
120*e670fd5cSchristosobjectClass: olc${BACKEND}Config
121*e670fd5cSchristosolcDatabase: {1}$BACKEND
122*e670fd5cSchristosolcSuffix: $BASEDN
123*e670fd5cSchristosolcDbDirectory: $DBDIR1
124*e670fd5cSchristosolcRootDN: $MANAGERDN
125*e670fd5cSchristosolcRootPW: $PASSWD
126*e670fd5cSchristosEOF
127*e670fd5cSchristosRC=$?
128*e670fd5cSchristosif test $RC != 0 ; then
129*e670fd5cSchristos	echo "ldapadd failed for database config ($RC)!"
130*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
131*e670fd5cSchristos	exit $RC
132*e670fd5cSchristosfi
133*e670fd5cSchristos
134*e670fd5cSchristosif test $INDEXDB = indexdb ; then
135*e670fd5cSchristos	$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
136*e670fd5cSchristosdn: olcDatabase={1}$BACKEND,cn=config
137*e670fd5cSchristoschangetype: modify
138*e670fd5cSchristosadd: olcDbIndex
139*e670fd5cSchristosolcDbIndex: objectClass,entryUUID,entryCSN eq
140*e670fd5cSchristosolcDbIndex: cn,uid pres,eq,sub
141*e670fd5cSchristosEOF
142*e670fd5cSchristos	RC=$?
143*e670fd5cSchristos	if test $RC != 0 ; then
144*e670fd5cSchristos		echo "ldapmodify failed for index config ($RC)!"
145*e670fd5cSchristos		test $KILLSERVERS != no && kill -HUP $KILLPIDS
146*e670fd5cSchristos		exit $RC
147*e670fd5cSchristos	fi
148*e670fd5cSchristosfi
149*e670fd5cSchristos
150*e670fd5cSchristosecho "Using ldapadd to populate the database..."
151*e670fd5cSchristos$LDAPADD -H $URI1 -D "$MANAGERDN" -w $PASSWD < $LDIFORDERED >>$TESTOUT 2>&1
152*e670fd5cSchristosRC=$?
153*e670fd5cSchristosif test $RC != 0 ; then
154*e670fd5cSchristos	echo "ldapadd failed ($RC)!"
155*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
156*e670fd5cSchristos	exit $RC
157*e670fd5cSchristosfi
158*e670fd5cSchristos
159*e670fd5cSchristosecho
160*e670fd5cSchristos
161*e670fd5cSchristosecho "Adding olcAuthzRegexp rule for static mapping..."
162*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
163*e670fd5cSchristosdn: cn=config
164*e670fd5cSchristoschangetype: modify
165*e670fd5cSchristosadd: olcAuthzRegexp
166*e670fd5cSchristosolcAuthzRegexp: uid=manager,cn=[^,]+,cn=auth $MANAGERDN
167*e670fd5cSchristosEOF
168*e670fd5cSchristosRC=$?
169*e670fd5cSchristosif test $RC != 0; then
170*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
171*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
172*e670fd5cSchristos	exit $RC
173*e670fd5cSchristosfi
174*e670fd5cSchristos
175*e670fd5cSchristosID=Manager
176*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
177*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $PASSWD
178*e670fd5cSchristosRC=$?
179*e670fd5cSchristosif test $RC != 0; then
180*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
181*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
182*e670fd5cSchristos	exit $RC
183*e670fd5cSchristosfi
184*e670fd5cSchristos
185*e670fd5cSchristosecho
186*e670fd5cSchristos
187*e670fd5cSchristosecho "Adding olcAuthzRegexp rule to search by uid..."
188*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
189*e670fd5cSchristosdn: cn=config
190*e670fd5cSchristoschangetype: modify
191*e670fd5cSchristosadd: olcAuthzRegexp
192*e670fd5cSchristosolcAuthzRegexp: uid=([^,]+),cn=[^,]+,cn=auth ldap:///$BASEDN??sub?(uid=\$1)
193*e670fd5cSchristosEOF
194*e670fd5cSchristosRC=$?
195*e670fd5cSchristosif test $RC != 0; then
196*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
197*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
198*e670fd5cSchristos	exit $RC
199*e670fd5cSchristosfi
200*e670fd5cSchristos
201*e670fd5cSchristosID=Manager
202*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
203*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $PASSWD
204*e670fd5cSchristosRC=$?
205*e670fd5cSchristosif test $RC != 0; then
206*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
207*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
208*e670fd5cSchristos	exit $RC
209*e670fd5cSchristosfi
210*e670fd5cSchristos
211*e670fd5cSchristosID=bjensen
212*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
213*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $ID
214*e670fd5cSchristosRC=$?
215*e670fd5cSchristosif test $RC != 0; then
216*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
217*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
218*e670fd5cSchristos	exit $RC
219*e670fd5cSchristosfi
220*e670fd5cSchristos
221*e670fd5cSchristosecho
222*e670fd5cSchristos
223*e670fd5cSchristosecho "Inserting olcAuthzRegexp rule before the last..."
224*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
225*e670fd5cSchristosdn: cn=config
226*e670fd5cSchristoschangetype: modify
227*e670fd5cSchristosadd: olcAuthzRegexp
228*e670fd5cSchristosolcAuthzRegexp: {1}uid=babs,cn=[^,]+,cn=auth ldap:///$BASEDN??sub?(uid=bjensen)
229*e670fd5cSchristosEOF
230*e670fd5cSchristosRC=$?
231*e670fd5cSchristosif test $RC != 0; then
232*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
233*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
234*e670fd5cSchristos	exit $RC
235*e670fd5cSchristosfi
236*e670fd5cSchristos
237*e670fd5cSchristosID=Manager
238*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
239*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $PASSWD
240*e670fd5cSchristosRC=$?
241*e670fd5cSchristosif test $RC != 0; then
242*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
243*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
244*e670fd5cSchristos	exit $RC
245*e670fd5cSchristosfi
246*e670fd5cSchristos
247*e670fd5cSchristosID=babs
248*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
249*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w bjensen
250*e670fd5cSchristosRC=$?
251*e670fd5cSchristosif test $RC != 0; then
252*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
253*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
254*e670fd5cSchristos	exit $RC
255*e670fd5cSchristosfi
256*e670fd5cSchristos
257*e670fd5cSchristosID=bjensen
258*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
259*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $ID
260*e670fd5cSchristosRC=$?
261*e670fd5cSchristosif test $RC != 0; then
262*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
263*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
264*e670fd5cSchristos	exit $RC
265*e670fd5cSchristosfi
266*e670fd5cSchristos
267*e670fd5cSchristosecho
268*e670fd5cSchristos
269*e670fd5cSchristosecho "Deleting the first olcAuthzRegexp rule..."
270*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
271*e670fd5cSchristosdn: cn=config
272*e670fd5cSchristoschangetype: modify
273*e670fd5cSchristosdelete: olcAuthzRegexp
274*e670fd5cSchristosolcAuthzRegexp: {0}
275*e670fd5cSchristosEOF
276*e670fd5cSchristosRC=$?
277*e670fd5cSchristosif test $RC != 0; then
278*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
279*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
280*e670fd5cSchristos	exit $RC
281*e670fd5cSchristosfi
282*e670fd5cSchristos
283*e670fd5cSchristosID=Manager
284*e670fd5cSchristosecho "Testing ldapwhoami as $ID (should fail)..."
285*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $PASSWD
286*e670fd5cSchristosRC=$?
287*e670fd5cSchristosif test $RC != 49; then
288*e670fd5cSchristos	echo "ldapwhoami unexpected result ($RC)!"
289*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
290*e670fd5cSchristos	exit $RC
291*e670fd5cSchristosfi
292*e670fd5cSchristos
293*e670fd5cSchristosID=babs
294*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
295*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w bjensen
296*e670fd5cSchristosRC=$?
297*e670fd5cSchristosif test $RC != 0; then
298*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
299*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
300*e670fd5cSchristos	exit $RC
301*e670fd5cSchristosfi
302*e670fd5cSchristos
303*e670fd5cSchristosID=bjensen
304*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
305*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $ID
306*e670fd5cSchristosRC=$?
307*e670fd5cSchristosif test $RC != 0; then
308*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
309*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
310*e670fd5cSchristos	exit $RC
311*e670fd5cSchristosfi
312*e670fd5cSchristos
313*e670fd5cSchristosecho
314*e670fd5cSchristos
315*e670fd5cSchristosecho "Updating an olcAuthzRegexp rule in place..."
316*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
317*e670fd5cSchristosdn: cn=config
318*e670fd5cSchristoschangetype: modify
319*e670fd5cSchristosdelete: olcAuthzRegexp
320*e670fd5cSchristosolcAuthzRegexp: {0}
321*e670fd5cSchristos-
322*e670fd5cSchristosadd: olcAuthzRegexp
323*e670fd5cSchristosolcAuthzRegexp: {0}uid=biff,cn=[^,]+,cn=auth ldap:///$BASEDN??sub?(uid=bjorn)
324*e670fd5cSchristosEOF
325*e670fd5cSchristosRC=$?
326*e670fd5cSchristosif test $RC != 0; then
327*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
328*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
329*e670fd5cSchristos	exit $RC
330*e670fd5cSchristosfi
331*e670fd5cSchristos
332*e670fd5cSchristosID=babs
333*e670fd5cSchristosecho "Testing ldapwhoami as $ID (should fail)..."
334*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w bjensen
335*e670fd5cSchristosRC=$?
336*e670fd5cSchristosif test $RC != 49; then
337*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
338*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
339*e670fd5cSchristos	exit $RC
340*e670fd5cSchristosfi
341*e670fd5cSchristos
342*e670fd5cSchristosID=biff
343*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
344*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w bjorn
345*e670fd5cSchristosRC=$?
346*e670fd5cSchristosif test $RC != 0; then
347*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
348*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
349*e670fd5cSchristos	exit $RC
350*e670fd5cSchristosfi
351*e670fd5cSchristos
352*e670fd5cSchristosID=bjensen
353*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
354*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $ID
355*e670fd5cSchristosRC=$?
356*e670fd5cSchristosif test $RC != 0; then
357*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
358*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
359*e670fd5cSchristos	exit $RC
360*e670fd5cSchristosfi
361*e670fd5cSchristos
362*e670fd5cSchristosecho
363*e670fd5cSchristos
364*e670fd5cSchristosecho "Deleting all olcAuthzRegexp rules..."
365*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
366*e670fd5cSchristosdn: cn=config
367*e670fd5cSchristoschangetype: modify
368*e670fd5cSchristosdelete: olcAuthzRegexp
369*e670fd5cSchristosEOF
370*e670fd5cSchristosRC=$?
371*e670fd5cSchristosif test $RC != 0; then
372*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
373*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
374*e670fd5cSchristos	exit $RC
375*e670fd5cSchristosfi
376*e670fd5cSchristos
377*e670fd5cSchristosID=bjensen
378*e670fd5cSchristosecho "Testing ldapwhoami as $ID (should fail)..."
379*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $ID
380*e670fd5cSchristosRC=$?
381*e670fd5cSchristosif test $RC != 49; then
382*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
383*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
384*e670fd5cSchristos	exit $RC
385*e670fd5cSchristosfi
386*e670fd5cSchristos
387*e670fd5cSchristosecho
388*e670fd5cSchristos
389*e670fd5cSchristosecho "Initializing olcAuthIDRewrite engine..."
390*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
391*e670fd5cSchristosdn: cn=config
392*e670fd5cSchristoschangetype: modify
393*e670fd5cSchristosadd: olcAuthIDRewrite
394*e670fd5cSchristosolcAuthIDRewrite: rewriteEngine ON
395*e670fd5cSchristosolcAuthIDRewrite: rewriteContext authid
396*e670fd5cSchristosEOF
397*e670fd5cSchristosRC=$?
398*e670fd5cSchristosif test $RC != 0; then
399*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
400*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
401*e670fd5cSchristos	exit $RC
402*e670fd5cSchristosfi
403*e670fd5cSchristos
404*e670fd5cSchristosecho
405*e670fd5cSchristos
406*e670fd5cSchristosecho "Adding olcAuthIDRewrite rule for static mapping..."
407*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
408*e670fd5cSchristosdn: cn=config
409*e670fd5cSchristoschangetype: modify
410*e670fd5cSchristosadd: olcAuthIDRewrite
411*e670fd5cSchristosolcAuthIDRewrite: rewriteRule uid=manager,cn=[^,]+,cn=auth $MANAGERDN :
412*e670fd5cSchristosEOF
413*e670fd5cSchristosRC=$?
414*e670fd5cSchristosif test $RC != 0; then
415*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
416*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
417*e670fd5cSchristos	exit $RC
418*e670fd5cSchristosfi
419*e670fd5cSchristos
420*e670fd5cSchristosID=Manager
421*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
422*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $PASSWD
423*e670fd5cSchristosRC=$?
424*e670fd5cSchristosif test $RC != 0; then
425*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
426*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
427*e670fd5cSchristos	exit $RC
428*e670fd5cSchristosfi
429*e670fd5cSchristos
430*e670fd5cSchristosecho
431*e670fd5cSchristos
432*e670fd5cSchristosecho "Adding olcAuthIDRewrite rule to search by uid..."
433*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
434*e670fd5cSchristosdn: cn=config
435*e670fd5cSchristoschangetype: modify
436*e670fd5cSchristosadd: olcAuthIDRewrite
437*e670fd5cSchristosolcAuthIDRewrite: rewriteRule uid=([^,]+),cn=[^,]+,cn=auth ldap:///$BASEDN??sub?(uid=\$1) :
438*e670fd5cSchristosEOF
439*e670fd5cSchristosRC=$?
440*e670fd5cSchristosif test $RC != 0; then
441*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
442*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
443*e670fd5cSchristos	exit $RC
444*e670fd5cSchristosfi
445*e670fd5cSchristos
446*e670fd5cSchristosID=Manager
447*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
448*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $PASSWD
449*e670fd5cSchristosRC=$?
450*e670fd5cSchristosif test $RC != 0; then
451*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
452*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
453*e670fd5cSchristos	exit $RC
454*e670fd5cSchristosfi
455*e670fd5cSchristos
456*e670fd5cSchristosID=bjensen
457*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
458*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $ID
459*e670fd5cSchristosRC=$?
460*e670fd5cSchristosif test $RC != 0; then
461*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
462*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
463*e670fd5cSchristos	exit $RC
464*e670fd5cSchristosfi
465*e670fd5cSchristos
466*e670fd5cSchristosecho
467*e670fd5cSchristos
468*e670fd5cSchristosecho "Inserting olcAuthIDRewrite rule before the last..."
469*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
470*e670fd5cSchristosdn: cn=config
471*e670fd5cSchristoschangetype: modify
472*e670fd5cSchristosadd: olcAuthIDRewrite
473*e670fd5cSchristosolcAuthIDRewrite: {3}rewriteRule uid=babs,cn=[^,]+,cn=auth ldap:///$BASEDN??sub?(uid=bjensen) :
474*e670fd5cSchristosEOF
475*e670fd5cSchristosRC=$?
476*e670fd5cSchristosif test $RC != 0; then
477*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
478*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
479*e670fd5cSchristos	exit $RC
480*e670fd5cSchristosfi
481*e670fd5cSchristos
482*e670fd5cSchristosID=Manager
483*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
484*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $PASSWD
485*e670fd5cSchristosRC=$?
486*e670fd5cSchristosif test $RC != 0; then
487*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
488*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
489*e670fd5cSchristos	exit $RC
490*e670fd5cSchristosfi
491*e670fd5cSchristos
492*e670fd5cSchristosID=babs
493*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
494*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w bjensen
495*e670fd5cSchristosRC=$?
496*e670fd5cSchristosif test $RC != 0; then
497*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
498*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
499*e670fd5cSchristos	exit $RC
500*e670fd5cSchristosfi
501*e670fd5cSchristos
502*e670fd5cSchristosID=bjensen
503*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
504*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $ID
505*e670fd5cSchristosRC=$?
506*e670fd5cSchristosif test $RC != 0; then
507*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
508*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
509*e670fd5cSchristos	exit $RC
510*e670fd5cSchristosfi
511*e670fd5cSchristos
512*e670fd5cSchristosecho
513*e670fd5cSchristos
514*e670fd5cSchristosecho "Deleting the first olcAuthIDRewrite rule..."
515*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
516*e670fd5cSchristosdn: cn=config
517*e670fd5cSchristoschangetype: modify
518*e670fd5cSchristosdelete: olcAuthIDRewrite
519*e670fd5cSchristosolcAuthIDRewrite: {2}
520*e670fd5cSchristosEOF
521*e670fd5cSchristosRC=$?
522*e670fd5cSchristosif test $RC != 0; then
523*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
524*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
525*e670fd5cSchristos	exit $RC
526*e670fd5cSchristosfi
527*e670fd5cSchristos
528*e670fd5cSchristosID=Manager
529*e670fd5cSchristosecho "Testing ldapwhoami as $ID (should fail)..."
530*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $PASSWD
531*e670fd5cSchristosRC=$?
532*e670fd5cSchristosif test $RC != 49; then
533*e670fd5cSchristos	echo "ldapwhoami unexpected result ($RC)!"
534*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
535*e670fd5cSchristos	exit $RC
536*e670fd5cSchristosfi
537*e670fd5cSchristos
538*e670fd5cSchristosID=babs
539*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
540*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w bjensen
541*e670fd5cSchristosRC=$?
542*e670fd5cSchristosif test $RC != 0; then
543*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
544*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
545*e670fd5cSchristos	exit $RC
546*e670fd5cSchristosfi
547*e670fd5cSchristos
548*e670fd5cSchristosID=bjensen
549*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
550*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $ID
551*e670fd5cSchristosRC=$?
552*e670fd5cSchristosif test $RC != 0; then
553*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
554*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
555*e670fd5cSchristos	exit $RC
556*e670fd5cSchristosfi
557*e670fd5cSchristos
558*e670fd5cSchristosecho
559*e670fd5cSchristos
560*e670fd5cSchristosecho "Updating an olcAuthIDRewrite rule in place..."
561*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
562*e670fd5cSchristosdn: cn=config
563*e670fd5cSchristoschangetype: modify
564*e670fd5cSchristosdelete: olcAuthIDRewrite
565*e670fd5cSchristosolcAuthIDRewrite: {2}
566*e670fd5cSchristos-
567*e670fd5cSchristosadd: olcAuthIDRewrite
568*e670fd5cSchristosolcAuthIDRewrite: {2}rewriteRule uid=biff,cn=[^,]+,cn=auth ldap:///$BASEDN??sub?(uid=bjorn) :
569*e670fd5cSchristosEOF
570*e670fd5cSchristosRC=$?
571*e670fd5cSchristosif test $RC != 0; then
572*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
573*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
574*e670fd5cSchristos	exit $RC
575*e670fd5cSchristosfi
576*e670fd5cSchristos
577*e670fd5cSchristosID=babs
578*e670fd5cSchristosecho "Testing ldapwhoami as $ID (should fail)..."
579*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w bjensen
580*e670fd5cSchristosRC=$?
581*e670fd5cSchristosif test $RC != 49; then
582*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
583*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
584*e670fd5cSchristos	exit $RC
585*e670fd5cSchristosfi
586*e670fd5cSchristos
587*e670fd5cSchristosID=biff
588*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
589*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w bjorn
590*e670fd5cSchristosRC=$?
591*e670fd5cSchristosif test $RC != 0; then
592*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
593*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
594*e670fd5cSchristos	exit $RC
595*e670fd5cSchristosfi
596*e670fd5cSchristos
597*e670fd5cSchristosID=bjensen
598*e670fd5cSchristosecho "Testing ldapwhoami as $ID..."
599*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $ID
600*e670fd5cSchristosRC=$?
601*e670fd5cSchristosif test $RC != 0; then
602*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
603*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
604*e670fd5cSchristos	exit $RC
605*e670fd5cSchristosfi
606*e670fd5cSchristos
607*e670fd5cSchristosecho
608*e670fd5cSchristos
609*e670fd5cSchristosecho "Deleting all olcAuthIDRewrite rules..."
610*e670fd5cSchristos$LDAPMODIFY -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
611*e670fd5cSchristosdn: cn=config
612*e670fd5cSchristoschangetype: modify
613*e670fd5cSchristosdelete: olcAuthIDRewrite
614*e670fd5cSchristosEOF
615*e670fd5cSchristosRC=$?
616*e670fd5cSchristosif test $RC != 0; then
617*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
618*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
619*e670fd5cSchristos	exit $RC
620*e670fd5cSchristosfi
621*e670fd5cSchristos
622*e670fd5cSchristosID=bjensen
623*e670fd5cSchristosecho "Testing ldapwhoami as $ID (should fail)..."
624*e670fd5cSchristos$LDAPSASLWHOAMI -H $URI1 -Y $MECH -U $ID -w $ID
625*e670fd5cSchristosRC=$?
626*e670fd5cSchristosif test $RC != 49; then
627*e670fd5cSchristos	echo "ldapwhoami failed ($RC)!"
628*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
629*e670fd5cSchristos	exit $RC
630*e670fd5cSchristosfi
631*e670fd5cSchristos
632*e670fd5cSchristosecho
633*e670fd5cSchristos
634*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS
635*e670fd5cSchristos
636*e670fd5cSchristosecho ">>>>> Test succeeded"
637*e670fd5cSchristos
638*e670fd5cSchristostest $KILLSERVERS != no && wait
639*e670fd5cSchristos
640*e670fd5cSchristosexit 0
641