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_chmod_001_pos
35 #
36 # DESCRIPTION:
37 # Verify chmod permission settings on files and directories, as both root
38 # and non-root users.
39 #
40 # STRATEGY:
41 # 1. Loop root and $ACL_STAFF1 as root and non-root users.
42 # 2. Create test file and directory in exported filesystem.
43 # 3. Execute 'chmod' with specified options.
44 # 4. Check 'ls -l' output and compare with expect results.
45 #
46 # TESTABILITY: explicit
47 #
48 # TEST_AUTOMATION_LEVEL: automated
49 #
50 # __stc_assertion_end
51 #
52 ################################################################################
53
54 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
55 && set -x
56
57 # "init_map" "options" "expect_map"
58 set -A argv \
59 "000" "a+rw" "rw-rw-rw-" "000" "a+rwx" "rwxrwxrwx" \
60 "000" "u+xr" "r-x------" "000" "gu-xw" "---------" \
61 "644" "a-r" "-w-------" "644" "augo-x" "rw-r--r--" \
62 "644" "=x" "--x--x--x" "644" "u-rw" "---r--r--" \
63 "644" "uo+x" "rwxr--r-x" "644" "ga-wr" "---------" \
64 "777" "augo+x" "rwxrwxrwx" "777" "go-xr" "rwx-w--w-" \
65 "777" "o-wx" "rwxrwxr--" "777" "ou-rx" "-w-rwx-w-" \
66 "777" "a+rwx" "rwxrwxrwx" "777" "u=rw" "rw-rwxrwx" \
67 "000" "123" "--x-w--wx" "000" "412" "r----x-w-" \
68 "231" "562" "r-xrw--w-" "712" "000" "---------" \
69 "777" "121" "--x-w---x" "123" "775" "rwxrwxr-x"
70
71 echo "ASSERTION: Verify chmod permission settings on files and directories"
72
73 #
74 # Verify file or directory have correct map after chmod
75 #
76 # $1 file or directory
77 #
78 function test_chmod_mapping #<file-dir>
79 {
80 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
81 && set -x
82
83 typeset node=$1
84 typeset -i i=0
85
86 while (( i < ${#argv[@]} )); do
87 usr_exec $CHMOD ${argv[i]} $node
88 if (($? != 0)); then
89 echo "usr_exec $CHMOD ${argv[i]} $node"
90 return 1
91 fi
92
93 usr_exec $CHMOD ${argv[((i + 1))]} $node
94 if (($? != 0)); then
95 echo "usr_exec $CHMOD ${argv[((i + 1))]} $node"
96 return 1
97 fi
98
99 typeset mode
100 eval "mode=$(get_mode ${node})"
101
102 if [[ $mode != "-${argv[((i + 2))]}"* && \
103 $mode != "d${argv[((i + 2))]}"* ]]
104 then
105 echo "FAIL: '${argv[i]}' '${argv[((i + 1))]}' \
106 '${argv[((i + 2))]}'"
107 cleanup $STF_FAIL
108 fi
109
110 (( i += 3 ))
111 done
112
113 return 0
114 }
115
116 for user in root $ACL_STAFF1; do
117 RUN_CHECK set_cur_usr $user || cleanup $STF_FAIL
118
119 # Test file
120 RUN_CHECK usr_exec $TOUCH $testfile || cleanup $STF_FAIL
121 RUN_CHECK test_chmod_mapping $testfile || cleanup $STF_FAIL
122
123 RUN_CHECK $CHMOD A+user:$ACL_STAFF2:write_acl:allow $testfile \
124 || cleanup $STF_FAIL
125 RUN_CHECK set_cur_usr $ACL_STAFF2 || cleanup $STF_FAIL
126
127 # Test directory
128 RUN_CHECK usr_exec $MKDIR $testdir || cleanup $STF_FAIL
129 RUN_CHECK test_chmod_mapping $testdir || cleanup $STF_FAIL
130
131 # Grant privileges of write_acl and retest the chmod commands.
132
133 RUN_CHECK usr_exec $CHMOD A+user:$ACL_STAFF2:write_acl:allow $testfile \
134 || cleanup $STF_FAIL
135 RUN_CHECK usr_exec $CHMOD A+user:$ACL_STAFF2:write_acl:allow $testdir \
136 || cleanup $STF_FAIL
137
138 RUN_CHECK set_cur_usr $ACL_STAFF2 || cleanup $STF_FAIL
139 RUN_CHECK test_chmod_mapping $testfile || cleanup $STF_FAIL
140 RUN_CHECK test_chmod_mapping $testdir || cleanup $STF_FAIL
141
142 RUN_CHECK set_cur_usr $user || cleanup $STF_FAIL
143
144 RUN_CHECK usr_exec $RM $testfile || cleanup $STF_FAIL
145 RUN_CHECK usr_exec $RM -rf $testdir || cleanup $STF_FAIL
146 done
147
148 cleanup $STF_PASS