1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/acl/acl_common.kshlib
33
34#
35# DESCRIPTION:
36#	Verifies that cp will not be able to include file attribute when
37#	attribute is unreadable (unless the user is root)
38#
39# STRATEGY:
40#	1. In directory A, create several files and add attribute files for them
41#	2. chmod all files'the attribute files to '000'.
42#	3. Implement 'cp -@p' to files.
43#	4. Verify attribute files are not existing for non-root user.
44#
45
46verify_runnable "both"
47
48log_assert "Verifies that cp won't be able to include file attribute when " \
49	"attribute is unreadable (except root)"
50log_onexit cleanup
51
52function test_unreadable_attr
53{
54	typeset initfiles=$(ls -R $INI_DIR/*)
55
56	typeset -i i=0
57	while (( i < NUM_FILE )); do
58		typeset f=$(getitem $i $initfiles)
59		typeset -i j=0
60		while (( j < NUM_ATTR )); do
61			# chmod all the attribute files to '000'.
62			usr_exec runat $f chmod 000 attribute.$j
63
64			(( j += 1 ))
65		done
66
67		#
68		# Implement 'cp -@p' to the file whose attribute files
69		# models are '000'.
70		#
71		usr_exec cp -@p $f $TST_DIR > /dev/null 2>&1
72
73		typeset testfiles=$(ls -R $TST_DIR/*)
74		typeset tf=$(getitem $i $testfiles)
75		typeset ls_attr=$(usr_exec ls -@ $tf | \
76			awk '{print substr($1, 11, 1)}')
77
78		case $ZFS_ACL_CUR_USER in
79		root)
80			case $ls_attr in
81			@)
82				log_note "SUCCESS: root enable to cp attribute"\
83					"when attribute files is unreadable"
84				break ;;
85			*)
86				log_fail "root should enable to cp attribute " \
87					"when attribute files is unreadable"
88				break ;;
89			esac
90			;;
91		$ZFS_ACL_STAFF1)
92			case $ls_attr in
93			@)
94				log_fail "non-root shouldn't enable to cp " \
95					"attribute when attribute files is " \
96					"unreadable."
97				break ;;
98			*)
99				log_note "SUCCESS: non-root doesn't enable to "\
100					"cp attribute when attribute files is "\
101					"unreadable."
102				break ;;
103			esac
104			;;
105		*)
106		esac
107
108
109		(( i += 1 ))
110	done
111}
112
113for user in root $ZFS_ACL_STAFF1; do
114	log_must set_cur_usr $user
115
116	log_must create_files $TESTDIR
117	test_unreadable_attr
118
119	log_must cleanup
120done
121
122log_pass "'cp -@p' won't include file attribute passed."
123