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_rwx_pos001
35 #
36 # DESCRIPTION:
37 # chmod A{+|-|=} have the correct behaviour to the ACL list.
38 #
39 # STRATEGY:
40 # 1. loop check root and non-root users
41 # 2. chmod file or dir with specified options
42 # 3. get ACE after behaviours of chmod
43 # 4. compare specified ACE and excpect ACE
44 #
45 # TESTABILITY: explicit
46 #
47 # TEST_AUTOMATION_LEVEL: automated
48 #
49 # __stc_assertion_end
50 #
51 ################################################################################
52
53 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
54 && set -x
55
56 echo "ASSERTION: chmod A{+|-|=} have the correct behaviour to the ACL list."
57
58 typeset -i trival_count=6 head=0 mid end
59 ((mid = RANDOM % $trival_count))
60 ((end = trival_count - 1))
61
62 opts="+ - ="
63 nums="$head $mid $end"
64 set -A file_ACEs \
65 "user:$ACL_STAFF1:read_data:allow" \
66 "user:$ACL_STAFF2:write_data:allow" \
67 "user:$ACL_OTHER1:execute:allow"
68 set -A dir_ACEs \
69 "user:$ACL_STAFF1:list_directory/read_data:allow" \
70 "user:$ACL_STAFF2:add_file/write_data:allow" \
71 "user:$ACL_OTHER1:execute:allow"
72
73 function test_chmod_ACE_list #$opt $num $ace-spec $node
74 {
75 [[ :$NFSGEN_DEBUG: = *:${NAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
76 && set -x
77
78 typeset opt=A$2$1
79 typeset -i num=$2
80 typeset ace=$3
81 typeset node=$4
82 typeset -i expect_count=0
83
84 # Get expect ACE count
85 case $opt in
86 A[0-9]*+) (( expect_count = trival_count + 1 )) ;;
87 A[0-9]*-) (( expect_count = trival_count - 1 )) ;;
88 A[0-9]*=) (( expect_count = trival_count )) ;;
89 *) echo "Error option: '$opt'" && cleanup $STF_FAIL ;;
90 esac
91
92 # Invoke chmod A[number]{+|-|=}<acl-specification> file|dir
93 if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then
94 RUN_CHECK usr_exec $CHMOD "$opt$ace" "$node" \
95 || cleanup $STF_FAIL
96 else
97 RUN_CHECK usr_exec $CHMOD "$opt" "$node" \
98 || cleanup $STF_FAIL
99 fi
100
101 # Get the current ACE count and specified ACE
102 typeset cur_ace cur_count
103 eval "cur_ace=$(get_ACE $node $num)" || cleanup $STF_FAIL
104 eval "cur_count=$(count_ACE $node)" || cleanup $STF_FAIL
105
106 # Compare with expected results
107 if [[ $opt == A[0-9]*+ || $opt == A[0-9]*= ]]; then
108 if [[ "$num:$ace" != "$cur_ace" ]]; then
109 echo "FAIL: $CHMOD $opt$ace $node"
110 cleanup $STF_FAIL
111 fi
112 fi
113 if [[ "$expect_count" != "$cur_count" ]]; then
114 echo "FAIL: '$expect_count' != '$cur_count'"
115 cleanup $STF_FAIL
116 fi
117 }
118
119 for user in root $ACL_STAFF1 $ACL_OTHER1; do
120 RUN_CHECK set_cur_usr $user || cleanup $STF_FAIL
121
122 for opt in $opts; do
123 for num in $nums; do
124 for ace in $file_ACEs; do
125 # ls -l $TESTDIR
126 RUN_CHECK usr_exec $TOUCH $testfile \
127 || cleanup $STF_FAIL
128 test_chmod_ACE_list $opt $num $ace $testfile
129 RUN_CHECK $RM -f $testfile || cleanup $STF_FAIL
130 done
131 for ace in $dir_ACEs; do
132 # ls -l $TESTDIR
133 RUN_CHECK usr_exec $MKDIR -p $testdir \
134 || cleanup $STF_FAIL
135 test_chmod_ACE_list $opt $num $ace $testdir
136 RUN_CHECK $RM -rf $testdir || cleanup $STF_FAIL
137 done
138 done
139 done
140 done
141
142 # chmod A{+|-|=} behave to the ACL list passed.
143 cleanup $STF_PASS