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