2010-01-20 10:27:08 +11:00
|
|
|
##/bin/bash
|
2004-09-15 05:57:50 +00:00
|
|
|
#-----------------------------------------------------------------------
|
|
|
|
|
# Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
# (at your option) any later version.
|
2001-04-02 00:41:31 +00:00
|
|
|
#
|
2004-09-15 05:57:50 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
2001-04-02 00:41:31 +00:00
|
|
|
#
|
2004-09-15 05:57:50 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
# USA
|
|
|
|
|
#
|
|
|
|
|
# Contact information: Silicon Graphics, Inc., 1500 Crittenden Lane,
|
|
|
|
|
# Mountain View, CA 94043, USA, or: http://www.sgi.com
|
|
|
|
|
#-----------------------------------------------------------------------
|
2001-04-02 00:41:31 +00:00
|
|
|
# common extended attribute and ACL support
|
|
|
|
|
|
2014-04-28 10:55:12 +10:00
|
|
|
# filesystems that want to test maximum supported acl counts need to
|
|
|
|
|
# add support in here
|
|
|
|
|
_acl_get_max()
|
|
|
|
|
{
|
|
|
|
|
case $FSTYP in
|
|
|
|
|
xfs)
|
|
|
|
|
# CRC format filesystems have much larger ACL counts. The actual
|
|
|
|
|
# number is into the thousands, but testing that meany takes too
|
|
|
|
|
# long, so just test well past the old limit of 25.
|
|
|
|
|
xfs_info $TEST_DIR | _filter_mkfs > /dev/null 2> $tmp.info
|
|
|
|
|
. $tmp.info
|
|
|
|
|
rm $tmp.info
|
|
|
|
|
if [ $_fs_has_crcs -eq 0 ]; then
|
|
|
|
|
echo 25
|
|
|
|
|
else
|
|
|
|
|
echo 5461
|
|
|
|
|
fi
|
|
|
|
|
;;
|
2014-06-18 09:31:01 +10:00
|
|
|
jfs)
|
|
|
|
|
echo 8191
|
|
|
|
|
;;
|
2016-02-29 10:19:23 +11:00
|
|
|
f2fs)
|
2016-04-05 11:48:46 +10:00
|
|
|
_fs_options $TEST_DEV | grep "inline_xattr" >/dev/null 2>&1
|
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
|
echo 531
|
|
|
|
|
else
|
|
|
|
|
echo 506
|
|
|
|
|
fi
|
2016-02-29 10:19:23 +11:00
|
|
|
;;
|
2014-04-28 10:55:12 +10:00
|
|
|
*)
|
|
|
|
|
echo 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_require_acl_get_max()
|
|
|
|
|
{
|
|
|
|
|
if [ $(_acl_get_max) -eq 0 ]; then
|
|
|
|
|
_notrun "$FSTYP does not define maximum ACL count"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-02 00:41:31 +00:00
|
|
|
# pick three unused user/group ids, store them as $acl[1-3]
|
|
|
|
|
#
|
|
|
|
|
_acl_setup_ids()
|
|
|
|
|
{
|
2010-07-30 21:52:39 +00:00
|
|
|
eval `(_cat_passwd; _cat_group) | awk -F: '
|
2001-04-02 00:41:31 +00:00
|
|
|
{ ids[$3]=1 }
|
|
|
|
|
END {
|
|
|
|
|
j=1
|
|
|
|
|
for(i=1; i<1000000 && j<=3;i++){
|
|
|
|
|
if (! (i in ids)) {
|
|
|
|
|
printf "acl%d=%d;", j, i;
|
|
|
|
|
j++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}'`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# filter for the acl ids selected above
|
|
|
|
|
#
|
|
|
|
|
_acl_filter_id()
|
|
|
|
|
{
|
|
|
|
|
sed \
|
|
|
|
|
-e "s/u:$acl1/u:id1/" \
|
|
|
|
|
-e "s/u:$acl2/u:id2/" \
|
|
|
|
|
-e "s/u:$acl3/u:id3/" \
|
|
|
|
|
-e "s/g:$acl1/g:id1/" \
|
|
|
|
|
-e "s/g:$acl2/g:id2/" \
|
|
|
|
|
-e "s/g:$acl3/g:id3/" \
|
|
|
|
|
-e "s/ $acl1 / id1 /" \
|
|
|
|
|
-e "s/ $acl2 / id2 /" \
|
|
|
|
|
-e "s/ $acl3 / id3 /"
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-19 17:34:42 +00:00
|
|
|
_getfacl_filter_id()
|
|
|
|
|
{
|
|
|
|
|
sed \
|
|
|
|
|
-e "s/user:$acl1/user:id1/" \
|
|
|
|
|
-e "s/user:$acl2/user:id2/" \
|
|
|
|
|
-e "s/user:$acl3/user:id3/" \
|
|
|
|
|
-e "s/group:$acl1/group:id1/" \
|
|
|
|
|
-e "s/group:$acl2/group:id2/" \
|
|
|
|
|
-e "s/group:$acl3/group:id3/" \
|
|
|
|
|
-e "s/: $acl1/: id1/" \
|
|
|
|
|
-e "s/: $acl2/: id2/" \
|
|
|
|
|
-e "s/: $acl3/: id3/"
|
|
|
|
|
}
|
|
|
|
|
|
2001-04-02 00:41:31 +00:00
|
|
|
# filtered ls
|
|
|
|
|
#
|
|
|
|
|
_acl_ls()
|
|
|
|
|
{
|
2010-02-03 08:35:24 -06:00
|
|
|
_ls_l -n $* | awk '{ print $1, $3, $4, $NF }' | _acl_filter_id
|
2001-04-02 00:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
2004-08-10 03:55:47 +00:00
|
|
|
#
|
|
|
|
|
_acl_list()
|
|
|
|
|
{
|
|
|
|
|
_file1=$1
|
|
|
|
|
|
|
|
|
|
if [ $HOSTOS = "IRIX" ]; then
|
2004-09-15 05:57:50 +00:00
|
|
|
ls -dD $_file1 | _acl_filter_id
|
2004-08-10 03:55:47 +00:00
|
|
|
else
|
|
|
|
|
chacl -l $_file1 | _acl_filter_id
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-09 05:26:20 +00:00
|
|
|
# create an ACL with n ACEs in it
|
|
|
|
|
#
|
|
|
|
|
_create_n_aces()
|
|
|
|
|
{
|
2009-03-25 20:53:36 +01:00
|
|
|
let n=$1-4
|
2002-05-09 05:26:20 +00:00
|
|
|
acl='u::rwx,g::rwx,o::rwx,m::rwx' # 4 ace acl start
|
|
|
|
|
while [ $n -ne 0 ]; do
|
2009-03-25 20:53:36 +01:00
|
|
|
acl="$acl,u:$n:rwx"
|
|
|
|
|
let n=$n-1
|
2002-05-09 05:26:20 +00:00
|
|
|
done
|
|
|
|
|
echo $acl
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# filter user ace names to user ids
|
|
|
|
|
#
|
|
|
|
|
_filter_aces()
|
|
|
|
|
{
|
2010-08-13 15:45:24 +10:00
|
|
|
tmp_file=`mktemp /tmp/ace.XXXXXX`
|
|
|
|
|
|
|
|
|
|
(_cat_passwd; _cat_group) > $tmp_file
|
|
|
|
|
|
|
|
|
|
$AWK_PROG -v tmpfile=$tmp_file '
|
2002-05-09 05:26:20 +00:00
|
|
|
BEGIN {
|
|
|
|
|
FS=":"
|
2010-08-13 15:45:24 +10:00
|
|
|
while ( getline <tmpfile > 0 ) {
|
2002-05-09 05:26:20 +00:00
|
|
|
idlist[$1] = $3
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-05-22 02:21:06 +00:00
|
|
|
/^user/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
|
2004-11-23 13:52:17 +00:00
|
|
|
/^u/ { if ($2 in idlist) sub($2, idlist[$2]); print; next}
|
2002-05-22 02:21:06 +00:00
|
|
|
/^default:user/ { if ($3 in idlist) sub($3, idlist[$3]); print; next}
|
2002-05-09 05:26:20 +00:00
|
|
|
{print}
|
|
|
|
|
'
|
2010-08-13 15:45:24 +10:00
|
|
|
rm -f $tmp_file
|
2002-05-09 05:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
2004-11-23 13:52:17 +00:00
|
|
|
_filter_aces_notypes()
|
|
|
|
|
{
|
|
|
|
|
tr '\[' '\012' | tr ']' '\012' | tr ',' '\012' | _filter_aces|\
|
|
|
|
|
sed -e 's/u:/user:/' -e 's/g:/group:/' -e 's/o:/other:/' -e 's/m:/mask:/'
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-05 11:04:10 -06:00
|
|
|
_require_acls()
|
2002-05-09 05:26:20 +00:00
|
|
|
{
|
2015-11-02 11:00:09 +11:00
|
|
|
[ -n "$CHACL_PROG" ] || _notrun "chacl command not found"
|
2002-05-09 05:26:20 +00:00
|
|
|
|
2010-10-21 05:55:11 +02:00
|
|
|
#
|
|
|
|
|
# Test if chacl is able to list ACLs on the target filesystems. On really
|
|
|
|
|
# old kernels the system calls might not be implemented at all, but the
|
|
|
|
|
# more common case is that the tested filesystem simply doesn't support
|
|
|
|
|
# ACLs.
|
|
|
|
|
#
|
|
|
|
|
touch $TEST_DIR/syscalltest
|
|
|
|
|
chacl -l $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
|
2013-03-15 12:28:06 +00:00
|
|
|
cat $TEST_DIR/syscalltest.out >> $seqres.full
|
2010-10-21 05:55:11 +02:00
|
|
|
|
|
|
|
|
if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
|
|
|
|
|
_notrun "kernel does not support ACLs"
|
2002-05-09 05:26:20 +00:00
|
|
|
fi
|
2010-10-21 05:55:11 +02:00
|
|
|
if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
|
|
|
|
|
_notrun "ACLs not supported by this filesystem type: $FSTYP"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
rm -f $TEST_DIR/syscalltest.out
|
2002-05-09 05:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-15 05:57:50 +00:00
|
|
|
_list_acl()
|
|
|
|
|
{
|
|
|
|
|
file=$1
|
|
|
|
|
|
|
|
|
|
ls -dD $file | _acl_filter_id
|
|
|
|
|
}
|
|
|
|
|
|
2010-10-21 21:11:48 +02:00
|
|
|
_require_attrs()
|
|
|
|
|
{
|
2015-11-02 11:00:09 +11:00
|
|
|
[ -n "$ATTR_PROG" ] || _notrun "attr command not found"
|
|
|
|
|
[ -n "$GETFATTR_PROG" ] || _notrun "getfattr command not found"
|
|
|
|
|
[ -n "$SETFATTR_PROG" ] || _notrun "setfattr command not found"
|
2010-10-21 21:11:48 +02:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# Test if chacl is able to write an attribute on the target filesystems.
|
|
|
|
|
# On really old kernels the system calls might not be implemented at all,
|
|
|
|
|
# but the more common case is that the tested filesystem simply doesn't
|
|
|
|
|
# support attributes. Note that we can't simply list attributes as
|
|
|
|
|
# various security modules generate synthetic attributes not actually
|
|
|
|
|
# stored on disk.
|
|
|
|
|
#
|
|
|
|
|
touch $TEST_DIR/syscalltest
|
2017-07-19 01:06:35 -03:00
|
|
|
attr -s "user.xfstests" -V "attr" $TEST_DIR/syscalltest > $TEST_DIR/syscalltest.out 2>&1
|
2013-03-15 12:28:06 +00:00
|
|
|
cat $TEST_DIR/syscalltest.out >> $seqres.full
|
2010-10-21 21:11:48 +02:00
|
|
|
|
|
|
|
|
if grep -q 'Function not implemented' $TEST_DIR/syscalltest.out; then
|
|
|
|
|
_notrun "kernel does not support attrs"
|
|
|
|
|
fi
|
|
|
|
|
if grep -q 'Operation not supported' $TEST_DIR/syscalltest.out; then
|
|
|
|
|
_notrun "attrs not supported by this filesystem type: $FSTYP"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
rm -f $TEST_DIR/syscalltest.out
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-20 06:22:32 +00:00
|
|
|
_require_attr_v1()
|
|
|
|
|
{
|
|
|
|
|
_scratch_mkfs_xfs_supported -i attr=1 >/dev/null 2>&1 \
|
|
|
|
|
|| _notrun "attr v1 not supported on $SCRATCH_DEV"
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-13 14:58:16 +11:00
|
|
|
# check if we support the noattr2 mount option
|
|
|
|
|
_require_noattr2()
|
|
|
|
|
{
|
|
|
|
|
_scratch_mkfs_xfs > /dev/null 2>&1 \
|
|
|
|
|
|| _fail "_scratch_mkfs_xfs failed on $SCRATCH_DEV"
|
2015-12-21 18:07:43 +11:00
|
|
|
_scratch_mount -o noattr2 > /dev/null 2>&1 \
|
2014-03-13 14:58:16 +11:00
|
|
|
|| _notrun "noattr2 mount option not supported on $SCRATCH_DEV"
|
|
|
|
|
_scratch_unmount
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 12:28:20 -06:00
|
|
|
# getfattr -R returns info in readdir order which varies from fs to fs.
|
|
|
|
|
# This sorts the output by filename
|
|
|
|
|
_sort_getfattr_output()
|
|
|
|
|
{
|
|
|
|
|
awk '{a[FNR]=$0}END{n = asort(a); for(i=1; i <= n; i++) print a[i]"\n"}' RS=''
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-27 12:34:31 -06:00
|
|
|
# set maximum total attr space based on fs type
|
2017-05-03 11:54:13 +01:00
|
|
|
case "$FSTYP" in
|
|
|
|
|
xfs|udf|pvfs2|ceph)
|
2012-01-27 12:34:31 -06:00
|
|
|
MAX_ATTRS=1000
|
2017-05-03 11:54:13 +01:00
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
# Assume max ~1 block of attrs
|
2017-01-04 17:04:48 -08:00
|
|
|
BLOCK_SIZE=`_get_block_size $TEST_DIR`
|
2012-01-27 12:34:31 -06:00
|
|
|
# user.attribute_XXX="value.XXX" is about 32 bytes; leave some overhead
|
|
|
|
|
let MAX_ATTRS=$BLOCK_SIZE/40
|
2017-05-03 11:54:13 +01:00
|
|
|
esac
|
2012-01-27 12:34:31 -06:00
|
|
|
|
|
|
|
|
export MAX_ATTRS
|
|
|
|
|
|
|
|
|
|
# Set max attr value size based on fs type
|
2017-05-03 11:54:13 +01:00
|
|
|
case "$FSTYP" in
|
|
|
|
|
xfs|udf|btrfs)
|
2012-01-27 12:34:31 -06:00
|
|
|
MAX_ATTRVAL_SIZE=64
|
2017-05-03 11:54:13 +01:00
|
|
|
;;
|
|
|
|
|
pvfs2)
|
2017-04-07 16:09:43 -04:00
|
|
|
MAX_ATTRVAL_SIZE=8192
|
2017-05-03 11:54:13 +01:00
|
|
|
;;
|
|
|
|
|
ceph)
|
|
|
|
|
MAX_ATTRVAL_SIZE=65536
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
# Assume max ~1 block of attrs
|
2017-01-04 17:04:48 -08:00
|
|
|
BLOCK_SIZE=`_get_block_size $TEST_DIR`
|
2012-01-27 12:34:31 -06:00
|
|
|
# leave a little overhead
|
|
|
|
|
let MAX_ATTRVAL_SIZE=$BLOCK_SIZE-256
|
2017-05-03 11:54:13 +01:00
|
|
|
esac
|
2012-01-27 12:34:31 -06:00
|
|
|
|
|
|
|
|
export MAX_ATTRVAL_SIZE
|
2001-04-02 00:41:31 +00:00
|
|
|
# make sure this script returns success
|
2001-04-06 03:23:12 +00:00
|
|
|
/bin/true
|