]> git.sur5r.net Git - openldap/blob - tests/scripts/test006-acls
map referrals in regular metadata structure (need to remove some of the specific...
[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 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 mkdir -p $TESTDIR $DBDIR1
20
21 echo "Running slapadd to build slapd database..."
22 . $CONFFILTER $BACKEND $MONITORDB < $ACLCONF > $CONF1
23 $SLAPADD -f $CONF1 -l $LDIFORDERED
24 RC=$?
25 if test $RC != 0 ; then
26         echo "slapadd failed ($RC)!"
27         exit $RC
28 fi
29
30 echo "Starting slapd on TCP/IP port $PORT1..."
31 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
32 PID=$!
33 if test $WAIT != 0 ; then
34     echo PID $PID
35     read foo
36 fi
37 KILLPIDS="$PID"
38
39 echo "Testing slapd access control..."
40 for i in 0 1 2 3 4 5; do
41         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
42                 'objectclass=*' > /dev/null 2>&1
43         RC=$?
44         if test $RC = 0 ; then
45                 break
46         fi
47         echo "Waiting 5 seconds for slapd to start..."
48         sleep 5
49 done
50
51 if test $RC != 0 ; then
52         echo "ldapsearch failed ($RC)!"
53         test $KILLSERVERS != no && kill -HUP $KILLPIDS
54         exit $RC
55 fi
56
57 cat /dev/null > $SEARCHOUT
58
59 echo "# Try to read an entry inside the Alumni Association container.
60 # It should give us noSuchObject if we're not bound..." \
61 >> $SEARCHOUT
62 $LDAPSEARCH -b "$JAJDN" -h $LOCALHOST -p $PORT1 "(objectclass=*)" \
63         >> $SEARCHOUT 2>&1
64
65 echo "# ... and should return all attributes if we're bound as anyone
66 # under Example." \
67 >> $SEARCHOUT
68 $LDAPSEARCH -b "$JAJDN" -h $LOCALHOST -p $PORT1 \
69         -D "$BABSDN" -w bjensen "(objectclass=*)"  >> $SEARCHOUT 2>&1
70
71 #
72 # Check group access. Try to modify Babs' entry. Two attempts:
73 # 1) bound as "James A Jones 1" - should fail
74 # 2) bound as "Bjorn Jensen" - should succeed
75
76 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
77         $TESTOUT 2>&1 << EOMODS5
78 dn: $BABSDN
79 changetype: modify
80 replace: drink
81 drink: wine
82
83 EOMODS5
84
85
86 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
87         $TESTOUT 2>&1 << EOMODS6
88 dn: $BABSDN
89 changetype: modify
90 add: homephone
91 homephone: +1 313 555 5444
92
93 EOMODS6
94
95 #
96 # Try to add a "member" attribute to the "ITD Staff" group.  It should
97 # fail when we add some DN other than our own, and should succeed when
98 # we add our own DN.
99 # bjensen
100 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj > \
101         $TESTOUT 2>&1 << EOMODS1
102 version: 1
103 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
104 changetype: modify
105 add: uniquemember
106 uniquemember: cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com
107
108 EOMODS1
109
110 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
111         $TESTOUT 2>&1 << EOMODS2
112 version: 1
113
114 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
115 changetype: modify
116 add: uniquemember
117 uniquemember: cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com
118 EOMODS2
119
120 #
121 # Try to modify the "ITD Staff" group.  Two attempts are made:
122 # 1) bound as "James A Jones 1" - should fail
123 # 2) bound as "Bjorn Jensen" - should succeed
124 #
125 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
126         $TESTOUT 2>&1 << EOMODS3
127
128 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
129 changetype: modify
130 delete: description
131
132 EOMODS3
133
134 $LDAPMODIFY -D "$BJORNSDN" -h $LOCALHOST -p $PORT1 -w bjorn >> \
135         $TESTOUT 2>&1 << EOMODS4
136 # COMMENT
137 version: 1
138 # comment
139 dn: cn=ITD Staff, ou=Groups, dc=example, dc=com
140 # comment
141 changetype: modify
142 # comment
143 add: ou
144 # comment
145 ou: Groups
146 # comment
147 EOMODS4
148
149 #
150 # Try to modify the "ITD Staff" group.  Two attempts are made:
151 # 1) bound as "James A Jones 1" - should succeed
152 # 2) bound as "Barbara Jensen" - should fail
153 # should exploit sets
154 #
155 $LDAPMODIFY -D "$JAJDN" -h $LOCALHOST -p $PORT1 -w jaj >> \
156         $TESTOUT 2>&1 << EOMODS5
157 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
158 changetype: modify
159 add: description
160 description: added by jaj (should succeed)
161 -
162 EOMODS5
163
164 $LDAPMODIFY -D "$BABSDN" -h $LOCALHOST -p $PORT1 -w bjensen >> \
165         $TESTOUT 2>&1 << EOMODS6
166 dn: cn=Alumni Assoc Staff, ou=Groups, dc=example, dc=com
167 changetype: modify
168 add: description
169 description: added by bjensen (should fail)
170 -
171 EOMODS6
172
173 echo "Using ldapsearch to retrieve all the entries..."
174 echo "# Using ldapsearch to retrieve all the entries..." >> $SEARCHOUT
175 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
176             'objectClass=*' >> $SEARCHOUT 2>&1
177 RC=$?
178 test $KILLSERVERS != no && kill -HUP $KILLPIDS
179 if test $RC != 0 ; then
180         echo "ldapsearch failed ($RC)!"
181         exit $RC
182 fi
183
184 LDIF=$ACLOUTMASTER
185
186 echo "Filtering ldapsearch results..."
187 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
188 echo "Filtering original ldif used to create database..."
189 . $LDIFFILTER < $LDIF > $LDIFFLT
190 echo "Comparing filter output..."
191 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
192
193 if test $? != 0 ; then
194         echo "comparison failed - operations did not complete correctly"
195         exit 1
196 fi
197
198 echo ">>>>> Test succeeded"
199 exit 0