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