7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / acl / nontrivial / zfs_acl_chmod_xattr_002_pos.ksh
blobc0a44e31bbf39d229858fadb7e1df75f0bc87582
1 #!/bin/ksh -p
3 # CDDL HEADER START
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]
20 # CDDL HEADER END
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/tests/functional/acl/acl_common.kshlib
35 # DESCRIPTION:
36 # Verify that the write_xattr for remove the extended attributes of
37 # owner/group/everyone are correct.
39 # STRATEGY:
40 # 1. Create file and directory in zfs filesystem
41 # 2. Set special write_xattr ACE to the file and directory
42 # 3. Try to remove the extended attributes of the file and directory
43 # 4. Verify above operation is successful.
46 verify_runnable "both"
48 function cleanup
50 cd $cwd
52 cleanup_test_files $TESTDIR/basedir
54 if [[ -e $TESTDIR/$ARCHIVEFILE ]]; then
55 log_must rm -f $TESTDIR/$ARCHIVEFILE
58 return 0
61 # owner@ group group_users other_users
62 set -A users \
63 "root" "root" "$ZFS_ACL_ADMIN" "$ZFS_ACL_OTHER1" \
64 "$ZFS_ACL_STAFF1" "$ZFS_ACL_STAFF_GROUP" "$ZFS_ACL_STAFF2" \
65 "$ZFS_ACL_OTHER1"
67 set -A a_access \
68 "write_xattr:allow" \
69 "write_xattr:deny"
71 set -A a_flag "owner@" "group@" "everyone@"
73 MYTESTFILE=/etc/passwd
75 log_assert "Verify that the permission of write_xattr for " \
76 "owner/group/everyone while remove extended attributes are correct."
77 log_onexit cleanup
79 function operate_node #user node acl
81 typeset user=$1
82 typeset node=$2
83 typeset acl_t=$3
84 typeset ret
86 if [[ $user == "" || $node == "" ]]; then
87 log_fail "user, node are not defined."
90 chgusr_exec $user runat $node rm -f attr.0 ; ret=$?
92 if [[ $ret -eq 0 ]]; then
93 log_must cleanup_test_files $TESTDIR/basedir
94 log_must tar xpf@ $TESTDIR/$ARCHIVEFILE
97 return $ret
100 function logname #acl_target owner user
102 typeset acl_target=$1
103 typeset owner=$2
104 typeset user=$3
105 typeset ret="log_mustnot"
107 # To super user, read and write deny permission was override.
108 if [[ $user == root || $owner == $user ]] then
109 ret="log_must"
112 print $ret
115 function check_chmod_results #node flag acl_target owner g_usr o_usr
117 typeset node=$1
118 typeset flag=$2
119 typeset acl_target=$2:$3
120 typeset owner=$4
121 typeset g_usr=$5
122 typeset o_usr=$6
123 typeset log
125 if [[ $flag == "owner@" || $flag == "everyone@" ]]; then
126 log=$(logname $acl_target $owner $ZFS_ACL_CUR_USER)
127 $log operate_node $ZFS_ACL_CUR_USER $node $acl_target
129 if [[ $flag == "group@" || $flag == "everyone@" ]]; then
130 log=$(logname $acl_target $owner $g_usr)
131 $log operate_node $g_usr $node $acl_target
133 if [[ $flag == "everyone@" ]]; then
134 log=$(logname $acl_target $owner $o_usr)
135 $log operate_node $o_usr $node $acl_target
139 function test_chmod_basic_access #node owner g_usr o_usr
141 typeset node=${1%/}
142 typeset owner=$2
143 typeset g_usr=$3
144 typeset o_usr=$4
145 typeset flag acl_p acl_t parent
147 parent=${node%/*}
149 for flag in ${a_flag[@]}; do
150 for acl_t in "${a_access[@]}"; do
151 log_must usr_exec chmod A+$flag:$acl_t $node
153 log_must tar cpf@ $TESTDIR/$ARCHIVEFILE basedir
155 check_chmod_results "$node" "$flag" \
156 "$acl_t" "$owner" "$g_usr" "$o_usr"
158 log_must usr_exec chmod A0- $node
159 done
160 done
163 function setup_test_files #base_node user group
165 typeset base_node=$1
166 typeset user=$2
167 typeset group=$3
169 cleanup_test_files $base_node
171 log_must mkdir -p $base_node
172 log_must chown $user:$group $base_node
174 log_must set_cur_usr $user
176 # Prepare all files/sub-dirs for testing.
178 file0=$base_node/testfile_rm
180 dir0=$base_node/testdir_rm
182 log_must usr_exec touch $file0
183 log_must usr_exec chmod 444 $file0
185 log_must usr_exec runat $file0 cp $MYTESTFILE attr.0
187 log_must usr_exec mkdir -p $dir0
188 log_must usr_exec chmod 555 $dir0
190 log_must usr_exec runat $dir0 cp $MYTESTFILE attr.0
192 log_must usr_exec chmod 555 $base_node
193 return 0
196 function cleanup_test_files #base_node
198 typeset base_node=$1
200 if [[ -d $base_node ]]; then
201 log_must rm -rf $base_node
202 elif [[ -e $base_node ]]; then
203 log_must rm -f $base_node
206 return 0
209 typeset cwd=$PWD
210 typeset ARCHIVEFILE=archive.tar
212 typeset -i i=0
213 typeset -i j=0
214 typeset target
216 while (( i < ${#users[@]} )); do
217 setup_test_files $TESTDIR/basedir ${users[i]} ${users[((i+1))]}
218 cd $TESTDIR
221 while (( j < 1 )); do
222 eval target=\$file$j
223 test_chmod_basic_access $target ${users[i]} \
224 "${users[((i+2))]}" "${users[((i+3))]}"
226 eval target=\$dir$j
227 test_chmod_basic_access $target ${users[i]} \
228 "${users[((i+2))]}" "${users[((i+3))]}"
230 (( j = j + 1 ))
231 done
233 (( i += 4 ))
234 done
236 log_pass "Verify that the permission of write_xattr for " \
237 "owner/group/everyone while remove extended attributes are correct."