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