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 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27 # ACL setfacl/getfacl negative basic test
28 #
29
30 if [ -z "$DEBUG" ]; then
31 export DEBUG=0
32 else
33 [ "$DEBUG" != "0" ] && set -x
34 fi
35
36 NAME=`basename $0`
37 CDIR=`pwd`
38
39 # Source for common functions
40 . $CDIR/ACL.utils
41
42 # Preparation: create temp file/directory for testing
43 # Assume MNTPTR is the base test directory.
44 TDIR=$MNTPTR/$NAME.dir.$$
45 EFILE=$TMPDIR/$NAME.err.$$
46
47 function test_setup
48 {
49 [ "$DEBUG" != "0" ] && set -x
50 echo "\n" > $EFILE
51 mkdir -m 0777 $TDIR >> $EFILE 2>&1 || return $?
52 }
53
54 function cleanup
55 {
56 [ "$DEBUG" != "0" ] && set -x
57 rm -fr $TDIR $EFILE $TMPDIR/$NAME.*.$$
58 exit $1
59 }
60
61 # Test assertion driver
62 function run_assertion
63 {
64 [ "$DEBUG" != "0" ] && set -x
65 OP=${1}
66 TOBJ=${2}
67 ULIST=${3}
68 CKLIST=$4
69
70 echo "\n" > $EFILE
71 for ac in $ULIST
72 do
73 CMD="setfacl -$OP $ac $TOBJ"
74 $CMD > $EFILE 2>&1
75 if [ $? -eq 0 ]; then
76 echo "\t Test FAIL: <$CMD> did not fail"
77 cat $EFILE
78 return $FAIL
79 fi
80 [ "$DEBUG" != "0" ] && echo "CMD=<$CMD>" && cat $EFILE
81 done
82 get_acls $TOBJ $TMPDIR/$NAME.ga.$$ || return $FAIL
83 [ -n "$CKLIST" ] && ULIST=$CKLIST
84 ULIST=$(echo $ULIST | sed 's/,/ /g')
85 ck_aces m "$ULIST" $TMPDIR/$NAME.ga.$$ || return $FAIL
86 [ "$DEBUG" != "0" ] && cat $TMPDIR/$NAME.ga.$$
87
88 echo "\t Test PASS"
89
90 }
91
92 # Start main program here:
93 # ----------------------------------------------------------------------
94 test_setup
95 if [ $? -ne 0 ]; then
96 echo "$NAME{setup}: preparation for $NAME test"
97 echo "\t UNINITIATED - no assertions will be run"
98 cat $EFILE
99 cleanup $UNINITIATED
100 fi
101
102 # Assertions
103 # ----------------------------------------------------------------------
104 # a: setfacl to delete default user/group/other of a dir
105 if [[ $TestZFS == 1 ]]; then
106 ULIST="user::rwx group::rwx"
107 else
108 ULIST="user::rwx group::rwx other:rwx"
109 fi
110 ASSERTION="setfacl to delete these ACLs:\n\t<$ULIST> on a dir; expect fail"
111 echo "$NAME{a}: $ASSERTION"
112 run_assertion d $TDIR "$ULIST" ""
113
114 # b: reset the ACLs in dir with no user for owner
115 ULIST="group::rwx other:rwx"
116 ASSERTION="setfacl to reset ACLs in a dir w/no user owner:\n\t"
117 ASSERTION="$ASSERTION<$ULIST>, expect fail"
118 echo "$NAME{b}: $ASSERTION"
119 run_assertion s $TDIR "$ULIST" ""
120
121 # c: reset the ACLs in dir with no group for owner
122 ULIST="user::rwx other:rwx"
123 ASSERTION="setfacl to reset ACLs in a dir w/no group owner:\n\t"
124 ASSERTION="$ASSERTION<$ULIST>, expect fail"
125 echo "$NAME{c}: $ASSERTION"
126 run_assertion s $TDIR "$ULIST" ""
127
128 # d: reset the ACLs in dir with no other entry
129 ULIST="user::rwx group::rwx"
130 ASSERTION="setfacl to reset ACLs in a dir w/no other entry:\n\t"
131 ASSERTION="$ASSERTION<$ULIST>, expect fail"
132 echo "$NAME{d}: $ASSERTION"
133 run_assertion s $TDIR "$ULIST" ""
134
135 # e: reset the ACLs in dir w/additional user, but not mask
136 ULIST="user::rwx,group::rwx,other:rwx,user:$TUSER1:rwx"
137 ASSERTION="setfacl to reset ACLs in a dir w/additional user, but not\n\t"
138 ASSERTION="$ASSERTION mask: <$ULIST>, expect fail"
139 echo "$NAME{e}: $ASSERTION"
140 run_assertion s $TDIR "$ULIST" "user::rwx,group::rwx,other:rwx"
141
142 # f: reset the ACLs in dir w/two same users
143 ULIST="user::rwx,group::rwx,other:rwx,mask:rwx"
144 ULIST="$ULIST,user:$TUSER2:rwx,user:$TUSER2:rwx"
145 ASSERTION="setfacl to reset ACLs in a dir w/two same users, \n <$ULIST>"
146 ASSERTION="$ASSERTION\n\texpect fail"
147 echo "$NAME{f}: $ASSERTION"
148 run_assertion s $TDIR "$ULIST" "user::rwx,group::rwx,other:rwx,mask:rwx"
149
150 # g: reset the ACLs in dir w/two same group
151 ULIST="user::rwx,group::rwx,other:rwx,mask:rwx"
152 ULIST="$ULIST,group:bin:r-x,group:bin:rwx"
153 ASSERTION="setfacl to reset ACLs in a dir w/two same group, \n <$ULIST>"
154 ASSERTION="$ASSERTION\n\texpect fail"
155 echo "$NAME{g}: $ASSERTION"
156 run_assertion s $TDIR "$ULIST" "user::rwx,group::rwx,other:rwx,mask:rwx"
157
158 # h: reset the ACLs in dir w/two default users
159 ULIST="user::rwx,group::rwx,other:rwx,mask:rwx"
160 ULIST="$ULIST,default:user:$TUSER1:r-x,default:user:$TUSER2:--x"
161 ASSERTION="setfacl to reset ACLs in a dir w/two default users,\n <$ULIST>"
162 ASSERTION="$ASSERTION\n\texpect fail"
163 echo "$NAME{h}: $ASSERTION"
164 run_assertion s $TDIR "$ULIST" "user::rwx,group::rwx,other:rwx,mask:rwx"
165
166 # i: reset the ACLs in dir w/two default groups
167 ULIST="user::rwx,group::rwx,other:rwx,mask:rwx"
168 ULIST="$ULIST,default:group:sys:r-x,default:group:sys:--x"
169 ASSERTION="setfacl to reset ACLs in a dir w/two default groups,\n <$ULIST>"
170 ASSERTION="$ASSERTION\n\texpect fail"
171 echo "$NAME{i}: $ASSERTION"
172 run_assertion s $TDIR "$ULIST" "user::rwx,group::rwx,other:rwx,mask:rwx"
173
174 # j: reset the ACLs in dir w/two default mask entries
175 ULIST="user::rwx,group::rwx,other:rwx,mask:rwx"
176 ULIST="$ULIST,default:mask:r-x,default:mask:--x"
177 ASSERTION="setfacl to reset ACLs in a dir w/two default mask entries,\n"
178 ASSERTION="$ASSERTION <$ULIST>\n\texpect fail"
179 echo "$NAME{j}: $ASSERTION"
180 run_assertion s $TDIR "$ULIST" "user::rwx,group::rwx,other:rwx,mask:rwx"
181
182
183 # Finally cleanup and exit
184 cleanup $PASS