6875 fix zfs-tests ACL cases
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / acl / nontrivial / zfs_acl_chmod_inherit_004_pos.ksh
blob98b5568e8dc0c18136e96094477e938335a2ada3
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.
28 # Copyright (c) 2012 by Delphix. All rights reserved.
29 # Copyright 2016 Nexenta Systems, Inc.
32 . $STF_SUITE/tests/functional/acl/acl_common.kshlib
34 # DESCRIPTION:
35 # Verify aclinherit=passthrough-x will inherit the execute permission only if
36 # file creation mode requests it.
38 # STRATEGY:
39 # 1. Use both super user and non-super user to run the test case.
40 # 2. Set aclinherit=passthrough-x
41 # 3. Create basedir and a set of files, one with 644 and one with 755 mode.
42 # 4. Verify that execute permission is inherited only if file creation mode
43 # requests them.
45 verify_runnable "both"
47 function cleanup
49 [[ -d $basedir ]] && log_must $RM -rf $basedir
52 log_assert "aclinherit=passthrough-x should inherit the execute permission" \
53 "only if file creation mode requests it"
54 log_onexit cleanup
56 set -A aces \
57 "owner@:rwxp:f:allow" \
58 "group@:rxp:f:allow" \
59 "everyone@:rxp:f:allow"
61 typeset basedir="$TESTDIR/basedir"
62 typeset nfile1="$basedir/nfile1" nfile2="$basedir/nfile2"
64 function check_execute_bit
66 typeset ace
67 typeset file=$1
68 typeset -i i=0
70 while ((i < 6)); do
71 ace=$(get_ACE $file $i)
72 if [[ "$ace" == *"execute"* ]]; then
73 return 0
75 ((i = i + 1))
76 done
78 return 1
81 function verify_inherit
83 typeset -i i=0
85 log_must usr_exec $MKDIR $basedir
87 # Modify owner@, group@ and everyone@ ACEs to include execute
88 # permission (see above), and make them file-inheritable
89 while ((i < ${#aces[*]})); do
90 log_must usr_exec $CHMOD A$i=${aces[i]} $basedir
91 ((i = i + 1))
92 done
94 # Create file with 644 mode
95 log_must usr_exec $TOUCH $nfile1
96 # Check that execute permission wasn't inherited
97 log_mustnot check_execute_bit $nfile1
99 # Use cp(1) to copy over /usr/bin/true
100 log_must usr_exec $CP $TRUE $nfile2
101 # Check that execute permission was inherited
102 log_must check_execute_bit $nfile2
105 log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS
106 log_must $ZFS set aclinherit=passthrough-x $TESTPOOL/$TESTFS
108 for user in root $ZFS_ACL_STAFF1; do
109 log_must set_cur_usr $user
110 verify_inherit
111 cleanup
112 done
114 log_pass "aclinherit=passthrough-x should inherit the execute permission" \
115 "only if file creation mode requests it"