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) modify 'groups' in the ACL entries to a file;
29 # then verify ACLs are set correctly with getfacl(1).
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 TFILE=$MNTPTR/$NAME.file.$$
47 EFILE=$TMPDIR/$NAME.err.$$
48
49 function test_setup
50 {
51 [ "$DEBUG" != "0" ] && set -x
52 echo "\n" > $EFILE
53 echo "This is test file for $NAME" > $TFILE 2>> $EFILE || return $?
54 chmod 0666 $TFILE >> $EFILE 2>&1 || return $?
55 }
56
57 function cleanup
58 {
59 [ "$DEBUG" != "0" ] && set -x
60 rm -fr $TFILE $EFILE $TMPDIR/$NAME.*.$$ $TMPDIR/*.err.$$
61 exit $1
62 }
63
64 # Test assertion driver
65 function run_assertion
66 {
67 [ "$DEBUG" != "0" ] && set -x
68 OP=${1}
69 TOBJ=${2}
70 ULIST=${3}
71 WHO=$4
72 CANREAD=$5
73
74 echo "\n" > $EFILE
75 set_acls $OP $TOBJ "$ULIST" $WHO || return $FAIL
76 get_acls $TOBJ $TMPDIR/$NAME.ga.$$ || return $FAIL
77 ck_aces $OP "$ULIST" $TMPDIR/$NAME.ga.$$ || return $FAIL
78 # try to read the file as user in another group
79 if [ -n "$CANREAD" ]; then
80 # get the user and try to read
81 su $TUSER3 -c "cat $TOBJ" > $TMPDIR/$NAME.ga2.$$ 2>&1
82 if [[ $? -eq 0 && $CANREAD != "true" ]]; then
83 echo "\t Test FAIL, user<$user> still can read $TOBJ"
84 grep $user $TMPDIR/$NAME.ga.$$
85 cat $TMPDIR/$NAME.ga2.$$
86 return $FAIL
87 fi
88 [ "$DEBUG" != "0" ] && cat $TMPDIR/$NAME.ga2.$$
89 fi
90
91 echo "\t Test PASS"
92
93 }
94
95 # Start main program here:
96 # ----------------------------------------------------------------------
97 test_setup
98 if [ $? -ne 0 ]; then
99 echo "$NAME{setup}: preparation for $NAME test"
100 echo "\t UNINITIATED - no assertions will be run"
101 cat $EFILE
102 cleanup $UNINITIATED
103 fi
104
105 # Assertions
106 # ----------------------------------------------------------------------
107 # setfacl to modify/delete user & perms to a file:
108 ULIST="other:rwx staff:rw- bin:--x nobody:r-x"
109 ASSERTION="setfacl to add <$ULIST>\n\tgroups to the file, expect successful"
110 echo "$NAME{a}: $ASSERTION"
111 run_assertion m $TFILE "$ULIST" group
112
113 # b: setfacl to modify group & perms in a file, expect successful
114 ULIST="other:-w- staff:r-- bin:-wx nobody:rwx"
115 ASSERTION="setfacl to modify <$ULIST>\n\tgroups to the file,"
116 ASSERTION="$ASSERTION expect successful"
117 echo "$NAME{b}: $ASSERTION"
118 run_assertion m $TFILE "$ULIST" group
119
120 # c: setfacl to modify mask in a file, expect successful
121 ULIST="mask:--x"
122 ASSERTION="setfacl to modify <$ULIST> to the file, expect successful"
123 echo "$NAME{c}: $ASSERTION"
124 run_assertion m $TFILE $ULIST ""
125
126 # d: verify groups' perms are correct after the mask changed
127 ULIST="other:--- staff:--- bin:--x nobody:--x"
128 ASSERTION="verify effective perms on file of groups \n\t<$ULIST> set correctly"
129 echo "$NAME{d}: $ASSERTION"
130 get_acls $TFILE $TMPDIR/$NAME.gd.$$ && \
131 ck_aces me "$ULIST" $TMPDIR/$NAME.gd.$$ && echo "\t Test PASS"
132
133 # e: setfacl to modify group w/all perms; but can't read the file due to mask
134 ULIST="staff:rwx"
135 ASSERTION="setfacl to modify <$ULIST> to the file; but group\n\tshould still"
136 ASSERTION="$ASSERTION not able to read the file due to mask set before."
137 echo "$NAME{e}: $ASSERTION"
138 run_assertion m $TFILE $ULIST group true
139
140 # f: setfacl to delete group & perms in the file, expect successful
141 ULIST="other:-w- staff:rwx bin:-wx nobody:rwx"
142 ASSERTION="delete groups <$ULIST>\n\tACLs from the file, expect successful"
143 echo "$NAME{f}: $ASSERTION"
144 run_assertion d $TFILE "$ULIST" group
145
146
147 # Finally cleanup and exit
148 cleanup $PASS