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