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