]> git.sur5r.net Git - openldap/blob - tests/scripts/test006-acls
fix slapi_sdn_isempty() logic
[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-2005 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 echo "Testing slapd access control..."
48 for i in 0 1 2 3 4 5; do
49         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
50                 'objectclass=*' > /dev/null 2>&1
51         RC=$?
52         if test $RC = 0 ; then
53                 break
54         fi
55         echo "Waiting 5 seconds for slapd to start..."
56         sleep 5
57 done
58
59 if test $RC != 0 ; then
60         echo "ldapsearch failed ($RC)!"
61         test $KILLSERVERS != no && kill -HUP $KILLPIDS
62         exit $RC
63 fi
64
65 cat /dev/null > $SEARCHOUT
66
67 echo "# Try to read an entry inside the Alumni Association container.
68 # It should give us noSuchObject if we're not bound..." \
69 >> $SEARCHOUT
70 # FIXME: temporarily remove the "No such object" message to make
71 # the test succeed even if SLAP_ACL_HONOR_DISCLOSE is not #define'd
72 $LDAPSEARCH -b "$JAJDN" -h $LOCALHOST -p $PORT1 "(objectclass=*)" \
73         2>&1 | grep -v "^No such object" >> $SEARCHOUT
74
75 echo "# ... and should return all attributes if we're bound as anyone
76 # under Example." \
77 >> $SEARCHOUT
78 $LDAPSEARCH -b "$JAJDN" -h $LOCALHOST -p $PORT1 \
79         -D "$BABSDN" -w bjensen "(objectclass=*)"  >> $SEARCHOUT 2>&1
80
81 #
82 # Check group access. Try to modify Babs' entry. Two attempts:
83 # 1) bound as "James A Jones 1" - should fail
84 # 2) bound as "Bjorn Jensen" - should succeed
85
86 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
87         $TESTOUT 2>&1 << EOMODS5
88 dn: $BABSDN
89 changetype: modify
90 replace: drink
91 drink: wine
92
93 EOMODS5
94
95
96 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
97         $TESTOUT 2>&1 << EOMODS6
98 dn: $BABSDN
99 changetype: modify
100 add: homephone
101 homephone: +1 313 555 5444
102
103 EOMODS6
104
105 #
106 # Try to add a "member" attribute to the "ITD Staff" group.  It should
107 # fail when we add some DN other than our own, and should succeed when
108 # we add our own DN.
109 # bjensen
110 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj > \
111         $TESTOUT 2>&1 << EOMODS1
112 version: 1
113 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
114 changetype: modify
115 add: uniquemember
116 uniquemember: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
117
118 EOMODS1
119
120 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
121         $TESTOUT 2>&1 << EOMODS2
122 version: 1
123
124 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
125 changetype: modify
126 add: uniquemember
127 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
128 EOMODS2
129
130 #
131 # Try to modify the "ITD Staff" group.  Two attempts are made:
132 # 1) bound as "James A Jones 1" - should fail
133 # 2) bound as "Bjorn Jensen" - should succeed
134 #
135 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
136         $TESTOUT 2>&1 << EOMODS3
137
138 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
139 changetype: modify
140 delete: description
141
142 EOMODS3
143
144 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
145         $TESTOUT 2>&1 << EOMODS4
146 # COMMENT
147 version: 1
148 # comment
149 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
150 # comment
151 changetype: modify
152 # comment
153 add: ou
154 # comment
155 ou: Groups
156 # comment
157 EOMODS4
158
159 #
160 # Try to modify the "ITD Staff" group.  Two attempts are made:
161 # 1) bound as "James A Jones 1" - should succeed
162 # 2) bound as "Barbara Jensen" - should fail
163 # should exploit sets
164 #
165 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
166         $TESTOUT 2>&1 << EOMODS5
167 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
168 changetype: modify
169 add: description
170 description: added by jaj (should succeed)
171 -
172 EOMODS5
173
174 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
175         $TESTOUT 2>&1 << EOMODS6
176 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
177 changetype: modify
178 add: description
179 description: added by bjensen (should fail)
180 -
181 EOMODS6
182
183 $LDAPMODIFY -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD >> \
184         $TESTOUT 2>&1 << EOMODS7
185 dn: ou=Add & Delete,dc=example,dc=com
186 changetype: add
187 objectClass: organizationalUnit
188 ou: Add & Delete
189 EOMODS7
190
191 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
192         $TESTOUT 2>&1 << EOMODS8
193 dn: cn=Added by Babs (must fail),ou=Add & Delete,dc=example,dc=com
194 changetype: add
195 objectClass: inetOrgPerson
196 cn: Added by Babs (must fail)
197 sn: None
198 EOMODS8
199
200 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
201         $TESTOUT 2>&1 << EOMODS9
202 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
203 changetype: add
204 objectClass: inetOrgPerson
205 cn: Added by Bjorn (must succeed)
206 sn: None
207
208 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
209 changetype: add
210 objectClass: inetOrgPerson
211 cn: Added by Bjorn (will be deleted)
212 sn: None
213
214 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
215 changetype: add
216 objectClass: inetOrgPerson
217 cn: Added by Bjorn (will be renamed)
218 sn: None
219
220 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
221 changetype: modify
222 add: description
223 description: this attribute value has been added __after__entry creation
224 description: this attribute value will be deleted by Babs (must succeed)
225 description: Bjorn will try to delete this attribute value (should fail)
226 -
227 EOMODS9
228
229 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
230         $TESTOUT 2>&1 << EOMODS10
231 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
232 changetype: delete
233 EOMODS10
234
235 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
236         $TESTOUT 2>&1 << EOMODS11
237 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
238 changetype: modrdn
239 newrdn: cn=Added by Bjorn (renamed by Bjorn)
240 deleteoldrdn: 1
241 EOMODS11
242
243 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
244         $TESTOUT 2>&1 << EOMODS12
245 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
246 changetype: modrdn
247 newrdn: cn=Added by Bjorn (renamed by Babs)
248 deleteoldrdn: 1
249 EOMODS12
250
251 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
252         $TESTOUT 2>&1 << EOMODS13
253 dn: cn=Added by Bjorn (will be renamed),ou=Add & Delete,dc=example,dc=com
254 changetype: modrdn
255 newrdn: cn=Added by Bjorn (renamed by Jaj)
256 deleteoldrdn: 1
257 EOMODS13
258
259 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
260         $TESTOUT 2>&1 << EOMODS14
261 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
262 changetype: modify
263 delete: description
264 description: Bjorn will try to delete this attribute value (should fail)
265 -
266 EOMODS14
267
268 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
269         $TESTOUT 2>&1 << EOMODS15
270 dn: cn=Added by Bjorn (will be deleted),ou=Add & Delete,dc=example,dc=com
271 changetype: delete
272
273 dn: cn=Added by Bjorn (must succeed),ou=Add & Delete,dc=example,dc=com
274 changetype: modify
275 delete: description
276 description: this attribute value will be deleted by Babs (must succeed)
277 -
278 EOMODS15
279
280 echo "Using ldapsearch to retrieve all the entries..."
281 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
282 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
283             'objectClass=*' >> $SEARCHOUT 2>&1
284 RC=$?
285 test $KILLSERVERS != no && kill -HUP $KILLPIDS
286 if test $RC != 0 ; then
287         echo "ldapsearch failed ($RC)!"
288         exit $RC
289 fi
290
291 LDIF=$ACLOUTMASTER
292
293 echo "Filtering ldapsearch results..."
294 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
295 echo "Filtering original ldif used to create database..."
296 . $LDIFFILTER < $LDIF > $LDIFFLT
297 echo "Comparing filter output..."
298 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
299
300 if test $? != 0 ; then
301         echo "comparison failed - operations did not complete correctly"
302         exit 1
303 fi
304
305 echo ">>>>> Test succeeded"
306 exit 0