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#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/tests/acl/acl_common.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_acl_chmod_inherit_001_pos
34#
35# DESCRIPTION:
36#	Verify chmod have correct behaviour to directory and file when setting
37#	different inherit strategy to them.
38#
39# STRATEGY:
40#	1. Loop super user and non-super user to run the test case.
41#	2. Create basedir and a set of subdirectores and files within it.
42#	3. Separately chmod basedir with different inherite options.
43#	4. Then create nested directories and files like the following.
44#
45#                                                   _ odir4
46#                                                  |_ ofile4
47#                                         _ odir3 _|
48#                                        |_ ofile3
49#                               _ odir1 _|
50#                              |_ ofile2
51#                     basefile |
52#          chmod -->  basedir -|
53#                              |_ nfile1
54#                              |_ ndir1 _
55#                                        |_ nfile2
56#                                        |_ ndir2 _
57#                                                  |_ nfile3
58#                                                  |_ ndir3
59#
60#	5. Verify each directories and files have the correct access control
61#	   capability.
62#
63# TESTABILITY: explicit
64#
65# TEST_AUTOMATION_LEVEL: automated
66#
67# CODING_STATUS: COMPLETED (2005-11-15)
68#
69# __stc_assertion_end
70#
71################################################################################
72
73verify_runnable "both"
74
75function cleanup
76{
77	if [[ -f $basefile ]]; then
78		log_must $RM -f $basefile
79	fi
80	if [[ -d $basedir ]]; then
81		log_must $RM -rf $basedir
82	fi
83}
84
85log_assert "Verify chmod have correct behaviour to directory and file when " \
86	"setting different inherit strategies to them."
87log_onexit cleanup
88
89# Define inherit flag
90set -A object_flag file_inherit dir_inherit file_inherit/dir_inherit
91set -A strategy_flag "" inherit_only no_propagate inherit_only/no_propagate
92
93# Defile the based directory and file
94basedir=$TESTDIR/basedir;  basefile=$TESTDIR/basefile
95
96test_requires ZFS_ACL
97
98# Define the existed files and directories before chmod
99odir1=$basedir/odir1; odir2=$odir1/odir2; odir3=$odir2/odir3
100ofile1=$basedir/ofile1; ofile2=$odir1/ofile2; ofile3=$odir2/ofile3
101
102# Define the files and directories will be created after chmod
103ndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3
104nfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3
105
106# Verify all the node have expected correct access control
107allnodes="$basedir $ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3"
108allnodes="$allnodes $odir1 $odir2 $odir3 $ofile1 $ofile2 $ofile3"
109
110#
111# According to inherited flag, verify subdirectories and files within it has
112# correct inherited access control.
113#
114function verify_inherit #<object> [strategy]
115{
116	# Define the nodes which will be affected by inherit.
117	typeset inherit_nodes
118	typeset obj=$1
119	typeset str=$2
120
121	log_must usr_exec $MKDIR -p $ndir3
122	log_must usr_exec $TOUCH $nfile1 $nfile2 $nfile3
123
124	# Except for inherit_only, the basedir was affected always.
125	if [[ $str != *"inherit_only"* ]]; then
126		inherit_nodes="$inherit_nodes $basedir"
127	fi
128	# Get the files which inherited ACE.
129	if [[ $obj == *"file_inherit"* ]]; then
130		inherit_nodes="$inherit_nodes $nfile1"
131
132		if [[ $str != *"no_propagate"* ]]; then
133			inherit_nodes="$inherit_nodes $nfile2 $nfile3"
134		fi
135	fi
136	# Get the directores which inherited ACE.
137	if [[ $obj == *"dir_inherit"* ]]; then
138		inherit_nodes="$inherit_nodes $ndir1"
139
140		if [[ $str != *"no_propagate"* ]]; then
141			inherit_nodes="$inherit_nodes $ndir2 $ndir3"
142		fi
143	fi
144
145	for node in $allnodes; do
146		if [[ " $inherit_nodes " == *" $node "* ]]; then
147			log_mustnot chgusr_exec $ZFS_ACL_OTHER1 $LS -vd $node \
148				> /dev/null 2>&1
149		else
150			log_must chgusr_exec $ZFS_ACL_OTHER1 $LS -vd $node \
151				> /dev/null 2>&1
152		fi
153	done
154}
155
156for user in root $ZFS_ACL_STAFF1; do
157	log_must set_cur_usr $user
158
159	for obj in "${object_flag[@]}"; do
160		for str in "${strategy_flag[@]}"; do
161			typeset inh_opt=$obj
162			(( ${#str} != 0 )) && inh_opt=$inh_opt/$str
163			aclspec="A+user:$ZFS_ACL_OTHER1:read_acl:$inh_opt:deny"
164
165			log_must usr_exec $MKDIR $basedir
166			log_must usr_exec $TOUCH $basefile
167			log_must usr_exec $MKDIR -p $odir3
168			log_must usr_exec $TOUCH $ofile1 $ofile2 $ofile3
169
170			#
171			# Inherit flag can only be placed on a directory,
172			# otherwise it will fail.
173			#
174			log_must usr_exec $CHMOD $aclspec $basefile
175
176			#
177			# Place on a directory should succeed.
178			#
179			log_must usr_exec $CHMOD $aclspec $basedir
180
181			verify_inherit $obj $str
182
183			log_must usr_exec $RM -rf $basefile $basedir
184		done
185	done
186done
187
188log_pass "Verify chmod inherit behaviour passed."
189