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