xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/acl/nontrivial/zfs_acl_chmod_rwx_001_pos.ksh (revision 1d32ba663e202c24a5a1f2e5aef83fffb447cb7f)
1d583b39bSJohn Wren Kennedy#!/bin/ksh -p
2d583b39bSJohn Wren Kennedy#
3d583b39bSJohn Wren Kennedy# CDDL HEADER START
4d583b39bSJohn Wren Kennedy#
5d583b39bSJohn Wren Kennedy# The contents of this file are subject to the terms of the
6d583b39bSJohn Wren Kennedy# Common Development and Distribution License (the "License").
7d583b39bSJohn Wren Kennedy# You may not use this file except in compliance with the License.
8d583b39bSJohn Wren Kennedy#
9d583b39bSJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d583b39bSJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11d583b39bSJohn Wren Kennedy# See the License for the specific language governing permissions
12d583b39bSJohn Wren Kennedy# and limitations under the License.
13d583b39bSJohn Wren Kennedy#
14d583b39bSJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15d583b39bSJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16d583b39bSJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17d583b39bSJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18d583b39bSJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19d583b39bSJohn Wren Kennedy#
20d583b39bSJohn Wren Kennedy# CDDL HEADER END
21d583b39bSJohn Wren Kennedy#
22d583b39bSJohn Wren Kennedy
23d583b39bSJohn Wren Kennedy#
24d583b39bSJohn Wren Kennedy# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25d583b39bSJohn Wren Kennedy# Use is subject to license terms.
26d583b39bSJohn Wren Kennedy#
27d583b39bSJohn Wren Kennedy
28d583b39bSJohn Wren Kennedy#
29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
30d583b39bSJohn Wren Kennedy#
31d583b39bSJohn Wren Kennedy
32d583b39bSJohn Wren Kennedy. $STF_SUITE/tests/functional/acl/acl_common.kshlib
33d583b39bSJohn Wren Kennedy
34d583b39bSJohn Wren Kennedy#
35d583b39bSJohn Wren Kennedy# DESCRIPTION:
36d583b39bSJohn Wren Kennedy#	chmod A{+|-|=} have the correct behaviour to the ACL list.
37d583b39bSJohn Wren Kennedy#
38d583b39bSJohn Wren Kennedy# STRATEGY:
39d583b39bSJohn Wren Kennedy#	1. loop check root and non-root users
40d583b39bSJohn Wren Kennedy#	2. chmod file or dir with specified options
41d583b39bSJohn Wren Kennedy#	3. get ACE after behaviours of chmod
42d583b39bSJohn Wren Kennedy#	4. compare specified ACE and expect ACE
43d583b39bSJohn Wren Kennedy#
44d583b39bSJohn Wren Kennedy
45d583b39bSJohn Wren Kennedyverify_runnable "both"
46d583b39bSJohn Wren Kennedy
47d583b39bSJohn Wren Kennedylog_assert "chmod A{+|-|=} have the correct behaviour to the ACL list."
48d583b39bSJohn Wren Kennedylog_onexit cleanup
49d583b39bSJohn Wren Kennedy
50d583b39bSJohn Wren Kennedytypeset -i trival_count=3 head=0 mid end
51d583b39bSJohn Wren Kennedy((mid = RANDOM % $trival_count))
52d583b39bSJohn Wren Kennedy((end = trival_count - 1))
53d583b39bSJohn Wren Kennedy
54d583b39bSJohn Wren Kennedyopts="+ - ="
55d583b39bSJohn Wren Kennedynums="$head $mid $end"
56d583b39bSJohn Wren Kennedyset -A file_ACEs \
57d583b39bSJohn Wren Kennedy    "user:$ZFS_ACL_STAFF1:read_data:allow" \
58d583b39bSJohn Wren Kennedy    "user:$ZFS_ACL_STAFF2:write_data:allow" \
59d583b39bSJohn Wren Kennedy    "user:$ZFS_ACL_OTHER1:execute:allow"
60d583b39bSJohn Wren Kennedyset -A dir_ACEs \
61d583b39bSJohn Wren Kennedy    "user:$ZFS_ACL_STAFF1:list_directory/read_data:allow" \
62d583b39bSJohn Wren Kennedy    "user:$ZFS_ACL_STAFF2:add_file/write_data:allow" \
63d583b39bSJohn Wren Kennedy    "user:$ZFS_ACL_OTHER1:execute:allow"
64d583b39bSJohn Wren Kennedy
65d583b39bSJohn Wren Kennedyfunction test_chmod_ACE_list #$opt $num $ace-spec $node
66d583b39bSJohn Wren Kennedy{
67d583b39bSJohn Wren Kennedy	typeset opt=A$2$1
68d583b39bSJohn Wren Kennedy	typeset -i num=$2
69d583b39bSJohn Wren Kennedy	typeset ace=$3
70d583b39bSJohn Wren Kennedy	typeset node=$4
71d583b39bSJohn Wren Kennedy	typeset -i expect_count=0
72d583b39bSJohn Wren Kennedy
73d583b39bSJohn Wren Kennedy	# Get expect ACE count
74d583b39bSJohn Wren Kennedy	case $opt in
75d583b39bSJohn Wren Kennedy		A[0-9]*+) (( expect_count = trival_count + 1 )) ;;
76d583b39bSJohn Wren Kennedy		A[0-9]*-) (( expect_count = trival_count - 1 )) ;;
77d583b39bSJohn Wren Kennedy		A[0-9]*=) (( expect_count = trival_count )) ;;
78d583b39bSJohn Wren Kennedy		*) log_fail "Error option: '$opt'" ;;
79d583b39bSJohn Wren Kennedy	esac
80d583b39bSJohn Wren Kennedy
81d583b39bSJohn Wren Kennedy	# Invoke chmod A[number]{+|-|=}<acl-specification> file|dir
82d583b39bSJohn Wren Kennedy	if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then
83*1d32ba66SJohn Wren Kennedy		log_must usr_exec chmod "$opt$ace" "$node"
84d583b39bSJohn Wren Kennedy	else
85*1d32ba66SJohn Wren Kennedy		log_must usr_exec chmod "$opt" "$node"
86d583b39bSJohn Wren Kennedy	fi
87d583b39bSJohn Wren Kennedy
88d583b39bSJohn Wren Kennedy	# Get the current ACE count and specified ACE
89d583b39bSJohn Wren Kennedy	typeset cur_ace cur_count
90d583b39bSJohn Wren Kennedy	cur_ace=$(get_ACE $node $num)
91d583b39bSJohn Wren Kennedy	cur_count=$(count_ACE $node)
92d583b39bSJohn Wren Kennedy
93d583b39bSJohn Wren Kennedy	# Compare with expected results
94d583b39bSJohn Wren Kennedy	if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then
95d583b39bSJohn Wren Kennedy		if [[ "$num:$ace" != "$cur_ace" ]]; then
96*1d32ba66SJohn Wren Kennedy			log_fail "FAIL: chmod $opt$ace $node"
97d583b39bSJohn Wren Kennedy		fi
98d583b39bSJohn Wren Kennedy	fi
99d583b39bSJohn Wren Kennedy	if [[ "$expect_count" != "$cur_count" ]]; then
100d583b39bSJohn Wren Kennedy		log_fail "FAIL: '$expect_count' != '$cur_count'"
101d583b39bSJohn Wren Kennedy	fi
102d583b39bSJohn Wren Kennedy}
103d583b39bSJohn Wren Kennedy
104d583b39bSJohn Wren Kennedyfor user in root $ZFS_ACL_STAFF1 $ZFS_ACL_OTHER1; do
105d583b39bSJohn Wren Kennedy	log_must set_cur_usr $user
106d583b39bSJohn Wren Kennedy
107d583b39bSJohn Wren Kennedy	for opt in $opts; do
108d583b39bSJohn Wren Kennedy		for num in $nums; do
109d583b39bSJohn Wren Kennedy			for ace in $file_ACEs; do
110d583b39bSJohn Wren Kennedy				ls -l $TESTDIR
111*1d32ba66SJohn Wren Kennedy				log_must usr_exec touch $testfile
112d583b39bSJohn Wren Kennedy				test_chmod_ACE_list $opt $num $ace $testfile
113*1d32ba66SJohn Wren Kennedy				log_must rm -f $testfile
114d583b39bSJohn Wren Kennedy			done
115d583b39bSJohn Wren Kennedy			for ace in $dir_ACEs; do
116d583b39bSJohn Wren Kennedy				ls -l $TESTDIR
117*1d32ba66SJohn Wren Kennedy				log_must usr_exec mkdir -p $testdir
118d583b39bSJohn Wren Kennedy				test_chmod_ACE_list $opt $num $ace $testdir
119*1d32ba66SJohn Wren Kennedy				log_must rm -rf $testdir
120d583b39bSJohn Wren Kennedy			done
121d583b39bSJohn Wren Kennedy		done
122d583b39bSJohn Wren Kennedy	done
123d583b39bSJohn Wren Kennedydone
124d583b39bSJohn Wren Kennedy
125d583b39bSJohn Wren Kennedylog_pass "chmod A{+|-|=} behave to the ACL list passed."
126