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_001_pos.ksh 1.5 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_001_pos 39# 40# DESCRIPTION: 41# Verify chmod permission settings on files and directories, as both root 42# and non-root users. 43# 44# STRATEGY: 45# 1. Loop root and $ZFS_ACL_STAFF1 as root and non-root users. 46# 2. Create test file and directory in zfs filesystem. 47# 3. Execute 'chmod' with specified options. 48# 4. Check 'ls -l' output and compare with expect results. 49# 50# TESTABILITY: explicit 51# 52# TEST_AUTOMATION_LEVEL: automated 53# 54# CODING_STATUS: COMPLETED (2005-09-27) 55# 56# __stc_assertion_end 57# 58################################################################################ 59 60verify_runnable "both" 61 62# "init_map" "options" "expect_map" 63set -A argv \ 64 "000" "a+rw" "rw-rw-rw-" "000" "a+rwx" "rwxrwxrwx" \ 65 "000" "u+xr" "r-x------" "000" "gu-xw" "---------" \ 66 "644" "a-r" "-w-------" "644" "augo-x" "rw-r--r--" \ 67 "644" "=x" "--x--x--x" "644" "u-rw" "---r--r--" \ 68 "644" "uo+x" "rwxr--r-x" "644" "ga-wr" "---------" \ 69 "777" "augo+x" "rwxrwxrwx" "777" "go-xr" "rwx-w--w-" \ 70 "777" "o-wx" "rwxrwxr--" "777" "ou-rx" "-w-rwx-w-" \ 71 "777" "a+rwx" "rwxrwxrwx" "777" "u=rw" "rw-rwxrwx" \ 72 "000" "123" "--x-w--wx" "000" "412" "r----x-w-" \ 73 "231" "562" "r-xrw--w-" "712" "000" "---------" \ 74 "777" "121" "--x-w---x" "123" "775" "rwxrwxr-x" 75 76log_assert " Verify chmod permission settings on files and directories" 77log_onexit cleanup 78 79# 80# Verify file or directory have correct map after chmod 81# 82# $1 file or directory 83# 84function test_chmod_mapping #<file-dir> 85{ 86 typeset node=$1 87 typeset -i i=0 88 89 while (( i < ${#argv[@]} )); do 90 usr_exec $CHMOD ${argv[i]} $node 91 if (($? != 0)); then 92 log_note "usr_exec $CHMOD ${argv[i]} $node" 93 return 1 94 fi 95 96 usr_exec $CHMOD ${argv[((i + 1))]} $node 97 if (($? != 0)); then 98 log_note "usr_exec $CHMOD ${argv[((i + 1))]} $node" 99 return 1 100 fi 101 102 typeset mode 103 mode=$(get_mode ${node}) 104 105 if [[ $mode != "-${argv[((i + 2))]}"* && \ 106 $mode != "d${argv[((i + 2))]}"* ]] 107 then 108 log_fail "FAIL: '${argv[i]}' '${argv[((i + 1))]}' \ 109 '${argv[((i + 2))]}'" 110 fi 111 112 (( i += 3 )) 113 done 114 115 return 0 116} 117 118for user in root $ZFS_ACL_STAFF1; do 119 log_must set_cur_usr $user 120 121 # Test file 122 log_must usr_exec $TOUCH $testfile 123 log_must test_chmod_mapping $testfile 124 125 if [ "$ZFS_ACL" != "" ] ; then 126 log_must $CHMOD A+user:$ZFS_ACL_STAFF2:write_acl:allow $testfile 127 fi 128 log_must set_cur_usr $ZFS_ACL_STAFF2 129 130 # Test directory 131 log_must usr_exec $MKDIR $testdir 132 log_must test_chmod_mapping $testdir 133 134 if [ "$ZFS_ACL" != "" ] ; then 135 # Grant privileges of write_acl and retest the chmod commands. 136 acl="user:$ZFS_ACL_STAFF2:write_acl:allow" 137 log_must usr_exec $CHMOD A+${acl} $testfile 138 log_must usr_exec $CHMOD A+${acl} $testdir 139 140 log_must set_cur_usr $ZFS_ACL_STAFF2 141 log_must test_chmod_mapping $testfile 142 log_must test_chmod_mapping $testdir 143 fi 144 145 log_must set_cur_usr $user 146 147 log_must usr_exec $RM $testfile 148 log_must usr_exec $RM -rf $testdir 149done 150 151log_pass "Setting permissions using 'chmod' completed successfully." 152