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