fix after xfs_support change & tweak reboot
[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
54 _cleanup()
55 {
56     rm -f $tmp.*
57     rm -rf $TEST_DIR/$seq.dir1
58 }
59
60 _ls()
61 {
62     ls -ln $* | awk '{ print $1, $3, $4, $NF }' | _filter_id
63
64
65
66 _setup_ids()
67 {
68     eval `cat /etc/passwd /etc/group | gawk -F: '
69       { ids[$3]=1 }
70       END {
71         j=1
72         for(i=1; i<1000000 && j<=3;i++){
73           if (! (i in ids)) {
74              printf "acl%d=%d;", j, i;           
75              j++
76           }
77         }       
78       }'`
79 }
80
81 _filter_id()
82 {
83     sed \
84        -e "s/u:$acl1/u:id1/" \
85        -e "s/u:$acl2/u:id2/" \
86        -e "s/u:$acl3/u:id3/" \
87        -e "s/g:$acl1/g:id1/" \
88        -e "s/g:$acl2/g:id2/" \
89        -e "s/g:$acl3/g:id3/" \
90        -e "s/ $acl1 / id1 /" \
91        -e "s/ $acl2 / id2 /" \
92        -e "s/ $acl3 / id3 /"
93 }
94
95 # -----
96 # minimal access ACL has ACEs: USER_OBJ, GROUP_OBJ, OTHER_OBJ
97 # This is set with chacl(1) and can be changed by chmod(1).
98 #
99 # Test that this is being set for ACL and for std unix permissions
100 # Test that we can get back the same ACL.
101 # Test std permissions for rwx.
102 # -----
103 #
104 # Test out default ACLs and that the ACL is being PASSed
105 # onto the children of the dir.
106 #
107 # -----
108 # Test out access check for extended ACLs.
109 # -> 3 extra ACEs: MASK, GROUP, USER
110 # -> the GROUP compares with egid of process _and_ the supplementary
111 #    groups (as found in /etc/group)
112 #
113 # Test that mask works for USER, GROUP, GROUP_OBJ
114 # Test that the ACE type priority is working
115 #   -> this would be done by simultaneously matching on ACEs
116 #   -> interesting if it allows user to specify ACEs in any order
117 #
118 rm -f $seq.full
119
120 _need_to_be_root
121 _setup_ids
122
123 [ -x /bin/chacl ] || _notrun "chacl command not found"
124 [ -x $runas ] || _notrun "$runas executable not found"
125
126 # get dir
127 cd $TEST_DIR
128 rm -rf $seq.dir1
129 mkdir $seq.dir1
130 cd $seq.dir1
131
132 # test if acl_get syscall is operational
133 # and hence the ACL config has been turned on  
134 touch syscalltest
135 if chacl -l syscalltest 2>&1 | tee -a $here/$seq.full | grep 'Function not implemented' >/dev/null
136 then
137   cd $here
138   _notrun "requires kernel ACL support"
139 fi
140
141 #-------------------------------------------------------
142 # real QA test starts here
143 echo "QA output created by $seq"
144
145 echo ""
146 echo "=== Test minimal ACE ==="
147
148 echo "Setup file"
149 # Note: as this is a shell script,
150 #       will need read and execute permission set
151 #       in order to execute it.
152 touch file1
153 cat <<EOF >file1
154 #!/bin/sh
155 echo "Test was executed"
156 EOF
157 chmod u=rwx file1
158 chmod g=rw- file1
159 chmod o=r-- file1
160 chown $acl1.$acl2 file1
161 _ls file1
162
163 echo ""
164 echo "--- Test get and set of ACL ---"
165 chacl -l file1 | _filter_id
166 echo "Expect to FAIL" 
167 chacl u::r--,g::rwx,o:rw- file1 2>&1
168 echo "Expect to PASS" 
169 chacl u::r--,g::rwx,o::rw- file1 2>&1
170 chacl -l file1 | _filter_id
171
172 echo ""
173 echo "--- Test sync of ACL with std permissions ---"
174 _ls file1
175 chmod u+w file1
176 _ls file1
177 chacl -l file1 | _filter_id
178
179 echo ""
180 echo "--- Test owner permissions ---"
181 chacl u::r-x,g::---,o::--- file1 2>&1
182 chacl -l file1 | _filter_id
183 # change to owner
184 echo "Expect to PASS" 
185 $runas -u $acl1 -g $acl1 ./file1 2>&1
186 echo "Expect to FAIL" 
187 $runas -u $acl2 -g $acl2 ./file1 2>&1
188
189 echo ""
190 echo "--- Test group permissions ---"
191 chacl u::---,g::r-x,o::--- file1 2>&1
192 chacl -l file1 | _filter_id
193 echo "Expect to FAIL - acl1 is owner" 
194 $runas -u $acl1 -g $acl1 ./file1 2>&1
195 echo "Expect to PASS - acl2 matches group" 
196 $runas -u $acl2 -g $acl2 ./file1 2>&1
197 echo "Expect to PASS - acl2 matches sup group" 
198 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
199 echo "Expect to FAIL - acl3 is not in group" 
200 $runas -u $acl3 -g $acl3 ./file1 2>&1
201
202 echo ""
203 echo "--- Test other permissions ---"
204 chacl u::---,g::---,o::r-x file1 2>&1
205 chacl -l file1 | _filter_id
206 echo "Expect to FAIL - acl1 is owner" 
207 $runas -u $acl1 -g $acl1 ./file1 2>&1
208 echo "Expect to FAIL - acl2 is in group" 
209 $runas -u $acl2 -g $acl2 ./file1 2>&1
210 echo "Expect to FAIL - acl2 is in sup. group" 
211 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
212 echo "Expect to PASS - acl3 is not owner or in group" 
213 $runas -u $acl3 -g $acl3 ./file1 2>&1
214
215 #-------------------------------------------------------
216
217 echo ""
218 echo "=== Test Extended ACLs ==="
219
220 echo ""
221 echo "--- Test adding a USER ACE ---"
222 echo "Expect to FAIL as no MASK provided"
223 chacl u::---,g::---,o::---,u:$acl2:r-x file1 2>&1
224 echo "Ensure that ACL has not been changed"
225 chacl -l file1 | _filter_id
226 echo "Expect to PASS - USER ACE matches user"
227 chacl u::---,g::---,o::---,u:$acl2:r-x,m::rwx file1 2>&1
228 chacl -l file1 | _filter_id
229 $runas -u $acl2 -g $acl2 ./file1 2>&1
230 echo "Expect to FAIL - USER ACE does not match user"
231 $runas -u $acl3 -g $acl3 ./file1 2>&1
232
233 echo ""
234 echo "--- Test adding a GROUP ACE ---"
235 echo "Expect to FAIL as no MASK provided"
236 chacl u::---,g::---,o::---,g:$acl2:r-x file1 2>&1
237 echo "Ensure that ACL has not been changed"
238 chacl -l file1 | _filter_id
239 chacl u::---,g::---,o::---,g:$acl2:r-x,m::rwx file1 2>&1
240 chacl -l file1 | _filter_id
241 echo "Expect to PASS - GROUP ACE matches group"
242 $runas -u $acl2 -g $acl2 ./file1 2>&1
243 echo "Expect to PASS - GROUP ACE matches sup group"
244 $runas -u $acl2 -g $acl1 -s $acl2 ./file1 2>&1
245 echo "Expect to FAIL - GROUP ACE does not match group"
246 $runas -u $acl3 -g $acl3 ./file1 2>&1
247
248 #-------------------------------------------------------
249
250 echo ""
251 echo "--- Test MASK ---"
252
253 # group
254 chacl u::---,g::---,o::---,g:$acl2:r-x,m::-w- file1 2>&1
255 chacl -l file1 | _filter_id
256 echo "Expect to FAIL as MASK prohibits execution"
257 $runas -u $acl2 -g $acl2 ./file1 2>&1
258
259 # user
260 chacl u::---,g::---,o::---,u:$acl2:r-x,m::-w- file1 2>&1
261 echo "Expect to FAIL as MASK prohibits execution"
262 $runas -u $acl2 -g $acl2 ./file1 2>&1
263
264 # user
265 chacl u::---,g::---,o::---,u:$acl2:r-x,m::r-x file1 2>&1
266 echo "Expect to PASS as MASK allows execution"
267 $runas -u $acl2 -g $acl2 ./file1 2>&1
268
269 #-------------------------------------------------------
270
271 echo ""
272 echo "--- Test ACE priority ---"
273
274 chacl o::rwx,g::rwx,u:$acl1:rwx,u::---,m::rwx file1 2>&1
275 echo "Expect to FAIL as should match on owner"
276 $runas -u $acl1 -g $acl2 ./file1 2>&1
277
278 chacl o::---,g::---,u:$acl2:rwx,u::---,m::rwx file1 2>&1
279 echo "Expect to PASS as should match on user"
280 $runas -u $acl2 -g $acl2 ./file1 2>&1
281
282
283 #-------------------------------------------------------
284
285 echo ""
286 echo "=== Test can read ACLs without access permissions ==="
287 # This was a bug in kernel code where syscred wasn't being used
288 # to override the capabilities
289 chacl o::---,g::---,u::--- file1 2>&1
290 chacl -l file1 | _filter_id
291
292 #-------------------------------------------------------
293
294 echo ""
295 echo "=== Test Default ACLs ==="
296 mkdir acldir
297 chacl -b "u::rwx,g::rwx,o::rwx" "u::r-x,g::r--,o::---" ./acldir 2>&1
298 chacl -l acldir | _filter_id
299
300 cd acldir
301 touch file2
302 _ls file2
303 chacl -l file2 | _filter_id
304 cd ..
305
306 #-------------------------------------------------------
307
308 # success, all done
309 status=0
310 exit