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#	Verifies that cp will not be able to include file attribute when
37d583b39bSJohn Wren Kennedy#	attribute is unreadable (unless the user is root)
38d583b39bSJohn Wren Kennedy#
39d583b39bSJohn Wren Kennedy# STRATEGY:
40d583b39bSJohn Wren Kennedy#	1. In directory A, create several files and add attribute files for them
41d583b39bSJohn Wren Kennedy#	2. chmod all files'the attribute files to '000'.
42d583b39bSJohn Wren Kennedy#	3. Implement 'cp -@p' to files.
43d583b39bSJohn Wren Kennedy#	4. Verify attribute files are not existing for non-root user.
44d583b39bSJohn Wren Kennedy#
45d583b39bSJohn Wren Kennedy
46d583b39bSJohn Wren Kennedyverify_runnable "both"
47d583b39bSJohn Wren Kennedy
48d583b39bSJohn Wren Kennedylog_assert "Verifies that cp won't be able to include file attribute when " \
49d583b39bSJohn Wren Kennedy	"attribute is unreadable (except root)"
50d583b39bSJohn Wren Kennedylog_onexit cleanup
51d583b39bSJohn Wren Kennedy
52d583b39bSJohn Wren Kennedyfunction test_unreadable_attr
53d583b39bSJohn Wren Kennedy{
54*1d32ba66SJohn Wren Kennedy	typeset initfiles=$(ls -R $INI_DIR/*)
55d583b39bSJohn Wren Kennedy
56d583b39bSJohn Wren Kennedy	typeset -i i=0
57d583b39bSJohn Wren Kennedy	while (( i < NUM_FILE )); do
58d583b39bSJohn Wren Kennedy		typeset f=$(getitem $i $initfiles)
59d583b39bSJohn Wren Kennedy		typeset -i j=0
60d583b39bSJohn Wren Kennedy		while (( j < NUM_ATTR )); do
61d583b39bSJohn Wren Kennedy			# chmod all the attribute files to '000'.
62*1d32ba66SJohn Wren Kennedy			usr_exec runat $f chmod 000 attribute.$j
63d583b39bSJohn Wren Kennedy
64d583b39bSJohn Wren Kennedy			(( j += 1 ))
65d583b39bSJohn Wren Kennedy		done
66d583b39bSJohn Wren Kennedy
67d583b39bSJohn Wren Kennedy		#
68d583b39bSJohn Wren Kennedy		# Implement 'cp -@p' to the file whose attribute files
69d583b39bSJohn Wren Kennedy		# models are '000'.
70d583b39bSJohn Wren Kennedy		#
71*1d32ba66SJohn Wren Kennedy		usr_exec cp -@p $f $TST_DIR > /dev/null 2>&1
72d583b39bSJohn Wren Kennedy
73*1d32ba66SJohn Wren Kennedy		typeset testfiles=$(ls -R $TST_DIR/*)
74d583b39bSJohn Wren Kennedy		typeset tf=$(getitem $i $testfiles)
75*1d32ba66SJohn Wren Kennedy		typeset ls_attr=$(usr_exec ls -@ $tf | \
76*1d32ba66SJohn Wren Kennedy			awk '{print substr($1, 11, 1)}')
77d583b39bSJohn Wren Kennedy
78d583b39bSJohn Wren Kennedy		case $ZFS_ACL_CUR_USER in
79d583b39bSJohn Wren Kennedy		root)
80d583b39bSJohn Wren Kennedy			case $ls_attr in
81d583b39bSJohn Wren Kennedy			@)
82d583b39bSJohn Wren Kennedy				log_note "SUCCESS: root enable to cp attribute"\
83d583b39bSJohn Wren Kennedy					"when attribute files is unreadable"
84d583b39bSJohn Wren Kennedy				break ;;
85d583b39bSJohn Wren Kennedy			*)
86d583b39bSJohn Wren Kennedy				log_fail "root should enable to cp attribute " \
87d583b39bSJohn Wren Kennedy					"when attribute files is unreadable"
88d583b39bSJohn Wren Kennedy				break ;;
89d583b39bSJohn Wren Kennedy			esac
90d583b39bSJohn Wren Kennedy			;;
91d583b39bSJohn Wren Kennedy		$ZFS_ACL_STAFF1)
92d583b39bSJohn Wren Kennedy			case $ls_attr in
93d583b39bSJohn Wren Kennedy			@)
94d583b39bSJohn Wren Kennedy				log_fail "non-root shouldn't enable to cp " \
95d583b39bSJohn Wren Kennedy					"attribute when attribute files is " \
96d583b39bSJohn Wren Kennedy					"unreadable."
97d583b39bSJohn Wren Kennedy				break ;;
98d583b39bSJohn Wren Kennedy			*)
99d583b39bSJohn Wren Kennedy				log_note "SUCCESS: non-root doesn't enable to "\
100d583b39bSJohn Wren Kennedy					"cp attribute when attribute files is "\
101d583b39bSJohn Wren Kennedy					"unreadable."
102d583b39bSJohn Wren Kennedy				break ;;
103d583b39bSJohn Wren Kennedy			esac
104d583b39bSJohn Wren Kennedy			;;
105d583b39bSJohn Wren Kennedy		*)
106d583b39bSJohn Wren Kennedy		esac
107d583b39bSJohn Wren Kennedy
108d583b39bSJohn Wren Kennedy
109d583b39bSJohn Wren Kennedy		(( i += 1 ))
110d583b39bSJohn Wren Kennedy	done
111d583b39bSJohn Wren Kennedy}
112d583b39bSJohn Wren Kennedy
113d583b39bSJohn Wren Kennedyfor user in root $ZFS_ACL_STAFF1; do
114d583b39bSJohn Wren Kennedy	log_must set_cur_usr $user
115d583b39bSJohn Wren Kennedy
116d583b39bSJohn Wren Kennedy	log_must create_files $TESTDIR
117d583b39bSJohn Wren Kennedy	test_unreadable_attr
118d583b39bSJohn Wren Kennedy
119d583b39bSJohn Wren Kennedy	log_must cleanup
120d583b39bSJohn Wren Kennedydone
121d583b39bSJohn Wren Kennedy
122d583b39bSJohn Wren Kennedylog_pass "'cp -@p' won't include file attribute passed."