tidy up the feature checking - can bite in either enfd/acct quota cases.
[xfstests-dev.git] / 051
1 #! /bin/sh
2 # XFS QA Test No. 051
3 # $Id: 1.1 $
4 #
5 # Test out ACLs.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
9
10 # This program is free software; you can redistribute it and/or modify it
11 # under the terms of version 2 of the GNU General Public License as
12 # published by the Free Software Foundation.
13
14 # This program is distributed in the hope that it would be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18 # Further, this software is distributed without any warranty that it is
19 # free of the rightful claim of any third person regarding infringement
20 # or the like.  Any license provided herein, whether implied or
21 # otherwise, applies only to this software file.  Patent licenses, if
22 # any, provided herein do not apply to combinations of this program with
23 # other software, or any other product whatsoever.
24
25 # You should have received a copy of the GNU General Public License along
26 # with this program; if not, write the Free Software Foundation, Inc., 59
27 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
28
29 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
30 # Mountain View, CA  94043, or:
31
32 # http://www.sgi.com 
33
34 # For further information regarding this notice, see: 
35
36 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
37 #-----------------------------------------------------------------------
38 #
39 # creator
40 owner=tes@sgi.com
41
42 seq=`basename $0`
43
44 here=`pwd`
45 tmp=/tmp/$$
46 runas=$here/src/runas
47 status=1        # FAILure is the default!
48 trap "_cleanup; exit \$status" 0 1 2 3 15
49
50 # get standard environment, filters and checks
51 . ./common.rc
52 . ./common.filter
53
54 _cleanup()
55 {
56     rm -f $tmp.*
57     rm -rf $TEST_DIR/$seq.dir1
58 }
59
60 _ls()
61 {
62     ls -ln $* | awk '{ print $1, $3, $4, $NF }' | _filter_id
63
64
65 _get_newid()
66 {
67     cat /etc/passwd /etc/group $tmp.ids | gawk -F: '
68       { ids[$3]=1 }
69       END {
70         for(i=1;i<1000000;i++){
71           if (! (i in ids)) {
72              print i;            
73              exit
74           }
75         }       
76       }'
77 }
78
79 _setup_ids()
80 {
81     touch $tmp.ids
82     acl1=`_get_newid`; echo "::$acl1" >>$tmp.ids
83     acl2=`_get_newid`; echo "::$acl2" >>$tmp.ids
84     acl3=`_get_newid`; echo "::$acl3" >>$tmp.ids
85 }
86
87 _filter_id()
88 {
89     sed \
90        -e "s/u:$acl1/u:id1/" \
91        -e "s/u:$acl2/u:id2/" \
92        -e "s/u:$acl3/u:id3/" \
93        -e "s/g:$acl1/g:id1/" \
94        -e "s/g:$acl2/g:id2/" \
95        -e "s/g:$acl3/g:id3/" \
96        -e "s/ $acl1 / id1 /" \
97        -e "s/ $acl2 / id2 /" \
98        -e "s/ $acl3 / id3 /" \
99 }
100
101 # -----
102 # minimal access ACL has ACEs: USER_OBJ, GROUP_OBJ, OTHER_OBJ
103 # This is set with chacl(1) and can be changed by chmod(1).
104 #
105 # Test that this is being set for ACL and for std unix permissions
106 # Test that we can get back the same ACL.
107 # Test std permissions for rwx.
108 # -----
109 #
110 # Test out default ACLs and that the ACL is being PASSed
111 # onto the children of the dir.
112 #
113 # -----
114 # Test out access check for extended ACLs.
115 # -> 3 extra ACEs: MASK, GROUP, USER
116 # -> the GROUP compares with egid of process _and_ the supplementary
117 #    groups (as found in /etc/group)
118 #
119 # Test that mask works for USER, GROUP, GROUP_OBJ
120 # Test that the ACE type priority is working
121 #   -> this would be done by simultaneously matching on ACEs
122 #   -> interesting if it allows user to specify ACEs in any order
123 #
124 rm -f $seq.full
125
126 _need_to_be_root
127 _setup_ids
128
129 [ -x /bin/chacl ] || _notrun "chacl command not found"
130 [ -x $runas ] || _notrun "$runas executable not found"
131
132 # get dir
133 cd $TEST_DIR
134 rm -rf $seq.dir1
135 mkdir $seq.dir1
136 cd $seq.dir1
137
138 # test if acl_get syscall is operational
139 # and hence the ACL config has been turned on  
140 touch syscalltest
141 if chacl -l syscalltest 2>&1 | tee -a $here/$seq.full | grep 'Function not implemented' >/dev/null
142 then
143   cd $here
144   _notrun "requires kernel ACL support"
145 fi
146
147 #-------------------------------------------------------
148 # real QA test starts here
149 echo "QA output created by $seq"
150
151 echo ""
152 echo "=== Test minimal ACE ==="
153
154 echo "Setup file"
155 touch file1
156 cat <<EOF >file1
157 #!/bin/sh
158 echo "Test was executed"
159 EOF
160 chmod u=rwx file1
161 chmod g=rw- file1
162 chmod o=r-- file1
163 chown $acl1.$acl2 file1
164 _ls file1
165
166 echo ""
167 echo "--- Test get and set of ACL ---"
168 chacl -l file1 | _filter_id
169 echo "Expect to FAIL" 
170 chacl u::r--,g::rwx,o:rw- file1 2>&1
171 echo "Expect to PASS" 
172 chacl u::r--,g::rwx,o::rw- file1 2>&1
173 chacl -l file1 | _filter_id
174
175 echo ""
176 echo "--- Test sync of ACL with std permissions ---"
177 _ls file1
178 chmod u+w file1
179 _ls file1
180 chacl -l file1 | _filter_id
181
182 echo ""
183 echo "--- Test owner permissions ---"
184 chacl u::r-x,g::---,o::--- file1 2>&1
185 chacl -l file1 | _filter_id
186 # change to owner
187 echo "Expect to PASS" 
188 $runas -u $acl1 -g $acl1 ./file1 2>&1
189 echo "Expect to FAIL" 
190 $runas -u $acl2 -g $acl2 ./file1 2>&1
191
192 echo ""
193 echo "--- Test group permissions ---"
194 chacl u::---,g::r-x,o::--- file1 2>&1
195 chacl -l file1 | _filter_id
196 echo "Expect to FAIL - acl1 is owner" 
197 $runas -u $acl1 -g $acl1 ./file1 2>&1
198 echo "Expect to PASS - acl2 matches group" 
199 $runas -u $acl2 -g $acl2 ./file1 2>&1
200 echo "Expect to PASS - acl2 matches sup group" 
201 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
202 echo "Expect to FAIL - acl3 is not in group" 
203 $runas -u $acl3 -g $acl3 ./file1 2>&1
204
205 echo ""
206 echo "--- Test other permissions ---"
207 chacl u::---,g::---,o::r-x file1 2>&1
208 chacl -l file1 | _filter_id
209 echo "Expect to FAIL - acl1 is owner" 
210 $runas -u $acl1 -g $acl1 ./file1 2>&1
211 echo "Expect to FAIL - acl2 is in group" 
212 $runas -u $acl2 -g $acl2 ./file1 2>&1
213 echo "Expect to FAIL - acl2 is in sup. group" 
214 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
215 echo "Expect to PASS - acl3 is not owner or in group" 
216 $runas -u $acl3 -g $acl3 ./file1 2>&1
217
218 #-------------------------------------------------------
219
220 echo ""
221 echo "=== Test Extended ACLs ==="
222
223 echo ""
224 echo "--- Test adding a USER ACE ---"
225 echo "Expect to FAIL as no MASK provided"
226 chacl u::---,g::---,o::---,u:$acl2:r-x file1 2>&1
227 echo "Ensure that ACL has not been changed"
228 chacl -l file1 | _filter_id
229 echo "Expect to PASS - USER ACE matches user"
230 chacl u::---,g::---,o::---,u:$acl2:r-x,m::rwx file1 2>&1
231 chacl -l file1 | _filter_id
232 $runas -u $acl2 -g $acl2 ./file1 2>&1
233 echo "Expect to FAIL - USER ACE does not match user"
234 $runas -u $acl3 -g $acl3 ./file1 2>&1
235
236 echo ""
237 echo "--- Test adding a GROUP ACE ---"
238 echo "Expect to FAIL as no MASK provided"
239 chacl u::---,g::---,o::---,g:$acl2:r-x file1 2>&1
240 echo "Ensure that ACL has not been changed"
241 chacl -l file1 | _filter_id
242 chacl u::---,g::---,o::---,g:$acl2:r-x,m::rwx file1 2>&1
243 chacl -l file1 | _filter_id
244 echo "Expect to PASS - GROUP ACE matches group"
245 $runas -u $acl2 -g $acl2 ./file1 2>&1
246 echo "Expect to PASS - GROUP ACE matches sup group"
247 $runas -u $acl2 -g $acl1 -s $acl2 ./file1 2>&1
248 echo "Expect to FAIL - GROUP ACE does not match group"
249 $runas -u $acl3 -g $acl3 ./file1 2>&1
250
251 #-------------------------------------------------------
252
253 echo ""
254 echo "--- Test MASK ---"
255 chacl u::---,g::---,o::---,g:$acl2:r-x,m::-wx file1 2>&1
256 chacl -l file1 | _filter_id
257 echo "Expect to FAIL as MASK prohibits execution"
258 $runas -u $acl2 -g $acl2 ./file1 2>&1
259 chacl u::---,g::---,o::---,u:$acl2:r-x,m::-wx file1 2>&1
260 echo "Expect to FAIL as MASK prohibits execution"
261 $runas -u $acl2 -g $acl2 ./file1 2>&1
262
263 chacl u::---,g::---,o::---,u:$acl2:r-x,m::r-x file1 2>&1
264 echo "Expect to PASS as MASK allows execution"
265 $runas -u $acl2 -g $acl2 ./file1 2>&1
266
267 #-------------------------------------------------------
268
269 echo ""
270 echo "--- Test ACE priority ---"
271
272 chacl o::rwx,g::rwx,u:$acl1:rwx,u::---,m::rwx file1 2>&1
273 echo "Expect to FAIL as should match on owner"
274 $runas -u $acl1 -g $acl2 ./file1 2>&1
275
276 chacl o::---,g::---,u:$acl2:rwx,u::---,m::rwx file1 2>&1
277 echo "Expect to PASS as should match on user"
278 $runas -u $acl2 -g $acl2 ./file1 2>&1
279
280
281 #-------------------------------------------------------
282
283 echo ""
284 echo "=== Test can read ACLs without access permissions ==="
285 # This was a bug in kernel code where syscred wasn't being used
286 # to override the capabilities
287 chacl o::---,g::---,u::--- file1 2>&1
288 chacl -l file1 | _filter_id
289
290 #-------------------------------------------------------
291
292 echo ""
293 echo "=== Test Default ACLs ==="
294 mkdir acldir
295 chacl -b "u::rwx,g::rwx,o::rwx" "u::r-x,g::r--,o::---" ./acldir 2>&1
296 chacl -l acldir | _filter_id
297
298 cd acldir
299 touch file2
300 _ls file2
301 chacl -l file2 | _filter_id
302 cd ..
303
304 #-------------------------------------------------------
305
306 # success, all done
307 status=0
308 exit