fix _require_scratch test for extN, resierfs, gfs2, and btrfs
[xfstests-dev.git] / 099
1 #! /bin/sh
2 # FS QA Test No. 099. Modified from UDFQA test 036.
3 #
4 # ACL test
5 #-----------------------------------------------------------------------
6 # Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it would be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write the Free Software Foundation,
19 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 #
21 #-----------------------------------------------------------------------
22 #
23 #_acl_list
24 # modifier
25 owner=ajones@sgi.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
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 runas=$here/src/runas
41
42 TARGET_DIR=$SCRATCH_MNT
43 [ "$FSTYP" == "xfs" ] && TARGET_DIR=$TEST_DIR
44
45 _cleanup()
46 {
47     rm -f $tmp.*
48     cd $TARGET_DIR
49     rm -rf $seq.dir1
50     cd /
51 }
52
53 # -----
54 # minimal access ACL has ACEs: USER_OBJ, GROUP_OBJ, OTHER_OBJ
55 # This is set with chacl(1) and can be changed by chmod(1).
56 #
57 # Test that this is being set for ACL and for std unix permissions
58 # Test that we can get back the same ACL.
59 # Test std permissions for rwx.
60 # -----
61 #
62 # Test out default ACLs and that the ACL is being PASSed
63 # onto the children of the dir.
64 #
65 # -----
66 # Test out access check for extended ACLs.
67 # -> 3 extra ACEs: MASK, GROUP, USER
68 # -> the GROUP compares with egid of process _and_ the supplementary
69 #    groups (as found in /etc/group)
70 #
71 # Test that mask works for USER, GROUP, GROUP_OBJ
72 # Test that the ACE type priority is working
73 #   -> this would be done by simultaneously matching on ACEs
74 #   -> interesting if it allows user to specify ACEs in any order
75 #
76 rm -f $seq.full
77
78 #-------------------------------------------------------
79 # real QA test starts here
80 _supported_fs generic
81 _supported_os IRIX
82
83 _acl_setup_ids
84 _acl_requirements
85 [ -x $runas ] || _notrun "$runas executable not found"
86
87 # get dir
88 #export FILE_SYS=xfs
89 _require_scratch
90 _setup_testdir
91
92 cd $TARGET_DIR
93 rm -rf $seq.dir1 # in case file is left over from previous runs.
94 mkdir $seq.dir1
95 cd $seq.dir1
96
97 echo ""
98 echo "=== Test minimal ACE ==="
99
100 echo "Setup file"
101 # Note: as this is a shell script,
102 #       will need read and execute permission set
103 #       in order to execute it.
104 touch file1
105 cat <<EOF >file1
106 #!/bin/sh
107 echo "Test was executed"
108 EOF
109 chmod u=rwx file1
110 chmod g=rw- file1
111 chmod o=r-- file1
112 chown $acl1.$acl2 file1
113 _acl_ls file1
114
115 echo ""
116 echo "--- Test get and set of ACL ---"
117 echo "Note: IRIX interface gave an empty ACL - Linux outputs an ACL"
118 _acl_list file1
119 echo "Try using single colon separator"
120 echo "Note: IRIX interface FAILs because of single colon - Linux one allows it" 
121 chacl u::r--,g::rwx,o:rw- file1 2>&1
122 echo "Expect to PASS" 
123 chacl u::r--,g::rwx,o::rw- file1 2>&1
124 _acl_list file1
125
126 echo ""
127 echo "--- Test sync of ACL with std permissions ---"
128 _acl_ls file1
129 chmod u+w file1
130 _acl_ls file1
131 _acl_list file1
132
133 echo ""
134 echo "--- Test owner permissions ---"
135 chacl u::r-x,g::---,o::--- file1 2>&1
136 _acl_list file1
137 # change to owner
138 echo "Expect to PASS" 
139 $runas -u $acl1 -g $acl1 ./file1 2>&1
140 echo "Expect to FAIL" 
141 $runas -u $acl2 -g $acl2 ./file1 2>&1
142
143 echo ""
144 echo "--- Test group permissions ---"
145 chacl u::---,g::r-x,o::--- file1 2>&1
146 _acl_list file1
147 echo "Expect to FAIL - acl1 is owner" 
148 $runas -u $acl1 -g $acl1 ./file1 2>&1
149 echo "Expect to PASS - acl2 matches group" 
150 $runas -u $acl2 -g $acl2 ./file1 2>&1
151 echo "Expect to PASS - acl2 matches sup group" 
152 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
153 echo "Expect to FAIL - acl3 is not in group" 
154 $runas -u $acl3 -g $acl3 ./file1 2>&1
155
156 echo ""
157 echo "--- Test other permissions ---"
158 chacl u::---,g::---,o::r-x file1 2>&1
159 _acl_list file1
160 echo "Expect to FAIL - acl1 is owner" 
161 $runas -u $acl1 -g $acl1 ./file1 2>&1
162 echo "Expect to FAIL - acl2 is in group" 
163 $runas -u $acl2 -g $acl2 ./file1 2>&1
164 echo "Expect to FAIL - acl2 is in sup. group" 
165 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
166 echo "Expect to PASS - acl3 is not owner or in group" 
167 $runas -u $acl3 -g $acl3 ./file1 2>&1
168
169 #-------------------------------------------------------
170
171 echo ""
172 echo "=== Test Extended ACLs ==="
173
174 echo ""
175 echo "--- Test adding a USER ACE ---"
176 echo "Expect to FAIL as no MASK provided"
177 chacl u::---,g::---,o::---,u:$acl2:r-x file1 2>&1 | _acl_filter_id
178 echo "Ensure that ACL has not been changed"
179 _acl_list file1
180 echo "Expect to PASS - USER ACE matches user"
181 chacl u::---,g::---,o::---,u:$acl2:r-x,m::rwx file1 2>&1
182 _acl_list file1
183 $runas -u $acl2 -g $acl2 ./file1 2>&1
184 echo "Expect to FAIL - USER ACE does not match user"
185 $runas -u $acl3 -g $acl3 ./file1 2>&1
186
187 echo ""
188 echo "--- Test adding a GROUP ACE ---"
189 echo "Expect to FAIL as no MASK provided"
190 chacl u::---,g::---,o::---,g:$acl2:r-x file1 2>&1 | _acl_filter_id
191 echo "Ensure that ACL has not been changed"
192 _acl_list file1
193 chacl u::---,g::---,o::---,g:$acl2:r-x,m::rwx file1 2>&1
194 _acl_list file1 | _acl_filter_id
195 echo "Expect to PASS - GROUP ACE matches group"
196 $runas -u $acl2 -g $acl2 ./file1 2>&1
197 echo "Expect to PASS - GROUP ACE matches sup group"
198 $runas -u $acl2 -g $acl1 -s $acl2 ./file1 2>&1
199 echo "Expect to FAIL - GROUP ACE does not match group"
200 $runas -u $acl3 -g $acl3 ./file1 2>&1
201
202 #-------------------------------------------------------
203
204 echo ""
205 echo "--- Test MASK ---"
206
207 # group
208 chacl u::---,g::---,o::---,g:$acl2:r-x,m::-w- file1 2>&1
209 _acl_list file1
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::-w- file1 2>&1
215 echo "Expect to FAIL as MASK prohibits execution"
216 $runas -u $acl2 -g $acl2 ./file1 2>&1
217
218 # user
219 chacl u::---,g::---,o::---,u:$acl2:r-x,m::r-x file1 2>&1
220 echo "Expect to PASS as MASK allows execution"
221 $runas -u $acl2 -g $acl2 ./file1 2>&1
222
223 #-------------------------------------------------------
224
225 echo ""
226 echo "--- Test ACE priority ---"
227
228 chacl o::rwx,g::rwx,u:$acl1:rwx,u::---,m::rwx file1 2>&1
229 echo "Expect to FAIL as should match on owner"
230 $runas -u $acl1 -g $acl2 ./file1 2>&1
231
232 chacl o::---,g::---,u:$acl2:rwx,u::---,m::rwx file1 2>&1
233 echo "Expect to PASS as should match on user"
234 $runas -u $acl2 -g $acl2 ./file1 2>&1
235
236
237 #-------------------------------------------------------
238
239 echo ""
240 echo "=== Test can read ACLs without access permissions ==="
241 # This was a bug in kernel code where syscred wasn't being used
242 # to override the capabilities
243 chacl o::---,g::---,u::--- file1 2>&1
244 _acl_list file1
245
246 #-------------------------------------------------------
247
248 echo ""
249 echo "=== Test Default ACLs ==="
250 # make test clearer by testing with and without umask
251 umask 0
252
253 mkdir acldir
254 chacl -b "u::rwx,g::rwx,o::rwx" "u::r-x,g::r--,o::---" acldir 2>&1
255 _acl_list acldir
256 cd acldir
257
258 touch file2
259 _acl_ls file2
260 _acl_list file2
261
262 #ensure that umask is not having an effect 
263 #so set it and see
264 umask 722
265 touch file3
266 _acl_ls file3
267 _acl_list file3
268
269 cd ..
270 umask 022
271
272
273 #-------------------------------------------------------
274
275 echo ""
276 echo "=== Removing ACLs ==="
277 _acl_list file1
278 _acl_list acldir
279 _acl_list acldir/file2
280 echo "Remove ACLs..."
281 chacl -R file1
282 chacl -B acldir
283 chacl -R acldir/file2
284 echo "Note: IRIX interface would mean empty ACLs - Linux would show mode ACLs" 
285 _acl_list file1
286 _acl_list acldir
287 _acl_list acldir/file2
288
289 #-------------------------------------------------------
290
291 echo ""
292 echo "=== Test out error messages for ACL text parsing  ==="
293
294 touch file1
295 set -x
296 chacl u file1
297 chacl u: file1
298 chacl u:rumpledumpleunknownuser file1
299 chacl u:rumpledumpleunknownuser: file1
300 chacl g:rumpledumpleunknowngrp file1
301 chacl g:rumpledumpleunknowngrp: file1
302 chacl o:user1:rwx file1
303 chacl m:user1:rwx file1
304 chacl a::rwx file1
305 set +x
306
307 #-------------------------------------------------------
308
309 echo ""
310 echo "=== Test out large ACLs  ==="
311 touch largeaclfile
312 XFS_ACL_MAX_ENTRIES=25
313 num_aces_pre=`expr $XFS_ACL_MAX_ENTRIES - 1`
314 num_aces_post=`expr $XFS_ACL_MAX_ENTRIES + 1`
315
316 acl1=`_create_n_aces $num_aces_pre`
317 acl2=`_create_n_aces $XFS_ACL_MAX_ENTRIES`
318 acl3=`_create_n_aces $num_aces_post`
319
320 echo "1 below xfs acl max"
321 chacl $acl1 largeaclfile
322 _acl_list largeaclfile | _filter_aces_notypes
323
324 echo "xfs acl max"
325 chacl $acl2 largeaclfile
326 _acl_list largeaclfile | _filter_aces_notypes
327
328 echo "1 above xfs acl max"
329 chacl $acl3 largeaclfile
330 _acl_list largeaclfile | _filter_aces_notypes
331
332 #-------------------------------------------------------
333
334 if [ "$FSTYP" == "udf" ]; then
335     cd /
336     umount $TARGET_DIR
337     # Check the filesystem
338     _check_scratch_fs
339 fi
340 # success, all done
341 status=0
342 exit