2 #-----------------------------------------------------------------------
3 # Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 # Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
20 # Mountain View, CA 94043, USA, or: http://www.sgi.com
21 #-----------------------------------------------------------------------
22 # common extended attribute and ACL support
24 # pick three unused user/group ids, store them as $acl[1-3]
28 eval `(_cat_passwd; _cat_group) | awk -F: '
32 for(i=1; i<1000000 && j<=3;i++){
34 printf "acl%d=%d;", j, i;
41 # filter for the acl ids selected above
46 -e "s/u:$acl1/u:id1/" \
47 -e "s/u:$acl2/u:id2/" \
48 -e "s/u:$acl3/u:id3/" \
49 -e "s/g:$acl1/g:id1/" \
50 -e "s/g:$acl2/g:id2/" \
51 -e "s/g:$acl3/g:id3/" \
52 -e "s/ $acl1 / id1 /" \
53 -e "s/ $acl2 / id2 /" \
61 _ls_l -n $* | awk '{ print $1, $3, $4, $NF }' | _acl_filter_id
69 if [ $HOSTOS = "IRIX" ]; then
70 ls -dD $_file1 | _acl_filter_id
72 chacl -l $_file1 | _acl_filter_id
76 # create an ACL with n ACEs in it
81 acl='u::rwx,g::rwx,o::rwx,m::rwx' # 4 ace acl start
82 while [ $n -ne 0 ]; do
89 # filter user ace names to user ids
93 tmp_file=`mktemp /tmp/ace.XXXXXX`
95 (_cat_passwd; _cat_group) > $tmp_file
97 $AWK_PROG -v tmpfile=$tmp_file '
100 while ( getline <tmpfile > 0 ) {
104 /^user/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
105 /^u/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
106 /^default:user/ { if ($3 in idlist) sub($3, idlist[$3]); print; next}
112 _filter_aces_notypes()
114 tr '\[' '\012' | tr ']' '\012' | tr ',' '\012' | _filter_aces|\
115 sed -e 's/u:/user:/' -e 's/g:/group:/' -e 's/o:/other:/' -e 's/m:/mask:/'
120 if [ ! -x /bin/chacl -a ! -x /usr/bin/chacl -a ! -x /sbin/chacl ]; then
121 _notrun "chacl command not found"
125 # Test if chacl is able to list ACLs on the target filesystems. On really
126 # old kernels the system calls might not be implemented at all, but the
127 # more common case is that the tested filesystem simply doesn't support
130 touch $TEST_DIR/syscalltest
131 chacl -l $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
132 cat $TEST_DIR/syscalltest.out >> $here/$seq.full
134 if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
135 _notrun "kernel does not support ACLs"
137 if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
138 _notrun "ACLs not supported by this filesystem type: $FSTYP"
141 rm -f $TEST_DIR/syscalltest.out
148 ls -dD $file | _acl_filter_id
153 [ -n $ATTR_PROG ] || _notrun "attr command not found"
154 [ -n $GETFATTR_PROG ] || _notrun "getfattr command not found"
155 [ -n $SETFATTR_PROG ] || _notrun "setfattr command not found"
158 # Test if chacl is able to write an attribute on the target filesystems.
159 # On really old kernels the system calls might not be implemented at all,
160 # but the more common case is that the tested filesystem simply doesn't
161 # support attributes. Note that we can't simply list attributes as
162 # various security modules generate synthetic attributes not actually
165 touch $TEST_DIR/syscalltest
166 attr -s "user.xfstests" -V "attr" $TEST_DIR > $TEST_DIR/syscalltest.out 2>&1
167 cat $TEST_DIR/syscalltest.out >> $here/$seq.full
169 if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
170 _notrun "kernel does not support attrs"
172 if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
173 _notrun "attrs not supported by this filesystem type: $FSTYP"
176 rm -f $TEST_DIR/syscalltest.out
179 # getfattr -R returns info in readdir order which varies from fs to fs.
180 # This sorts the output by filename
181 _sort_getfattr_output()
183 awk '{a[FNR]=$0}END{n = asort(a); for(i=1; i <= n; i++) print a[i]"\n"}' RS=''
186 # set maximum total attr space based on fs type
187 if [ "$FSTYP" == "xfs" -o "$FSTYP" == "udf" ]; then
189 else # Assume max ~1 block of attrs
190 BLOCK_SIZE=`stat -f $TEST_DIR | grep "Block size" | cut -d " " -f3`
191 # user.attribute_XXX="value.XXX" is about 32 bytes; leave some overhead
192 let MAX_ATTRS=$BLOCK_SIZE/40
197 # Set max attr value size based on fs type
198 if [ "$FSTYP" == "xfs" -o "$FSTYP" == "udf" -o "$FSTYP" == "btrfs" ]; then
200 else # Assume max ~1 block of attrs
201 BLOCK_SIZE=`stat -f $TEST_DIR | grep "Block size" | cut -d " " -f3`
202 # leave a little overhead
203 let MAX_ATTRVAL_SIZE=$BLOCK_SIZE-256
206 export MAX_ATTRVAL_SIZE
207 # make sure this script returns success