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_inherit_001_pos.ksh 1.5 09/05/19 SMI" 30# 31 32. $STF_SUITE/tests/acl/acl_common.kshlib 33 34################################################################################# 35# 36# __stc_assertion_start 37# 38# ID: zfs_acl_chmod_inherit_001_pos 39# 40# DESCRIPTION: 41# Verify chmod have correct behaviour to directory and file when setting 42# different inherit strategy to them. 43# 44# STRATEGY: 45# 1. Loop super user and non-super user to run the test case. 46# 2. Create basedir and a set of subdirectores and files within it. 47# 3. Separately chmod basedir with different inherite options. 48# 4. Then create nested directories and files like the following. 49# 50# _ odir4 51# |_ ofile4 52# _ odir3 _| 53# |_ ofile3 54# _ odir1 _| 55# |_ ofile2 56# basefile | 57# chmod --> basedir -| 58# |_ nfile1 59# |_ ndir1 _ 60# |_ nfile2 61# |_ ndir2 _ 62# |_ nfile3 63# |_ ndir3 64# 65# 5. Verify each directories and files have the correct access control 66# capability. 67# 68# TESTABILITY: explicit 69# 70# TEST_AUTOMATION_LEVEL: automated 71# 72# CODING_STATUS: COMPLETED (2005-11-15) 73# 74# __stc_assertion_end 75# 76################################################################################ 77 78verify_runnable "both" 79 80function cleanup 81{ 82 if [[ -f $basefile ]]; then 83 log_must $RM -f $basefile 84 fi 85 if [[ -d $basedir ]]; then 86 log_must $RM -rf $basedir 87 fi 88} 89 90log_assert "Verify chmod have correct behaviour to directory and file when " \ 91 "setting different inherit strategies to them." 92log_onexit cleanup 93 94# Define inherit flag 95set -A object_flag file_inherit dir_inherit file_inherit/dir_inherit 96set -A strategy_flag "" inherit_only no_propagate inherit_only/no_propagate 97 98# Defile the based directory and file 99basedir=$TESTDIR/basedir; basefile=$TESTDIR/basefile 100 101test_requires ZFS_ACL 102 103# Define the existed files and directories before chmod 104odir1=$basedir/odir1; odir2=$odir1/odir2; odir3=$odir2/odir3 105ofile1=$basedir/ofile1; ofile2=$odir1/ofile2; ofile3=$odir2/ofile3 106 107# Define the files and directories will be created after chmod 108ndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3 109nfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3 110 111# Verify all the node have expected correct access control 112allnodes="$basedir $ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3" 113allnodes="$allnodes $odir1 $odir2 $odir3 $ofile1 $ofile2 $ofile3" 114 115# 116# According to inherited flag, verify subdirectories and files within it has 117# correct inherited access control. 118# 119function verify_inherit #<object> [strategy] 120{ 121 # Define the nodes which will be affected by inherit. 122 typeset inherit_nodes 123 typeset obj=$1 124 typeset str=$2 125 126 log_must usr_exec $MKDIR -p $ndir3 127 log_must usr_exec $TOUCH $nfile1 $nfile2 $nfile3 128 129 # Except for inherit_only, the basedir was affected always. 130 if [[ $str != *"inherit_only"* ]]; then 131 inherit_nodes="$inherit_nodes $basedir" 132 fi 133 # Get the files which inherited ACE. 134 if [[ $obj == *"file_inherit"* ]]; then 135 inherit_nodes="$inherit_nodes $nfile1" 136 137 if [[ $str != *"no_propagate"* ]]; then 138 inherit_nodes="$inherit_nodes $nfile2 $nfile3" 139 fi 140 fi 141 # Get the directores which inherited ACE. 142 if [[ $obj == *"dir_inherit"* ]]; then 143 inherit_nodes="$inherit_nodes $ndir1" 144 145 if [[ $str != *"no_propagate"* ]]; then 146 inherit_nodes="$inherit_nodes $ndir2 $ndir3" 147 fi 148 fi 149 150 for node in $allnodes; do 151 if [[ " $inherit_nodes " == *" $node "* ]]; then 152 log_mustnot chgusr_exec $ZFS_ACL_OTHER1 $LS -vd $node \ 153 > /dev/null 2>&1 154 else 155 log_must chgusr_exec $ZFS_ACL_OTHER1 $LS -vd $node \ 156 > /dev/null 2>&1 157 fi 158 done 159} 160 161for user in root $ZFS_ACL_STAFF1; do 162 log_must set_cur_usr $user 163 164 for obj in "${object_flag[@]}"; do 165 for str in "${strategy_flag[@]}"; do 166 typeset inh_opt=$obj 167 (( ${#str} != 0 )) && inh_opt=$inh_opt/$str 168 aclspec="A+user:$ZFS_ACL_OTHER1:read_acl:$inh_opt:deny" 169 170 log_must usr_exec $MKDIR $basedir 171 log_must usr_exec $TOUCH $basefile 172 log_must usr_exec $MKDIR -p $odir3 173 log_must usr_exec $TOUCH $ofile1 $ofile2 $ofile3 174 175 # 176 # Inherit flag can only be placed on a directory, 177 # otherwise it will fail. 178 # 179 log_must usr_exec $CHMOD $aclspec $basefile 180 181 # 182 # Place on a directory should succeed. 183 # 184 log_must usr_exec $CHMOD $aclspec $basedir 185 186 verify_inherit $obj $str 187 188 log_must usr_exec $RM -rf $basefile $basedir 189 done 190 done 191done 192 193log_pass "Verify chmod inherit behaviour passed." 194