xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/lloadd/test006-sasl (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 = "yes" ; then
20*e670fd5cSchristos    if test $USE_SASL = "no" ; then
21*e670fd5cSchristos        echo "Not asked to test SASL, skipping test, set SLAPD_USE_SASL to enable..."
22*e670fd5cSchristos        exit 0
23*e670fd5cSchristos    fi
24*e670fd5cSchristos    if test $USE_SASL = "yes" ; then
25*e670fd5cSchristos        MECH="DIGEST-MD5"
26*e670fd5cSchristos    else
27*e670fd5cSchristos        MECH="$USE_SASL"
28*e670fd5cSchristos    fi
29*e670fd5cSchristos    echo "Using SASL authc[/authz] with mech=$MECH; unset SLAPD_USE_SASL to disable"
30*e670fd5cSchristoselse
31*e670fd5cSchristos    echo "SASL support not available, test skipped"
32*e670fd5cSchristos    exit 0
33*e670fd5cSchristosfi
34*e670fd5cSchristos
35*e670fd5cSchristosmkdir -p $TESTDIR $DBDIR1 $DBDIR2
36*e670fd5cSchristoscp -r $DATADIR/tls $TESTDIR
37*e670fd5cSchristos
38*e670fd5cSchristoscd $TESTWD
39*e670fd5cSchristos
40*e670fd5cSchristos$SLAPPASSWD -g -n >$CONFIGPWF
41*e670fd5cSchristosecho "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
42*e670fd5cSchristos
43*e670fd5cSchristosecho "Running slapadd to build slapd database..."
44*e670fd5cSchristos. $CONFFILTER $BACKEND < $TLSSASLCONF > $CONF2
45*e670fd5cSchristosecho 'authz-regexp "^uid=([^,]*),.+" ldap:///dc=example,dc=com??sub?(|(cn=$1)(uid=$1))' >>$CONF2
46*e670fd5cSchristos$SLAPADD -f $CONF2 -l $LDIFORDERED
47*e670fd5cSchristosRC=$?
48*e670fd5cSchristosif test $RC != 0 ; then
49*e670fd5cSchristos    echo "slapadd failed ($RC)!"
50*e670fd5cSchristos    exit $RC
51*e670fd5cSchristosfi
52*e670fd5cSchristos
53*e670fd5cSchristosecho "Starting a slapd on TCP/IP port $PORT2..."
54*e670fd5cSchristos$SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
55*e670fd5cSchristosPID=$!
56*e670fd5cSchristosif test $WAIT != 0 ; then
57*e670fd5cSchristos    echo PID $PID
58*e670fd5cSchristos    read foo
59*e670fd5cSchristosfi
60*e670fd5cSchristosPID2="$PID"
61*e670fd5cSchristosKILLPIDS="$PID"
62*e670fd5cSchristos
63*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
64*e670fd5cSchristos    $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
65*e670fd5cSchristos        '(objectclass=*)' > /dev/null 2>&1
66*e670fd5cSchristos    RC=$?
67*e670fd5cSchristos    if test $RC = 0 ; then
68*e670fd5cSchristos        break
69*e670fd5cSchristos    fi
70*e670fd5cSchristos    echo "Waiting $SLEEP1 seconds for slapd to start..."
71*e670fd5cSchristos    sleep $SLEEP1
72*e670fd5cSchristosdone
73*e670fd5cSchristosif test $RC != 0 ; then
74*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
75*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
76*e670fd5cSchristos    exit $RC
77*e670fd5cSchristosfi
78*e670fd5cSchristos
79*e670fd5cSchristosecho "Running slapadd to build slapd database..."
80*e670fd5cSchristos. $CONFFILTER $BACKEND < $CONFTWO > $CONF3
81*e670fd5cSchristosecho 'authz-regexp "^uid=([^,]*),.+" ldap:///dc=example,dc=com??sub?(|(cn=$1)(uid=$1))' >>$CONF3
82*e670fd5cSchristos$SLAPADD -f $CONF3 -l $LDIFORDERED
83*e670fd5cSchristosRC=$?
84*e670fd5cSchristosif test $RC != 0 ; then
85*e670fd5cSchristos    echo "slapadd failed ($RC)!"
86*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
87*e670fd5cSchristos    exit $RC
88*e670fd5cSchristosfi
89*e670fd5cSchristos
90*e670fd5cSchristosecho "Running slapindex to index slapd database..."
91*e670fd5cSchristos$SLAPINDEX -f $CONF3
92*e670fd5cSchristosRC=$?
93*e670fd5cSchristosif test $RC != 0 ; then
94*e670fd5cSchristos    echo "warning: slapindex failed ($RC)"
95*e670fd5cSchristos    echo "  assuming no indexing support"
96*e670fd5cSchristosfi
97*e670fd5cSchristos
98*e670fd5cSchristosecho "Starting second slapd on TCP/IP port $PORT3..."
99*e670fd5cSchristos$SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 &
100*e670fd5cSchristosPID=$!
101*e670fd5cSchristosif test $WAIT != 0 ; then
102*e670fd5cSchristos    echo PID $PID
103*e670fd5cSchristos    read foo
104*e670fd5cSchristosfi
105*e670fd5cSchristosPID2="$PID"
106*e670fd5cSchristosKILLPIDS="$KILLPIDS $PID"
107*e670fd5cSchristos
108*e670fd5cSchristossleep $SLEEP0
109*e670fd5cSchristos
110*e670fd5cSchristosecho "Testing slapd searching..."
111*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
112*e670fd5cSchristos    $LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \
113*e670fd5cSchristos        '(objectclass=*)' > /dev/null 2>&1
114*e670fd5cSchristos    RC=$?
115*e670fd5cSchristos    if test $RC = 0 ; then
116*e670fd5cSchristos        break
117*e670fd5cSchristos    fi
118*e670fd5cSchristos    echo "Waiting $SLEEP1 seconds for slapd to start..."
119*e670fd5cSchristos    sleep $SLEEP1
120*e670fd5cSchristosdone
121*e670fd5cSchristosif test $RC != 0 ; then
122*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
123*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
124*e670fd5cSchristos    exit $RC
125*e670fd5cSchristosfi
126*e670fd5cSchristos
127*e670fd5cSchristosecho "Starting lloadd on TCP/IP port $PORT1..."
128*e670fd5cSchristos. $CONFFILTER $BACKEND < $LLOADDSASLCONF > $CONF1.lloadd
129*e670fd5cSchristosif test $AC_lloadd = lloaddyes; then
130*e670fd5cSchristos    $LLOADD -f $CONF1.lloadd -h $URI1 -d $LVL > $LOG1 2>&1 &
131*e670fd5cSchristoselse
132*e670fd5cSchristos    . $CONFFILTER $BACKEND < $SLAPDLLOADCONF > $CONF1.slapd
133*e670fd5cSchristos    $SLAPD -f $CONF1.slapd -h $URI6 -d $LVL > $LOG1 2>&1 &
134*e670fd5cSchristosfi
135*e670fd5cSchristosPID=$!
136*e670fd5cSchristosif test $WAIT != 0 ; then
137*e670fd5cSchristos    echo PID $PID
138*e670fd5cSchristos    read foo
139*e670fd5cSchristosfi
140*e670fd5cSchristosKILLPIDS="$KILLPIDS $PID"
141*e670fd5cSchristos
142*e670fd5cSchristosecho "Testing lloadd searching..."
143*e670fd5cSchristosfor i in 0 1 2 3 4 5; do
144*e670fd5cSchristos    $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
145*e670fd5cSchristos        '(objectclass=*)' > /dev/null 2>&1
146*e670fd5cSchristos    RC=$?
147*e670fd5cSchristos    if test $RC = 0 ; then
148*e670fd5cSchristos        break
149*e670fd5cSchristos    fi
150*e670fd5cSchristos    echo "Waiting $SLEEP1 seconds for lloadd to start..."
151*e670fd5cSchristos    sleep $SLEEP1
152*e670fd5cSchristosdone
153*e670fd5cSchristos
154*e670fd5cSchristosif test $RC != 0 ; then
155*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
156*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
157*e670fd5cSchristos    exit $RC
158*e670fd5cSchristosfi
159*e670fd5cSchristos
160*e670fd5cSchristosecho "Checking whether $MECH is supported..."
161*e670fd5cSchristos$LDAPSEARCH -s base -b "" -H $URI1 \
162*e670fd5cSchristos    'objectClass=*' supportedSASLMechanisms > $SEARCHOUT 2>&1
163*e670fd5cSchristosRC=$?
164*e670fd5cSchristosif test $RC != 0 ; then
165*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
166*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
167*e670fd5cSchristos    exit $RC
168*e670fd5cSchristosfi
169*e670fd5cSchristos
170*e670fd5cSchristosgrep "supportedSASLMechanisms: $MECH" $SEARCHOUT > $TESTOUT
171*e670fd5cSchristosRC=$?
172*e670fd5cSchristosif test $RC != 0 ; then
173*e670fd5cSchristos    echo "SASL mechanism $MECH is not available, test skipped"
174*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
175*e670fd5cSchristos    exit 0
176*e670fd5cSchristosfi
177*e670fd5cSchristos
178*e670fd5cSchristosAUTHZID="u:bjorn"
179*e670fd5cSchristosecho "Testing lloadd's identity can assert any authzid..."
180*e670fd5cSchristos$LDAPWHOAMI -D "$MANAGERDN" -H $URI1 -w $PASSWD \
181*e670fd5cSchristos    -e\!"authzid=$AUTHZID" > $TESTOUT 2>&1
182*e670fd5cSchristosRC=$?
183*e670fd5cSchristosif test $RC != 0 ; then
184*e670fd5cSchristos    echo "ldapwhoami failed ($RC)!"
185*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
186*e670fd5cSchristos    exit $RC
187*e670fd5cSchristosfi
188*e670fd5cSchristos
189*e670fd5cSchristosAUTHZID="u:bjorn"
190*e670fd5cSchristosecho "Testing a different identity cannot do the same thing..."
191*e670fd5cSchristos$LDAPWHOAMI -D "$BABSDN" -H $URI1 -w bjensen \
192*e670fd5cSchristos    -e\!"authzid=$AUTHZID" >> $TESTOUT 2>/dev/null
193*e670fd5cSchristosRC=$?
194*e670fd5cSchristosif test $RC != 1 ; then
195*e670fd5cSchristos    echo "ldapwhoami failed ($RC)!"
196*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
197*e670fd5cSchristos    exit $RC
198*e670fd5cSchristosfi
199*e670fd5cSchristos
200*e670fd5cSchristosecho "Validating WhoAmI? results..."
201*e670fd5cSchristosecho 'dn:cn=bjorn jensen,ou=information technology division,ou=people,dc=example,dc=com' > $TESTDIR/whoami.out
202*e670fd5cSchristosecho 'Result: Protocol error (2)
203*e670fd5cSchristosAdditional info: proxy authorization control specified multiple times' >> $TESTDIR/whoami.out
204*e670fd5cSchristos$CMP $TESTDIR/whoami.out $TESTOUT > $CMPOUT
205*e670fd5cSchristos
206*e670fd5cSchristosRC=$?
207*e670fd5cSchristosif test $RC != 0 ; then
208*e670fd5cSchristos    echo "Comparison failed"
209*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
210*e670fd5cSchristos    exit $RC
211*e670fd5cSchristoselse
212*e670fd5cSchristos    echo "Success"
213*e670fd5cSchristosfi
214*e670fd5cSchristos
215*e670fd5cSchristos
216*e670fd5cSchristosID="jaj"
217*e670fd5cSchristosecho "Testing ldapsearch as $ID for \"$BASEDN\" with SASL bind and identity assertion..."
218*e670fd5cSchristos$LDAPSASLSEARCH -H $URI1 -b "$BASEDN" \
219*e670fd5cSchristos    -Q -Y $MECH -O maxbufsize=0 -U "$ID" -w jaj > $SEARCHOUT 2>&1
220*e670fd5cSchristos
221*e670fd5cSchristosRC=$?
222*e670fd5cSchristosif test $RC != 0 ; then
223*e670fd5cSchristos    echo "ldapsearch failed ($RC)!"
224*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
225*e670fd5cSchristos    exit $RC
226*e670fd5cSchristosfi
227*e670fd5cSchristos
228*e670fd5cSchristosecho "Filtering ldapsearch results..."
229*e670fd5cSchristos$LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT
230*e670fd5cSchristosecho "Filtering original ldif used to create database..."
231*e670fd5cSchristos$LDIFFILTER -s e < $LDIF > $LDIFFLT
232*e670fd5cSchristosecho "Comparing filter output..."
233*e670fd5cSchristos$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
234*e670fd5cSchristos
235*e670fd5cSchristosif test $? != 0 ; then
236*e670fd5cSchristos    echo "comparison failed - search with SASL bind and identity assertion didn't succeed"
237*e670fd5cSchristos    test $KILLSERVERS != no && kill -HUP $KILLPIDS
238*e670fd5cSchristos    exit 1
239*e670fd5cSchristosfi
240*e670fd5cSchristos
241*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS
242*e670fd5cSchristos
243*e670fd5cSchristosif test $RC != 0 ; then
244*e670fd5cSchristos    echo ">>>>> Test failed"
245*e670fd5cSchristoselse
246*e670fd5cSchristos    echo ">>>>> Test succeeded"
247*e670fd5cSchristos    RC=0
248*e670fd5cSchristosfi
249*e670fd5cSchristos
250*e670fd5cSchristostest $KILLSERVERS != no && wait
251*e670fd5cSchristos
252*e670fd5cSchristosexit $RC
253