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