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 'users' in the ACL entries to a
29 # directory; 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 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 CANREAD=$5
72
73 echo "\n" > $EFILE
74 set_acls $OP $TOBJ "$ULIST" $WHO || return $FAIL
75 get_acls $TOBJ $TMPDIR/$NAME.ga.$$ || return $FAIL
76 ULIST=$(echo $ULIST | sed 's/,/ /g')
77 ck_aces $OP "$ULIST" $TMPDIR/$NAME.ga.$$ || return $FAIL
78 # try to read the directory as user in ULIST
79 if [ -n "$CANREAD" ]; then
80 # get the user and try to read
81 user=$(echo $ULIST | nawk -F\: '{print $1}')
82 su $user -c "ls $TOBJ" > $TMPDIR/$NAME.ga2.$$ 2>&1
83 if [[ $? -eq 0 && $CANREAD != "true" ]]; then
84 echo "\t Test FAIL, user<$user> still can ls $TOBJ"
85 grep $user $TMPDIR/$NAME.ga.$$
86 cat $TMPDIR/$NAME.ga2.$$
87 return $FAIL
88 fi
89 fi
90 [ "$DEBUG" != "0" ] && cat $TMPDIR/$NAME.ga2.$$
91
92 echo "\t Test PASS"
93
94 }
95
96 # Start main program here:
97 # ----------------------------------------------------------------------
98 test_setup
99 if [ $? -ne 0 ]; then
100 echo "$NAME{setup}: preparation for $NAME test"
101 echo "\t UNINITIATED - no assertions will be run"
102 cat $EFILE
103 cleanup $UNINITIATED
104 fi
105
106 # Assertions
107 # ----------------------------------------------------------------------
108 # a: setfacl to modify/delete user & perms to a directory:
109 ULIST="$TUSER1:rwx $TUSER2:rw- $TUSER3:--x sys:r-x"
110 ASSERTION="setfacl to add <$ULIST>\n\tusers to the dir, expect successful"
111 echo "$NAME{a}: $ASSERTION"
112 run_assertion m $TDIR "$ULIST" user
113
114 # b: setfacl to modify user & perms in a dir, expect successful
115 ULIST="$TUSER1:r-x $TUSER3:rwx sys:rw-"
116 ASSERTION="setfacl to modify users <$ULIST>\n\tto the directory,"
117 ASSERTION="$ASSERTION expect successful"
118 echo "$NAME{b}: $ASSERTION"
119 run_assertion m $TDIR "$ULIST" user
120
121 # c: setfacl to modify mask in a directory, expect successful
122 ULIST="mask:-w-"
123 ASSERTION="setfacl to modify <$ULIST> to the dir, expect successful"
124 echo "$NAME{c}: $ASSERTION"
125 run_assertion m $TDIR $ULIST ""
126
127 # d: verify users' perms are correct after the mask changed
128 ULIST="$TUSER1:--- $TUSER3-w- sys:-w-"
129 ASSERTION="verify effective perms on dir of users \n\t<$ULIST> set correctly"
130 echo "$NAME{d}: $ASSERTION"
131 get_acls $TDIR $TMPDIR/$NAME.gd.$$ && \
132 ck_aces me "$ULIST" $TMPDIR/$NAME.gd.$$ && echo "\t Test PASS"
133
134 # e: setfacl to modify user w/all perms; but can't <ls dir> due to mask
135 ULIST="$TUSER2:rwx"
136 ASSERTION="setfacl to modify <$ULIST> to the dir; but user\n\tshould still"
137 ASSERTION="$ASSERTION not able to <ls> the directory due to mask set before."
138 echo "$NAME{e}: $ASSERTION"
139 run_assertion m $TDIR $ULIST user true
140
141 # f: setfacl to delete user & perms in the directory, expect successful
142 ULIST="$TUSER1:r-x $TUSER2:r-- $TUSER3:rwx sys:rw-"
143 ASSERTION="delete users <$ULIST>\n\tACLs from the directory, expect successful"
144 echo "$NAME{f}: $ASSERTION"
145 run_assertion d $TDIR "$ULIST" user
146
147
148 # Finally cleanup and exit
149 cleanup $PASS