1#!/bin/ksh -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
28. $STF_SUITE/tests/functional/acl/acl_common.kshlib
29
30#
31# DESCRIPTION:
32#	Verify  1) Illegal options to chmod should fail.
33#		2) Delete all the ACE will lead to fail.
34#		3) Add ACE exceed 1024 will cause to fail.
35#
36# STRATEGY:
37#	1. Loop root and non-root users
38#	2. Verify all kinds of illegal option will lead to chmod failed.
39#	3. Verify 'chmod A0-' will fail when try to delete all the ACE.
40#	4. Verify 'chmod A+' will succeed when the ACE number exceed 1024.
41#
42
43verify_runnable "both"
44
45log_assert "Verify illegal operating to ACL, it will fail."
46log_onexit cleanup
47
48function err_opts #node
49{
50	typeset A_opts="+A@ -A#- +A% =A^ =A# =A@ +A#\ asd \
51			A+@ A-#- A+% A=^ A=# A=@ A+#"
52
53	log_note "Illegal option to chmod should fail."
54	for A in ${A_opts[@]}; do
55		log_mustnot usr_exec $CHMOD ${A}owner@:read_data:allow $node
56		log_mustnot usr_exec $CHMOD A+ asd owner@:execute:deny $node
57	done
58
59	typeset type_opts="everyone groups owner user@ users"
60	for tp in ${type_opts[@]}; do
61		log_mustnot usr_exec $CHMOD A+$tp:read_data:deny $node
62	done
63
64	return 0
65}
66
67function del_all_ACE #node
68{
69	typeset node=$1
70	typeset -i cnt
71
72	cnt=$(count_ACE $node)
73	while (( cnt > 0 )); do
74		if (( cnt == 1 )); then
75			log_mustnot $CHMOD A0- $node
76		else
77			log_must $CHMOD A0- $node
78		fi
79
80		(( cnt -= 1 ))
81	done
82
83	return 0
84}
85
86function exceed_max_ACE #node
87{
88	typeset node=$1
89	typeset -i max=1024
90	typeset -i cnt
91
92	cnt=$(count_ACE $node)
93
94	# One more ACE exceed the max limitation.
95	(( max = max - cnt + 1 ))
96	while (( max > 0 )); do
97		if (( max == 1 )); then
98			log_mustnot $CHMOD A+owner@:read_data:allow $node
99		else
100			$CHMOD A+owner@:read_data:allow $node
101			if (($? != 0)); then
102				((cnt = 1024 - max))
103				log_fail "Add No.$cnt ACL item failed."
104			fi
105		fi
106
107		(( max -= 1 ))
108	done
109
110	return 0
111}
112
113typeset node
114typeset func_name="err_opts del_all_ACE exceed_max_ACE"
115
116for usr in "root" "$ZFS_ACL_STAFF1"; do
117	log_must set_cur_usr $usr
118
119	for node in $testfile $testdir; do
120		log_must usr_exec $TOUCH $testfile
121		log_must usr_exec $MKDIR $testdir
122
123		for func in $func_name; do
124			log_must eval "$func $node"
125		done
126
127		log_must usr_exec $RM -rf $testfile $testdir
128	done
129done
130
131log_pass "Verify illegal operating to ACL passed."
132