Fix test 049 so that it works with larger default log sizes
[xfstests-dev.git] / 051
1 #! /bin/sh
2 # XFS QA Test No. 051
3 #
4 # Test out ACLs.
5 #
6 #-----------------------------------------------------------------------
7 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
8
9 # This program is free software; you can redistribute it and/or modify it
10 # under the terms of version 2 of the GNU General Public License as
11 # published by the Free Software Foundation.
12
13 # This program is distributed in the hope that it would be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
17 # Further, this software is distributed without any warranty that it is
18 # free of the rightful claim of any third person regarding infringement
19 # or the like.  Any license provided herein, whether implied or
20 # otherwise, applies only to this software file.  Patent licenses, if
21 # any, provided herein do not apply to combinations of this program with
22 # other software, or any other product whatsoever.
23
24 # You should have received a copy of the GNU General Public License along
25 # with this program; if not, write the Free Software Foundation, Inc., 59
26 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
27
28 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
29 # Mountain View, CA  94043, or:
30
31 # http://www.sgi.com 
32
33 # For further information regarding this notice, see: 
34
35 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
36 #-----------------------------------------------------------------------
37 #
38 # creator
39 owner=tes@sgi.com
40
41 seq=`basename $0`
42
43 here=`pwd`
44 tmp=/tmp/$$
45 runas=$here/src/runas
46 status=1        # FAILure is the default!
47 trap "_cleanup; exit \$status" 0 1 2 3 15
48
49 # get standard environment, filters and checks
50 . ./common.rc
51 . ./common.filter
52 . ./common.attr
53
54 _cleanup()
55 {
56     rm -f $tmp.*
57     rm -rf $TEST_DIR/$seq.dir1
58 }
59
60 # -----
61 # minimal access ACL has ACEs: USER_OBJ, GROUP_OBJ, OTHER_OBJ
62 # This is set with chacl(1) and can be changed by chmod(1).
63 #
64 # Test that this is being set for ACL and for std unix permissions
65 # Test that we can get back the same ACL.
66 # Test std permissions for rwx.
67 # -----
68 #
69 # Test out default ACLs and that the ACL is being PASSed
70 # onto the children of the dir.
71 #
72 # -----
73 # Test out access check for extended ACLs.
74 # -> 3 extra ACEs: MASK, GROUP, USER
75 # -> the GROUP compares with egid of process _and_ the supplementary
76 #    groups (as found in /etc/group)
77 #
78 # Test that mask works for USER, GROUP, GROUP_OBJ
79 # Test that the ACE type priority is working
80 #   -> this would be done by simultaneously matching on ACEs
81 #   -> interesting if it allows user to specify ACEs in any order
82 #
83 rm -f $seq.full
84
85 _need_to_be_root
86 _acl_setup_ids
87 _acl_requirements
88 [ -x $runas ] || _notrun "$runas executable not found"
89
90 # get dir
91 cd $TEST_DIR
92 rm -rf $seq.dir1
93 mkdir $seq.dir1
94 cd $seq.dir1
95
96 #-------------------------------------------------------
97 # real QA test starts here
98 echo "QA output created by $seq"
99
100 echo ""
101 echo "=== Test minimal ACE ==="
102
103 echo "Setup file"
104 # Note: as this is a shell script,
105 #       will need read and execute permission set
106 #       in order to execute it.
107 touch file1
108 cat <<EOF >file1
109 #!/bin/sh
110 echo "Test was executed"
111 EOF
112 chmod u=rwx file1
113 chmod g=rw- file1
114 chmod o=r-- file1
115 chown $acl1.$acl2 file1
116 _acl_ls file1
117
118 echo ""
119 echo "--- Test get and set of ACL ---"
120 echo "Note: Old interface gave an empty ACL - now output an ACL"
121 chacl -l file1 | _acl_filter_id
122 echo "Try using single colon separator"
123 echo "Note: Old interface FAILed because of single colon - new one allows it" 
124 chacl u::r--,g::rwx,o:rw- file1 2>&1
125 echo "Expect to PASS" 
126 chacl u::r--,g::rwx,o::rw- file1 2>&1
127 chacl -l file1 | _acl_filter_id
128
129 echo ""
130 echo "--- Test sync of ACL with std permissions ---"
131 _acl_ls file1
132 chmod u+w file1
133 _acl_ls file1
134 chacl -l file1 | _acl_filter_id
135
136 echo ""
137 echo "--- Test owner permissions ---"
138 chacl u::r-x,g::---,o::--- file1 2>&1
139 chacl -l file1 | _acl_filter_id
140 # change to owner
141 echo "Expect to PASS" 
142 $runas -u $acl1 -g $acl1 ./file1 2>&1
143 echo "Expect to FAIL" 
144 $runas -u $acl2 -g $acl2 ./file1 2>&1
145
146 echo ""
147 echo "--- Test group permissions ---"
148 chacl u::---,g::r-x,o::--- file1 2>&1
149 chacl -l file1 | _acl_filter_id
150 echo "Expect to FAIL - acl1 is owner" 
151 $runas -u $acl1 -g $acl1 ./file1 2>&1
152 echo "Expect to PASS - acl2 matches group" 
153 $runas -u $acl2 -g $acl2 ./file1 2>&1
154 echo "Expect to PASS - acl2 matches sup group" 
155 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
156 echo "Expect to FAIL - acl3 is not in group" 
157 $runas -u $acl3 -g $acl3 ./file1 2>&1
158
159 echo ""
160 echo "--- Test other permissions ---"
161 chacl u::---,g::---,o::r-x file1 2>&1
162 chacl -l file1 | _acl_filter_id
163 echo "Expect to FAIL - acl1 is owner" 
164 $runas -u $acl1 -g $acl1 ./file1 2>&1
165 echo "Expect to FAIL - acl2 is in group" 
166 $runas -u $acl2 -g $acl2 ./file1 2>&1
167 echo "Expect to FAIL - acl2 is in sup. group" 
168 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
169 echo "Expect to PASS - acl3 is not owner or in group" 
170 $runas -u $acl3 -g $acl3 ./file1 2>&1
171
172 #-------------------------------------------------------
173
174 echo ""
175 echo "=== Test Extended ACLs ==="
176
177 echo ""
178 echo "--- Test adding a USER ACE ---"
179 echo "Expect to FAIL as no MASK provided"
180 chacl u::---,g::---,o::---,u:$acl2:r-x file1 2>&1 | _acl_filter_id
181 echo "Ensure that ACL has not been changed"
182 chacl -l file1 | _acl_filter_id
183 echo "Expect to PASS - USER ACE matches user"
184 chacl u::---,g::---,o::---,u:$acl2:r-x,m::rwx file1 2>&1
185 chacl -l file1 | _acl_filter_id
186 $runas -u $acl2 -g $acl2 ./file1 2>&1
187 echo "Expect to FAIL - USER ACE does not match user"
188 $runas -u $acl3 -g $acl3 ./file1 2>&1
189
190 echo ""
191 echo "--- Test adding a GROUP ACE ---"
192 echo "Expect to FAIL as no MASK provided"
193 chacl u::---,g::---,o::---,g:$acl2:r-x file1 2>&1 | _acl_filter_id
194 echo "Ensure that ACL has not been changed"
195 chacl -l file1 | _acl_filter_id
196 chacl u::---,g::---,o::---,g:$acl2:r-x,m::rwx file1 2>&1
197 chacl -l file1 | _acl_filter_id
198 echo "Expect to PASS - GROUP ACE matches group"
199 $runas -u $acl2 -g $acl2 ./file1 2>&1
200 echo "Expect to PASS - GROUP ACE matches sup group"
201 $runas -u $acl2 -g $acl1 -s $acl2 ./file1 2>&1
202 echo "Expect to FAIL - GROUP ACE does not match group"
203 $runas -u $acl3 -g $acl3 ./file1 2>&1
204
205 #-------------------------------------------------------
206
207 echo ""
208 echo "--- Test MASK ---"
209
210 # group
211 chacl u::---,g::---,o::---,g:$acl2:r-x,m::-w- file1 2>&1
212 chacl -l file1 | _acl_filter_id
213 echo "Expect to FAIL as MASK prohibits execution"
214 $runas -u $acl2 -g $acl2 ./file1 2>&1
215
216 # user
217 chacl u::---,g::---,o::---,u:$acl2:r-x,m::-w- file1 2>&1
218 echo "Expect to FAIL as MASK prohibits execution"
219 $runas -u $acl2 -g $acl2 ./file1 2>&1
220
221 # user
222 chacl u::---,g::---,o::---,u:$acl2:r-x,m::r-x file1 2>&1
223 echo "Expect to PASS as MASK allows execution"
224 $runas -u $acl2 -g $acl2 ./file1 2>&1
225
226 #-------------------------------------------------------
227
228 echo ""
229 echo "--- Test ACE priority ---"
230
231 chacl o::rwx,g::rwx,u:$acl1:rwx,u::---,m::rwx file1 2>&1
232 echo "Expect to FAIL as should match on owner"
233 $runas -u $acl1 -g $acl2 ./file1 2>&1
234
235 chacl o::---,g::---,u:$acl2:rwx,u::---,m::rwx file1 2>&1
236 echo "Expect to PASS as should match on user"
237 $runas -u $acl2 -g $acl2 ./file1 2>&1
238
239
240 #-------------------------------------------------------
241
242 echo ""
243 echo "=== Test can read ACLs without access permissions ==="
244 # This was a bug in kernel code where syscred wasn't being used
245 # to override the capabilities
246 chacl o::---,g::---,u::--- file1 2>&1
247 chacl -l file1 | _acl_filter_id
248
249 #-------------------------------------------------------
250
251 echo ""
252 echo "=== Test Default ACLs ==="
253 # make test clearer by testing with and without umask
254 umask 0
255
256 mkdir acldir
257 chacl -b "u::rwx,g::rwx,o::rwx" "u::r-x,g::r--,o::---" acldir 2>&1
258 chacl -l acldir | _acl_filter_id
259 cd acldir
260
261 touch file2
262 _acl_ls file2
263 chacl -l file2 | _acl_filter_id
264
265 #ensure that umask is not having an effect 
266 #so set it and see
267 umask 722
268 touch file3
269 _acl_ls file3
270 chacl -l file3 | _acl_filter_id
271
272 cd ..
273 umask 022
274
275
276 #-------------------------------------------------------
277
278 echo ""
279 echo "=== Removing ACLs ==="
280 chacl -l file1 | _acl_filter_id
281 chacl -l acldir | _acl_filter_id
282 chacl -l acldir/file2 | _acl_filter_id
283 echo "Remove ACLs..."
284 chacl -R file1
285 chacl -B acldir
286 chacl -R acldir/file2
287 echo "Note: Old interface would mean empty ACLs - now we show mode ACLs" 
288 chacl -l file1 | _acl_filter_id
289 chacl -l acldir | _acl_filter_id
290 chacl -l acldir/file2 | _acl_filter_id
291
292
293 #-------------------------------------------------------
294
295 echo ""
296 echo "=== Recursive change ACL ==="
297 rm -fr root
298 mkdir root
299 pushd root >/dev/null
300 # create an arbitrary little tree
301 for i in 1 2 3 4 5 6 7 8 9 0
302 do
303         mkdir -p a/$i
304         mkdir -p b/c$i/$i
305         touch a/$i/mumble
306 done
307 popd >/dev/null
308 chown -R 12345.54321 root
309 echo "Change #1..."
310 $runas -u 12345 -g 54321 -- `which chacl` -r u::rwx,g::-w-,o::--x root
311 find root -print | xargs chacl -l
312 echo "Change #2..."
313 $runas -u 12345 -g 54321 -- `which chacl` -r u::---,g::---,o::--- root
314 find root -print | xargs chacl -l
315
316
317 #-------------------------------------------------------
318
319 echo ""
320 echo "=== Test out error messages for ACL text parsing  ==="
321 echo "Note: Old interface gave more informative error msgs"
322
323 touch file1
324 set -x
325 chacl u file1
326 chacl u: file1
327 chacl u:rumpledumpleunknownuser file1
328 chacl u:rumpledumpleunknownuser: file1
329 chacl g:rumpledumpleunknowngrp file1
330 chacl g:rumpledumpleunknowngrp: file1
331 chacl o:user1:rwx file1
332 chacl m:user1:rwx file1
333 chacl a::rwx file1
334 set +x
335
336 #-------------------------------------------------------
337
338 echo ""
339 echo "=== Test out large ACLs  ==="
340 touch largeaclfile
341 XFS_ACL_MAX_ENTRIES=25
342 num_aces_pre=`expr $XFS_ACL_MAX_ENTRIES - 1`
343 num_aces_post=`expr $XFS_ACL_MAX_ENTRIES + 1`
344
345 acl1=`_create_n_aces $num_aces_pre`
346 acl2=`_create_n_aces $XFS_ACL_MAX_ENTRIES`
347 acl3=`_create_n_aces $num_aces_post`
348 acl4=`_create_n_aces 16` # Andreas G. libacl size for initial get
349 acl5=`_create_n_aces 17` # 1 over A.G. libacl initial size
350
351 echo "1 below xfs acl max"
352 chacl $acl1 largeaclfile
353 getfacl largeaclfile | _filter_aces
354
355 echo "xfs acl max"
356 chacl $acl2 largeaclfile
357 getfacl largeaclfile | _filter_aces
358
359 echo "1 above xfs acl max"
360 chacl $acl3 largeaclfile
361 getfacl largeaclfile | _filter_aces
362
363 echo "use 16 aces"
364 chacl $acl4 largeaclfile
365 getfacl largeaclfile | _filter_aces
366
367 echo "use 17 aces"
368 chacl $acl5 largeaclfile
369 getfacl largeaclfile | _filter_aces
370
371 #-------------------------------------------------------
372
373 # success, all done
374 status=0
375 exit