1d583b39bSJohn Wren Kennedy#!/bin/ksh -p
2d583b39bSJohn Wren Kennedy#
3d583b39bSJohn Wren Kennedy# CDDL HEADER START
4d583b39bSJohn Wren Kennedy#
5d583b39bSJohn Wren Kennedy# The contents of this file are subject to the terms of the
6d583b39bSJohn Wren Kennedy# Common Development and Distribution License (the "License").
7d583b39bSJohn Wren Kennedy# You may not use this file except in compliance with the License.
8d583b39bSJohn Wren Kennedy#
9d583b39bSJohn Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10d583b39bSJohn Wren Kennedy# or http://www.opensolaris.org/os/licensing.
11d583b39bSJohn Wren Kennedy# See the License for the specific language governing permissions
12d583b39bSJohn Wren Kennedy# and limitations under the License.
13d583b39bSJohn Wren Kennedy#
14d583b39bSJohn Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
15d583b39bSJohn Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16d583b39bSJohn Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
17d583b39bSJohn Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
18d583b39bSJohn Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
19d583b39bSJohn Wren Kennedy#
20d583b39bSJohn Wren Kennedy# CDDL HEADER END
21d583b39bSJohn Wren Kennedy#
22d583b39bSJohn Wren Kennedy
23d583b39bSJohn Wren Kennedy#
24d583b39bSJohn Wren Kennedy# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25d583b39bSJohn Wren Kennedy# Use is subject to license terms.
26d583b39bSJohn Wren Kennedy#
27d583b39bSJohn Wren Kennedy
28*1d32ba66SJohn Wren Kennedy#
29*1d32ba66SJohn Wren Kennedy# Copyright (c) 2016 by Delphix. All rights reserved.
30*1d32ba66SJohn Wren Kennedy#
31*1d32ba66SJohn Wren Kennedy
32d583b39bSJohn Wren Kennedy. $STF_SUITE/tests/functional/acl/acl_common.kshlib
33d583b39bSJohn Wren Kennedy
34d583b39bSJohn Wren Kennedy#
35d583b39bSJohn Wren Kennedy# DESCRIPTION:
36d583b39bSJohn Wren Kennedy#	Verify that '/usr/bin/cp [-p]' supports ZFS ACL
37d583b39bSJohn Wren Kennedy#
38d583b39bSJohn Wren Kennedy# STRATEGY:
39d583b39bSJohn Wren Kennedy#	1. Create file and  directory in zfs filesystem
40d583b39bSJohn Wren Kennedy#	2. Set special ACE to the file and directory
41d583b39bSJohn Wren Kennedy#	3. Copy the file/directory within and across zfs file system
42d583b39bSJohn Wren Kennedy#	4. Verify that the ACL of file/directroy is not changed, when you are
43d583b39bSJohn Wren Kennedy#	   inserting an ACL with a user: or group: entry on the top.
44d583b39bSJohn Wren Kennedy#	   (abstractions entry are treated special, since they represent the
45d583b39bSJohn Wren Kennedy#	   traditional permission bit mapping.)
46d583b39bSJohn Wren Kennedy#
47d583b39bSJohn Wren Kennedy
48d583b39bSJohn Wren Kennedyverify_runnable "both"
49d583b39bSJohn Wren Kennedy
50d583b39bSJohn Wren Kennedyfunction cleanup
51d583b39bSJohn Wren Kennedy{
52d583b39bSJohn Wren Kennedy	if datasetexists $TESTPOOL/$TESTFS1; then
53*1d32ba66SJohn Wren Kennedy		log_must zfs destroy -f $TESTPOOL/$TESTFS1
54d583b39bSJohn Wren Kennedy	fi
55*1d32ba66SJohn Wren Kennedy	[[ -d $TESTDIR1 ]] && log_must rm -rf $TESTDIR1
56*1d32ba66SJohn Wren Kennedy	[[ -d $TESTDIR ]] && log_must rm -rf $TESTDIR/*
57d583b39bSJohn Wren Kennedy}
58d583b39bSJohn Wren Kennedy
59*1d32ba66SJohn Wren Kennedylog_assert "Verify that 'cp [-p]' supports ZFS ACLs."
60d583b39bSJohn Wren Kennedylog_onexit cleanup
61d583b39bSJohn Wren Kennedy
62d583b39bSJohn Wren Kennedylog_note "Create the second zfs file system: $TESTPOOL/$TESTFS1."
63*1d32ba66SJohn Wren Kennedylog_must zfs create $TESTPOOL/$TESTFS1
64*1d32ba66SJohn Wren Kennedylog_must zfs set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
65*1d32ba66SJohn Wren Kennedylog_must zfs set aclmode=passthrough $TESTPOOL/$TESTFS1
66*1d32ba66SJohn Wren Kennedylog_must chmod 777 $TESTDIR1
67d583b39bSJohn Wren Kennedy
68d583b39bSJohn Wren Kennedy# Define target directory.
69d583b39bSJohn Wren Kennedydstdir=$TESTDIR1/dstdir.$$
70d583b39bSJohn Wren Kennedy
71d583b39bSJohn Wren Kennedyfor user in root $ZFS_ACL_STAFF1; do
72d583b39bSJohn Wren Kennedy	# Set the current user
73d583b39bSJohn Wren Kennedy	log_must set_cur_usr $user
74d583b39bSJohn Wren Kennedy
75d583b39bSJohn Wren Kennedy	for obj in $testfile $testdir; do
76d583b39bSJohn Wren Kennedy		# Create source object and target directroy
77*1d32ba66SJohn Wren Kennedy		log_must usr_exec touch $testfile
78*1d32ba66SJohn Wren Kennedy		log_must usr_exec mkdir $testdir $dstdir
79d583b39bSJohn Wren Kennedy
80d583b39bSJohn Wren Kennedy		# Add the new ACE on the head.
81*1d32ba66SJohn Wren Kennedy		log_must usr_exec chmod \
82d583b39bSJohn Wren Kennedy			A0+user:$ZFS_ACL_OTHER1:read_acl:deny $obj
83d583b39bSJohn Wren Kennedy
84*1d32ba66SJohn Wren Kennedy		cmd_str="cp -p"
85*1d32ba66SJohn Wren Kennedy		[[ -d $obj ]] && cmd_str="cp -rp"
86d583b39bSJohn Wren Kennedy		log_must usr_exec $cmd_str $obj $dstdir
87d583b39bSJohn Wren Kennedy		log_must usr_exec $cmd_str $obj $TESTDIR1
88d583b39bSJohn Wren Kennedy
89d583b39bSJohn Wren Kennedy		for dir in $dstdir $TESTDIR1; do
90d583b39bSJohn Wren Kennedy			log_must compare_modes $obj $dir/${obj##*/}
91d583b39bSJohn Wren Kennedy			log_must compare_acls $obj $dir/${obj##*/}
92d583b39bSJohn Wren Kennedy		done
93d583b39bSJohn Wren Kennedy
94d583b39bSJohn Wren Kennedy		# Delete all the test file and directory
95*1d32ba66SJohn Wren Kennedy		log_must usr_exec rm -rf $TESTDIR/* $TESTDIR1/*
96d583b39bSJohn Wren Kennedy	done
97d583b39bSJohn Wren Kennedydone
98d583b39bSJohn Wren Kennedy
99*1d32ba66SJohn Wren Kennedylog_pass "'cp [-p]' succeeds to support ZFS ACLs."
100