generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 099
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 099
6 #
7 # Test out ACLs.
8 #
9 #!/bin/bash
10 . ./common/preamble
11 _begin_fstest acl auto quick
12
13 # Import common functions.
14 . ./common/filter
15 . ./common/attr
16
17 # Override the default cleanup function.
18 _cleanup()
19 {
20     cd /
21     rm -f $tmp.*
22     [ -n "$TEST_DIR" ] && rm -rf $TEST_DIR/$seq.dir1
23 }
24
25 # -----
26 # minimal access ACL has ACEs: USER_OBJ, GROUP_OBJ, OTHER_OBJ
27 # This is set with chacl(1) and can be changed by chmod(1).
28 #
29 # Test that this is being set for ACL and for std unix permissions
30 # Test that we can get back the same ACL.
31 # Test std permissions for rwx.
32 # -----
33 #
34 # Test out default ACLs and that the ACL is being PASSed
35 # onto the children of the dir.
36 #
37 # -----
38 # Test out access check for extended ACLs.
39 # -> 3 extra ACEs: MASK, GROUP, USER
40 # -> the GROUP compares with egid of process _and_ the supplementary
41 #    groups (as found in /etc/group)
42 #
43 # Test that mask works for USER, GROUP, GROUP_OBJ
44 # Test that the ACE type priority is working
45 #   -> this would be done by simultaneously matching on ACEs
46 #   -> interesting if it allows user to specify ACEs in any order
47 #
48
49 # real QA test starts here
50 _supported_fs generic
51 _require_test
52 _require_runas
53
54 _acl_setup_ids
55 _require_acls
56
57 # get dir
58 cd $TEST_DIR
59 rm -rf $seq.dir1
60 mkdir $seq.dir1
61 cd $seq.dir1
62
63 echo ""
64 echo "=== Test minimal ACE ==="
65
66 echo "Setup file"
67 # Note: as this is a shell script,
68 #       will need read and execute permission set
69 #       in order to execute it.
70 touch file1
71 cat <<EOF >file1
72 echo "Test was executed"
73 EOF
74 chmod u=rwx file1
75 chmod g=rw- file1
76 chmod o=r-- file1
77 chown $acl1.$acl2 file1
78 _acl_ls file1
79
80 echo ""
81 echo "--- Test get and set of ACL ---"
82 echo "Note: Old interface gave an empty ACL - now output an ACL"
83 chacl -l file1 | _acl_filter_id
84 echo "Try using single colon separator"
85 echo "Note: Old interface FAILed because of single colon - new one allows it" 
86 chacl u::r--,g::rwx,o:rw- file1 2>&1
87 echo "Expect to PASS" 
88 chacl u::r--,g::rwx,o::rw- file1 2>&1
89 chacl -l file1 | _acl_filter_id
90
91 echo ""
92 echo "--- Test sync of ACL with std permissions ---"
93 _acl_ls file1
94 chmod u+w file1
95 _acl_ls file1
96 chacl -l file1 | _acl_filter_id
97
98 echo ""
99 echo "--- Test owner permissions ---"
100 chacl u::r-x,g::---,o::--- file1 2>&1
101 chacl -l file1 | _acl_filter_id
102 # change to owner
103 echo "Expect to PASS" 
104 _runas -u $acl1 -g $acl1 ./file1 2>&1
105 echo "Expect to FAIL" 
106 _runas -u $acl2 -g $acl2 ./file1 2>&1
107
108 echo ""
109 echo "--- Test group permissions ---"
110 chacl u::---,g::r-x,o::--- file1 2>&1
111 chacl -l file1 | _acl_filter_id
112 echo "Expect to FAIL - acl1 is owner" 
113 _runas -u $acl1 -g $acl1 ./file1 2>&1
114 echo "Expect to PASS - acl2 matches group" 
115 _runas -u $acl2 -g $acl2 ./file1 2>&1
116 echo "Expect to PASS - acl2 matches sup group" 
117 _runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
118 echo "Expect to FAIL - acl3 is not in group" 
119 _runas -u $acl3 -g $acl3 ./file1 2>&1
120
121 echo ""
122 echo "--- Test other permissions ---"
123 chacl u::---,g::---,o::r-x file1 2>&1
124 chacl -l file1 | _acl_filter_id
125 echo "Expect to FAIL - acl1 is owner" 
126 _runas -u $acl1 -g $acl1 ./file1 2>&1
127 echo "Expect to FAIL - acl2 is in group" 
128 _runas -u $acl2 -g $acl2 ./file1 2>&1
129 echo "Expect to FAIL - acl2 is in sup. group" 
130 _runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
131 echo "Expect to PASS - acl3 is not owner or in group" 
132 _runas -u $acl3 -g $acl3 ./file1 2>&1
133
134 #-------------------------------------------------------
135
136 echo ""
137 echo "=== Test Extended ACLs ==="
138
139 echo ""
140 echo "--- Test adding a USER ACE ---"
141 echo "Expect to FAIL as no MASK provided"
142 chacl u::---,g::---,o::---,u:$acl2:r-x file1 2>&1 | _acl_filter_id
143 echo "Ensure that ACL has not been changed"
144 chacl -l file1 | _acl_filter_id
145 echo "Expect to PASS - USER ACE matches user"
146 chacl u::---,g::---,o::---,u:$acl2:r-x,m::rwx file1 2>&1
147 chacl -l file1 | _acl_filter_id
148 _runas -u $acl2 -g $acl2 ./file1 2>&1
149 echo "Expect to FAIL - USER ACE does not match user"
150 _runas -u $acl3 -g $acl3 ./file1 2>&1
151
152 echo ""
153 echo "--- Test adding a GROUP ACE ---"
154 echo "Expect to FAIL as no MASK provided"
155 chacl u::---,g::---,o::---,g:$acl2:r-x file1 2>&1 | _acl_filter_id
156 echo "Ensure that ACL has not been changed"
157 chacl -l file1 | _acl_filter_id
158 chacl u::---,g::---,o::---,g:$acl2:r-x,m::rwx file1 2>&1
159 chacl -l file1 | _acl_filter_id
160 echo "Expect to PASS - GROUP ACE matches group"
161 _runas -u $acl2 -g $acl2 ./file1 2>&1
162 echo "Expect to PASS - GROUP ACE matches sup group"
163 _runas -u $acl2 -g $acl1 -s $acl2 ./file1 2>&1
164 echo "Expect to FAIL - GROUP ACE does not match group"
165 _runas -u $acl3 -g $acl3 ./file1 2>&1
166
167 #-------------------------------------------------------
168
169 echo ""
170 echo "--- Test MASK ---"
171
172 # group
173 chacl u::---,g::---,o::---,g:$acl2:r-x,m::-w- file1 2>&1
174 chacl -l file1 | _acl_filter_id
175 echo "Expect to FAIL as MASK prohibits execution"
176 _runas -u $acl2 -g $acl2 ./file1 2>&1
177
178 # user
179 chacl u::---,g::---,o::---,u:$acl2:r-x,m::-w- file1 2>&1
180 echo "Expect to FAIL as MASK prohibits execution"
181 _runas -u $acl2 -g $acl2 ./file1 2>&1
182
183 # user
184 chacl u::---,g::---,o::---,u:$acl2:r-x,m::r-x file1 2>&1
185 echo "Expect to PASS as MASK allows execution"
186 _runas -u $acl2 -g $acl2 ./file1 2>&1
187
188 #-------------------------------------------------------
189
190 echo ""
191 echo "--- Test ACE priority ---"
192
193 chacl o::rwx,g::rwx,u:$acl1:rwx,u::---,m::rwx file1 2>&1
194 echo "Expect to FAIL as should match on owner"
195 _runas -u $acl1 -g $acl2 ./file1 2>&1
196
197 chacl o::---,g::---,u:$acl2:rwx,u::---,m::rwx file1 2>&1
198 echo "Expect to PASS as should match on user"
199 _runas -u $acl2 -g $acl2 ./file1 2>&1
200
201 #-------------------------------------------------------
202
203 echo ""
204 echo "=== Test can read ACLs without access permissions ==="
205 # This was a bug in kernel code where syscred wasn't being used
206 # to override the capabilities
207 chacl o::---,g::---,u::--- file1 2>&1
208 chacl -l file1 | _acl_filter_id
209
210 #-------------------------------------------------------
211
212 echo ""
213 echo "=== Test Default ACLs ==="
214 # make test clearer by testing with and without umask
215 umask 0
216
217 mkdir acldir
218 chacl -b "u::rwx,g::rwx,o::rwx" "u::r-x,g::r--,o::---" acldir 2>&1
219 chacl -l acldir | _acl_filter_id
220 cd acldir
221
222 touch file2
223 _acl_ls file2
224 chacl -l file2 | _acl_filter_id
225
226 #ensure that umask is not having an effect 
227 #so set it and see
228 umask 722
229 touch file3
230 _acl_ls file3
231 chacl -l file3 | _acl_filter_id
232
233 cd ..
234 umask 022
235
236 #-------------------------------------------------------
237
238 echo ""
239 echo "=== Removing ACLs ==="
240 chacl -l file1 | _acl_filter_id
241 chacl -l acldir | _acl_filter_id
242 chacl -l acldir/file2 | _acl_filter_id
243 echo "Remove ACLs..."
244 chacl -R file1
245 chacl -B acldir
246 chacl -R acldir/file2
247 echo "Note: Old interface would mean empty ACLs - now we show mode ACLs" 
248 chacl -l file1 | _acl_filter_id
249 chacl -l acldir | _acl_filter_id
250 chacl -l acldir/file2 | _acl_filter_id
251
252 #-------------------------------------------------------
253
254 echo ""
255 echo "=== Recursive change ACL ==="
256 rm -fr root
257 mkdir root
258 pushd root >/dev/null
259 # create an arbitrary little tree
260 for i in 1 2 3 4 5 6 7 8 9 0
261 do
262         mkdir -p a/$i
263         mkdir -p b/c$i/$i
264         touch a/$i/mumble
265 done
266 popd >/dev/null
267 chown -R 12345.54321 root
268 echo "Change #1..."
269 _runas -u 12345 -g 54321 -- chacl -r u::rwx,g::-w-,o::--x root
270 find root -print | sort | xargs chacl -l
271 echo "Change #2..."
272 _runas -u 12345 -g 54321 -- chacl -r u::---,g::---,o::--- root
273 find root -print | sort | xargs chacl -l
274
275 #-------------------------------------------------------
276
277 echo ""
278 echo "=== Test out error messages for ACL text parsing  ==="
279 echo "Note: Old interface gave more informative error msgs"
280
281 touch file1
282 set -x
283 chacl u file1
284 chacl u: file1
285 chacl u:rumpledumpleunknownuser file1
286 chacl u:rumpledumpleunknownuser: file1
287 chacl g:rumpledumpleunknowngrp file1
288 chacl g:rumpledumpleunknowngrp: file1
289 chacl o:user1:rwx file1
290 chacl m:user1:rwx file1
291 chacl a::rwx file1
292 set +x
293
294 # success, all done
295 status=0
296 exit