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 positive basic test
28 # Call setfacl(1) verify "default" ACL entries and inherited
29 # of a directory.
30 #
31
32 if [ -z "$DEBUG" ]; then
33 export DEBUG=0
34 else
35 [ "$DEBUG" != "0" ] && set -x
36 fi
37
38 NAME=`basename $0`
39 CDIR=`pwd`
40
41 # Source for common functions
42 . $CDIR/ACL.utils
43
44 # Preparation: create temp file/directory for testing
45 # Assume MNTPTR is the base test directory.
46 TDIR=$MNTPTR/$NAME.dir.$$
47 EFILE=$TMPDIR/$NAME.err.$$
48
49 function test_setup
50 {
51 [ "$DEBUG" != "0" ] && set -x
52 echo "\n" > $EFILE
53 mkdir -m 0777 $TDIR >> $EFILE 2>&1 || return $?
54 }
55
56 function cleanup
57 {
58 [ "$DEBUG" != "0" ] && set -x
59 rm -fr $TDIR $EFILE $TMPDIR/$NAME.*.$$
60 exit $1
61 }
62
63 # Test assertion driver
64 function run_assertion
65 {
66 [ "$DEBUG" != "0" ] && set -x
67 OP=${1}
68 TOBJ=${2}
69 ULIST=${3}
70 WHO=$4
71
72 echo "\n" > $EFILE
73 set_acls $OP $TOBJ "$ULIST" $WHO || return $FAIL
74 get_acls $TOBJ $TMPDIR/$NAME.ga.$$ || return $FAIL
75 ULIST=$(echo $ULIST | sed 's/,/ /g')
76 ck_aces $OP "$ULIST" $TMPDIR/$NAME.ga.$$ || return $FAIL
77 [ "$DEBUG" != "0" ] && cat $TMPDIR/$NAME.ga.$$
78
79 echo "\t Test PASS"
80
81 }
82
83 # Start main program here:
84 # ----------------------------------------------------------------------
85 test_setup
86 if [ $? -ne 0 ]; then
87 echo "$NAME{setup}: preparation for $NAME test"
88 echo "\t UNINITIATED - no assertions will be run"
89 cat $EFILE
90 cleanup $UNINITIATED
91 fi
92
93 # Assertions
94 # ----------------------------------------------------------------------
95 # a: setfacl to to add default ACLs
96 ULIST="default:user::rwx,default:group::r-x,default:other:--x,default:mask:rwx"
97 ASSERTION="setfacl to add this default ACLs:\n <$ULIST>"
98 echo "$NAME{a}: $ASSERTION"
99 run_assertion m $TDIR $ULIST ""
100
101 # b: setfacl to to add default user ACL
102 ULIST="default:user:$TUSER1:rwx"
103 ASSERTION="setfacl to add default user ACL \n\t<$ULIST>; expect successful"
104 echo "$NAME{b}: $ASSERTION"
105 run_assertion m $TDIR $ULIST ""
106
107 # c: verify file acl inherited from parent directory
108 ASSERTION="verify newly created file interited default ACL from\n\tparent"
109 ASSERTION="$ASSERTION dir, include ACLs <$ULIST> set from above"
110 echo "$NAME{c}: $ASSERTION"
111 ULIST=$(echo $ULIST | sed 's/default:user://')
112 echo "new interited file" > $TDIR/$NAME.nfile.$$ 2> $EFILE
113 ckreturn $? "<create $TDIR/$NAME.nfile.$$> failed" $EFILE
114 if [ $? -eq 0 ]; then
115 if [[ $TestZFS == 1 ]]; then
116 ls -v $TDIR/$NAME.nfile.$$ | grep "user:$TUSER1" > /dev/null 2>&1
117 if [[ $? == 0 ]]; then
118 echo "\t Test PASS"
119 else
120 echo "Sub-file failed to inherite default ACL from parent."
121 ls -vd $TDIR/$NAME.ndir.$$
122 echo "\t Test FAIL"
123 fi
124 else
125 get_acls $TDIR/$NAME.nfile.$$ $TMPDIR/$NAME.gi.$$ && \
126 ck_aces m "$ULIST" $TMPDIR/$NAME.gi.$$ && echo "\t Test PASS"
127 fi
128 fi
129
130 # d: setfacl to to add default group ACL
131 ULIST="default:group:staff:r-x"
132 ASSERTION="setfacl to add default group ACL \n\t<$ULIST>; expect successful"
133 echo "$NAME{d}: $ASSERTION"
134 run_assertion m $TDIR $ULIST ""
135
136 # e: verify new directory acl inherited from parent directory
137 ASSERTION="verify new created dir interited default ACL from \n\tparent"
138 ASSERTION="$ASSERTION dir, include group ACL <$ULIST> set from above"
139 echo "$NAME{e}: $ASSERTION"
140 ULIST=$(echo $ULIST | sed 's/default:group://')
141 mkdir -m 0775 $TDIR/$NAME.ndir.$$ > $EFILE 2>&1
142 ckreturn $? "<mkdir $TDIR/$NAME.ndir.$$> failed" $EFILE
143 if [ $? -eq 0 ]; then
144 if [[ $TestZFS == 1 ]]; then
145 ls -vd $TDIR/$NAME.ndir.$$ | grep "group:staff" > /dev/null 2>&1
146 if [[ $? == 0 ]]; then
147 echo "\t Test PASS"
148 else
149 echo "Sub-dir failed to inherite default ACL from parent."
150 ls -vd $TDIR/$NAME.ndir.$$
151 echo "\t Test FAIL"
152 fi
153 else
154 get_acls $TDIR/$NAME.ndir.$$ $TMPDIR/$NAME.gi.$$ && \
155 ck_aces m "$ULIST" $TMPDIR/$NAME.gi.$$ && echo "\t Test PASS"
156 fi
157 fi
158
159 # f: setfacl to delete default user/group in the directory, expect successful
160 ULIST="default:user:$TUSER1:rwx default:group:staff:r-x"
161 ASSERTION="delete <$ULIST>\n\tACLs from the directory, expect successful"
162 echo "$NAME{f}: $ASSERTION"
163 run_assertion d $TDIR "$ULIST" ""
164
165 # g: verify new directory acl inherited from parent directory
166 ASSERTION="verify new created dir interited default ACL from parent don't\n\t"
167 ASSERTION="$ASSERTION have deleted <$ULIST> entries"
168 echo "$NAME{g}: $ASSERTION"
169 ULIST="user:$TUSER1:rwx group:staff:r-x"
170 mkdir -m 0700 $TDIR/$NAME.dirg.$$ > $EFILE 2>&1
171 ckreturn $? "<mkdir $TDIR/$NAME.dirg.$$> failed" $EFILE
172 if [ $? -eq 0 ]; then
173 if [[ $TestZFS == 1 ]]; then
174 ls -vd $TDIR/$NAME.dirg.$$ > $TMPDIR/$NAME.acl.$$
175 cat $TMPDIR/$NAME.acl.$$ | grep "user:$TUSER1" > /dev/null 2>&1
176 if [[ $? == 0 ]]; then
177 echo "the acl with user $TUSER1 is inherited, it's not expected"
178 cat $TMPDIR/$NAME.acl.$$
179 echo "\t Test FAIL"
180 fi
181 cat $TMPDIR/$NAME.acl.$$ | grep "group:staff" > /dev/null 2>&1
182 if [[ $? == 0 ]]; then
183 echo "the acl with group staff is inherited, it's not expected"
184 cat $TMPDIR/$NAME.acl.$$
185 echo "\t Test FAIL"
186 fi
187 echo "\t Test PASS"
188 else
189 get_acls $TDIR/$NAME.dirg.$$ $TMPDIR/$NAME.gi.$$ && \
190 ck_aces d "$ULIST" $TMPDIR/$NAME.gi.$$ && echo "\t Test PASS"
191 fi
192 fi
193
194
195 # Finally cleanup and exit
196 cleanup $PASS