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_rwx_001_pos
34#
35# DESCRIPTION:
36#	chmod A{+|-|=} have the correct behaviour to the ACL list.
37#
38# STRATEGY:
39#	1. loop check root and non-root users
40#	2. chmod file or dir with specified options
41#	3. get ACE after behaviours of chmod
42#	4. compare specified ACE and excpect ACE
43#
44# TESTABILITY: explicit
45#
46# TEST_AUTOMATION_LEVEL: automated
47#
48# CODING_STATUS: COMPLETED (2005-09-30)
49#
50# __stc_assertion_end
51#
52################################################################################
53
54verify_runnable "both"
55
56log_assert "chmod A{+|-|=} have the correct behaviour to the ACL list."
57log_onexit cleanup
58
59typeset -i trival_count=6 head=0 mid end
60((mid = RANDOM % $trival_count))
61((end = trival_count - 1))
62
63opts="+ - ="
64nums="$head $mid $end"
65set -A file_ACEs \
66	"user:$ZFS_ACL_STAFF1:read_data:allow" \
67	"user:$ZFS_ACL_STAFF2:write_data:allow" \
68	"user:$ZFS_ACL_OTHER1:execute:allow"
69set -A dir_ACEs \
70	"user:$ZFS_ACL_STAFF1:list_directory/read_data:allow" \
71	"user:$ZFS_ACL_STAFF2:add_file/write_data:allow" \
72	"user:$ZFS_ACL_OTHER1:execute:allow"
73
74function test_chmod_ACE_list #$opt $num $ace-spec $node
75{
76	typeset opt=A$2$1
77	typeset -i num=$2
78	typeset ace=$3
79	typeset node=$4
80	typeset -i expect_count=0
81
82	# Get expect ACE count
83	case $opt in
84		A[0-9]*+) (( expect_count = trival_count + 1 )) ;;
85		A[0-9]*-) (( expect_count = trival_count - 1 )) ;;
86		A[0-9]*=) (( expect_count = trival_count )) ;;
87		*) log_fail "Error option: '$opt'" ;;
88	esac
89
90	# Invoke chmod A[number]{+|-|=}<acl-specification> file|dir
91	if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then
92		log_must usr_exec $CHMOD "$opt$ace" "$node"
93	else
94		log_must usr_exec $CHMOD "$opt" "$node"
95	fi
96
97	# Get the current ACE count and specified ACE
98	typeset cur_ace cur_count
99	cur_ace=$(get_ACE $node $num)
100	cur_count=$(count_ACE $node)
101
102	# Compare with expected results
103	if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then
104		if [[ "$num:$ace" != "$cur_ace" ]]; then
105			log_fail "FAIL: $CHMOD $opt$ace $node"
106		fi
107	fi
108	if [[ "$expect_count" != "$cur_count" ]]; then
109		log_fail "FAIL: '$expect_count' != '$cur_count'"
110	fi
111}
112
113test_requires ZFS_ACL
114
115for user in root $ZFS_ACL_STAFF1 $ZFS_ACL_OTHER1; do
116	log_must set_cur_usr $user
117
118	for opt in $opts; do
119		for num in $nums; do
120			for ace in $file_ACEs; do
121				ls -l $TESTDIR
122				log_must usr_exec $TOUCH $testfile
123				test_chmod_ACE_list $opt $num $ace $testfile
124				log_must $RM -f $testfile
125			done
126			for ace in $dir_ACEs; do
127				ls -l $TESTDIR
128				log_must usr_exec $MKDIR -p $testdir
129				test_chmod_ACE_list $opt $num $ace $testdir
130				log_must $RM -rf $testdir
131			done
132		done
133	done
134done
135
136log_pass "chmod A{+|-|=} behave to the ACL list passed."
137