xfsqa: build dbtest on debian platforms
[xfstests-dev.git] / 099
1 #! /bin/bash
2 # FS QA Test No. 099. Modified from UDFQA test 036.
3 #
4 # ACL test
5 #-----------------------------------------------------------------------
6 # Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License as
10 # published by the Free Software Foundation.
11 #
12 # This program is distributed in the hope that it would be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write the Free Software Foundation,
19 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 #
21 #-----------------------------------------------------------------------
22 #
23 #_acl_list
24 # modifier
25 owner=ajones@sgi.com
26
27 seq=`basename $0`
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 # get standard environment, filters and checks
36 . ./common.rc
37 . ./common.filter
38 . ./common.attr
39
40 runas=$here/src/runas
41
42 TARGET_DIR=$SCRATCH_MNT
43 [ "$FSTYP" == "xfs" ] && TARGET_DIR=$TEST_DIR
44
45 _cleanup()
46 {
47     rm -f $tmp.*
48     cd $TARGET_DIR
49     rm -rf $seq.dir1
50     cd /
51 }
52
53 # -----
54 # minimal access ACL has ACEs: USER_OBJ, GROUP_OBJ, OTHER_OBJ
55 # This is set with chacl(1) and can be changed by chmod(1).
56 #
57 # Test that this is being set for ACL and for std unix permissions
58 # Test that we can get back the same ACL.
59 # Test std permissions for rwx.
60 # -----
61 #
62 # Test out default ACLs and that the ACL is being PASSed
63 # onto the children of the dir.
64 #
65 # -----
66 # Test out access check for extended ACLs.
67 # -> 3 extra ACEs: MASK, GROUP, USER
68 # -> the GROUP compares with egid of process _and_ the supplementary
69 #    groups (as found in /etc/group)
70 #
71 # Test that mask works for USER, GROUP, GROUP_OBJ
72 # Test that the ACE type priority is working
73 #   -> this would be done by simultaneously matching on ACEs
74 #   -> interesting if it allows user to specify ACEs in any order
75 #
76 rm -f $seq.full
77
78 #-------------------------------------------------------
79 # real QA test starts here
80 _supported_fs generic
81 _supported_os IRIX
82
83 _acl_setup_ids
84 _require_acls
85
86 [ -x $runas ] || _notrun "$runas executable not found"
87
88 # get dir
89 #export FILE_SYS=xfs
90 _require_scratch
91 _setup_testdir
92
93 cd $TARGET_DIR
94 rm -rf $seq.dir1 # in case file is left over from previous runs.
95 mkdir $seq.dir1
96 cd $seq.dir1
97
98 echo ""
99 echo "=== Test minimal ACE ==="
100
101 echo "Setup file"
102 # Note: as this is a shell script,
103 #       will need read and execute permission set
104 #       in order to execute it.
105 touch file1
106 cat <<EOF >file1
107 #!/bin/bash
108 echo "Test was executed"
109 EOF
110 chmod u=rwx file1
111 chmod g=rw- file1
112 chmod o=r-- file1
113 chown $acl1.$acl2 file1
114 _acl_ls file1
115
116 echo ""
117 echo "--- Test get and set of ACL ---"
118 echo "Note: IRIX interface gave an empty ACL - Linux outputs an ACL"
119 _acl_list file1
120 echo "Try using single colon separator"
121 echo "Note: IRIX interface FAILs because of single colon - Linux one allows it" 
122 chacl u::r--,g::rwx,o:rw- file1 2>&1
123 echo "Expect to PASS" 
124 chacl u::r--,g::rwx,o::rw- file1 2>&1
125 _acl_list file1
126
127 echo ""
128 echo "--- Test sync of ACL with std permissions ---"
129 _acl_ls file1
130 chmod u+w file1
131 _acl_ls file1
132 _acl_list file1
133
134 echo ""
135 echo "--- Test owner permissions ---"
136 chacl u::r-x,g::---,o::--- file1 2>&1
137 _acl_list file1
138 # change to owner
139 echo "Expect to PASS" 
140 $runas -u $acl1 -g $acl1 ./file1 2>&1
141 echo "Expect to FAIL" 
142 $runas -u $acl2 -g $acl2 ./file1 2>&1
143
144 echo ""
145 echo "--- Test group permissions ---"
146 chacl u::---,g::r-x,o::--- file1 2>&1
147 _acl_list file1
148 echo "Expect to FAIL - acl1 is owner" 
149 $runas -u $acl1 -g $acl1 ./file1 2>&1
150 echo "Expect to PASS - acl2 matches group" 
151 $runas -u $acl2 -g $acl2 ./file1 2>&1
152 echo "Expect to PASS - acl2 matches sup group" 
153 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
154 echo "Expect to FAIL - acl3 is not in group" 
155 $runas -u $acl3 -g $acl3 ./file1 2>&1
156
157 echo ""
158 echo "--- Test other permissions ---"
159 chacl u::---,g::---,o::r-x file1 2>&1
160 _acl_list file1
161 echo "Expect to FAIL - acl1 is owner" 
162 $runas -u $acl1 -g $acl1 ./file1 2>&1
163 echo "Expect to FAIL - acl2 is in group" 
164 $runas -u $acl2 -g $acl2 ./file1 2>&1
165 echo "Expect to FAIL - acl2 is in sup. group" 
166 $runas -u $acl2 -g $acl3 -s $acl2 ./file1 2>&1
167 echo "Expect to PASS - acl3 is not owner or in group" 
168 $runas -u $acl3 -g $acl3 ./file1 2>&1
169
170 #-------------------------------------------------------
171
172 echo ""
173 echo "=== Test Extended ACLs ==="
174
175 echo ""
176 echo "--- Test adding a USER ACE ---"
177 echo "Expect to FAIL as no MASK provided"
178 chacl u::---,g::---,o::---,u:$acl2:r-x file1 2>&1 | _acl_filter_id
179 echo "Ensure that ACL has not been changed"
180 _acl_list file1
181 echo "Expect to PASS - USER ACE matches user"
182 chacl u::---,g::---,o::---,u:$acl2:r-x,m::rwx file1 2>&1
183 _acl_list file1
184 $runas -u $acl2 -g $acl2 ./file1 2>&1
185 echo "Expect to FAIL - USER ACE does not match user"
186 $runas -u $acl3 -g $acl3 ./file1 2>&1
187
188 echo ""
189 echo "--- Test adding a GROUP ACE ---"
190 echo "Expect to FAIL as no MASK provided"
191 chacl u::---,g::---,o::---,g:$acl2:r-x file1 2>&1 | _acl_filter_id
192 echo "Ensure that ACL has not been changed"
193 _acl_list file1
194 chacl u::---,g::---,o::---,g:$acl2:r-x,m::rwx file1 2>&1
195 _acl_list file1 | _acl_filter_id
196 echo "Expect to PASS - GROUP ACE matches group"
197 $runas -u $acl2 -g $acl2 ./file1 2>&1
198 echo "Expect to PASS - GROUP ACE matches sup group"
199 $runas -u $acl2 -g $acl1 -s $acl2 ./file1 2>&1
200 echo "Expect to FAIL - GROUP ACE does not match group"
201 $runas -u $acl3 -g $acl3 ./file1 2>&1
202
203 #-------------------------------------------------------
204
205 echo ""
206 echo "--- Test MASK ---"
207
208 # group
209 chacl u::---,g::---,o::---,g:$acl2:r-x,m::-w- file1 2>&1
210 _acl_list file1
211 echo "Expect to FAIL as MASK prohibits execution"
212 $runas -u $acl2 -g $acl2 ./file1 2>&1
213
214 # user
215 chacl u::---,g::---,o::---,u:$acl2:r-x,m::-w- file1 2>&1
216 echo "Expect to FAIL as MASK prohibits execution"
217 $runas -u $acl2 -g $acl2 ./file1 2>&1
218
219 # user
220 chacl u::---,g::---,o::---,u:$acl2:r-x,m::r-x file1 2>&1
221 echo "Expect to PASS as MASK allows execution"
222 $runas -u $acl2 -g $acl2 ./file1 2>&1
223
224 #-------------------------------------------------------
225
226 echo ""
227 echo "--- Test ACE priority ---"
228
229 chacl o::rwx,g::rwx,u:$acl1:rwx,u::---,m::rwx file1 2>&1
230 echo "Expect to FAIL as should match on owner"
231 $runas -u $acl1 -g $acl2 ./file1 2>&1
232
233 chacl o::---,g::---,u:$acl2:rwx,u::---,m::rwx file1 2>&1
234 echo "Expect to PASS as should match on user"
235 $runas -u $acl2 -g $acl2 ./file1 2>&1
236
237
238 #-------------------------------------------------------
239
240 echo ""
241 echo "=== Test can read ACLs without access permissions ==="
242 # This was a bug in kernel code where syscred wasn't being used
243 # to override the capabilities
244 chacl o::---,g::---,u::--- file1 2>&1
245 _acl_list file1
246
247 #-------------------------------------------------------
248
249 echo ""
250 echo "=== Test Default ACLs ==="
251 # make test clearer by testing with and without umask
252 umask 0
253
254 mkdir acldir
255 chacl -b "u::rwx,g::rwx,o::rwx" "u::r-x,g::r--,o::---" acldir 2>&1
256 _acl_list acldir
257 cd acldir
258
259 touch file2
260 _acl_ls file2
261 _acl_list file2
262
263 #ensure that umask is not having an effect 
264 #so set it and see
265 umask 722
266 touch file3
267 _acl_ls file3
268 _acl_list file3
269
270 cd ..
271 umask 022
272
273
274 #-------------------------------------------------------
275
276 echo ""
277 echo "=== Removing ACLs ==="
278 _acl_list file1
279 _acl_list acldir
280 _acl_list acldir/file2
281 echo "Remove ACLs..."
282 chacl -R file1
283 chacl -B acldir
284 chacl -R acldir/file2
285 echo "Note: IRIX interface would mean empty ACLs - Linux would show mode ACLs" 
286 _acl_list file1
287 _acl_list acldir
288 _acl_list acldir/file2
289
290 #-------------------------------------------------------
291
292 echo ""
293 echo "=== Test out error messages for ACL text parsing  ==="
294
295 touch file1
296 set -x
297 chacl u file1
298 chacl u: file1
299 chacl u:rumpledumpleunknownuser file1
300 chacl u:rumpledumpleunknownuser: file1
301 chacl g:rumpledumpleunknowngrp file1
302 chacl g:rumpledumpleunknowngrp: file1
303 chacl o:user1:rwx file1
304 chacl m:user1:rwx file1
305 chacl a::rwx file1
306 set +x
307
308 #-------------------------------------------------------
309
310 echo ""
311 echo "=== Test out large ACLs  ==="
312 touch largeaclfile
313 XFS_ACL_MAX_ENTRIES=25
314 num_aces_pre=`expr $XFS_ACL_MAX_ENTRIES - 1`
315 num_aces_post=`expr $XFS_ACL_MAX_ENTRIES + 1`
316
317 acl1=`_create_n_aces $num_aces_pre`
318 acl2=`_create_n_aces $XFS_ACL_MAX_ENTRIES`
319 acl3=`_create_n_aces $num_aces_post`
320
321 echo "1 below xfs acl max"
322 chacl $acl1 largeaclfile
323 _acl_list largeaclfile | _filter_aces_notypes
324
325 echo "xfs acl max"
326 chacl $acl2 largeaclfile
327 _acl_list largeaclfile | _filter_aces_notypes
328
329 echo "1 above xfs acl max"
330 chacl $acl3 largeaclfile
331 _acl_list largeaclfile | _filter_aces_notypes
332
333 #-------------------------------------------------------
334
335 if [ "$FSTYP" == "udf" ]; then
336     cd /
337     umount $TARGET_DIR
338     # Check the filesystem
339     _check_scratch_fs
340 fi
341 # success, all done
342 status=0
343 exit