1#!/usr/local/bin/ksh93 -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. $STF_SUITE/tests/acl/acl_common.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_acl_cp_003_neg
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# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2006-06-01)
50#
51# __stc_assertion_end
52#
53################################################################################
54
55verify_runnable "both"
56
57log_assert "Verifies that cp won't be able to include file attribute when " \
58	"attribute is unreadable (except root)"
59log_onexit cleanup
60
61test_requires RUNAT ZFS_ACL ZFS_XATTR
62
63function test_unreadable_attr
64{
65	typeset initfiles=$($LS -R $INI_DIR/*)
66
67	typeset -i i=0
68	while (( i < NUM_FILE )); do
69		typeset f=$(getitem $i $initfiles)
70		typeset -i j=0
71		while (( j < NUM_ATTR )); do
72			# chmod all the attribute files to '000'.
73			usr_exec $RUNAT $f $CHMOD 000 attribute.$j
74
75			(( j += 1 ))
76		done
77
78		#
79		# Implement 'cp -@p' to the file whose attribute files
80		# models are '000'.
81		#
82		usr_exec $CP -@p $f $TST_DIR > /dev/null 2>&1
83
84		typeset testfiles=$($LS -R $TST_DIR/*)
85		typeset tf=$(getitem $i $testfiles)
86		typeset ls_attr=$(usr_exec $LS -@ $tf | \
87			$AWK '{print substr($1, 11, 1)}')
88
89		case $ZFS_ACL_CUR_USER in
90		root)
91			case $ls_attr in
92			@)
93				log_note "SUCCESS: root enable to cp attribute"\
94					"when attribute files is unreadable"
95				break ;;
96			*)
97				log_fail "root should enable to cp attribute " \
98					"when attribute files is unreadable"
99				break ;;
100			esac
101			;;
102		$ZFS_ACL_STAFF1)
103			case $ls_attr in
104			@)
105				log_fail "non-root shouldn't enable to cp " \
106					"attribute when attribute files is " \
107					"unreadable."
108				break ;;
109			*)
110				log_note "SUCCESS: non-root doesn't enable to "\
111					"cp attribute when attribute files is "\
112					"unreadable."
113				break ;;
114			esac
115			;;
116		*)
117		esac
118
119
120		(( i += 1 ))
121	done
122}
123
124for user in root $ZFS_ACL_STAFF1; do
125	log_must set_cur_usr $user
126
127	log_must create_files $TESTDIR
128	test_unreadable_attr
129
130	log_must cleanup
131done
132
133log_pass "'cp -@p' won't include file attribute passed."
134