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