]> git.sur5r.net Git - openldap/blob - tests/scripts/test041-aci
c56121bb1d28103b0fa93928039b0cc02cba4347
[openldap] / tests / scripts / test041-aci
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         ;;
23 esac
24
25 echo "running defines.sh"
26 . $SRCDIR/scripts/defines.sh
27
28 if test "$ACI" = "acino" ; then
29         echo "ACI not enabled; skipping..."
30         exit 0
31 fi
32
33 mkdir -p $TESTDIR $DBDIR1
34
35 echo "Running slapadd to build slapd database..."
36 . $CONFFILTER $BACKEND $MONITORDB < $ACICONF > $CONF1
37 $SLAPADD -f $CONF1 -l $LDIFORDERED
38 RC=$?
39 if test $RC != 0 ; then
40         echo "slapadd failed ($RC)!"
41         exit $RC
42 fi
43
44 echo "Starting slapd on TCP/IP port $PORT1..."
45 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
46 PID=$!
47 if test $WAIT != 0 ; then
48     echo PID $PID
49     read foo
50 fi
51 KILLPIDS="$PID"
52
53 echo "Testing slapd ACI access control..."
54 for i in 0 1 2 3 4 5; do
55         $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
56                 'objectclass=*' > /dev/null 2>&1
57         RC=$?
58         if test $RC = 0 ; then
59                 break
60         fi
61         echo "Waiting 5 seconds for slapd to start..."
62         sleep 5
63 done
64
65 if test $RC != 0 ; then
66         echo "ldapsearch failed ($RC)!"
67         test $KILLSERVERS != no && kill -HUP $KILLPIDS
68         exit $RC
69 fi
70
71 cat /dev/null > $SEARCHOUT
72 cat /dev/null > $TESTOUT
73
74 # Search must fail
75 BASEDN="dc=example,dc=com"
76 echo "Searching \"$BASEDN\" (should fail)..."
77 echo "# Searching \"$BASEDN\" (should fail)..." >> $SEARCHOUT
78 $LDAPSEARCH -s base -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
79         '(objectclass=*)' >> $SEARCHOUT 2>> $TESTOUT
80 RC=$?
81 if test $RC != 32 ; then
82         echo "ldapsearch should have failed with noSuchObject ($RC)!"
83         test $KILLSERVERS != no && kill -HUP $KILLPIDS
84         if test $RC = 0 ; then
85                 exit -1
86         fi
87         exit $RC
88 fi
89
90 # Bind must fail
91 BINDDN="cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
92 BINDPW=bjensen
93 echo "Testing ldapwhoami as ${BINDDN} (should fail)..."
94 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW
95 RC=$?
96 if test $RC = 0 ; then
97         echo "ldapwhoami should have failed!"
98         test $KILLSERVERS != no && kill -HUP $KILLPIDS
99         exit -1
100 fi
101
102 # Populate ACIs
103 echo "Writing ACIs as \"$MANAGERDN\"..."
104 $LDAPMODIFY -D "$MANAGERDN" -w $PASSWD -h $LOCALHOST -p $PORT1 \
105         >> $TESTOUT 2>&1 << EOMODS0
106 dn: dc=example,dc=com
107 changetype: modify
108 add: OpenLDAPaci
109 OpenLDAPaci: 0#subtree#grant;d,c,s,r;[all]#group/groupOfUniqueNames/uniqueMe
110  mber#cn=ITD Staff,ou=Groups,dc=example,dc=com
111 OpenLDAPaci: 1#entry#grant;d;[all]#public#
112
113 dn: ou=People,dc=example,dc=com
114 changetype: modify
115 add: OpenLDAPaci
116 OpenLDAPaci: 0#subtree#grant;x;userPassword#public#
117 OpenLDAPaci: 1#subtree#grant;w;userPassword#self#
118 OpenLDAPaci: 2#subtree#grant;w;userPassword#access-id#cn=Bjorn Jensen,ou=Inf
119  ormation Technology Division,ou=People,dc=example,dc=com
120
121 dn: ou=Groups,dc=example,dc=com
122 changetype: modify
123 add: OpenLDAPaci
124 OpenLDAPaci: 0#entry#grant;s;[all]#public#
125 OpenLDAPaci: 1#children#grant;r;member;r;uniqueMember#access-id#cn=Bjorn Jen
126  sen,ou=Information Technology Division,ou=People,dc=example,dc=com
127 EOMODS0
128 RC=$?
129 if test $RC != 0 ; then
130         echo "ldapmodify failed ($RC)!"
131         test $KILLSERVERS != no && kill -HUP $KILLPIDS
132         exit $RC
133 fi
134
135 # Search must succeed with no results
136 BASEDN="dc=example,dc=com"
137 echo "Searching \"$BASEDN\" (should succeed with no results)..."
138 echo "# Searching \"$BASEDN\" (should succeed with no results)..." >> $SEARCHOUT
139 $LDAPSEARCH -s base -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
140         '(objectclass=*)' >> $SEARCHOUT 2>> $TESTOUT
141 RC=$?
142 if test $RC != 0 ; then
143         ### TEMPORARY (see ITS#3963)
144         echo "ldapsearch failed ($RC)! IGNORED..."
145         ###echo "ldapsearch failed ($RC)!"
146         ###test $KILLSERVERS != no && kill -HUP $KILLPIDS
147         ###exit $RC
148 fi
149
150 BINDDN="cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
151 BINDPW=bjensen
152 echo "Testing ldapwhoami as ${BINDDN}..."
153 $LDAPWHOAMI -h $LOCALHOST -p $PORT1 -D "$BINDDN" -w $BINDPW
154 RC=$?
155 if test $RC != 0 ; then
156         echo "ldapwhoami failed ($RC)!"
157         test $KILLSERVERS != no && kill -HUP $KILLPIDS
158         exit $RC
159 fi
160
161 # Search must succeed 
162 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
163 BINDPW=bjorn
164 BASEDN="dc=example,dc=com"
165 echo "Searching \"$BASEDN\" as \"$BINDDN\" (should succeed)..."
166 echo "# Searching \"$BASEDN\" as \"$BINDDN\" (should succeed)..." >> $SEARCHOUT
167 $LDAPSEARCH -s base -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
168         -D "$BINDDN" -w "$BINDPW" \
169         '(objectClass=*)' >> $SEARCHOUT 2>> $TESTOUT
170 RC=$?
171 if test $RC != 0 ; then
172         echo "ldapsearch failed ($RC)!"
173         test $KILLSERVERS != no && kill -HUP $KILLPIDS
174         exit $RC
175 fi
176
177 # Passwd must succeed 
178 BINDDN="cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
179 BINDPW=bjorn
180 TGT="cn=John Doe,ou=Information Technology Division,ou=People,dc=example,dc=com"
181 NEWPW=jdoe
182 echo "Setting \"$TGT\" password..."
183 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
184         -w "$BINDPW" -s "$NEWPW" \
185         -D "$BINDDN" "$TGT" >> $TESTOUT 2>&1
186 RC=$?
187 if test $RC != 0 ; then
188         echo "ldappasswd failed ($RC)!"
189         test $KILLSERVERS != no && kill -HUP $KILLPIDS
190         exit $RC
191 fi
192
193 # Re-change as self...
194 echo "Changing self password..."
195 BINDDN="$TGT"
196 BINDPW=$NEWPW
197 TGT="cn=John Doe,ou=Information Technology Division,ou=People,dc=example,dc=com"
198 NEWPW=newcred
199 $LDAPPASSWD -h $LOCALHOST -p $PORT1 \
200         -w "$BINDPW" -s "$NEWPW" \
201         -D "$BINDDN" "$TGT" >> $TESTOUT 2>&1
202 RC=$?
203 if test $RC != 0 ; then
204         echo "ldappasswd failed ($RC)!"
205         test $KILLSERVERS != no && kill -HUP $KILLPIDS
206         exit $RC
207 fi
208
209 # Searching groups
210 BINDPW=$NEWPW
211 BASEDN="ou=Groups,dc=example,dc=com"
212 echo "Searching \"$BASEDN\" as \"$BINDDN\" (should succeed)..."
213 echo "# Searching \"$BASEDN\" as \"$BINDDN\" (should succeed)..." >> $SEARCHOUT
214 $LDAPSEARCH -s one -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
215         -D "$BINDDN" -w "$BINDPW" \
216         '(objectClass=*)' >> $SEARCHOUT 2>> $TESTOUT
217 RC=$?
218 if test $RC != 0 ; then
219         echo "ldapsearch failed ($RC)!"
220         test $KILLSERVERS != no && kill -HUP $KILLPIDS
221         exit $RC
222 fi
223
224 # Search must fail
225 BINDDN="cn=Barbara Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com"
226 BINDPW=bjensen
227 echo "Searching \"$BASEDN\" as \"$BINDDN\" (should succeed with no results)..."
228 echo "# Searching \"$BASEDN\" as \"$BINDDN\" (should succeed with no results)..." >> $SEARCHOUT
229 $LDAPSEARCH -s one -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
230         -D "$BINDDN" -w "$BINDPW" \
231         '(objectClass=*)' >> $SEARCHOUT 2>> $TESTOUT
232 RC=$?
233 if test $RC != 0 ; then
234         echo "ldapsearch failed ($RC)!"
235         test $KILLSERVERS != no && kill -HUP $KILLPIDS
236         exit $RC
237 fi
238
239 test $KILLSERVERS != no && kill -HUP $KILLPIDS
240
241 LDIF=$ACIOUT
242
243 echo "Filtering ldapsearch results..."
244 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
245 echo "Filtering original ldif used to create database..."
246 . $LDIFFILTER < $LDIF > $LDIFFLT
247 echo "Comparing filter output..."
248 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
249
250 if test $? != 0 ; then
251         echo "comparison failed - operations did not complete correctly"
252         exit 1
253 fi
254
255 echo ">>>>> Test succeeded"
256 exit 0