d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# CDDL HEADER START
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# The contents of this file are subject to the terms of the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Common Development and Distribution License (the "License").
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# You may not use this file except in compliance with the License.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# See the License for the specific language governing permissions
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# and limitations under the License.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# CDDL HEADER END
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Use is subject to license terms.
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# Copyright 2016 Nexenta Systems, Inc.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy. $STF_SUITE/tests/functional/acl/acl_common.kshlib
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# Verify chmod have correct behaviour to directory and file when
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# filesystem has the different aclinherit setting
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# 1. Use both super user and non-super user to run the test case.
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# 2. Create basedir and a set of subdirectores and files within it.
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# 3. Separately chmod basedir with different inherite options,
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# combine with the variable setting of aclinherit:
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# "discard", "noallow", "restricted" or "passthrough".
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# 4. Then create nested directories and files like the following.
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# chmod --> basedir -|
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# 5. Verify each directories and files have the correct access control
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# capability.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy [[ -d $basedir ]] && log_must rm -rf $basedir
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankovlog_assert "Verify chmod have correct behaviour to directory and file when" \
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov "filesystem has the different aclinherit setting"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Define inherit flag
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankovtypeset aclinherit_flag=("discard" "noallow" "restricted" "passthrough")
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedytypeset strategy_flag=("--" "i-" "-n" "in")
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# Define the base directory and file
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankovbasedir=$TESTDIR/basedir; ofile=$TESTDIR/ofile; odir=$TESTDIR/odir
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# Define the files and directories that will be created after chmod
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedyndir1=$basedir/ndir1; ndir2=$ndir1/ndir2; ndir3=$ndir2/ndir3
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedynfile1=$basedir/nfile1; nfile2=$ndir1/nfile2; nfile3=$ndir2/nfile3
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# Verify all nodes have expected correct access control
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedyallnodes="$ndir1 $ndir2 $ndir3 $nfile1 $nfile2 $nfile3"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# According to inherited flag, verify subdirectories and files within it has
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# correct inherited access control.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedyfunction verify_inherit #<aclinherit> <object> [strategy]
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy # Define the nodes which will be affected by inherit.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must usr_exec touch $nfile1 $nfile2 $nfile3
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov # Files should have inherited ACEs only if file_inherit is set
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov # Directories should have inherited ACEs if file_inherit without
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov if [[ (${obj:0:1} == "f" && ${str:1:1} != "n") ||
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov typeset -i i=0 count=0 inherited=0
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov # If current node isn't in inherit list, there's
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov # nothing to check, skip to checking trivial ACL
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov if [[ -d $node ]]; then
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov # Clear inheritance flags if no_propagate is set
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov elif [[ -f $node ]] ; then
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov if [[ -n $expacl && $expacl != $aclcur ]]; then
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov # There were no non-trivial ACEs to check, do the trivial ones
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ -d $node ]]; then
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov elif [[ -f $node ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ $? -ne 0 ]]; then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must zfs set aclmode=passthrough $TESTPOOL/$TESTFS
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs set aclinherit=$inherit $TESTPOOL/$TESTFS
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov ((${#str} != 0)) && inh_opt="${inh_opt}${str}--"
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov # write_acl/write_owner - to verify "restricted"
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov acls0="$ace_prefix1:-------A-W----:$inh_b:allow"
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov acls2="$ace_prefix3:-------A-W----:$inh_b:allow"
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov acls4="$ace_prefix2:-------A-W----:$inh_b:allow"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must usr_exec rm -rf $ofile $odir $basedir
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankovlog_pass "Verify chmod inherit behaviour co-op with aclinherit setting passed"