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 2007 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_rwx_003_pos
34#
35# DESCRIPTION:
36#	Verify that the read_data/write_data/execute permission for
37#	owner/group/everyone are correct.
38#
39# STRATEGY:
40#	1. Loop root and non-root user.
41#	2. Separated verify type@:access:allow|deny to file and directory
42#	3. To super user, read and write deny was override.
43#	4. According to ACE list and override rule, expect that
44#	   read/write/execute file or directory succeed or fail.
45#
46# TESTABILITY: explicit
47#
48# TEST_AUTOMATION_LEVEL: automated
49#
50# CODING_STATUS: COMPLETED (2005-10-09)
51#
52# __stc_assertion_end
53#
54################################################################################
55
56verify_runnable "both"
57
58#	owner@		group_users		other_users
59set -A users \
60	"root" 		"$ZFS_ACL_ADMIN" 	"$ZFS_ACL_OTHER1" \
61	"$ZFS_ACL_STAFF1" "$ZFS_ACL_STAFF2" 	"$ZFS_ACL_OTHER1"
62
63# In order to test execute permission, read_data was need firstly.
64set -A a_access "read_data" "write_data" "read_data/execute"
65set -A a_flag "owner@" "group@" "everyone@"
66
67log_assert "Verify that the read_data/write_data/execute permission for" \
68	"owner/group/everyone are correct."
69log_onexit cleanup
70
71function logname #node acl_spec user
72{
73	typeset node=$1
74	typeset acl_spec=$2
75	typeset user=$3
76
77	# To super user, read and write deny permission was override.
78	if [[ $acl_spec == *:allow ]] || \
79		[[ $user == root && -d $node ]] || \
80		[[ $user == root && $acl_spec != *"execute"* ]]
81	then
82		print "log_must"
83	elif [[ $acl_spec == *:deny ]]; then
84		print "log_mustnot"
85	fi
86}
87
88function check_chmod_results #node acl_spec g_usr o_usr
89{
90	typeset node=$1
91	typeset acl_spec=$2
92	typeset g_usr=$3
93	typeset o_usr=$4
94	typeset log
95
96	if [[ $acl_spec == "owner@:"* || $acl_spec == "everyone@:"* ]]; then
97		log=$(logname $node $acl_spec $ZFS_ACL_CUR_USER)
98		$log rwx_node $ZFS_ACL_CUR_USER $node $acl_spec
99	fi
100	if [[ $acl_spec == "group@:"* || $acl_spec == "everyone@:"* ]]; then
101		log=$(logname $node $acl_spec $g_usr)
102		$log rwx_node $g_usr $node $acl_spec
103	fi
104	if [[ $acl_spec == "everyone@"* ]]; then
105		log=$(logname $node $acl_spec $o_usr)
106		$log rwx_node $o_usr $node $acl_spec
107	fi
108}
109
110function test_chmod_basic_access #node group_user other_user
111{
112	typeset node=$1
113	typeset g_usr=$2
114	typeset o_usr=$3
115	typeset flag access acl_spec
116
117	for flag in ${a_flag[@]}; do
118		for access in ${a_access[@]}; do
119			for tp in allow deny; do
120				acl_spec="$flag:$access:$tp"
121				log_must usr_exec $CHMOD A+$acl_spec $node
122				check_chmod_results \
123					$node $acl_spec $g_usr $o_usr
124				log_must usr_exec $CHMOD A0- $node
125			done
126		done
127	done
128}
129
130test_requires ZFS_ACL
131
132typeset -i i=0
133while (( i < ${#users[@]} )); do
134	log_must set_cur_usr ${users[i]}
135
136	log_must usr_exec $TOUCH $testfile
137	test_chmod_basic_access $testfile ${users[((i+1))]} ${users[((i+2))]}
138	log_must usr_exec $MKDIR $testdir
139	test_chmod_basic_access $testdir ${users[((i+1))]} ${users[((i+2))]}
140
141	log_must usr_exec $RM -rf $testfile $testdir
142
143	(( i += 3 ))
144done
145
146log_pass "Verify that the read_data/write_data/execute permission for" \
147	"owner/group/everyone passed."
148