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