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