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_001_pos
34#
35# DESCRIPTION:
36#	Verify chmod permission settings on files and directories, as both root
37#	and non-root users.
38#
39# STRATEGY:
40#	1. Loop root and $ZFS_ACL_STAFF1 as root and non-root users.
41#	2. Create test file and directory in zfs filesystem.
42#	3. Execute 'chmod' with specified options.
43#	4. Check 'ls -l' output and compare with expect results.
44#
45# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2005-09-27)
50#
51# __stc_assertion_end
52#
53################################################################################
54
55verify_runnable "both"
56
57# 	"init_map" "options" "expect_map"
58set -A argv \
59	"000" "a+rw"	"rw-rw-rw-" 	"000" "a+rwx"	"rwxrwxrwx" \
60	"000" "u+xr"	"r-x------"	"000" "gu-xw"	"---------" \
61	"644" "a-r"	"-w-------"	"644" "augo-x"	"rw-r--r--" \
62	"644" "=x"	"--x--x--x"	"644" "u-rw"	"---r--r--" \
63	"644" "uo+x"	"rwxr--r-x"	"644" "ga-wr"	"---------" \
64	"777" "augo+x"	"rwxrwxrwx"	"777" "go-xr"	"rwx-w--w-" \
65	"777" "o-wx"	"rwxrwxr--" 	"777" "ou-rx"	"-w-rwx-w-" \
66	"777" "a+rwx"	"rwxrwxrwx"	"777" "u=rw"	"rw-rwxrwx" \
67	"000" "123"	"--x-w--wx"	"000" "412"	"r----x-w-" \
68	"231" "562"	"r-xrw--w-"	"712" "000"	"---------" \
69	"777" "121"	"--x-w---x"	"123" "775"	"rwxrwxr-x"
70
71log_assert " Verify chmod permission settings on files and directories"
72log_onexit cleanup
73
74#
75# Verify file or directory have correct map after chmod
76#
77# $1 file or directory
78#
79function test_chmod_mapping #<file-dir>
80{
81	typeset node=$1
82	typeset -i i=0
83
84	while (( i < ${#argv[@]} )); do
85		usr_exec $CHMOD ${argv[i]} $node
86		if (($? != 0)); then
87			log_note "usr_exec $CHMOD ${argv[i]} $node"
88			return 1
89		fi
90
91		usr_exec $CHMOD ${argv[((i + 1))]} $node
92		if (($? != 0)); then
93			log_note "usr_exec $CHMOD ${argv[((i + 1))]} $node"
94			return 1
95		fi
96
97		typeset mode
98		mode=$(get_mode ${node})
99
100		if [[ $mode != "-${argv[((i + 2))]}"* && \
101			$mode != "d${argv[((i + 2))]}"* ]]
102		then
103			log_fail "FAIL: '${argv[i]}' '${argv[((i + 1))]}' \
104				'${argv[((i + 2))]}'"
105		fi
106
107		(( i += 3 ))
108	done
109
110	return 0
111}
112
113for user in root $ZFS_ACL_STAFF1; do
114	log_must set_cur_usr $user
115
116	# Test file
117	log_must usr_exec $TOUCH $testfile
118	log_must test_chmod_mapping $testfile
119
120	if [ "$ZFS_ACL" != "" ] ; then
121		log_must $CHMOD A+user:$ZFS_ACL_STAFF2:write_acl:allow $testfile
122	fi
123	log_must set_cur_usr $ZFS_ACL_STAFF2
124
125	# Test directory
126	log_must usr_exec $MKDIR $testdir
127	log_must test_chmod_mapping $testdir
128
129	if [ "$ZFS_ACL" != "" ] ; then
130		# Grant privileges of write_acl and retest the chmod commands.
131		acl="user:$ZFS_ACL_STAFF2:write_acl:allow"
132		log_must usr_exec $CHMOD A+${acl} $testfile
133		log_must usr_exec $CHMOD A+${acl} $testdir
134
135		log_must set_cur_usr $ZFS_ACL_STAFF2
136		log_must test_chmod_mapping $testfile
137		log_must test_chmod_mapping $testdir
138	fi
139
140	log_must set_cur_usr $user
141
142	log_must usr_exec $RM $testfile
143	log_must usr_exec $RM -rf $testdir
144done
145
146log_pass "Setting permissions using 'chmod' completed successfully."
147