]> git.sur5r.net Git - openldap/blob - tests/scripts/test006-acls
ITS#3671 must release conn->c_mutex to allow blocked writers to exit
[openldap] / tests / scripts / test006-acls
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 mkdir -p $TESTDIR $DBDIR1
20
21 echo "Running slapadd to build slapd database..."
22 . $CONFFILTER $BACKEND $MONITORDB < $ACLCONF > $CONF1
23 $SLAPADD -f $CONF1 -l $LDIFORDERED
24 RC=$?
25 if test $RC != 0 ; then
26         echo "slapadd failed ($RC)!"
27         exit $RC
28 fi
29
30 echo "Starting slapd on TCP/IP port $PORT1..."
31 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
32 PID=$!
33 if test $WAIT != 0 ; then
34     echo PID $PID
35     read foo
36 fi
37 KILLPIDS="$PID"
38
39 echo "Testing slapd access control..."
40 for i in 0 1 2 3 4 5; do
41         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
42                 'objectclass=*' > /dev/null 2>&1
43         RC=$?
44         if test $RC = 0 ; then
45                 break
46         fi
47         echo "Waiting 5 seconds for slapd to start..."
48         sleep 5
49 done
50
51 if test $RC != 0 ; then
52         echo "ldapsearch failed ($RC)!"
53         test $KILLSERVERS != no && kill -HUP $KILLPIDS
54         exit $RC
55 fi
56
57 cat /dev/null > $SEARCHOUT
58
59 echo "# Try to read an entry inside the Alumni Association container.
60 # It should give us noSuchObject if we're not bound..." \
61 >> $SEARCHOUT
62 # FIXME: temporarily remove the "No such object" message to make
63 # the test succeed even if SLAP_ACL_HONOR_DISCLOSE is not #define'd
64 $LDAPSEARCH -b "$JAJDN" -h $LOCALHOST -p $PORT1 "(objectclass=*)" \
65         2>&1 | grep -v "^No such object" >> $SEARCHOUT
66
67 echo "# ... and should return all attributes if we're bound as anyone
68 # under Example." \
69 >> $SEARCHOUT
70 $LDAPSEARCH -b "$JAJDN" -h $LOCALHOST -p $PORT1 \
71         -D "$BABSDN" -w bjensen "(objectclass=*)"  >> $SEARCHOUT 2>&1
72
73 #
74 # Check group access. Try to modify Babs' entry. Two attempts:
75 # 1) bound as "James A Jones 1" - should fail
76 # 2) bound as "Bjorn Jensen" - should succeed
77
78 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
79         $TESTOUT 2>&1 << EOMODS5
80 dn: $BABSDN
81 changetype: modify
82 replace: drink
83 drink: wine
84
85 EOMODS5
86
87
88 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
89         $TESTOUT 2>&1 << EOMODS6
90 dn: $BABSDN
91 changetype: modify
92 add: homephone
93 homephone: +1 313 555 5444
94
95 EOMODS6
96
97 #
98 # Try to add a "member" attribute to the "ITD Staff" group.  It should
99 # fail when we add some DN other than our own, and should succeed when
100 # we add our own DN.
101 # bjensen
102 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj > \
103         $TESTOUT 2>&1 << EOMODS1
104 version: 1
105 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
106 changetype: modify
107 add: uniquemember
108 uniquemember: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
109
110 EOMODS1
111
112 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
113         $TESTOUT 2>&1 << EOMODS2
114 version: 1
115
116 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
117 changetype: modify
118 add: uniquemember
119 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
120 EOMODS2
121
122 #
123 # Try to modify the "ITD Staff" group.  Two attempts are made:
124 # 1) bound as "James A Jones 1" - should fail
125 # 2) bound as "Bjorn Jensen" - should succeed
126 #
127 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
128         $TESTOUT 2>&1 << EOMODS3
129
130 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
131 changetype: modify
132 delete: description
133
134 EOMODS3
135
136 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
137         $TESTOUT 2>&1 << EOMODS4
138 # COMMENT
139 version: 1
140 # comment
141 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
142 # comment
143 changetype: modify
144 # comment
145 add: ou
146 # comment
147 ou: Groups
148 # comment
149 EOMODS4
150
151 #
152 # Try to modify the "ITD Staff" group.  Two attempts are made:
153 # 1) bound as "James A Jones 1" - should succeed
154 # 2) bound as "Barbara Jensen" - should fail
155 # should exploit sets
156 #
157 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
158         $TESTOUT 2>&1 << EOMODS5
159 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
160 changetype: modify
161 add: description
162 description: added by jaj (should succeed)
163 -
164 EOMODS5
165
166 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
167         $TESTOUT 2>&1 << EOMODS6
168 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
169 changetype: modify
170 add: description
171 description: added by bjensen (should fail)
172 -
173 EOMODS6
174
175 $LDAPMODIFY -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
176         $TESTOUT 2>&1 << EOMODS7
177 dn: ou=Add/Delete,dc=example,dc=com
178 changetype: add
179 objectClass: organizationalUnit
180 ou: Add/Delete
181 EOMODS7
182
183 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
184         $TESTOUT 2>&1 << EOMODS8
185 dn: cn=Added by Babs (must fail),ou=Add/Delete,dc=example,dc=com
186 changetype: add
187 objectClass: inetOrgPerson
188 cn: Added by Babs (must fail)
189 sn: None
190 EOMODS8
191
192 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
193         $TESTOUT 2>&1 << EOMODS9
194 dn: cn=Added by Bjorn (must succeed),ou=Add/Delete,dc=example,dc=com
195 changetype: add
196 objectClass: inetOrgPerson
197 cn: Added by Bjorn (must succeed)
198 sn: None
199
200 dn: cn=Added by Bjorn (will be deleted),ou=Add/Delete,dc=example,dc=com
201 changetype: add
202 objectClass: inetOrgPerson
203 cn: Added by Bjorn (will be deleted)
204 sn: None
205
206 dn: cn=Added by Bjorn (will be renamed),ou=Add/Delete,dc=example,dc=com
207 changetype: add
208 objectClass: inetOrgPerson
209 cn: Added by Bjorn (will be renamed)
210 sn: None
211
212 dn: cn=Added by Bjorn (must succeed),ou=Add/Delete,dc=example,dc=com
213 changetype: modify
214 add: description
215 description: this attribute value has been added __after__entry creation
216 description: this attribute value will be deleted by Babs (must succeed)
217 description: Bjorn will try to delete this attribute value (should fail)
218 -
219 EOMODS9
220
221 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
222         $TESTOUT 2>&1 << EOMODS10
223 dn: cn=Added by Bjorn (will be deleted),ou=Add/Delete,dc=example,dc=com
224 changetype: delete
225 EOMODS10
226
227 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
228         $TESTOUT 2>&1 << EOMODS11
229 dn: cn=Added by Bjorn (will be renamed),ou=Add/Delete,dc=example,dc=com
230 changetype: modrdn
231 newrdn: cn=Added by Bjorn (renamed by Bjorn)
232 deleteoldrdn: 1
233 EOMODS11
234
235 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
236         $TESTOUT 2>&1 << EOMODS12
237 dn: cn=Added by Bjorn (will be renamed),ou=Add/Delete,dc=example,dc=com
238 changetype: modrdn
239 newrdn: cn=Added by Bjorn (renamed by Babs)
240 deleteoldrdn: 1
241 EOMODS12
242
243 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
244         $TESTOUT 2>&1 << EOMODS13
245 dn: cn=Added by Bjorn (will be renamed),ou=Add/Delete,dc=example,dc=com
246 changetype: modrdn
247 newrdn: cn=Added by Bjorn (renamed by Jaj)
248 deleteoldrdn: 1
249 EOMODS13
250
251 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
252         $TESTOUT 2>&1 << EOMODS14
253 dn: cn=Added by Bjorn (must succeed),ou=Add/Delete,dc=example,dc=com
254 changetype: modify
255 delete: description
256 description: Bjorn will try to delete this attribute value (should fail)
257 -
258 EOMODS14
259
260 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
261         $TESTOUT 2>&1 << EOMODS15
262 dn: cn=Added by Bjorn (will be deleted),ou=Add/Delete,dc=example,dc=com
263 changetype: delete
264
265 dn: cn=Added by Bjorn (must succeed),ou=Add/Delete,dc=example,dc=com
266 changetype: modify
267 delete: description
268 description: this attribute value will be deleted by Babs (must succeed)
269 -
270 EOMODS15
271
272 echo "Using ldapsearch to retrieve all the entries..."
273 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
274 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
275             'objectClass=*' >> $SEARCHOUT 2>&1
276 RC=$?
277 test $KILLSERVERS != no && kill -HUP $KILLPIDS
278 if test $RC != 0 ; then
279         echo "ldapsearch failed ($RC)!"
280         exit $RC
281 fi
282
283 LDIF=$ACLOUTMASTER
284
285 echo "Filtering ldapsearch results..."
286 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
287 echo "Filtering original ldif used to create database..."
288 . $LDIFFILTER < $LDIF > $LDIFFLT
289 echo "Comparing filter output..."
290 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
291
292 if test $? != 0 ; then
293         echo "comparison failed - operations did not complete correctly"
294         exit 1
295 fi
296
297 echo ">>>>> Test succeeded"
298 exit 0