xref: /netbsd-src/external/bsd/openldap/dist/contrib/slapd-modules/variant/tests/scripts/test006-acl (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 2016-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*e670fd5cSchristos## ACKNOWLEDGEMENTS:
17*e670fd5cSchristos## This module was written in 2016 by Ondřej Kuzník for Symas Corp.
18*e670fd5cSchristos
19*e670fd5cSchristoscase "$BACKEND" in ldif | null)
20*e670fd5cSchristos	echo "$BACKEND backend does not support access controls, test skipped"
21*e670fd5cSchristos	exit 0
22*e670fd5cSchristosesac
23*e670fd5cSchristos
24*e670fd5cSchristosecho "running defines.sh"
25*e670fd5cSchristos. $SRCDIR/scripts/defines.sh
26*e670fd5cSchristos
27*e670fd5cSchristosCONF=$ACLCONF
28*e670fd5cSchristos. ${SCRIPTDIR}/common.sh
29*e670fd5cSchristos
30*e670fd5cSchristosecho "Applying test-specific configuration..."
31*e670fd5cSchristos. $CONFFILTER $BACKEND $MONITORDB < data/test006-config.ldif | \
32*e670fd5cSchristos$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
33*e670fd5cSchristos	>> $TESTOUT 2>&1
34*e670fd5cSchristosRC=$?
35*e670fd5cSchristosif test $RC != 0 ; then
36*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
37*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
38*e670fd5cSchristos	exit $RC
39*e670fd5cSchristosfi
40*e670fd5cSchristos
41*e670fd5cSchristos$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD >> \
42*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
43*e670fd5cSchristosdn: ou=Add & Delete,dc=example,dc=com
44*e670fd5cSchristoschangetype: add
45*e670fd5cSchristosobjectClass: organizationalUnit
46*e670fd5cSchristosou: Add & Delete
47*e670fd5cSchristos
48*e670fd5cSchristosdn: cn=group,ou=Add & Delete,dc=example,dc=com
49*e670fd5cSchristoschangetype: add
50*e670fd5cSchristosobjectclass: groupOfNames
51*e670fd5cSchristosmember: dc=example,dc=com
52*e670fd5cSchristos
53*e670fd5cSchristosdn: sn=Doe,ou=Add & Delete,dc=example,dc=com
54*e670fd5cSchristoschangetype: add
55*e670fd5cSchristosobjectclass: OpenLDAPperson
56*e670fd5cSchristoscn: John
57*e670fd5cSchristosuid: jd
58*e670fd5cSchristos
59*e670fd5cSchristosdn: sn=Elliot,ou=Add & Delete,dc=example,dc=com
60*e670fd5cSchristoschangetype: add
61*e670fd5cSchristosobjectclass: OpenLDAPperson
62*e670fd5cSchristoscn: Mark
63*e670fd5cSchristosuid: me
64*e670fd5cSchristosEOMODS
65*e670fd5cSchristosRC=$?
66*e670fd5cSchristosif test $RC != 0 ; then
67*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
68*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
69*e670fd5cSchristos	exit $RC
70*e670fd5cSchristosfi
71*e670fd5cSchristos
72*e670fd5cSchristosecho "Testing search ACL processing..."
73*e670fd5cSchristos
74*e670fd5cSchristosecho "# Try to read an entry inside the Alumni Association container.
75*e670fd5cSchristos# It should give us noSuchObject if we're not bound..." \
76*e670fd5cSchristos>> $SEARCHOUT
77*e670fd5cSchristos# FIXME: temporarily remove the "No such object" message to make
78*e670fd5cSchristos# the test succeed even if SLAP_ACL_HONOR_DISCLOSE is not #define'd
79*e670fd5cSchristos$LDAPSEARCH -b "$MELLIOTDN" -H $URI1 "(objectclass=*)" \
80*e670fd5cSchristos	2>&1 | grep -v "No such object" >> $SEARCHOUT
81*e670fd5cSchristos
82*e670fd5cSchristosecho >>$SEARCHOUT
83*e670fd5cSchristosecho "# ... and should return appropriate attributes if we're bound as anyone
84*e670fd5cSchristos# under Example." \
85*e670fd5cSchristos>> $SEARCHOUT
86*e670fd5cSchristos$LDAPSEARCH -b "$MELLIOTDN" -H $URI1 \
87*e670fd5cSchristos	-D "$BABSDN" -w bjensen "(objectclass=*)" >> $SEARCHOUT 2>&1
88*e670fd5cSchristos
89*e670fd5cSchristos$LDAPSEARCH -b "$MELLIOTDN" -H $URI1 \
90*e670fd5cSchristos	-D "$BJORNSDN" -w bjorn "(objectclass=*)" >> $SEARCHOUT 2>&1
91*e670fd5cSchristos
92*e670fd5cSchristosecho >>$SEARCHOUT
93*e670fd5cSchristosecho "# Add & Delete subtree contents as seen by Babs" >> $SEARCHOUT
94*e670fd5cSchristos$LDAPSEARCH -b "ou=Add & Delete,dc=example,dc=com" -H $URI1 \
95*e670fd5cSchristos	-D "$BABSDN" -w bjensen "(objectclass=*)" >> $SEARCHOUT 2>&1
96*e670fd5cSchristos
97*e670fd5cSchristosecho >>$SEARCHOUT
98*e670fd5cSchristosecho "# Add & Delete subtree contents as seen by Bjorn" >> $SEARCHOUT
99*e670fd5cSchristos$LDAPSEARCH -b "ou=Add & Delete,dc=example,dc=com" -H $URI1 \
100*e670fd5cSchristos	-D "$BJORNSDN" -w bjorn "(objectclass=*)" >> $SEARCHOUT 2>&1
101*e670fd5cSchristos
102*e670fd5cSchristosecho "Testing modifications..."
103*e670fd5cSchristosecho "... ACL on the alternative entry"
104*e670fd5cSchristos$LDAPMODIFY -D "$BJORNSDN" -H $URI1 -w bjorn >> \
105*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
106*e670fd5cSchristosdn: cn=group,ou=Add & Delete,dc=example,dc=com
107*e670fd5cSchristoschangetype: modify
108*e670fd5cSchristosadd: seealso
109*e670fd5cSchristosseealso: $BJORNSDN
110*e670fd5cSchristosEOMODS
111*e670fd5cSchristosRC=$?
112*e670fd5cSchristosif test $RC != 0 ; then
113*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
114*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
115*e670fd5cSchristos	exit $RC
116*e670fd5cSchristosfi
117*e670fd5cSchristos
118*e670fd5cSchristos$LDAPMODIFY -D "$BABSDN" -H $URI1 -w bjensen >> \
119*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
120*e670fd5cSchristosdn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
121*e670fd5cSchristoschangetype: modify
122*e670fd5cSchristosadd: description
123*e670fd5cSchristosdescription: added by bjensen (should fail)
124*e670fd5cSchristosEOMODS
125*e670fd5cSchristosRC=$?
126*e670fd5cSchristoscase $RC in
127*e670fd5cSchristos50)
128*e670fd5cSchristos	;;
129*e670fd5cSchristos0)
130*e670fd5cSchristos	echo "ldapmodify should have failed ($RC)!"
131*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
132*e670fd5cSchristos	exit -1
133*e670fd5cSchristos	;;
134*e670fd5cSchristos*)
135*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
136*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
137*e670fd5cSchristos	exit $RC
138*e670fd5cSchristos	;;
139*e670fd5cSchristosesac
140*e670fd5cSchristos
141*e670fd5cSchristos$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD >> \
142*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
143*e670fd5cSchristosdn: cn=group,ou=Add & Delete,dc=example,dc=com
144*e670fd5cSchristoschangetype: modify
145*e670fd5cSchristosadd: seealso
146*e670fd5cSchristosseealso: $BABSDN
147*e670fd5cSchristosEOMODS
148*e670fd5cSchristosRC=$?
149*e670fd5cSchristosif test $RC != 0 ; then
150*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
151*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
152*e670fd5cSchristos	exit $RC
153*e670fd5cSchristosfi
154*e670fd5cSchristos
155*e670fd5cSchristos$LDAPMODIFY -D "$BJORNSDN" -H $URI1 -w bjorn >> \
156*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
157*e670fd5cSchristosdn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
158*e670fd5cSchristoschangetype: modify
159*e670fd5cSchristosadd: description
160*e670fd5cSchristosdescription: added by bjorn (removed later)
161*e670fd5cSchristosEOMODS
162*e670fd5cSchristosRC=$?
163*e670fd5cSchristosif test $RC != 0 ; then
164*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
165*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
166*e670fd5cSchristos	exit $RC
167*e670fd5cSchristosfi
168*e670fd5cSchristos
169*e670fd5cSchristos$LDAPMODIFY -D "$BABSDN" -H $URI1 -w bjensen >> \
170*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
171*e670fd5cSchristosdn: cn=Group,ou=Add & Delete,dc=example,dc=com
172*e670fd5cSchristoschangetype: modify
173*e670fd5cSchristosdelete: description
174*e670fd5cSchristosdescription: added by bjorn (removed later)
175*e670fd5cSchristosEOMODS
176*e670fd5cSchristosRC=$?
177*e670fd5cSchristosif test $RC != 0 ; then
178*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
179*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
180*e670fd5cSchristos	exit $RC
181*e670fd5cSchristosfi
182*e670fd5cSchristos
183*e670fd5cSchristos$LDAPMODIFY -D "$BJORNSDN" -H $URI1 -w bjorn >> \
184*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
185*e670fd5cSchristosdn: cn=Added by Bjorn,ou=Add & Delete,dc=example,dc=com
186*e670fd5cSchristoschangetype: add
187*e670fd5cSchristosobjectClass: inetOrgPerson
188*e670fd5cSchristossn: Jensen
189*e670fd5cSchristosEOMODS
190*e670fd5cSchristosRC=$?
191*e670fd5cSchristosif test $RC != 0 ; then
192*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
193*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
194*e670fd5cSchristos	exit $RC
195*e670fd5cSchristosfi
196*e670fd5cSchristos
197*e670fd5cSchristos$LDAPMODIFY -D "$BJORNSDN" -H $URI1 -w bjorn >> \
198*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
199*e670fd5cSchristosdn: cn=Group,ou=Add & Delete,dc=example,dc=com
200*e670fd5cSchristoschangetype: modify
201*e670fd5cSchristosadd: description
202*e670fd5cSchristosdescription: another one added by bjorn (should succeed)
203*e670fd5cSchristosEOMODS
204*e670fd5cSchristosRC=$?
205*e670fd5cSchristosif test $RC != 0 ; then
206*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
207*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
208*e670fd5cSchristos	exit $RC
209*e670fd5cSchristosfi
210*e670fd5cSchristos
211*e670fd5cSchristosecho "... ACL on the variant entry"
212*e670fd5cSchristos$LDAPMODIFY -D "$BABSDN" -H $URI1 -w bjensen >> \
213*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
214*e670fd5cSchristosdn: cn=Group,ou=Add & Delete,dc=example,dc=com
215*e670fd5cSchristoschangetype: modify
216*e670fd5cSchristosadd: description
217*e670fd5cSchristosdescription: added by bjensen (should fail)
218*e670fd5cSchristosEOMODS
219*e670fd5cSchristosRC=$?
220*e670fd5cSchristoscase $RC in
221*e670fd5cSchristos50)
222*e670fd5cSchristos	;;
223*e670fd5cSchristos0)
224*e670fd5cSchristos	echo "ldapmodify should have failed ($RC)!"
225*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
226*e670fd5cSchristos	exit -1
227*e670fd5cSchristos	;;
228*e670fd5cSchristos*)
229*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
230*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
231*e670fd5cSchristos	exit $RC
232*e670fd5cSchristos	;;
233*e670fd5cSchristosesac
234*e670fd5cSchristos
235*e670fd5cSchristos$LDAPMODIFY -D "$BJORNSDN" -H $URI1 -w bjorn >> \
236*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
237*e670fd5cSchristosdn: sn=Doe,ou=Add & Delete,dc=example,dc=com
238*e670fd5cSchristoschangetype: modify
239*e670fd5cSchristosadd: description
240*e670fd5cSchristosdescription: added by bjorn (will be removed)
241*e670fd5cSchristosEOMODS
242*e670fd5cSchristosRC=$?
243*e670fd5cSchristosif test $RC != 0 ; then
244*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
245*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
246*e670fd5cSchristos	exit $RC
247*e670fd5cSchristosfi
248*e670fd5cSchristos
249*e670fd5cSchristos$LDAPMODIFY -D "$BABSDN" -H $URI1 -w bjensen >> \
250*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
251*e670fd5cSchristosdn: cn=Added by Bjorn,ou=Add & Delete,dc=example,dc=com
252*e670fd5cSchristoschangetype: modify
253*e670fd5cSchristosreplace: description
254*e670fd5cSchristosdescription: added by bjensen (should fail)
255*e670fd5cSchristosEOMODS
256*e670fd5cSchristosRC=$?
257*e670fd5cSchristoscase $RC in
258*e670fd5cSchristos50)
259*e670fd5cSchristos	;;
260*e670fd5cSchristos0)
261*e670fd5cSchristos	echo "ldapmodify should have failed ($RC)!"
262*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
263*e670fd5cSchristos	exit -1
264*e670fd5cSchristos	;;
265*e670fd5cSchristos*)
266*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
267*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
268*e670fd5cSchristos	exit $RC
269*e670fd5cSchristos	;;
270*e670fd5cSchristosesac
271*e670fd5cSchristos
272*e670fd5cSchristos$LDAPMODIFY -D "$JAJDN" -H $URI1 -w jaj >> \
273*e670fd5cSchristos	$TESTOUT 2>&1 << EOMODS
274*e670fd5cSchristosdn: sn=Elliot,ou=Add & Delete,dc=example,dc=com
275*e670fd5cSchristoschangetype: modify
276*e670fd5cSchristosdelete: description
277*e670fd5cSchristosdescription: added by bjorn (will be removed)
278*e670fd5cSchristos-
279*e670fd5cSchristosadd: description
280*e670fd5cSchristosdescription: added by jaj (should succeed)
281*e670fd5cSchristosEOMODS
282*e670fd5cSchristosRC=$?
283*e670fd5cSchristosif test $RC != 0 ; then
284*e670fd5cSchristos	echo "ldapmodify failed ($RC)!"
285*e670fd5cSchristos	test $KILLSERVERS != no && kill -HUP $KILLPIDS
286*e670fd5cSchristos	exit $RC
287*e670fd5cSchristosfi
288*e670fd5cSchristos
289*e670fd5cSchristossleep $SLEEP0
290*e670fd5cSchristos
291*e670fd5cSchristosecho >>$SEARCHOUT
292*e670fd5cSchristosecho "Using ldapsearch to retrieve all the entries..."
293*e670fd5cSchristosecho "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
294*e670fd5cSchristos$LDAPSEARCH -S "" -b "ou=Add & Delete,dc=example,dc=com" \
295*e670fd5cSchristos	-D "$MANAGERDN" -H $URI1 -w $PASSWD \
296*e670fd5cSchristos	'objectClass=*' >> $SEARCHOUT 2>&1
297*e670fd5cSchristosRC=$?
298*e670fd5cSchristosif test $RC != 0 ; then
299*e670fd5cSchristos	echo "ldapsearch failed ($RC)!"
300*e670fd5cSchristos	exit $RC
301*e670fd5cSchristosfi
302*e670fd5cSchristos
303*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS
304*e670fd5cSchristos
305*e670fd5cSchristosLDIF=data/test006-out.ldif
306*e670fd5cSchristos
307*e670fd5cSchristosecho "Filtering ldapsearch results..."
308*e670fd5cSchristos$LDIFFILTER -s e < $SEARCHOUT > $SEARCHFLT
309*e670fd5cSchristosecho "Filtering expected entries..."
310*e670fd5cSchristos$LDIFFILTER -s e < $LDIF > $LDIFFLT
311*e670fd5cSchristosecho "Comparing filter output..."
312*e670fd5cSchristos$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
313*e670fd5cSchristos
314*e670fd5cSchristosif test $? != 0 ; then
315*e670fd5cSchristos	echo "comparison failed - operations did not complete correctly"
316*e670fd5cSchristos	exit 1
317*e670fd5cSchristosfi
318*e670fd5cSchristos
319*e670fd5cSchristosecho ">>>>> Test succeeded"
320*e670fd5cSchristos
321*e670fd5cSchristostest $KILLSERVERS != no && wait
322*e670fd5cSchristos
323*e670fd5cSchristosexit 0
324