]> git.sur5r.net Git - openldap/blob - tests/scripts/test006-acls
test for ITS#4587; another bit of fix for that
[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-2006 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)
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 # ITS#4253, ITS#4255
84 echo "# Checking exact/regex attrval clause" >> $SEARCHOUT
85 $LDAPSEARCH -h $LOCALHOST -p $PORT1 \
86         -D "$BABSDN" -w bjensen \
87         -b "$MELLIOTDN" -s base "(objectclass=*)" cn >> $SEARCHOUT 2>&1
88 $LDAPSEARCH -h $LOCALHOST -p $PORT1 \
89         -D "$BJORNSDN" -w bjorn \
90         -b "$MELLIOTDN" -s base "(objectclass=*)" cn >> $SEARCHOUT 2>&1
91
92 $LDAPSEARCH -h $LOCALHOST -p $PORT1 \
93         -D "$BABSDN" -w bjensen \
94         -b "$JOHNDDN" -s base "(objectclass=*)" cn >> $SEARCHOUT 2>&1
95 $LDAPSEARCH -h $LOCALHOST -p $PORT1 \
96         -D "$BJORNSDN" -w bjorn \
97         -b "$JOHNDDN" -s base "(objectclass=*)" cn >> $SEARCHOUT 2>&1
98
99 $LDAPSEARCH -h $LOCALHOST -p $PORT1 \
100         -D "$BABSDN" -w bjensen \
101         -b "$BJORNSDN" -s base "(objectclass=*)" cn >> $SEARCHOUT 2>&1
102 $LDAPSEARCH -h $LOCALHOST -p $PORT1 \
103         -D "$BJORNSDN" -w bjorn \
104         -b "$BABSDN" -s base "(objectclass=*)" cn >> $SEARCHOUT 2>&1
105
106 # check selfwrite access (ITS#4587).  Two attempts are made:
107 # 1) delete someone else (should fail)
108 # 2) delete self (should succeed)
109 #
110 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
111         $TESTOUT 2>&1 << EOMODS
112 dn: cn=All Staff,ou=Groups,dc=example,dc=com
113 changetype: modify
114 delete: member
115 member: $BABSDN
116 EOMODS
117 RC=$?
118 case $RC in
119 50)
120         ;;
121 0)
122         echo "ldapmodify should have failed ($RC)!"
123         test $KILLSERVERS != no && kill -HUP $KILLPIDS
124         exit -1
125         ;;
126 *)
127         echo "ldapmodify failed ($RC)!"
128         test $KILLSERVERS != no && kill -HUP $KILLPIDS
129         exit $RC
130         ;;
131 esac
132
133 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
134         $TESTOUT 2>&1 << EOMODS
135 dn: cn=All Staff,ou=Groups,dc=example,dc=com
136 changetype: modify
137 delete: member
138 member: $JAJDN
139 EOMODS
140 RC=$?
141 if test $RC != 0 ; then
142         echo "ldapmodify failed ($RC)!"
143         test $KILLSERVERS != no && kill -HUP $KILLPIDS
144         exit $RC
145 fi
146
147 #
148 # Check group access. Try to modify Babs' entry. Two attempts:
149 # 1) bound as "James A Jones 1" - should fail
150 # 2) bound as "Bjorn Jensen" - should succeed
151
152 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
153         $TESTOUT 2>&1 << EOMODS5
154 dn: $BABSDN
155 changetype: modify
156 replace: drink
157 drink: wine
158 EOMODS5
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 "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
176         $TESTOUT 2>&1 << EOMODS6
177 dn: $BABSDN
178 changetype: modify
179 add: homephone
180 homephone: +1 313 555 5444
181 EOMODS6
182 RC=$?
183 case $RC in
184 0)
185         ;;
186 *)
187         echo "ldapmodify failed ($RC)!"
188         test $KILLSERVERS != no && kill -HUP $KILLPIDS
189         exit $RC
190         ;;
191 esac
192
193 #
194 # Try to add a "member" attribute to the "ITD Staff" group.  It should
195 # fail when we add some DN other than our own, and should succeed when
196 # we add our own DN.
197 # bjensen
198 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj > \
199         $TESTOUT 2>&1 << EOMODS1
200 version: 1
201 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
202 changetype: modify
203 add: uniquemember
204 uniquemember: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
205 EOMODS1
206 RC=$?
207 case $RC in
208 50)
209         ;;
210 0)
211         echo "ldapmodify should have failed ($RC)!"
212         test $KILLSERVERS != no && kill -HUP $KILLPIDS
213         exit -1
214         ;;
215 *)
216         echo "ldapmodify failed ($RC)!"
217         test $KILLSERVERS != no && kill -HUP $KILLPIDS
218         exit $RC
219         ;;
220 esac
221
222 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
223         $TESTOUT 2>&1 << EOMODS2
224 version: 1
225
226 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
227 changetype: modify
228 add: uniquemember
229 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
230 EOMODS2
231 RC=$?
232 case $RC in
233 0)
234         ;;
235 *)
236         echo "ldapmodify failed ($RC)!"
237         test $KILLSERVERS != no && kill -HUP $KILLPIDS
238         exit $RC
239         ;;
240 esac
241
242 #
243 # Try to modify the "ITD Staff" group.  Two attempts are made:
244 # 1) bound as "James A Jones 1" - should fail
245 # 2) bound as "Bjorn Jensen" - should succeed
246 #
247 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
248         $TESTOUT 2>&1 << EOMODS3
249
250 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
251 changetype: modify
252 delete: description
253 EOMODS3
254 RC=$?
255 case $RC in
256 50)
257         ;;
258 0)
259         echo "ldapmodify should have failed ($RC)!"
260         test $KILLSERVERS != no && kill -HUP $KILLPIDS
261         exit -1
262         ;;
263 *)
264         echo "ldapmodify failed ($RC)!"
265         test $KILLSERVERS != no && kill -HUP $KILLPIDS
266         exit $RC
267         ;;
268 esac
269
270 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
271         $TESTOUT 2>&1 << EOMODS4
272 # COMMENT
273 version: 1
274 # comment
275 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
276 # comment
277 changetype: modify
278 # comment
279 add: ou
280 # comment
281 ou: Groups
282 # comment
283 EOMODS4
284 RC=$?
285 case $RC in
286 0)
287         ;;
288 *)
289         echo "ldapmodify failed ($RC)!"
290         test $KILLSERVERS != no && kill -HUP $KILLPIDS
291         exit $RC
292         ;;
293 esac
294
295 #
296 # Try to modify the "ITD Staff" group.  Two attempts are made:
297 # 1) bound as "James A Jones 1" - should succeed
298 # 2) bound as "Barbara Jensen" - should fail
299 # should exploit sets
300 #
301 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
302         $TESTOUT 2>&1 << EOMODS5
303 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
304 changetype: modify
305 add: description
306 description: added by jaj (should succeed)
307 -
308 EOMODS5
309 RC=$?
310 case $RC in
311 0)
312         ;;
313 *)
314         echo "ldapmodify failed ($RC)!"
315         test $KILLSERVERS != no && kill -HUP $KILLPIDS
316         exit $RC
317         ;;
318 esac
319
320 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
321         $TESTOUT 2>&1 << EOMODS6
322 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
323 changetype: modify
324 add: description
325 description: added by bjensen (should fail)
326 -
327 EOMODS6
328 RC=$?
329 case $RC in
330 50)
331         ;;
332 0)
333         echo "ldapmodify should have failed ($RC)!"
334         test $KILLSERVERS != no && kill -HUP $KILLPIDS
335         exit -1
336         ;;
337 *)
338         echo "ldapmodify failed ($RC)!"
339         test $KILLSERVERS != no && kill -HUP $KILLPIDS
340         exit $RC
341         ;;
342 esac
343
344 $LDAPMODIFY -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
345         $TESTOUT 2>&1 << EOMODS7
346 dn: ou=Add & Delete,dc=example,dc=com
347 changetype: add
348 objectClass: organizationalUnit
349 ou: Add & Delete
350 EOMODS7
351 RC=$?
352 if test $RC != 0 ; then
353         echo "ldapmodify failed ($RC)!"
354         test $KILLSERVERS != no && kill -HUP $KILLPIDS
355         exit $RC
356 fi
357
358 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
359         $TESTOUT 2>&1 << EOMODS8
360 dn: cn=Added by Babs (must fail),ou=Add & Delete,dc=example,dc=com
361 changetype: add
362 objectClass: inetOrgPerson
363 cn: Added by Babs (must fail)
364 sn: None
365 EOMODS8
366 RC=$?
367 case $RC in
368 50)
369         ;;
370 0)
371         echo "ldapmodify should have failed ($RC)!"
372         test $KILLSERVERS != no && kill -HUP $KILLPIDS
373         exit -1
374         ;;
375 *)
376         echo "ldapmodify failed ($RC)!"
377         test $KILLSERVERS != no && kill -HUP $KILLPIDS
378         exit $RC
379         ;;
380 esac
381
382 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
383         $TESTOUT 2>&1 << EOMODS9
384 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
385 changetype: add
386 objectClass: inetOrgPerson
387 cn: Added by Bjorn (must succeed)
388 sn: None
389
390 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
391 changetype: add
392 objectClass: inetOrgPerson
393 cn: Added by Bjorn (will be deleted)
394 sn: None
395
396 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
397 changetype: add
398 objectClass: inetOrgPerson
399 cn: Added by Bjorn (will be renamed)
400 sn: None
401
402 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
403 changetype: modify
404 add: description
405 description: this attribute value has been added __after__entry creation
406 description: this attribute value will be deleted by Babs (must succeed)
407 description: Bjorn will try to delete this attribute value (should fail)
408 -
409 EOMODS9
410 RC=$?
411 case $RC in
412 0)
413         ;;
414 *)
415         echo "ldapmodify failed ($RC)!"
416         test $KILLSERVERS != no && kill -HUP $KILLPIDS
417         exit $RC
418         ;;
419 esac
420
421 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
422         $TESTOUT 2>&1 << EOMODS10
423 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
424 changetype: delete
425 EOMODS10
426 RC=$?
427 case $RC in
428 50)
429         ;;
430 0)
431         echo "ldapmodify should have failed ($RC)!"
432         test $KILLSERVERS != no && kill -HUP $KILLPIDS
433         exit -1
434         ;;
435 *)
436         echo "ldapmodify failed ($RC)!"
437         test $KILLSERVERS != no && kill -HUP $KILLPIDS
438         exit $RC
439         ;;
440 esac
441
442 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
443         $TESTOUT 2>&1 << EOMODS11
444 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
445 changetype: modrdn
446 newrdn: cn=Added by Bjorn (renamed by Bjorn)
447 deleteoldrdn: 1
448 EOMODS11
449 RC=$?
450 case $RC in
451 50)
452         ;;
453 0)
454         echo "ldapmodify should have failed ($RC)!"
455         test $KILLSERVERS != no && kill -HUP $KILLPIDS
456         exit -1
457         ;;
458 *)
459         echo "ldapmodify failed ($RC)!"
460         test $KILLSERVERS != no && kill -HUP $KILLPIDS
461         exit $RC
462         ;;
463 esac
464
465 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
466         $TESTOUT 2>&1 << EOMODS12
467 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
468 changetype: modrdn
469 newrdn: cn=Added by Bjorn (renamed by Babs)
470 deleteoldrdn: 1
471 EOMODS12
472 RC=$?
473 case $RC in
474 50)
475         ;;
476 0)
477         echo "ldapmodify should have failed ($RC)!"
478         test $KILLSERVERS != no && kill -HUP $KILLPIDS
479         exit -1
480         ;;
481 *)
482         echo "ldapmodify failed ($RC)!"
483         test $KILLSERVERS != no && kill -HUP $KILLPIDS
484         exit $RC
485         ;;
486 esac
487
488 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
489         $TESTOUT 2>&1 << EOMODS13
490 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
491 changetype: modrdn
492 newrdn: cn=Added by Bjorn (renamed by Jaj)
493 deleteoldrdn: 1
494 EOMODS13
495 RC=$?
496 case $RC in
497 0)
498         ;;
499 *)
500         echo "ldapmodify failed ($RC)!"
501         test $KILLSERVERS != no && kill -HUP $KILLPIDS
502         exit $RC
503         ;;
504 esac
505
506 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
507         $TESTOUT 2>&1 << EOMODS14
508 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
509 changetype: modify
510 delete: description
511 description: Bjorn will try to delete this attribute value (should fail)
512 -
513 EOMODS14
514 RC=$?
515 case $RC in
516 50)
517         ;;
518 0)
519         echo "ldapmodify should have failed ($RC)!"
520         test $KILLSERVERS != no && kill -HUP $KILLPIDS
521         exit -1
522         ;;
523 *)
524         echo "ldapmodify failed ($RC)!"
525         test $KILLSERVERS != no && kill -HUP $KILLPIDS
526         exit $RC
527         ;;
528 esac
529
530 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
531         $TESTOUT 2>&1 << EOMODS15
532 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
533 changetype: delete
534
535 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
536 changetype: modify
537 delete: description
538 description: this attribute value will be deleted by Babs (must succeed)
539 -
540 EOMODS15
541 RC=$?
542 case $RC in
543 0)
544         ;;
545 *)
546         echo "ldapmodify failed ($RC)!"
547         test $KILLSERVERS != no && kill -HUP $KILLPIDS
548         exit $RC
549         ;;
550 esac
551
552 echo "Using ldapsearch to retrieve all the entries..."
553 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
554 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
555             'objectClass=*' >> $SEARCHOUT 2>&1
556 RC=$?
557 test $KILLSERVERS != no && kill -HUP $KILLPIDS
558 if test $RC != 0 ; then
559         echo "ldapsearch failed ($RC)!"
560         exit $RC
561 fi
562
563 LDIF=$ACLOUTMASTER
564
565 echo "Filtering ldapsearch results..."
566 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
567 echo "Filtering original ldif used to create database..."
568 . $LDIFFILTER < $LDIF > $LDIFFLT
569 echo "Comparing filter output..."
570 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
571
572 if test $? != 0 ; then
573         echo "comparison failed - operations did not complete correctly"
574         exit 1
575 fi
576
577 echo ">>>>> Test succeeded"
578
579 test $KILLSERVERS != no && wait
580
581 exit 0