]> git.sur5r.net Git - openldap/blob - tests/scripts/test006-acls
further checks for ITS#4587
[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).  6 attempts are made:
107 # 1) delete someone else (should fail)
108 # 2) delete self (should succeed)
109 # 3) add someone else (should fail)
110 # 4) add someone else and self (should fail)
111 # 5) add self and someone else (should fail)
112 # 6) add self (should succeed)
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: $BABSDN
120 EOMODS
121 RC=$?
122 case $RC in
123 50)
124         ;;
125 0)
126         echo "ldapmodify should have failed ($RC)!"
127         test $KILLSERVERS != no && kill -HUP $KILLPIDS
128         exit -1
129         ;;
130 *)
131         echo "ldapmodify failed ($RC)!"
132         test $KILLSERVERS != no && kill -HUP $KILLPIDS
133         exit $RC
134         ;;
135 esac
136
137 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
138         $TESTOUT 2>&1 << EOMODS
139 dn: cn=All Staff,ou=Groups,dc=example,dc=com
140 changetype: modify
141 delete: member
142 member: $JAJDN
143 EOMODS
144 RC=$?
145 if test $RC != 0 ; then
146         echo "ldapmodify failed ($RC)!"
147         test $KILLSERVERS != no && kill -HUP $KILLPIDS
148         exit $RC
149 fi
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 EOMODS
158 RC=$?
159 case $RC in
160 50)
161         ;;
162 0)
163         echo "ldapmodify should have failed ($RC)!"
164         test $KILLSERVERS != no && kill -HUP $KILLPIDS
165         exit -1
166         ;;
167 *)
168         echo "ldapmodify failed ($RC)!"
169         test $KILLSERVERS != no && kill -HUP $KILLPIDS
170         exit $RC
171         ;;
172 esac
173
174 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
175         $TESTOUT 2>&1 << EOMODS
176 dn: cn=All Staff,ou=Groups,dc=example,dc=com
177 changetype: modify
178 add: member
179 member: cn=Foo,ou=Bar
180 member: $JAJDN
181 EOMODS
182 RC=$?
183 case $RC in
184 50)
185         ;;
186 0)
187         echo "ldapmodify should have failed ($RC)!"
188         test $KILLSERVERS != no && kill -HUP $KILLPIDS
189         exit -1
190         ;;
191 *)
192         echo "ldapmodify failed ($RC)!"
193         test $KILLSERVERS != no && kill -HUP $KILLPIDS
194         exit $RC
195         ;;
196 esac
197
198 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
199         $TESTOUT 2>&1 << EOMODS
200 dn: cn=All Staff,ou=Groups,dc=example,dc=com
201 changetype: modify
202 add: member
203 member: $JAJDN
204 member: cn=Foo,ou=Bar
205 EOMODS
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 << EOMODS
224 dn: cn=All Staff,ou=Groups,dc=example,dc=com
225 changetype: modify
226 add: member
227 member: $JAJDN
228 EOMODS
229 RC=$?
230 if test $RC != 0 ; then
231         echo "ldapmodify failed ($RC)!"
232         test $KILLSERVERS != no && kill -HUP $KILLPIDS
233         exit $RC
234 fi
235
236 #
237 # Check group access. Try to modify Babs' entry. Two attempts:
238 # 1) bound as "James A Jones 1" - should fail
239 # 2) bound as "Bjorn Jensen" - should succeed
240
241 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
242         $TESTOUT 2>&1 << EOMODS5
243 dn: $BABSDN
244 changetype: modify
245 replace: drink
246 drink: wine
247 EOMODS5
248 RC=$?
249 case $RC in
250 50)
251         ;;
252 0)
253         echo "ldapmodify should have failed ($RC)!"
254         test $KILLSERVERS != no && kill -HUP $KILLPIDS
255         exit -1
256         ;;
257 *)
258         echo "ldapmodify failed ($RC)!"
259         test $KILLSERVERS != no && kill -HUP $KILLPIDS
260         exit $RC
261         ;;
262 esac
263
264 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
265         $TESTOUT 2>&1 << EOMODS6
266 dn: $BABSDN
267 changetype: modify
268 add: homephone
269 homephone: +1 313 555 5444
270 EOMODS6
271 RC=$?
272 case $RC in
273 0)
274         ;;
275 *)
276         echo "ldapmodify failed ($RC)!"
277         test $KILLSERVERS != no && kill -HUP $KILLPIDS
278         exit $RC
279         ;;
280 esac
281
282 #
283 # Try to add a "member" attribute to the "ITD Staff" group.  It should
284 # fail when we add some DN other than our own, and should succeed when
285 # we add our own DN.
286 # bjensen
287 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj > \
288         $TESTOUT 2>&1 << EOMODS1
289 version: 1
290 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
291 changetype: modify
292 add: uniquemember
293 uniquemember: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
294 EOMODS1
295 RC=$?
296 case $RC in
297 50)
298         ;;
299 0)
300         echo "ldapmodify should have failed ($RC)!"
301         test $KILLSERVERS != no && kill -HUP $KILLPIDS
302         exit -1
303         ;;
304 *)
305         echo "ldapmodify failed ($RC)!"
306         test $KILLSERVERS != no && kill -HUP $KILLPIDS
307         exit $RC
308         ;;
309 esac
310
311 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
312         $TESTOUT 2>&1 << EOMODS2
313 version: 1
314
315 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
316 changetype: modify
317 add: uniquemember
318 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
319 EOMODS2
320 RC=$?
321 case $RC in
322 0)
323         ;;
324 *)
325         echo "ldapmodify failed ($RC)!"
326         test $KILLSERVERS != no && kill -HUP $KILLPIDS
327         exit $RC
328         ;;
329 esac
330
331 #
332 # Try to modify the "ITD Staff" group.  Two attempts are made:
333 # 1) bound as "James A Jones 1" - should fail
334 # 2) bound as "Bjorn Jensen" - should succeed
335 #
336 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
337         $TESTOUT 2>&1 << EOMODS3
338
339 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
340 changetype: modify
341 delete: description
342 EOMODS3
343 RC=$?
344 case $RC in
345 50)
346         ;;
347 0)
348         echo "ldapmodify should have failed ($RC)!"
349         test $KILLSERVERS != no && kill -HUP $KILLPIDS
350         exit -1
351         ;;
352 *)
353         echo "ldapmodify failed ($RC)!"
354         test $KILLSERVERS != no && kill -HUP $KILLPIDS
355         exit $RC
356         ;;
357 esac
358
359 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
360         $TESTOUT 2>&1 << EOMODS4
361 # COMMENT
362 version: 1
363 # comment
364 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
365 # comment
366 changetype: modify
367 # comment
368 add: ou
369 # comment
370 ou: Groups
371 # comment
372 EOMODS4
373 RC=$?
374 case $RC in
375 0)
376         ;;
377 *)
378         echo "ldapmodify failed ($RC)!"
379         test $KILLSERVERS != no && kill -HUP $KILLPIDS
380         exit $RC
381         ;;
382 esac
383
384 #
385 # Try to modify the "ITD Staff" group.  Two attempts are made:
386 # 1) bound as "James A Jones 1" - should succeed
387 # 2) bound as "Barbara Jensen" - should fail
388 # should exploit sets
389 #
390 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
391         $TESTOUT 2>&1 << EOMODS5
392 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
393 changetype: modify
394 add: description
395 description: added by jaj (should succeed)
396 -
397 EOMODS5
398 RC=$?
399 case $RC in
400 0)
401         ;;
402 *)
403         echo "ldapmodify failed ($RC)!"
404         test $KILLSERVERS != no && kill -HUP $KILLPIDS
405         exit $RC
406         ;;
407 esac
408
409 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
410         $TESTOUT 2>&1 << EOMODS6
411 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
412 changetype: modify
413 add: description
414 description: added by bjensen (should fail)
415 -
416 EOMODS6
417 RC=$?
418 case $RC in
419 50)
420         ;;
421 0)
422         echo "ldapmodify should have failed ($RC)!"
423         test $KILLSERVERS != no && kill -HUP $KILLPIDS
424         exit -1
425         ;;
426 *)
427         echo "ldapmodify failed ($RC)!"
428         test $KILLSERVERS != no && kill -HUP $KILLPIDS
429         exit $RC
430         ;;
431 esac
432
433 $LDAPMODIFY -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
434         $TESTOUT 2>&1 << EOMODS7
435 dn: ou=Add & Delete,dc=example,dc=com
436 changetype: add
437 objectClass: organizationalUnit
438 ou: Add & Delete
439 EOMODS7
440 RC=$?
441 if test $RC != 0 ; then
442         echo "ldapmodify failed ($RC)!"
443         test $KILLSERVERS != no && kill -HUP $KILLPIDS
444         exit $RC
445 fi
446
447 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
448         $TESTOUT 2>&1 << EOMODS8
449 dn: cn=Added by Babs (must fail),ou=Add & Delete,dc=example,dc=com
450 changetype: add
451 objectClass: inetOrgPerson
452 cn: Added by Babs (must fail)
453 sn: None
454 EOMODS8
455 RC=$?
456 case $RC in
457 50)
458         ;;
459 0)
460         echo "ldapmodify should have failed ($RC)!"
461         test $KILLSERVERS != no && kill -HUP $KILLPIDS
462         exit -1
463         ;;
464 *)
465         echo "ldapmodify failed ($RC)!"
466         test $KILLSERVERS != no && kill -HUP $KILLPIDS
467         exit $RC
468         ;;
469 esac
470
471 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
472         $TESTOUT 2>&1 << EOMODS9
473 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
474 changetype: add
475 objectClass: inetOrgPerson
476 cn: Added by Bjorn (must succeed)
477 sn: None
478
479 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
480 changetype: add
481 objectClass: inetOrgPerson
482 cn: Added by Bjorn (will be deleted)
483 sn: None
484
485 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
486 changetype: add
487 objectClass: inetOrgPerson
488 cn: Added by Bjorn (will be renamed)
489 sn: None
490
491 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
492 changetype: modify
493 add: description
494 description: this attribute value has been added __after__entry creation
495 description: this attribute value will be deleted by Babs (must succeed)
496 description: Bjorn will try to delete this attribute value (should fail)
497 -
498 EOMODS9
499 RC=$?
500 case $RC in
501 0)
502         ;;
503 *)
504         echo "ldapmodify failed ($RC)!"
505         test $KILLSERVERS != no && kill -HUP $KILLPIDS
506         exit $RC
507         ;;
508 esac
509
510 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
511         $TESTOUT 2>&1 << EOMODS10
512 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
513 changetype: delete
514 EOMODS10
515 RC=$?
516 case $RC in
517 50)
518         ;;
519 0)
520         echo "ldapmodify should have failed ($RC)!"
521         test $KILLSERVERS != no && kill -HUP $KILLPIDS
522         exit -1
523         ;;
524 *)
525         echo "ldapmodify failed ($RC)!"
526         test $KILLSERVERS != no && kill -HUP $KILLPIDS
527         exit $RC
528         ;;
529 esac
530
531 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
532         $TESTOUT 2>&1 << EOMODS11
533 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
534 changetype: modrdn
535 newrdn: cn=Added by Bjorn (renamed by Bjorn)
536 deleteoldrdn: 1
537 EOMODS11
538 RC=$?
539 case $RC in
540 50)
541         ;;
542 0)
543         echo "ldapmodify should have failed ($RC)!"
544         test $KILLSERVERS != no && kill -HUP $KILLPIDS
545         exit -1
546         ;;
547 *)
548         echo "ldapmodify failed ($RC)!"
549         test $KILLSERVERS != no && kill -HUP $KILLPIDS
550         exit $RC
551         ;;
552 esac
553
554 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
555         $TESTOUT 2>&1 << EOMODS12
556 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
557 changetype: modrdn
558 newrdn: cn=Added by Bjorn (renamed by Babs)
559 deleteoldrdn: 1
560 EOMODS12
561 RC=$?
562 case $RC in
563 50)
564         ;;
565 0)
566         echo "ldapmodify should have failed ($RC)!"
567         test $KILLSERVERS != no && kill -HUP $KILLPIDS
568         exit -1
569         ;;
570 *)
571         echo "ldapmodify failed ($RC)!"
572         test $KILLSERVERS != no && kill -HUP $KILLPIDS
573         exit $RC
574         ;;
575 esac
576
577 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
578         $TESTOUT 2>&1 << EOMODS13
579 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
580 changetype: modrdn
581 newrdn: cn=Added by Bjorn (renamed by Jaj)
582 deleteoldrdn: 1
583 EOMODS13
584 RC=$?
585 case $RC in
586 0)
587         ;;
588 *)
589         echo "ldapmodify failed ($RC)!"
590         test $KILLSERVERS != no && kill -HUP $KILLPIDS
591         exit $RC
592         ;;
593 esac
594
595 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
596         $TESTOUT 2>&1 << EOMODS14
597 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
598 changetype: modify
599 delete: description
600 description: Bjorn will try to delete this attribute value (should fail)
601 -
602 EOMODS14
603 RC=$?
604 case $RC in
605 50)
606         ;;
607 0)
608         echo "ldapmodify should have failed ($RC)!"
609         test $KILLSERVERS != no && kill -HUP $KILLPIDS
610         exit -1
611         ;;
612 *)
613         echo "ldapmodify failed ($RC)!"
614         test $KILLSERVERS != no && kill -HUP $KILLPIDS
615         exit $RC
616         ;;
617 esac
618
619 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
620         $TESTOUT 2>&1 << EOMODS15
621 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
622 changetype: delete
623
624 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
625 changetype: modify
626 delete: description
627 description: this attribute value will be deleted by Babs (must succeed)
628 -
629 EOMODS15
630 RC=$?
631 case $RC in
632 0)
633         ;;
634 *)
635         echo "ldapmodify failed ($RC)!"
636         test $KILLSERVERS != no && kill -HUP $KILLPIDS
637         exit $RC
638         ;;
639 esac
640
641 echo "Using ldapsearch to retrieve all the entries..."
642 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
643 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
644             'objectClass=*' >> $SEARCHOUT 2>&1
645 RC=$?
646 test $KILLSERVERS != no && kill -HUP $KILLPIDS
647 if test $RC != 0 ; then
648         echo "ldapsearch failed ($RC)!"
649         exit $RC
650 fi
651
652 LDIF=$ACLOUTMASTER
653
654 echo "Filtering ldapsearch results..."
655 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
656 echo "Filtering original ldif used to create database..."
657 . $LDIFFILTER < $LDIF > $LDIFFLT
658 echo "Comparing filter output..."
659 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
660
661 if test $? != 0 ; then
662         echo "comparison failed - operations did not complete correctly"
663         exit 1
664 fi
665
666 echo ">>>>> Test succeeded"
667
668 test $KILLSERVERS != no && wait
669
670 exit 0