1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26 # Utilities for ACL setfacl/getfacl tests
27 #
28
29 if [ -z "$DEBUG" ]; then
30 export DEBUG=0
31 else
32 [ "$DEBUG" != "0" ] && set -x
33 fi
34
35 # sourcing framework global environment variables created after go_setup
36 # and for this purpose only this file should be sourced
37 if [[ ! -f $CONFIGFILE ]]; then
38 echo "$NAME: CONFIGFILE[$CONFIGFILE] not found;"
39 echo "\texit UNINITIATED."
40 exit 6
41 fi
42 . $CONFIGFILE
43
44 # Source for common functions
45 . $TESTROOT/testsh
46
47
48 #--------------------------------------------------------------
49 # call setfacl(1) to set the ACL entries to the object
50 # usage: set_acls OP TOBJ ALIST WHO [TATTR]
51 # OP: setfacl option, supports 'm' (modify) or 'd' (delete)
52 # TOBJ: test object to set ACLs
53 # ALIST: the ACL entries
54 # WHO: user, group, or none (mask)
55 # TATTR: Optional; if provided, this is the obj-name for runat
56 #
57 function set_acls
58 {
59 [ "$DEBUG" != "0" ] && set -x
60 OP=${1}
61 TOBJ=${2}
62 ALIST=${3}
63 WHO=$4
64 [[ -n "$WHO" && "$WHO" != "none" ]] && WHO="${WHO}:" || WHO=""
65 TATTR=""
66 [ $# -eq 5 ] && TATTR=$5
67 EFILE=$TMPDIR/set_acls.err.$$
68
69 [ "$DEBUG" != "0" ] && echo "calling set_acls() ..."
70 echo "\n" > $EFILE
71 for ac in $ALIST
72 do
73 CMD="setfacl -$OP $WHO$ac $TOBJ"
74 [ "$DEBUG" != "0" ] && echo "CMD=<$CMD>"
75 if [ -n "$TATTR" ]; then
76 runat $TATTR "$CMD" > $EFILE 2>&1
77 else
78 $CMD > $EFILE 2>&1
79 fi
80 ckreturn $? "<$CMD> failed" $EFILE
81 if [ $? -ne 0 ]; then
82 rm -f $EFILE
83 return $FAIL
84 fi
85 done
86 rm -f $EFILE
87 }
88
89
90 #--------------------------------------------------------------
91 # call getfacl(1) to get the ACL entries to the object
92 # usage: get_acls TOBJ OFILE [TATTR]
93 # TOBJ: test object to set ACLs
94 # OFILE: output file with ACL entries of TOBJ
95 # TATTR: Optional; if provided, this is the obj-name for runat
96 #
97 function get_acls
98 {
99 [ "$DEBUG" != "0" ] && set -x
100 TOBJ=${1}
101 OFILE=${2}
102 TATTR=""
103 [ $# -eq 3 ] && TATTR=$3
104 EFILE=$TMPDIR/get_acls.err.$$
105
106 [ "$DEBUG" != "0" ] && echo "calling get_acls() ..."
107 echo "\n" > $EFILE
108 CMD="getfacl $TOBJ"
109 [ "$DEBUG" != "0" ] && echo "CMD=<$CMD>"
110 if [ -n "$TATTR" ]; then
111 runat $TATTR "$CMD" 1> $OFILE 2> $EFILE
112 else
113 $CMD 1> $OFILE 2> $EFILE
114 fi
115 ckreturn $? "<$CMD> failed" $EFILE
116 if [ $? -ne 0 ]; then
117 rm -f $EFILE
118 return $FAIL
119 fi
120 rm -f $EFILE
121 }
122
123 #--------------------------------------------------------------
124 # checking on ACE list from the ACL output file from caller
125 # usage: ck_aces OP ALIST ACLFILE
126 # OP: Operation for ace to be verified,
127 # e.g. d-delete, m-modify, me-modify effective
128 # ALIST: List of ACEs to be verified
129 # ACLFILE:The ACL file from getfacl
130 #
131 function ck_aces
132 {
133 [ "$DEBUG" != "0" ] && set -x
134 OP=$1
135 ALIST=${2}
136 ACLFILE=${3}
137
138 [ "$DEBUG" != "0" ] && echo "calling ck_aces() ..."
139 for ace in $ALIST
140 do
141 case "$OP" in
142 'm' ) # ACL entry is modified
143 egrep "$ace" $ACLFILE > /dev/null 2>&1
144 if [ $? -ne 0 ]; then
145 echo "\t Test FAIL - didn't find <$ace> from $ACLFILE"
146 cat $ACLFILE
147 return $FAIL
148 fi ;;
149 'd' ) # ACL entry is deleted
150 egrep "$ace" $ACLFILE > /dev/null 2>&1
151 if [ $? -eq 0 ]; then
152 echo "\t Test FAIL - still see <$ace> from $ACLFILE, for OP=$OP"
153 cat $ACLFILE
154 return $FAIL
155 fi ;;
156 'me' ) # ACL effective field is modified
157 user=$(echo $ace | nawk -F\: '{print $1}')
158 perm=$(echo $ace | nawk -F\: '{print $2}')
159 nbit=$(egrep "$user\:" $ACLFILE | nawk -F\: '{print $4}')
160 if [ "$nbit" != "$perm" ]; then
161 echo "\t Test FAIL - didn't find effective for <$ace> from $ACLFILE"
162 cat $ACLFILE
163 return $FAIL
164 fi ;;
165 esac
166 done
167 [ "$DEBUG" != "0" ] && cat $ACLFILE
168 return $PASS
169 }