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.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
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 not inherited
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# when 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 inside of it.
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# 3. For the following values of the aclinherity property, add ACEs with
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# different inherit options to basedir:
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# "discard", "noallow", "restricted" and "passthrough".
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# 4. Create nested directories and files like the following.
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# chmod --> basedir -|
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# 5. Verify non-inherited directories and files have the correct access
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# control capability.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy [[ -d $basedir ]] && log_must rm -rf $basedir
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs set aclmode=discard $TESTPOOL/$TESTFS
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankovlog_assert "Verify different inherit options combined with different" \
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov "aclinherit property values"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Define inherit flag
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedytypeset aclinherit_flag=(discard noallow restricted passthrough)
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedytypeset object_flag=(file_inherit dir_inherit file_inherit/dir_inherit)
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedytypeset strategy_flag=("" inherit_only no_propagate inherit_only/no_propagate)
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov# Define the base directory and file
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedybasedir=$TESTDIR/basedir; ofile=$TESTDIR/ofile; odir=$TESTDIR/odir
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Define the files and directories 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
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Verify all the node 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.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy # isinherit: indicate if the current target is in the inherit list.
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov typeset -i count=0 pass=0 passcnt=0 isinherit=0 no_propagate=0
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must usr_exec touch $nfile1 $nfile2 $nfile3
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy # Get the inherit type/object_flag and non-inherited nodes.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ $obj == *"file_inherit"* && $obj == *"dir_inherit"* ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy non_inherit_nodes= $ndir2 $ndir3 $nfile2 $nfile3
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy non_inherit_nodes="$nfile1 $nfile2 $nfile3"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy non_inherit_nodes="$non_inherit_nodes $ndir2 $ndir3"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy non_inherit_nodes="$non_inherit_nodes $nfile2 $nfile3"
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov # Verify ACEs for all the dirs/files under basedir
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ " $non_inherit_nodes " == *" $node "* ]]; then
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov if [[ -d $node ]]; then
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov if [[ $no_propagate == 0 ]]; then
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov if [[ $expacl != $aclcur ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ $? -ne 0 ]]; then
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov elif [[ -f $node ]]; then
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov if [[ $? -ne 0 ]]; then
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov # If there are no ACEs to be checked, compare the trivial ones.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ -d $node ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy elif [[ -f $node ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ $? -ne 0 ]]; then
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov log_fail "Unexpected ACE: $node, $inherit ($str)"
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedylog_must zfs set aclmode=passthrough $TESTPOOL/$TESTFS
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs set aclinherit=$inherit $TESTPOOL/$TESTFS
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov # write_acl/write_owner -> to verify "restricted"
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov acl2="${ace_prefix1}:read_xattr:${inh_opt}:deny"
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankov acl3="${ace_prefix2}:read_xattr:${inh_opt}:allow"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy log_note "verify_inherit $inherit $obj $str"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy log_must verify_inherit $inherit $obj $str
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must usr_exec rm -rf $ofile $odir $basedir
232f5a2e6e6fcc0e7d4f5bd719cd5e6433a24020Yuri Pankovlog_pass "Verify different inherit options combined with different" \