Use umount/mount to ensure stuff is written to disk so that
[xfstests-dev.git] / 051
1 #! /bin/sh
2 # XFS QA Test No. 051
3 # $Id: 1.1 $
4 #
5 # Test out ACLs.
6 #
7 #-----------------------------------------------------------------------
8 # Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
9
10 # This program is free software; you can redistribute it and/or modify it
11 # under the terms of version 2 of the GNU General Public License as
12 # published by the Free Software Foundation.
13
14 # This program is distributed in the hope that it would be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18 # Further, this software is distributed without any warranty that it is
19 # free of the rightful claim of any third person regarding infringement
20 # or the like.  Any license provided herein, whether implied or
21 # otherwise, applies only to this software file.  Patent licenses, if
22 # any, provided herein do not apply to combinations of this program with
23 # other software, or any other product whatsoever.
24
25 # You should have received a copy of the GNU General Public License along
26 # with this program; if not, write the Free Software Foundation, Inc., 59
27 # Temple Place - Suite 330, Boston MA 02111-1307, USA.
28
29 # Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
30 # Mountain View, CA  94043, or:
31
32 # http://www.sgi.com 
33
34 # For further information regarding this notice, see: 
35
36 # http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
37 #-----------------------------------------------------------------------
38 #
39 # creator
40 owner=tes@sgi.com
41
42 seq=`basename $0`
43
44 here=`pwd`
45 tmp=/tmp/$$
46 runas=$here/src/runas
47 status=1        # FAILure is the default!
48 trap "_cleanup; exit \$status" 0 1 2 3 15
49
50 # get standard environment, filters and checks
51 . ./common.rc
52 . ./common.filter
53 . ./common.attr
54
55 _cleanup()
56 {
57     rm -f $tmp.*
58     rm -rf $TEST_DIR/$seq.dir1
59 }
60
61 # -----
62 # minimal access ACL has ACEs: USER_OBJ, GROUP_OBJ, OTHER_OBJ
63 # This is set with chacl(1) and can be changed by chmod(1).
64 #
65 # Test that this is being set for ACL and for std unix permissions
66 # Test that we can get back the same ACL.
67 # Test std permissions for rwx.
68 # -----
69 #
70 # Test out default ACLs and that the ACL is being PASSed
71 # onto the children of the dir.
72 #
73 # -----
74 # Test out access check for extended ACLs.
75 # -> 3 extra ACEs: MASK, GROUP, USER
76 # -> the GROUP compares with egid of process _and_ the supplementary
77 #    groups (as found in /etc/group)
78 #
79 # Test that mask works for USER, GROUP, GROUP_OBJ
80 # Test that the ACE type priority is working
81 #   -> this would be done by simultaneously matching on ACEs
82 #   -> interesting if it allows user to specify ACEs in any order
83 #
84 rm -f $seq.full
85
86 _need_to_be_root
87 _acl_setup_ids
88
89 [ -x /bin/chacl ] || _notrun "chacl command not found"
90 [ -x $runas ] || _notrun "$runas executable not found"
91
92 # get dir
93 cd $TEST_DIR
94 rm -rf $seq.dir1
95 mkdir $seq.dir1
96 cd $seq.dir1
97
98 # test if acl_get syscall is operational
99 # and hence the ACL config has been turned on  
100 touch syscalltest
101 if chacl -l syscalltest 2>&1 | tee -a $here/$seq.full | grep 'Function not implemented' >/dev/null
102 then
103   cd $here
104   _notrun "requires kernel ACL support"
105 fi
106
107 #-------------------------------------------------------
108 # real QA test starts here
109 echo "QA output created by $seq"
110
111 echo ""
112 echo "=== Test minimal ACE ==="
113
114 echo "Setup file"
115 # Note: as this is a shell script,
116 #       will need read and execute permission set
117 #       in order to execute it.
118 touch file1
119 cat <<EOF >file1
120 #!/bin/sh
121 echo "Test was executed"
122 EOF
123 chmod u=rwx file1
124 chmod g=rw- file1
125 chmod o=r-- file1
126 chown $acl1.$acl2 file1
127 _acl_ls file1
128
129 echo ""
130 echo "--- Test get and set of ACL ---"
131 chacl -l file1 | _acl_filter_id
132 echo "Expect to FAIL" 
133 chacl u::r--,g::rwx,o:rw- file1 2>&1
134 echo "Expect to PASS" 
135 chacl u::r--,g::rwx,o::rw- file1 2>&1
136 chacl -l file1 | _acl_filter_id
137
138 echo ""
139 echo "--- Test sync of ACL with std permissions ---"
140 _acl_ls file1
141 chmod u+w file1
142 _acl_ls file1
143 chacl -l file1 | _acl_filter_id
144
145 echo ""
146 echo "--- Test owner permissions ---"
147 chacl u::r-x,g::---,o::--- file1 2>&1
148 chacl -l file1 | _acl_filter_id
149 # change to owner
150 echo "Expect to PASS" 
151 $runas -u $acl1 -g $acl1 ./file1 2>&1
152 echo "Expect to FAIL" 
153 $runas -u $acl2 -g $acl2 ./file1 2>&1
154
155 echo ""
156 echo "--- Test group permissions ---"
157 chacl u::---,g::r-x,o::--- file1 2>&1
158 chacl -l file1 | _acl_filter_id
159 echo "Expect to FAIL - acl1 is owner" 
160 $runas -u $acl1 -g $acl1 ./file1 2>&1
161 echo "Expect to PASS - acl2 matches group" 
162 $runas -u $acl2 -g $acl2 ./file1 2>&1
163 echo "Expect to PASS - acl2 matches sup group" 
164 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
165 echo "Expect to FAIL - acl3 is not in group" 
166 $runas -u $acl3 -g $acl3 ./file1 2>&1
167
168 echo ""
169 echo "--- Test other permissions ---"
170 chacl u::---,g::---,o::r-x file1 2>&1
171 chacl -l file1 | _acl_filter_id
172 echo "Expect to FAIL - acl1 is owner" 
173 $runas -u $acl1 -g $acl1 ./file1 2>&1
174 echo "Expect to FAIL - acl2 is in group" 
175 $runas -u $acl2 -g $acl2 ./file1 2>&1
176 echo "Expect to FAIL - acl2 is in sup. group" 
177 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
178 echo "Expect to PASS - acl3 is not owner or in group" 
179 $runas -u $acl3 -g $acl3 ./file1 2>&1
180
181 #-------------------------------------------------------
182
183 echo ""
184 echo "=== Test Extended ACLs ==="
185
186 echo ""
187 echo "--- Test adding a USER ACE ---"
188 echo "Expect to FAIL as no MASK provided"
189 chacl u::---,g::---,o::---,u:$acl2:r-x file1 2>&1 | _acl_filter_id
190 echo "Ensure that ACL has not been changed"
191 chacl -l file1 | _acl_filter_id
192 echo "Expect to PASS - USER ACE matches user"
193 chacl u::---,g::---,o::---,u:$acl2:r-x,m::rwx file1 2>&1
194 chacl -l file1 | _acl_filter_id
195 $runas -u $acl2 -g $acl2 ./file1 2>&1
196 echo "Expect to FAIL - USER ACE does not match user"
197 $runas -u $acl3 -g $acl3 ./file1 2>&1
198
199 echo ""
200 echo "--- Test adding a GROUP ACE ---"
201 echo "Expect to FAIL as no MASK provided"
202 chacl u::---,g::---,o::---,g:$acl2:r-x file1 2>&1 | _acl_filter_id
203 echo "Ensure that ACL has not been changed"
204 chacl -l file1 | _acl_filter_id
205 chacl u::---,g::---,o::---,g:$acl2:r-x,m::rwx file1 2>&1
206 chacl -l file1 | _acl_filter_id
207 echo "Expect to PASS - GROUP ACE matches group"
208 $runas -u $acl2 -g $acl2 ./file1 2>&1
209 echo "Expect to PASS - GROUP ACE matches sup group"
210 $runas -u $acl2 -g $acl1 -s $acl2 ./file1 2>&1
211 echo "Expect to FAIL - GROUP ACE does not match group"
212 $runas -u $acl3 -g $acl3 ./file1 2>&1
213
214 #-------------------------------------------------------
215
216 echo ""
217 echo "--- Test MASK ---"
218
219 # group
220 chacl u::---,g::---,o::---,g:$acl2:r-x,m::-w- file1 2>&1
221 chacl -l file1 | _acl_filter_id
222 echo "Expect to FAIL as MASK prohibits execution"
223 $runas -u $acl2 -g $acl2 ./file1 2>&1
224
225 # user
226 chacl u::---,g::---,o::---,u:$acl2:r-x,m::-w- file1 2>&1
227 echo "Expect to FAIL as MASK prohibits execution"
228 $runas -u $acl2 -g $acl2 ./file1 2>&1
229
230 # user
231 chacl u::---,g::---,o::---,u:$acl2:r-x,m::r-x file1 2>&1
232 echo "Expect to PASS as MASK allows execution"
233 $runas -u $acl2 -g $acl2 ./file1 2>&1
234
235 #-------------------------------------------------------
236
237 echo ""
238 echo "--- Test ACE priority ---"
239
240 chacl o::rwx,g::rwx,u:$acl1:rwx,u::---,m::rwx file1 2>&1
241 echo "Expect to FAIL as should match on owner"
242 $runas -u $acl1 -g $acl2 ./file1 2>&1
243
244 chacl o::---,g::---,u:$acl2:rwx,u::---,m::rwx file1 2>&1
245 echo "Expect to PASS as should match on user"
246 $runas -u $acl2 -g $acl2 ./file1 2>&1
247
248
249 #-------------------------------------------------------
250
251 echo ""
252 echo "=== Test can read ACLs without access permissions ==="
253 # This was a bug in kernel code where syscred wasn't being used
254 # to override the capabilities
255 chacl o::---,g::---,u::--- file1 2>&1
256 chacl -l file1 | _acl_filter_id
257
258 #-------------------------------------------------------
259
260 echo ""
261 echo "=== Test Default ACLs ==="
262 # make test clearer by testing with and without umask
263 umask 0
264
265 mkdir acldir
266 chacl -b "u::rwx,g::rwx,o::rwx" "u::r-x,g::r--,o::---" acldir 2>&1
267 chacl -l acldir | _acl_filter_id
268 cd acldir
269
270 touch file2
271 _acl_ls file2
272 chacl -l file2 | _acl_filter_id
273
274 #ensure that umask is not having an effect 
275 #so set it and see
276 umask 722
277 touch file3
278 _acl_ls file3
279 chacl -l file3 | _acl_filter_id
280
281 cd ..
282 umask 022
283
284
285 #-------------------------------------------------------
286
287 echo ""
288 echo "=== Removing ACLs ==="
289 chacl -l file1 | _acl_filter_id
290 chacl -l acldir | _acl_filter_id
291 chacl -l acldir/file2 | _acl_filter_id
292 echo "Remove ACLs..."
293 chacl -R file1
294 chacl -B acldir
295 chacl -R acldir/file2
296 chacl -l file1 | _acl_filter_id
297 chacl -l acldir | _acl_filter_id
298 chacl -l acldir/file2 | _acl_filter_id
299
300
301 #-------------------------------------------------------
302
303 echo ""
304 echo "=== Recursive change ACL ==="
305 rm -fr root
306 mkdir root
307 pushd root >/dev/null
308 # create an arbitrary little tree
309 for i in 1 2 3 4 5 6 7 8 9 0
310 do
311         mkdir -p a/$i
312         mkdir -p b/c$i/$i
313         touch a/$i/mumble
314 done
315 popd >/dev/null
316 chown -R 12345.54321 root
317 echo "Change #1..."
318 $runas -u 12345 -g 54321 -- /bin/chacl -r u::rwx,g::-w-,o::--x root
319 find root -print | xargs chacl -l
320 echo "Change #2..."
321 $runas -u 12345 -g 54321 -- /bin/chacl -r u::---,g::---,o::--- root
322 find root -print | xargs chacl -l
323
324
325 #-------------------------------------------------------
326
327 echo ""
328 echo "=== Test out error messages for ACL text parsing  ==="
329
330 touch file1
331 set -x
332 chacl u file1
333 chacl u: file1
334 chacl u:rumpledumpleunknownuser file1
335 chacl u:rumpledumpleunknownuser: file1
336 chacl g:rumpledumpleunknowngrp file1
337 chacl g:rumpledumpleunknowngrp: file1
338 chacl o:user1:rwx file1
339 chacl m:user1:rwx file1
340 chacl a::rwx file1
341 set +x
342
343
344
345
346 #-------------------------------------------------------
347
348 # success, all done
349 status=0
350 exit