1 #! /usr/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 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 . $STF_SUITE/tests/acl/acl_common.kshlib
29
30 #################################################################################
31 #
32 # __stc_assertion_start
33 #
34 # ID: acl_cp_neg002
35 #
36 # DESCRIPTION:
37 # Verifies that cp will not be able to include file attribute when
38 # attribute is unreadable (unless the user is root)
39 #
40 # STRATEGY:
41 # 1. In directory A, create several files and add attribute files for them
42 # 2. chmod all files'the attribute files to '000'.
43 # 3. Implement 'cp -@p' to files.
44 # 4. Verify attribute files are not existing for non-root user.
45 #
46 # TESTABILITY: explicit
47 #
48 # TEST_AUTOMATION_LEVEL: automated
49 #
50 # CODING_STATUS: COMPLETED (2006-06-01)
51 #
52 # __stc_assertion_end
53 #
54 ################################################################################
55
56 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
57 && set -x
58
59 echo "ASSERTION: Verifies that cp won't be able to include file attribute when " \
60 "attribute is unreadable (except root)"
61
62 function test_unreadable_attr
63 {
64 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
65 && set -x
66
67 typeset initfiles=$($LS -R $INI_DIR/*)
68 typeset -i i=0
69 while (( i < NUM_FILE )); do
70 typeset f=$(getitem $i $initfiles)
71 typeset -i j=0
72 while (( j < NUM_ATTR )); do
73 # chmod all the attribute files to '000'.
74 RUN_CHECK usr_exec $RUNAT $f $CHMOD 000 attribute.$j
75 (( j += 1 ))
76 done
77
78 #
79 # Implement 'cp -@p' to the file whose attribute files
80 # models are '000'.
81 #
82 RUN_CHECK 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 RUN_CHECK usr_exec $LS -@ $tf | $AWK '{print substr($1, 11, 1)}' \
87 > $STF_TMPDIR/ls.$$ || cleanup $STF_FAIL $STF_TMPDIR/ls.$$
88 typeset ls_attr=$(cat $STF_TMPDIR/ls.$$)
89
90 case $ACL_CUR_USER in
91 root)
92 case $ls_attr in
93 @)
94 # SUCCESS: root enable to cp attribute
95 # when attribute files is unreadable
96 break ;;
97 *)
98 echo "root should enable to cp attribute " \
99 "when attribute files is unreadable"
100 cleanup $STF_FAIL
101 break ;;
102 esac
103 ;;
104 $ACL_STAFF1)
105 case $ls_attr in
106 @)
107 echo "non-root shouldn't enable to cp " \
108 "attribute when attribute files is " \
109 "unreadable."
110 cleanup $STF_FAIL
111 break ;;
112 *)
113 # SUCCESS: non-root doesn't enable to
114 # cp attribute when attribute files is
115 # unreadable.
116 break ;;
117 esac
118 ;;
119 *)
120 esac
121
122
123 (( i += 1 ))
124 done
125 }
126
127 for user in root $ACL_STAFF1; do
128 RUN_CHECK set_cur_usr $user || cleanup $STF_FAIL
129
130 RUN_CHECK create_files $TESTDIR || cleanup $STF_FAIL
131
132 test_unreadable_attr
133
134 cleanup
135 done
136
137 cleanup $STF_PASS