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