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