Remove temporary QA test hack to work around a failing large sector test
[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-2002 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 . ./common.attr
54
55 _cleanup()
56 {
57     rm -f $tmp.*
58     rm -rf $TEST_DIR/$seq.dir1
59 }
60
61 # -----
62 # minimal access ACL has ACEs: USER_OBJ, GROUP_OBJ, OTHER_OBJ
63 # This is set with chacl(1) and can be changed by chmod(1).
64 #
65 # Test that this is being set for ACL and for std unix permissions
66 # Test that we can get back the same ACL.
67 # Test std permissions for rwx.
68 # -----
69 #
70 # Test out default ACLs and that the ACL is being PASSed
71 # onto the children of the dir.
72 #
73 # -----
74 # Test out access check for extended ACLs.
75 # -> 3 extra ACEs: MASK, GROUP, USER
76 # -> the GROUP compares with egid of process _and_ the supplementary
77 #    groups (as found in /etc/group)
78 #
79 # Test that mask works for USER, GROUP, GROUP_OBJ
80 # Test that the ACE type priority is working
81 #   -> this would be done by simultaneously matching on ACEs
82 #   -> interesting if it allows user to specify ACEs in any order
83 #
84 rm -f $seq.full
85
86 _need_to_be_root
87 _acl_setup_ids
88 _acl_requirements
89 [ -x $runas ] || _notrun "$runas executable not found"
90
91 # get dir
92 cd $TEST_DIR
93 rm -rf $seq.dir1
94 mkdir $seq.dir1
95 cd $seq.dir1
96
97 #-------------------------------------------------------
98 # real QA test starts here
99 echo "QA output created by $seq"
100
101 echo ""
102 echo "=== Test minimal ACE ==="
103
104 echo "Setup file"
105 # Note: as this is a shell script,
106 #       will need read and execute permission set
107 #       in order to execute it.
108 touch file1
109 cat <<EOF >file1
110 #!/bin/sh
111 echo "Test was executed"
112 EOF
113 chmod u=rwx file1
114 chmod g=rw- file1
115 chmod o=r-- file1
116 chown $acl1.$acl2 file1
117 _acl_ls file1
118
119 echo ""
120 echo "--- Test get and set of ACL ---"
121 echo "Note: Old interface gave an empty ACL - now output an ACL"
122 chacl -l file1 | _acl_filter_id
123 echo "Try using single colon separator"
124 echo "Note: Old interface FAILed because of single colon - new one allows it" 
125 chacl u::r--,g::rwx,o:rw- file1 2>&1
126 echo "Expect to PASS" 
127 chacl u::r--,g::rwx,o::rw- file1 2>&1
128 chacl -l file1 | _acl_filter_id
129
130 echo ""
131 echo "--- Test sync of ACL with std permissions ---"
132 _acl_ls file1
133 chmod u+w file1
134 _acl_ls file1
135 chacl -l file1 | _acl_filter_id
136
137 echo ""
138 echo "--- Test owner permissions ---"
139 chacl u::r-x,g::---,o::--- file1 2>&1
140 chacl -l file1 | _acl_filter_id
141 # change to owner
142 echo "Expect to PASS" 
143 $runas -u $acl1 -g $acl1 ./file1 2>&1
144 echo "Expect to FAIL" 
145 $runas -u $acl2 -g $acl2 ./file1 2>&1
146
147 echo ""
148 echo "--- Test group permissions ---"
149 chacl u::---,g::r-x,o::--- file1 2>&1
150 chacl -l file1 | _acl_filter_id
151 echo "Expect to FAIL - acl1 is owner" 
152 $runas -u $acl1 -g $acl1 ./file1 2>&1
153 echo "Expect to PASS - acl2 matches group" 
154 $runas -u $acl2 -g $acl2 ./file1 2>&1
155 echo "Expect to PASS - acl2 matches sup group" 
156 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
157 echo "Expect to FAIL - acl3 is not in group" 
158 $runas -u $acl3 -g $acl3 ./file1 2>&1
159
160 echo ""
161 echo "--- Test other permissions ---"
162 chacl u::---,g::---,o::r-x file1 2>&1
163 chacl -l file1 | _acl_filter_id
164 echo "Expect to FAIL - acl1 is owner" 
165 $runas -u $acl1 -g $acl1 ./file1 2>&1
166 echo "Expect to FAIL - acl2 is in group" 
167 $runas -u $acl2 -g $acl2 ./file1 2>&1
168 echo "Expect to FAIL - acl2 is in sup. group" 
169 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
170 echo "Expect to PASS - acl3 is not owner or in group" 
171 $runas -u $acl3 -g $acl3 ./file1 2>&1
172
173 #-------------------------------------------------------
174
175 echo ""
176 echo "=== Test Extended ACLs ==="
177
178 echo ""
179 echo "--- Test adding a USER ACE ---"
180 echo "Expect to FAIL as no MASK provided"
181 chacl u::---,g::---,o::---,u:$acl2:r-x file1 2>&1 | _acl_filter_id
182 echo "Ensure that ACL has not been changed"
183 chacl -l file1 | _acl_filter_id
184 echo "Expect to PASS - USER ACE matches user"
185 chacl u::---,g::---,o::---,u:$acl2:r-x,m::rwx file1 2>&1
186 chacl -l file1 | _acl_filter_id
187 $runas -u $acl2 -g $acl2 ./file1 2>&1
188 echo "Expect to FAIL - USER ACE does not match user"
189 $runas -u $acl3 -g $acl3 ./file1 2>&1
190
191 echo ""
192 echo "--- Test adding a GROUP ACE ---"
193 echo "Expect to FAIL as no MASK provided"
194 chacl u::---,g::---,o::---,g:$acl2:r-x file1 2>&1 | _acl_filter_id
195 echo "Ensure that ACL has not been changed"
196 chacl -l file1 | _acl_filter_id
197 chacl u::---,g::---,o::---,g:$acl2:r-x,m::rwx file1 2>&1
198 chacl -l file1 | _acl_filter_id
199 echo "Expect to PASS - GROUP ACE matches group"
200 $runas -u $acl2 -g $acl2 ./file1 2>&1
201 echo "Expect to PASS - GROUP ACE matches sup group"
202 $runas -u $acl2 -g $acl1 -s $acl2 ./file1 2>&1
203 echo "Expect to FAIL - GROUP ACE does not match group"
204 $runas -u $acl3 -g $acl3 ./file1 2>&1
205
206 #-------------------------------------------------------
207
208 echo ""
209 echo "--- Test MASK ---"
210
211 # group
212 chacl u::---,g::---,o::---,g:$acl2:r-x,m::-w- file1 2>&1
213 chacl -l file1 | _acl_filter_id
214 echo "Expect to FAIL as MASK prohibits execution"
215 $runas -u $acl2 -g $acl2 ./file1 2>&1
216
217 # user
218 chacl u::---,g::---,o::---,u:$acl2:r-x,m::-w- file1 2>&1
219 echo "Expect to FAIL as MASK prohibits execution"
220 $runas -u $acl2 -g $acl2 ./file1 2>&1
221
222 # user
223 chacl u::---,g::---,o::---,u:$acl2:r-x,m::r-x file1 2>&1
224 echo "Expect to PASS as MASK allows execution"
225 $runas -u $acl2 -g $acl2 ./file1 2>&1
226
227 #-------------------------------------------------------
228
229 echo ""
230 echo "--- Test ACE priority ---"
231
232 chacl o::rwx,g::rwx,u:$acl1:rwx,u::---,m::rwx file1 2>&1
233 echo "Expect to FAIL as should match on owner"
234 $runas -u $acl1 -g $acl2 ./file1 2>&1
235
236 chacl o::---,g::---,u:$acl2:rwx,u::---,m::rwx file1 2>&1
237 echo "Expect to PASS as should match on user"
238 $runas -u $acl2 -g $acl2 ./file1 2>&1
239
240
241 #-------------------------------------------------------
242
243 echo ""
244 echo "=== Test can read ACLs without access permissions ==="
245 # This was a bug in kernel code where syscred wasn't being used
246 # to override the capabilities
247 chacl o::---,g::---,u::--- file1 2>&1
248 chacl -l file1 | _acl_filter_id
249
250 #-------------------------------------------------------
251
252 echo ""
253 echo "=== Test Default ACLs ==="
254 # make test clearer by testing with and without umask
255 umask 0
256
257 mkdir acldir
258 chacl -b "u::rwx,g::rwx,o::rwx" "u::r-x,g::r--,o::---" acldir 2>&1
259 chacl -l acldir | _acl_filter_id
260 cd acldir
261
262 touch file2
263 _acl_ls file2
264 chacl -l file2 | _acl_filter_id
265
266 #ensure that umask is not having an effect 
267 #so set it and see
268 umask 722
269 touch file3
270 _acl_ls file3
271 chacl -l file3 | _acl_filter_id
272
273 cd ..
274 umask 022
275
276
277 #-------------------------------------------------------
278
279 echo ""
280 echo "=== Removing ACLs ==="
281 chacl -l file1 | _acl_filter_id
282 chacl -l acldir | _acl_filter_id
283 chacl -l acldir/file2 | _acl_filter_id
284 echo "Remove ACLs..."
285 chacl -R file1
286 chacl -B acldir
287 chacl -R acldir/file2
288 echo "Note: Old interface would mean empty ACLs - now we show mode ACLs" 
289 chacl -l file1 | _acl_filter_id
290 chacl -l acldir | _acl_filter_id
291 chacl -l acldir/file2 | _acl_filter_id
292
293
294 #-------------------------------------------------------
295
296 echo ""
297 echo "=== Recursive change ACL ==="
298 rm -fr root
299 mkdir root
300 pushd root >/dev/null
301 # create an arbitrary little tree
302 for i in 1 2 3 4 5 6 7 8 9 0
303 do
304         mkdir -p a/$i
305         mkdir -p b/c$i/$i
306         touch a/$i/mumble
307 done
308 popd >/dev/null
309 chown -R 12345.54321 root
310 echo "Change #1..."
311 $runas -u 12345 -g 54321 -- `which chacl` -r u::rwx,g::-w-,o::--x root
312 find root -print | xargs chacl -l
313 echo "Change #2..."
314 $runas -u 12345 -g 54321 -- `which chacl` -r u::---,g::---,o::--- root
315 find root -print | xargs chacl -l
316
317
318 #-------------------------------------------------------
319
320 echo ""
321 echo "=== Test out error messages for ACL text parsing  ==="
322 echo "Note: Old interface gave more informative error msgs"
323
324 touch file1
325 set -x
326 chacl u file1
327 chacl u: file1
328 chacl u:rumpledumpleunknownuser file1
329 chacl u:rumpledumpleunknownuser: file1
330 chacl g:rumpledumpleunknowngrp file1
331 chacl g:rumpledumpleunknowngrp: file1
332 chacl o:user1:rwx file1
333 chacl m:user1:rwx file1
334 chacl a::rwx file1
335 set +x
336
337 #-------------------------------------------------------
338
339 echo ""
340 echo "=== Test out large ACLs  ==="
341 touch largeaclfile
342 XFS_ACL_MAX_ENTRIES=25
343 num_aces_pre=`expr $XFS_ACL_MAX_ENTRIES - 1`
344 num_aces_post=`expr $XFS_ACL_MAX_ENTRIES + 1`
345
346 acl1=`_create_n_aces $num_aces_pre`
347 acl2=`_create_n_aces $XFS_ACL_MAX_ENTRIES`
348 acl3=`_create_n_aces $num_aces_post`
349 acl4=`_create_n_aces 16` # Andreas G. libacl size for initial get
350 acl5=`_create_n_aces 17` # 1 over A.G. libacl initial size
351
352 echo "1 below xfs acl max"
353 chacl $acl1 largeaclfile
354 getfacl largeaclfile | _filter_aces
355
356 echo "xfs acl max"
357 chacl $acl2 largeaclfile
358 getfacl largeaclfile | _filter_aces
359
360 echo "1 above xfs acl max"
361 chacl $acl3 largeaclfile
362 getfacl largeaclfile | _filter_aces
363
364 echo "use 16 aces"
365 chacl $acl4 largeaclfile
366 getfacl largeaclfile | _filter_aces
367
368 echo "use 17 aces"
369 chacl $acl5 largeaclfile
370 getfacl largeaclfile | _filter_aces
371
372 #-------------------------------------------------------
373
374 # success, all done
375 status=0
376 exit