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
281d32ba66SJohn Wren Kennedy#
29*a01b7f54SJohn Wren Kennedy# Copyright (c) 2016, 2018 by Delphix. All rights reserved.
301d32ba66SJohn Wren Kennedy#
311d32ba66SJohn 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 & xattrs
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. Create xattr of the file and directory
42d583b39bSJohn Wren Kennedy#	4. Copy the file/directory within and across zfs file system
43d583b39bSJohn Wren Kennedy#	5. Verify that the ACL & xattrs of the file/directroy is not changed,
44d583b39bSJohn Wren Kennedy#	   when you are inserting an ACL with user: or group: entry on the top.
45d583b39bSJohn Wren Kennedy#	   (abstractions entry are treated special, since they represent the
46d583b39bSJohn Wren Kennedy#	   traditional permission bit mapping.)
47d583b39bSJohn Wren Kennedy#
48d583b39bSJohn Wren Kennedy
49d583b39bSJohn Wren Kennedyverify_runnable "both"
50d583b39bSJohn Wren Kennedy
51d583b39bSJohn Wren Kennedyfunction cleanup
52d583b39bSJohn Wren Kennedy{
53d583b39bSJohn Wren Kennedy	if datasetexists $TESTPOOL/$TESTFS1; then
541d32ba66SJohn Wren Kennedy		log_must zfs destroy -f $TESTPOOL/$TESTFS1
55d583b39bSJohn Wren Kennedy	fi
56*a01b7f54SJohn Wren Kennedy	log_must rm -rf $TESTDIR1 $TESTDIR/* $mytestfile
57d583b39bSJohn Wren Kennedy}
58d583b39bSJohn Wren Kennedy
591d32ba66SJohn 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."
631d32ba66SJohn Wren Kennedylog_must zfs create $TESTPOOL/$TESTFS1
641d32ba66SJohn Wren Kennedylog_must zfs set mountpoint=$TESTDIR1 $TESTPOOL/$TESTFS1
651d32ba66SJohn Wren Kennedylog_must zfs set aclmode=passthrough $TESTPOOL/$TESTFS1
661d32ba66SJohn Wren Kennedylog_must chmod 777 $TESTDIR1
67d583b39bSJohn Wren Kennedy
68d583b39bSJohn Wren Kennedy# Define target directory.
69d583b39bSJohn Wren Kennedydstdir=$TESTDIR1/dstdir.$$
70*a01b7f54SJohn Wren Kennedymytestfile=$(mktemp -t file.XXXX)
71*a01b7f54SJohn Wren Kennedylog_must dd if=/dev/urandom of=$mytestfile bs=1024k count=1
72*a01b7f54SJohn Wren Kennedylog_must chmod 644 $mytestfile
73d583b39bSJohn Wren Kennedy
74d583b39bSJohn Wren Kennedyfor user in root $ZFS_ACL_STAFF1; do
75d583b39bSJohn Wren Kennedy	# Set the current user
76d583b39bSJohn Wren Kennedy	log_must set_cur_usr $user
77d583b39bSJohn Wren Kennedy
78d583b39bSJohn Wren Kennedy	for obj in $testfile $testdir; do
79d583b39bSJohn Wren Kennedy		# Create source object and target directroy
801d32ba66SJohn Wren Kennedy		log_must usr_exec touch $testfile
811d32ba66SJohn Wren Kennedy		log_must usr_exec mkdir $testdir $dstdir
82d583b39bSJohn Wren Kennedy
831d32ba66SJohn Wren Kennedy		log_must usr_exec runat $testfile cp $mytestfile attr.0
841d32ba66SJohn Wren Kennedy		log_must usr_exec runat $testdir cp $mytestfile attr.0
85d583b39bSJohn Wren Kennedy
86d583b39bSJohn Wren Kennedy		# Add the new ACE on the head.
871d32ba66SJohn Wren Kennedy		log_must usr_exec chmod \
88d583b39bSJohn Wren Kennedy			A0+user:$ZFS_ACL_OTHER1:read_acl:deny $obj
89d583b39bSJohn Wren Kennedy
901d32ba66SJohn Wren Kennedy		cmd_str="cp -p@"
911d32ba66SJohn Wren Kennedy		[[ -d $obj ]] && cmd_str="cp -rp@"
92d583b39bSJohn Wren Kennedy		log_must usr_exec $cmd_str $obj $dstdir
93d583b39bSJohn Wren Kennedy		log_must usr_exec $cmd_str $obj $TESTDIR1
94d583b39bSJohn Wren Kennedy
95d583b39bSJohn Wren Kennedy		for dir in $dstdir $TESTDIR1; do
96d583b39bSJohn Wren Kennedy			log_must compare_modes $obj $dir/${obj##*/}
97d583b39bSJohn Wren Kennedy			log_must compare_acls $obj $dir/${obj##*/}
98d583b39bSJohn Wren Kennedy			log_must compare_xattrs $obj $dir/${obj##*/}
99d583b39bSJohn Wren Kennedy		done
100d583b39bSJohn Wren Kennedy
101d583b39bSJohn Wren Kennedy		# Delete all the test file and directory
1021d32ba66SJohn Wren Kennedy		log_must usr_exec rm -rf $TESTDIR/* $TESTDIR1/*
103d583b39bSJohn Wren Kennedy	done
104d583b39bSJohn Wren Kennedydone
105d583b39bSJohn Wren Kennedy
1061d32ba66SJohn Wren Kennedylog_pass "'cp [-p@]' succeeds to support ZFS ACLs."
107