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# 29# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/tests/functional/acl/acl_common.kshlib 33 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 expect ACE 43# 44 45verify_runnable "both" 46 47log_assert "chmod A{+|-|=} have the correct behaviour to the ACL list." 48log_onexit cleanup 49 50typeset -i trival_count=3 head=0 mid end 51((mid = RANDOM % $trival_count)) 52((end = trival_count - 1)) 53 54opts="+ - =" 55nums="$head $mid $end" 56set -A file_ACEs \ 57 "user:$ZFS_ACL_STAFF1:read_data:allow" \ 58 "user:$ZFS_ACL_STAFF2:write_data:allow" \ 59 "user:$ZFS_ACL_OTHER1:execute:allow" 60set -A dir_ACEs \ 61 "user:$ZFS_ACL_STAFF1:list_directory/read_data:allow" \ 62 "user:$ZFS_ACL_STAFF2:add_file/write_data:allow" \ 63 "user:$ZFS_ACL_OTHER1:execute:allow" 64 65function test_chmod_ACE_list #$opt $num $ace-spec $node 66{ 67 typeset opt=A$2$1 68 typeset -i num=$2 69 typeset ace=$3 70 typeset node=$4 71 typeset -i expect_count=0 72 73 # Get expect ACE count 74 case $opt in 75 A[0-9]*+) (( expect_count = trival_count + 1 )) ;; 76 A[0-9]*-) (( expect_count = trival_count - 1 )) ;; 77 A[0-9]*=) (( expect_count = trival_count )) ;; 78 *) log_fail "Error option: '$opt'" ;; 79 esac 80 81 # Invoke chmod A[number]{+|-|=}<acl-specification> file|dir 82 if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then 83 log_must usr_exec chmod "$opt$ace" "$node" 84 else 85 log_must usr_exec chmod "$opt" "$node" 86 fi 87 88 # Get the current ACE count and specified ACE 89 typeset cur_ace cur_count 90 cur_ace=$(get_ACE $node $num) 91 cur_count=$(count_ACE $node) 92 93 # Compare with expected results 94 if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then 95 if [[ "$num:$ace" != "$cur_ace" ]]; then 96 log_fail "FAIL: chmod $opt$ace $node" 97 fi 98 fi 99 if [[ "$expect_count" != "$cur_count" ]]; then 100 log_fail "FAIL: '$expect_count' != '$cur_count'" 101 fi 102} 103 104for user in root $ZFS_ACL_STAFF1 $ZFS_ACL_OTHER1; do 105 log_must set_cur_usr $user 106 107 for opt in $opts; do 108 for num in $nums; do 109 for ace in $file_ACEs; do 110 ls -l $TESTDIR 111 log_must usr_exec touch $testfile 112 test_chmod_ACE_list $opt $num $ace $testfile 113 log_must rm -f $testfile 114 done 115 for ace in $dir_ACEs; do 116 ls -l $TESTDIR 117 log_must usr_exec mkdir -p $testdir 118 test_chmod_ACE_list $opt $num $ace $testdir 119 log_must rm -rf $testdir 120 done 121 done 122 done 123done 124 125log_pass "chmod A{+|-|=} behave to the ACL list passed." 126