5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012 by Delphix. All rights reserved.
30 # Copyright 2016 Nexenta Systems, Inc.
33 .
$STF_SUITE/tests
/functional
/acl
/acl_common.kshlib
36 # Verify chmod have correct behaviour to directory and file not inherited
37 # when filesystem has the different aclinherit setting
40 # 1. Use both super user and non-super user to run the test case.
41 # 2. Create basedir and a set of subdirectores and files inside of it.
42 # 3. For the following values of the aclinherity property, add ACEs with
43 # different inherit options to basedir:
44 # "discard", "noallow", "restricted" and "passthrough".
45 # 4. Create nested directories and files like the following.
49 # chmod --> basedir -|
57 # 5. Verify non-inherited directories and files have the correct access
60 verify_runnable
"both"
64 [[ -f $ofile ]] && log_must
$RM -f $ofile
65 [[ -d $odir ]] && log_must
$RM -rf $odir
66 [[ -d $basedir ]] && log_must
$RM -rf $basedir
68 log_must
$ZFS set aclmode
=discard
$TESTPOOL/$TESTFS
71 log_assert
"Verify different inherit options combined with different" \
72 "aclinherit property values"
76 typeset aclinherit_flag
=(discard noallow restricted passthrough
)
77 typeset object_flag
=(file_inherit dir_inherit file_inherit
/dir_inherit
)
78 typeset strategy_flag
=("" inherit_only no_propagate inherit_only
/no_propagate
)
80 typeset ace_prefix1
="user:$ZFS_ACL_OTHER1"
81 typeset ace_prefix2
="user:$ZFS_ACL_OTHER2"
83 # Define the base directory and file
84 basedir
=$TESTDIR/basedir
; ofile
=$TESTDIR/ofile
; odir
=$TESTDIR/odir
86 # Define the files and directories will be created after chmod
87 ndir1
=$basedir/ndir1
; ndir2
=$ndir1/ndir2
; ndir3
=$ndir2/ndir3
88 nfile1
=$basedir/nfile1
; nfile2
=$ndir1/nfile2
; nfile3
=$ndir2/nfile3
90 # Verify all the node have expected correct access control
91 allnodes
="$ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3"
93 # According to inherited flag, verify subdirectories and files within it has
94 # correct inherited access control.
95 function verify_inherit
#<aclinherit> <object> [strategy]
97 # Define the nodes which will be affected by inherit.
98 typeset non_inherit_nodes
=""
103 typeset str1
="/inherit_only/inherited:"
104 typeset str2
="/inherited:"
106 # count: the ACE item to fetch
107 # passcnt: counter, if it achieves to maxaces,
108 # then no additional ACE should apply.
109 # isinherit: indicate if the current target is in the inherit list.
110 typeset
-i count
=0 pass
=0 passcnt
=0 isinherit
=0 no_propagate
=0
112 log_must usr_exec
$MKDIR -p $ndir3
113 log_must usr_exec
$TOUCH $nfile1 $nfile2 $nfile3
115 # Get the inherit type/object_flag and non-inherited nodes.
116 if [[ $obj == *"file_inherit"* && $obj == *"dir_inherit"* ]]; then
118 if [[ $str == *"no_propagate"* ]]; then
119 non_inherit_nodes
= $ndir2 $ndir3 $nfile2 $nfile3
122 elif [[ $obj == *"dir_inherit"* ]]; then
123 inherit_type
="directory"
124 non_inherit_nodes
="$nfile1 $nfile2 $nfile3"
125 if [[ $str == *"no_propagate"* ]]; then
126 non_inherit_nodes
="$non_inherit_nodes $ndir2 $ndir3"
131 non_inherit_nodes
="$ndir1 $ndir2 $ndir3"
132 if [[ $str == *"no_propagate"* ]]; then
133 non_inherit_nodes
="$non_inherit_nodes $nfile2 $nfile3"
137 # Verify ACEs for all the dirs/files under basedir
138 for node
in $allnodes; do
139 if [[ " $non_inherit_nodes " == *" $node "* ]]; then
147 while ((i
< maxaces
)); do
150 if [[ $inherit == "restricted" ]]; then
157 if [[ $expacl == *":allow" ]]; then
163 ((passcnt
= maxaces
))
167 if ((no_inherit
== 0)); then
172 if [[ -d $node ]]; then
173 # Verify ACEs for subdirectory
174 aclaction
=${expacl##*:}
176 if [[ $inherit_type == "directory" ||
177 $inherit_type == "both" ]]; then
178 expacl
=${acltemp}${str2}
179 expacl
=${expacl}${aclaction}
180 elif [[ $inherit_type == "file" ]]; then
181 if [[ $expacl != *"inherit_only"* ]]; then
182 # Directory should have
183 # "inherit_only" appended
184 expacl
=${acltemp}${str1}
185 expacl
=${expacl}${aclaction}
187 expacl
=${acltemp}${str2}
188 expacl
=${expacl}${aclaction}
191 aclcur
=$
(get_ACE
$node $count)
192 aclcur
=${aclcur#$count:}
193 if [[ $no_propagate == 0 ]]; then
194 if [[ $expacl != $aclcur ]]; then
197 log_fail
"$inherit $i #$count" \
202 # Compare if directory has trivial ACL
203 compare_acls
$node $odir
204 if [[ $?
-ne 0 ]]; then
207 log_fail
"unexpected ACE:"
208 "$node, $inherit ($str)"
211 # Verify ACE's for nested file
212 elif [[ -f $node ]]; then
213 compare_acls
$node $ofile
214 if [[ $?
-ne 0 ]]; then
217 log_fail
"unexpected ACE:" \
218 "$node, $inherit ($str)"
221 ((count
= count
+ 1))
225 # If there are no ACEs to be checked, compare the trivial ones.
226 if ((passcnt
== maxaces
)); then
227 if [[ -d $node ]]; then
228 compare_acls
$node $odir
229 elif [[ -f $node ]]; then
230 compare_acls
$node $ofile
233 if [[ $?
-ne 0 ]]; then
236 log_fail
"Unexpected ACE: $node, $inherit ($str)"
242 typeset
-i i
=0 maxaces
=4
243 typeset acl0 acl1 acl2 acl3
244 typeset acls0 acls1 acls2 acls3
246 log_must
$ZFS set aclmode
=passthrough
$TESTPOOL/$TESTFS
248 for inherit
in "${aclinherit_flag[@]}"; do
249 log_must
$ZFS set aclinherit
=$inherit $TESTPOOL/$TESTFS
251 for user
in root
$ZFS_ACL_STAFF1; do
252 log_must set_cur_usr
$user
254 for obj
in "${object_flag[@]}"; do
255 for str
in "${strategy_flag[@]}"; do
257 ((${#str} != 0)) && inh_opt
=$inh_opt/$str
259 # Prepare 4 ACES, which should include:
260 # deny -> to verify "noallow"
261 # write_acl/write_owner -> to verify "restricted"
262 acl0
="${ace_prefix1}:read_xattr/write_acl"
263 acl0
="${acl0}/write_owner:${inh_opt}:deny"
264 acl1
="${ace_prefix2}:read_xattr/write_acl"
265 acl1
="${acl1}/write_owner:${inh_opt}:allow"
266 acl2
="${ace_prefix1}:read_xattr:${inh_opt}:deny"
267 acl3
="${ace_prefix2}:read_xattr:${inh_opt}:allow"
269 # The ACEs filtered by write_acl/write_owner
271 acls1
="${ace_prefix2}:read_xattr"
272 acls1
="${acls1}:${inh_opt}:allow"
276 # Create basedir and tmp dir/file
279 log_note
"$user: $CHMOD $acl $basedir"
280 log_must usr_exec
$MKDIR $basedir
281 log_must usr_exec
$MKDIR $odir
282 log_must usr_exec
$TOUCH $ofile
287 log_must usr_exec
$CHMOD A
+$acl $basedir
290 log_note
"verify_inherit $inherit $obj $str"
291 log_must verify_inherit
$inherit $obj $str
293 log_must usr_exec
$RM -rf $ofile $odir $basedir
299 log_pass
"Verify different inherit options combined with different" \
300 "aclinherit property values"