1#!/usr/local/bin/ksh93 -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# $FreeBSD$
24
25#
26# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_acl_chmod_inherit_004_pos.ksh	1.1	09/05/19 SMI"
30#
31
32. $STF_SUITE/tests/acl/acl_common.kshlib
33
34#################################################################################
35#
36# __stc_assertion_start
37#
38# ID: zfs_acl_chmod_inherit_004_pos
39#
40# DESCRIPTION:
41#	Verify aclinherit=passthrough-x will inherit the 'x' bits while mode request.
42#
43# STRATEGY:
44#	1. Loop super user and non-super user to run the test case.
45#	2. Create basedir and a set of subdirectores and files within it.
46#	3. Set aclinherit=passthrough-x
47#	4. Verify only passthrough-x will inherit the 'x' bits while mode request.
48#
49# TESTABILITY: explicit
50#
51# TEST_AUTOMATION_LEVEL: automated
52#
53# CODING_STATUS: COMPLETED (2009-04-29)
54#
55# __stc_assertion_end
56#
57################################################################################
58
59verify_runnable "both"
60
61function cleanup
62{
63	if [[ -d $basedir ]]; then
64		log_must $RM -rf $basedir
65	fi
66}
67
68$ZPOOL upgrade -v | $GREP "passthrough\-x aclinherit support" > /dev/null 2>&1
69if (( $? != 0 )) ; then
70	log_unsupported "passthrough-x aclinherit not supported."
71fi
72
73log_assert "Verify aclinherit=passthrough-x will inherit the 'x' bits while mode request."
74log_onexit cleanup
75
76set -A aces "owner@:read_data/write_data/add_subdirectory/append_data/execute:dir_inherit/inherit_only:allow" \
77	"owner@:read_data/write_data/add_subdirectory/append_data/execute::allow" \
78	"group@:add_subdirectory/append_data/execute:dir_inherit/inherit_only:allow" \
79	"group@:add_subdirectory/append_data/execute::allow" \
80	"everyone@:add_subdirectory/append_data/execute:dir_inherit/inherit_only:allow" \
81	"everyone@:add_subdirectory/append_data/execute::allow" \
82	"owner@:read_data/write_data/add_subdirectory/append_data/execute:file_inherit/inherit_only:allow" \
83	"group@:read_data/add_subdirectory/append_data/execute:file_inherit/inherit_only:allow" \
84	"everyone@:read_data/add_subdirectory/append_data/execute:file_inherit/inherit_only:allow"
85
86# Defile the based directory and file
87basedir=$TESTDIR/basedir
88
89test_requires ZFS_ACL
90
91#
92# According to inherited flag, verify subdirectories and files within it has
93# correct inherited access control.
94#
95function verify_inherit # <object>
96{
97	typeset obj=$1
98
99	# Define the files and directories will be created after chmod
100	ndir1=$obj/ndir1; ndir2=$ndir1/ndir2
101	nfile1=$ndir1/nfile1.c; nfile2=$ndir1/nfile2
102
103	log_must usr_exec $MKDIR -p $ndir1
104
105	typeset -i i=0
106	while (( i < ${#aces[*]} )) ; do
107		if (( i < 6 )) ; then
108			log_must usr_exec $CHMOD A$i=${aces[i]} $ndir1
109		else
110			log_must usr_exec $CHMOD A$i+${aces[i]} $ndir1
111		fi
112		(( i = i + 1 ))
113	done
114	log_must usr_exec $MKDIR -p $ndir2
115	log_must usr_exec $TOUCH $nfile1
116
117	$CAT > $nfile1 <<EOF
118#include <stdlib.h>
119#include <stdio.h>
120int main()
121{ return 0; }
122EOF
123
124	mode=$(get_mode $ndir2)
125	if [[ $mode != "drwx--x--x"* ]] ; then
126		log_fail "Unexpect mode of $ndir2, expect: drwx--x--x, current: $mode"
127	fi
128
129	mode=$(get_mode $nfile1)
130	if [[ $mode != "-rw-r--r--"* ]] ; then
131		log_fail "Unexpect mode of $nfile1, expect: -rw-r--r--, current: $mode"
132	fi
133
134	if [[ -x /usr/sfw/bin/gcc ]] ; then
135		log_must /usr/sfw/bin/gcc -o $nfile2 $nfile1
136		mode=$(get_mode $nfile2)
137		if [[ $mode != "-rwxr-xr-x"* ]] ; then
138			log_fail "Unexpect mode of $nfile2, expect: -rwxr-xr-x, current: $mode"
139		fi
140	fi
141}
142
143#
144# Set aclmode=passthrough to make sure
145# the acl will not change during chmod.
146# A general testing should verify the combination of
147# aclmode/aclinherit works well,
148# here we just simple test them separately.
149#
150
151log_must $ZFS set aclmode=passthrough $TESTPOOL/$TESTFS
152log_must $ZFS set aclinherit=passthrough-x $TESTPOOL/$TESTFS
153
154for user in root $ZFS_ACL_STAFF1; do
155	log_must set_cur_usr $user
156
157	verify_inherit $basedir
158
159	cleanup
160done
161
162log_pass "Verify aclinherit=passthrough-x will inherit the 'x' bits while mode request."
163