]> git.sur5r.net Git - openldap/blob - tests/scripts/test006-acls
large X (for version.sh)
[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-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.
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 case "$BACKEND" in
17 bdb|hdb|ldbm)
18         ;;
19 *)
20         echo "Test does not support $BACKEND backend"
21         exit 0
22 esac
23
24 echo "running defines.sh"
25 . $SRCDIR/scripts/defines.sh
26
27 mkdir -p $TESTDIR $DBDIR1
28
29 echo "Running slapadd to build slapd database..."
30 . $CONFFILTER $BACKEND $MONITORDB < $ACLCONF > $CONF1
31 $SLAPADD -f $CONF1 -l $LDIFORDERED
32 RC=$?
33 if test $RC != 0 ; then
34         echo "slapadd failed ($RC)!"
35         exit $RC
36 fi
37
38 echo "Starting slapd on TCP/IP port $PORT1..."
39 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
40 PID=$!
41 if test $WAIT != 0 ; then
42     echo PID $PID
43     read foo
44 fi
45 KILLPIDS="$PID"
46
47 sleep 1
48
49 echo "Testing slapd access control..."
50 for i in 0 1 2 3 4 5; do
51         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
52                 'objectclass=*' > /dev/null 2>&1
53         RC=$?
54         if test $RC = 0 ; then
55                 break
56         fi
57         echo "Waiting 5 seconds for slapd to start..."
58         sleep 5
59 done
60
61 if test $RC != 0 ; then
62         echo "ldapsearch failed ($RC)!"
63         test $KILLSERVERS != no && kill -HUP $KILLPIDS
64         exit $RC
65 fi
66
67 cat /dev/null > $SEARCHOUT
68
69 echo "# Try to read an entry inside the Alumni Association container.
70 # It should give us noSuchObject if we're not bound..." \
71 >> $SEARCHOUT
72 # FIXME: temporarily remove the "No such object" message to make
73 # the test succeed even if SLAP_ACL_HONOR_DISCLOSE is not #define'd
74 $LDAPSEARCH -b "$JAJDN" -h $LOCALHOST -p $PORT1 "(objectclass=*)" \
75         2>&1 | grep -v "^No such object" >> $SEARCHOUT
76
77 echo "# ... and should return all attributes if we're bound as anyone
78 # under Example." \
79 >> $SEARCHOUT
80 $LDAPSEARCH -b "$JAJDN" -h $LOCALHOST -p $PORT1 \
81         -D "$BABSDN" -w bjensen "(objectclass=*)"  >> $SEARCHOUT 2>&1
82
83 # check selfwrite access (ITS#4587).  6 attempts are made:
84 # 1) delete someone else (should fail)
85 # 2) delete self (should succeed)
86 # 3) add someone else (should fail)
87 # 4) add someone else and self (should fail)
88 # 5) add self and someone else (should fail)
89 # 6) add self (should succeed)
90 #
91 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
92         $TESTOUT 2>&1 << EOMODS
93 dn: cn=All Staff,ou=Groups,dc=example,dc=com
94 changetype: modify
95 delete: member
96 member: $BABSDN
97 EOMODS
98 RC=$?
99 case $RC in
100 50)
101         ;;
102 0)
103         echo "ldapmodify should have failed ($RC)!"
104         test $KILLSERVERS != no && kill -HUP $KILLPIDS
105         exit -1
106         ;;
107 *)
108         echo "ldapmodify failed ($RC)!"
109         test $KILLSERVERS != no && kill -HUP $KILLPIDS
110         exit $RC
111         ;;
112 esac
113
114 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
115         $TESTOUT 2>&1 << EOMODS
116 dn: cn=All Staff,ou=Groups,dc=example,dc=com
117 changetype: modify
118 delete: member
119 member: $JAJDN
120 EOMODS
121 RC=$?
122 if test $RC != 0 ; then
123         echo "ldapmodify failed ($RC)!"
124         test $KILLSERVERS != no && kill -HUP $KILLPIDS
125         exit $RC
126 fi
127          
128 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
129         $TESTOUT 2>&1 << EOMODS
130 dn: cn=All Staff,ou=Groups,dc=example,dc=com
131 changetype: modify
132 add: member
133 member: cn=Foo,ou=Bar
134 EOMODS
135 RC=$?
136 case $RC in
137 50)
138         ;;
139 0)
140         echo "ldapmodify should have failed ($RC)!"
141         test $KILLSERVERS != no && kill -HUP $KILLPIDS
142         exit -1
143         ;;
144 *)
145         echo "ldapmodify failed ($RC)!"
146         test $KILLSERVERS != no && kill -HUP $KILLPIDS
147         exit $RC
148         ;;
149 esac
150          
151 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
152         $TESTOUT 2>&1 << EOMODS
153 dn: cn=All Staff,ou=Groups,dc=example,dc=com
154 changetype: modify
155 add: member
156 member: cn=Foo,ou=Bar
157 member: $JAJDN
158 EOMODS
159 RC=$?
160 case $RC in
161 50)
162         ;;
163 0)
164         echo "ldapmodify should have failed ($RC)!"
165         test $KILLSERVERS != no && kill -HUP $KILLPIDS
166         exit -1
167         ;;
168 *)
169         echo "ldapmodify failed ($RC)!"
170         test $KILLSERVERS != no && kill -HUP $KILLPIDS
171         exit $RC
172         ;;
173 esac
174          
175 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
176         $TESTOUT 2>&1 << EOMODS
177 dn: cn=All Staff,ou=Groups,dc=example,dc=com
178 changetype: modify
179 add: member
180 member: $JAJDN
181 member: cn=Foo,ou=Bar
182 EOMODS
183 RC=$?
184 case $RC in
185 50)
186         ;;
187 0)
188         echo "ldapmodify should have failed ($RC)!"
189         test $KILLSERVERS != no && kill -HUP $KILLPIDS
190         exit -1
191         ;;
192 *)
193         echo "ldapmodify failed ($RC)!"
194         test $KILLSERVERS != no && kill -HUP $KILLPIDS
195         exit $RC
196         ;;
197 esac
198          
199 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
200         $TESTOUT 2>&1 << EOMODS
201 dn: cn=All Staff,ou=Groups,dc=example,dc=com
202 changetype: modify
203 add: member
204 member: $JAJDN
205 EOMODS
206 RC=$?
207 if test $RC != 0 ; then
208         echo "ldapmodify failed ($RC)!"
209         test $KILLSERVERS != no && kill -HUP $KILLPIDS
210         exit $RC
211 fi
212
213 #
214 # Check group access. Try to modify Babs' entry. Two attempts:
215 # 1) bound as "James A Jones 1" - should fail
216 # 2) bound as "Bjorn Jensen" - should succeed
217
218 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
219         $TESTOUT 2>&1 << EOMODS5
220 dn: $BABSDN
221 changetype: modify
222 replace: drink
223 drink: wine
224
225 EOMODS5
226
227
228 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
229         $TESTOUT 2>&1 << EOMODS6
230 dn: $BABSDN
231 changetype: modify
232 add: homephone
233 homephone: +1 313 555 5444
234
235 EOMODS6
236
237 #
238 # Try to add a "member" attribute to the "ITD Staff" group.  It should
239 # fail when we add some DN other than our own, and should succeed when
240 # we add our own DN.
241 # bjensen
242 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj > \
243         $TESTOUT 2>&1 << EOMODS1
244 version: 1
245 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
246 changetype: modify
247 add: uniquemember
248 uniquemember: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
249
250 EOMODS1
251
252 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
253         $TESTOUT 2>&1 << EOMODS2
254 version: 1
255
256 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
257 changetype: modify
258 add: uniquemember
259 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
260 EOMODS2
261
262 #
263 # Try to modify the "ITD Staff" group.  Two attempts are made:
264 # 1) bound as "James A Jones 1" - should fail
265 # 2) bound as "Bjorn Jensen" - should succeed
266 #
267 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
268         $TESTOUT 2>&1 << EOMODS3
269
270 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
271 changetype: modify
272 delete: description
273
274 EOMODS3
275
276 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
277         $TESTOUT 2>&1 << EOMODS4
278 # COMMENT
279 version: 1
280 # comment
281 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
282 # comment
283 changetype: modify
284 # comment
285 add: ou
286 # comment
287 ou: Groups
288 # comment
289 EOMODS4
290
291 #
292 # Try to modify the "ITD Staff" group.  Two attempts are made:
293 # 1) bound as "James A Jones 1" - should succeed
294 # 2) bound as "Barbara Jensen" - should fail
295 # should exploit sets
296 #
297 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
298         $TESTOUT 2>&1 << EOMODS5
299 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
300 changetype: modify
301 add: description
302 description: added by jaj (should succeed)
303 -
304 EOMODS5
305
306 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
307         $TESTOUT 2>&1 << EOMODS6
308 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
309 changetype: modify
310 add: description
311 description: added by bjensen (should fail)
312 -
313 EOMODS6
314
315 $LDAPMODIFY -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
316         $TESTOUT 2>&1 << EOMODS7
317 dn: ou=Add & Delete,dc=example,dc=com
318 changetype: add
319 objectClass: organizationalUnit
320 ou: Add & Delete
321 EOMODS7
322
323 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
324         $TESTOUT 2>&1 << EOMODS8
325 dn: cn=Added by Babs (must fail),ou=Add & Delete,dc=example,dc=com
326 changetype: add
327 objectClass: inetOrgPerson
328 cn: Added by Babs (must fail)
329 sn: None
330 EOMODS8
331
332 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
333         $TESTOUT 2>&1 << EOMODS9
334 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
335 changetype: add
336 objectClass: inetOrgPerson
337 cn: Added by Bjorn (must succeed)
338 sn: None
339
340 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
341 changetype: add
342 objectClass: inetOrgPerson
343 cn: Added by Bjorn (will be deleted)
344 sn: None
345
346 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
347 changetype: add
348 objectClass: inetOrgPerson
349 cn: Added by Bjorn (will be renamed)
350 sn: None
351
352 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
353 changetype: modify
354 add: description
355 description: this attribute value has been added __after__entry creation
356 description: this attribute value will be deleted by Babs (must succeed)
357 description: Bjorn will try to delete this attribute value (should fail)
358 -
359 EOMODS9
360
361 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
362         $TESTOUT 2>&1 << EOMODS10
363 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
364 changetype: delete
365 EOMODS10
366
367 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
368         $TESTOUT 2>&1 << EOMODS11
369 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
370 changetype: modrdn
371 newrdn: cn=Added by Bjorn (renamed by Bjorn)
372 deleteoldrdn: 1
373 EOMODS11
374
375 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
376         $TESTOUT 2>&1 << EOMODS12
377 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
378 changetype: modrdn
379 newrdn: cn=Added by Bjorn (renamed by Babs)
380 deleteoldrdn: 1
381 EOMODS12
382
383 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
384         $TESTOUT 2>&1 << EOMODS13
385 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
386 changetype: modrdn
387 newrdn: cn=Added by Bjorn (renamed by Jaj)
388 deleteoldrdn: 1
389 EOMODS13
390
391 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
392         $TESTOUT 2>&1 << EOMODS14
393 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
394 changetype: modify
395 delete: description
396 description: Bjorn will try to delete this attribute value (should fail)
397 -
398 EOMODS14
399
400 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
401         $TESTOUT 2>&1 << EOMODS15
402 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
403 changetype: delete
404
405 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
406 changetype: modify
407 delete: description
408 description: this attribute value will be deleted by Babs (must succeed)
409 -
410 EOMODS15
411
412 echo "Using ldapsearch to retrieve all the entries..."
413 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
414 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
415             'objectClass=*' >> $SEARCHOUT 2>&1
416 RC=$?
417 test $KILLSERVERS != no && kill -HUP $KILLPIDS
418 if test $RC != 0 ; then
419         echo "ldapsearch failed ($RC)!"
420         exit $RC
421 fi
422
423 LDIF=$ACLOUTMASTER
424
425 echo "Filtering ldapsearch results..."
426 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
427 echo "Filtering original ldif used to create database..."
428 . $LDIFFILTER < $LDIF > $LDIFFLT
429 echo "Comparing filter output..."
430 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
431
432 if test $? != 0 ; then
433         echo "comparison failed - operations did not complete correctly"
434         exit 1
435 fi
436
437 echo ">>>>> Test succeeded"
438 exit 0