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