Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / tests / scripts / test006-acls
blob64befc783c21dee0a6bb6db79aa68fe5640b9b01
1 #! /bin/sh
2 # $OpenLDAP: pkg/ldap/tests/scripts/test006-acls,v 1.59.2.5 2008/02/11 23:26:51 kurt Exp $
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.
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>.
16 case "$BACKEND" in
17 bdb|hdb)
20 echo "Test does not support $BACKEND backend"
21 exit 0
22 esac
24 echo "running defines.sh"
25 . $SRCDIR/scripts/defines.sh
27 mkdir -p $TESTDIR $DBDIR1
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
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
45 KILLPIDS="$PID"
47 sleep 1
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
57 echo "Waiting 5 seconds for slapd to start..."
58 sleep 5
59 done
61 if test $RC != 0 ; then
62 echo "ldapsearch failed ($RC)!"
63 test $KILLSERVERS != no && kill -HUP $KILLPIDS
64 exit $RC
67 cat /dev/null > $SEARCHOUT
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
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
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
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
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
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)
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
126 echo "ldapmodify should have failed ($RC)!"
127 test $KILLSERVERS != no && kill -HUP $KILLPIDS
128 exit -1
131 echo "ldapmodify failed ($RC)!"
132 test $KILLSERVERS != no && kill -HUP $KILLPIDS
133 exit $RC
135 esac
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
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
163 echo "ldapmodify should have failed ($RC)!"
164 test $KILLSERVERS != no && kill -HUP $KILLPIDS
165 exit -1
168 echo "ldapmodify failed ($RC)!"
169 test $KILLSERVERS != no && kill -HUP $KILLPIDS
170 exit $RC
172 esac
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
187 echo "ldapmodify should have failed ($RC)!"
188 test $KILLSERVERS != no && kill -HUP $KILLPIDS
189 exit -1
192 echo "ldapmodify failed ($RC)!"
193 test $KILLSERVERS != no && kill -HUP $KILLPIDS
194 exit $RC
196 esac
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
211 echo "ldapmodify should have failed ($RC)!"
212 test $KILLSERVERS != no && kill -HUP $KILLPIDS
213 exit -1
216 echo "ldapmodify failed ($RC)!"
217 test $KILLSERVERS != no && kill -HUP $KILLPIDS
218 exit $RC
220 esac
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
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
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
253 echo "ldapmodify should have failed ($RC)!"
254 test $KILLSERVERS != no && kill -HUP $KILLPIDS
255 exit -1
258 echo "ldapmodify failed ($RC)!"
259 test $KILLSERVERS != no && kill -HUP $KILLPIDS
260 exit $RC
262 esac
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
276 echo "ldapmodify failed ($RC)!"
277 test $KILLSERVERS != no && kill -HUP $KILLPIDS
278 exit $RC
280 esac
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
300 echo "ldapmodify should have failed ($RC)!"
301 test $KILLSERVERS != no && kill -HUP $KILLPIDS
302 exit -1
305 echo "ldapmodify failed ($RC)!"
306 test $KILLSERVERS != no && kill -HUP $KILLPIDS
307 exit $RC
309 esac
311 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
312 $TESTOUT 2>&1 << EOMODS2
313 version: 1
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
325 echo "ldapmodify failed ($RC)!"
326 test $KILLSERVERS != no && kill -HUP $KILLPIDS
327 exit $RC
329 esac
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
336 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
337 $TESTOUT 2>&1 << EOMODS3
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
348 echo "ldapmodify should have failed ($RC)!"
349 test $KILLSERVERS != no && kill -HUP $KILLPIDS
350 exit -1
353 echo "ldapmodify failed ($RC)!"
354 test $KILLSERVERS != no && kill -HUP $KILLPIDS
355 exit $RC
357 esac
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
378 echo "ldapmodify failed ($RC)!"
379 test $KILLSERVERS != no && kill -HUP $KILLPIDS
380 exit $RC
382 esac
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
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)
397 EOMODS5
398 RC=$?
399 case $RC in
403 echo "ldapmodify failed ($RC)!"
404 test $KILLSERVERS != no && kill -HUP $KILLPIDS
405 exit $RC
407 esac
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)
416 EOMODS6
417 RC=$?
418 case $RC in
422 echo "ldapmodify should have failed ($RC)!"
423 test $KILLSERVERS != no && kill -HUP $KILLPIDS
424 exit -1
427 echo "ldapmodify failed ($RC)!"
428 test $KILLSERVERS != no && kill -HUP $KILLPIDS
429 exit $RC
431 esac
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
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
460 echo "ldapmodify should have failed ($RC)!"
461 test $KILLSERVERS != no && kill -HUP $KILLPIDS
462 exit -1
465 echo "ldapmodify failed ($RC)!"
466 test $KILLSERVERS != no && kill -HUP $KILLPIDS
467 exit $RC
469 esac
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
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
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
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)
498 EOMODS9
499 RC=$?
500 case $RC in
504 echo "ldapmodify failed ($RC)!"
505 test $KILLSERVERS != no && kill -HUP $KILLPIDS
506 exit $RC
508 esac
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
520 echo "ldapmodify should have failed ($RC)!"
521 test $KILLSERVERS != no && kill -HUP $KILLPIDS
522 exit -1
525 echo "ldapmodify failed ($RC)!"
526 test $KILLSERVERS != no && kill -HUP $KILLPIDS
527 exit $RC
529 esac
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
543 echo "ldapmodify should have failed ($RC)!"
544 test $KILLSERVERS != no && kill -HUP $KILLPIDS
545 exit -1
548 echo "ldapmodify failed ($RC)!"
549 test $KILLSERVERS != no && kill -HUP $KILLPIDS
550 exit $RC
552 esac
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
566 echo "ldapmodify should have failed ($RC)!"
567 test $KILLSERVERS != no && kill -HUP $KILLPIDS
568 exit -1
571 echo "ldapmodify failed ($RC)!"
572 test $KILLSERVERS != no && kill -HUP $KILLPIDS
573 exit $RC
575 esac
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
589 echo "ldapmodify failed ($RC)!"
590 test $KILLSERVERS != no && kill -HUP $KILLPIDS
591 exit $RC
593 esac
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)
602 EOMODS14
603 RC=$?
604 case $RC in
608 echo "ldapmodify should have failed ($RC)!"
609 test $KILLSERVERS != no && kill -HUP $KILLPIDS
610 exit -1
613 echo "ldapmodify failed ($RC)!"
614 test $KILLSERVERS != no && kill -HUP $KILLPIDS
615 exit $RC
617 esac
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
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)
629 EOMODS15
630 RC=$?
631 case $RC in
635 echo "ldapmodify failed ($RC)!"
636 test $KILLSERVERS != no && kill -HUP $KILLPIDS
637 exit $RC
639 esac
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
652 LDIF=$ACLOUTMASTER
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
661 if test $? != 0 ; then
662 echo "comparison failed - operations did not complete correctly"
663 exit 1
666 echo ">>>>> Test succeeded"
668 test $KILLSERVERS != no && wait
670 exit 0