1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
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.
8#
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.
13#
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]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
29# Copyright 2016 Nexenta Systems, Inc.
30#
31
32. $STF_SUITE/tests/functional/acl/acl_common.kshlib
33
34# DESCRIPTION:
35# Verify aclinherit=passthrough-x will inherit the execute permission only if
36# file creation mode requests it.
37#
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.
44
45verify_runnable "both"
46
47function cleanup
48{
49	[[ -d $basedir ]] && log_must rm -rf $basedir
50}
51
52log_assert "aclinherit=passthrough-x should inherit the execute permission" \
53    "only if file creation mode requests it"
54log_onexit cleanup
55
56set -A aces \
57    "owner@:rwxp:f:allow" \
58    "group@:rxp:f:allow" \
59    "everyone@:rxp:f:allow"
60
61typeset basedir="$TESTDIR/basedir"
62typeset nfile1="$basedir/nfile1" nfile2="$basedir/nfile2"
63
64function check_execute_bit
65{
66	typeset ace
67	typeset file=$1
68	typeset -i i=0
69
70	while ((i < 6)); do
71		ace=$(get_ACE $file $i)
72		if [[ "$ace" == *"execute"* ]]; then
73			return 0
74		fi
75		((i = i + 1))
76	done
77
78	return 1
79}
80
81function verify_inherit
82{
83	typeset -i i=0
84
85	log_must usr_exec mkdir $basedir
86
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
93
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
98
99	# Use cp(1) to copy over /usr/bin/true
100	log_must usr_exec cp /usr/bin/true $nfile2
101	# Check that execute permission was inherited
102	log_must check_execute_bit $nfile2
103}
104
105log_must zfs set aclmode=passthrough $TESTPOOL/$TESTFS
106log_must zfs set aclinherit=passthrough-x $TESTPOOL/$TESTFS
107
108for user in root $ZFS_ACL_STAFF1; do
109	log_must set_cur_usr $user
110	verify_inherit
111	cleanup
112done
113
114log_pass "aclinherit=passthrough-x should inherit the execute permission" \
115    "only if file creation mode requests it"
116