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