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