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