Print this page
7290 ZFS test suite needs to control what utilities it can run
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
*** 22,31 ****
--- 22,35 ----
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
+ #
+ # Copyright (c) 2016 by Delphix. All rights reserved.
+ #
+
. $STF_SUITE/tests/functional/acl/acl.cfg
. $STF_SUITE/include/libtest.shlib
#
# Get the given file/directory access mode
*** 37,47 ****
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! $LS -ld $obj | $AWK '{print $1}'
}
#
# Get the given file/directory ACL
#
--- 41,51 ----
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! ls -ld $obj | awk '{print $1}'
}
#
# Get the given file/directory ACL
#
*** 52,62 ****
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! $LS -vd $obj | $NAWK '(NR != 1) {print $0}'
}
#
# Get the given file/directory ACL
#
--- 56,66 ----
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! ls -vd $obj | nawk '(NR != 1) {print $0}'
}
#
# Get the given file/directory ACL
#
*** 67,77 ****
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! $LS -Vd $obj | $NAWK '(NR != 1) {print $0}'
}
#
# Check the given two files/directories have the same ACLs
#
--- 71,81 ----
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! ls -Vd $obj | nawk '(NR != 1) {print $0}'
}
#
# Check the given two files/directories have the same ACLs
#
*** 92,114 ****
typeset tmptgt=/tmp/compare_acls.tgt.$$
get_acl $src > $tmpsrc
get_acl $tgt > $tmptgt
typeset -i ret=0
! $DIFF $tmpsrc $tmptgt > /dev/null 2>&1
ret=$?
! $RM -f $tmpsrc $tmptgt
if (( ret != 0 )); then
return $ret
fi
get_compact_acl $src > $tmpsrc
get_compact_acl $tgt > $tmptgt
! $DIFF $tmpsrc $tmptgt > /dev/null 2>&1
ret=$?
! $RM -f $tmpsrc $tmptgt
return $ret
}
#
--- 96,118 ----
typeset tmptgt=/tmp/compare_acls.tgt.$$
get_acl $src > $tmpsrc
get_acl $tgt > $tmptgt
typeset -i ret=0
! diff $tmpsrc $tmptgt > /dev/null 2>&1
ret=$?
! rm -f $tmpsrc $tmptgt
if (( ret != 0 )); then
return $ret
fi
get_compact_acl $src > $tmpsrc
get_compact_acl $tgt > $tmptgt
! diff $tmpsrc $tmptgt > /dev/null 2>&1
ret=$?
! rm -f $tmpsrc $tmptgt
return $ret
}
#
*** 160,172 ****
typeset tmptgt=/tmp/compare_xattrs.tgt.$$
get_xattr $src > $tmpsrc
get_xattr $tgt > $tmptgt
typeset -i ret=0
! $DIFF $tmpsrc $tmptgt > /dev/null 2>&1
ret=$?
! $RM -f $tmpsrc $tmptgt
return $ret
}
#
--- 164,176 ----
typeset tmptgt=/tmp/compare_xattrs.tgt.$$
get_xattr $src > $tmpsrc
get_xattr $tgt > $tmptgt
typeset -i ret=0
! diff $tmpsrc $tmptgt > /dev/null 2>&1
ret=$?
! rm -f $tmpsrc $tmptgt
return $ret
}
#
*** 179,189 ****
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! $LS -ld $obj | $AWK '{print $1}' | $GREP "+\>" > /dev/null
return $?
}
#
--- 183,193 ----
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! ls -ld $obj | awk '{print $1}' | grep "+\>" > /dev/null
return $?
}
#
*** 196,206 ****
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! $LS -vd $obj | $NAWK '(NR == 1) {print $1}' | $GREP "+\>" > /dev/null
return $?
}
#
--- 200,210 ----
typeset obj=$1
if (( ${#obj} == 0 )); then
return 1
fi
! ls -vd $obj | nawk '(NR == 1) {print $1}' | grep "+\>" > /dev/null
return $?
}
#
*** 209,219 ****
# $1 legal login name
# $2-n commands and options
#
function chgusr_exec #<login_name> <commands> [...]
{
! $CHG_USR_EXEC $@
return $?
}
#
# Export the current user for the following usr_exec operating.
--- 213,223 ----
# $1 legal login name
# $2-n commands and options
#
function chgusr_exec #<login_name> <commands> [...]
{
! chg_usr_exec $@
return $?
}
#
# Export the current user for the following usr_exec operating.
*** 230,240 ****
#
# $1-n commands and options
#
function usr_exec #<commands> [...]
{
! $CHG_USR_EXEC "$ZFS_ACL_CUR_USER" $@
return $?
}
#
# Count how many ACEs for the speficied file or directory.
--- 234,244 ----
#
# $1-n commands and options
#
function usr_exec #<commands> [...]
{
! chg_usr_exec "$ZFS_ACL_CUR_USER" $@
return $?
}
#
# Count how many ACEs for the speficied file or directory.
*** 246,256 ****
if [[ ! -e $1 ]]; then
log_note "Need input file or directroy name."
return 1
fi
! $LS -vd $1 | $NAWK 'BEGIN {count=0}
(NR != 1)&&(/[0-9]:/) {count++}
END {print count}'
return 0
}
--- 250,260 ----
if [[ ! -e $1 ]]; then
log_note "Need input file or directroy name."
return 1
fi
! ls -vd $1 | nawk 'BEGIN {count=0}
(NR != 1)&&(/[0-9]:/) {count++}
END {print count}'
return 0
}
*** 284,295 ****
*) log_fail "Invalid parameter as ($format), " \
"only verbose|compact is supported."
;;
esac
! $LS $args $file > $tmpfile
! (( $? != 0 )) && log_fail "FAIL: $LS $args $file > $tmpfile"
while read line; do
[[ -z $line ]] && continue
if [[ $args == -vd ]]; then
if [[ $line == "$num":* ]]; then
(( next_num = num + 1 ))
--- 288,299 ----
*) log_fail "Invalid parameter as ($format), " \
"only verbose|compact is supported."
;;
esac
! ls $args $file > $tmpfile
! (( $? != 0 )) && log_fail "FAIL: ls $args $file > $tmpfile"
while read line; do
[[ -z $line ]] && continue
if [[ $args == -vd ]]; then
if [[ $line == "$num":* ]]; then
(( next_num = num + 1 ))
*** 306,317 ****
fi
(( next_num += 1 ))
fi
done < $tmpfile
! $RM -f $tmpfile
! (( $? != 0 )) && log_fail "FAIL: $RM -f $tmpfile"
}
#
# Cleanup exist user/group.
#
--- 310,321 ----
fi
(( next_num += 1 ))
fi
done < $tmpfile
! rm -f $tmpfile
! (( $? != 0 )) && log_fail "FAIL: rm -f $tmpfile"
}
#
# Cleanup exist user/group.
#
*** 335,345 ****
#
function cleanup
{
if [[ -d $TESTDIR ]]; then
cd $TESTDIR
! $RM -rf $TESTDIR/*
fi
}
#
# According to specified access or acl_spec, do relevant operating by using the
--- 339,349 ----
#
function cleanup
{
if [[ -d $TESTDIR ]]; then
cd $TESTDIR
! rm -rf $TESTDIR/*
fi
}
#
# According to specified access or acl_spec, do relevant operating by using the
*** 361,390 ****
fi
if [[ -d $node ]]; then
case $acl_spec in
*:read_data:*|read_data)
! chgusr_exec $user $LS -l $node > /dev/null 2>&1
return $? ;;
*:write_data:*|write_data)
if [[ -f ${node}/tmpfile ]]; then
! log_must $RM -f ${node}/tmpfile
fi
! chgusr_exec $user $TOUCH ${node}/tmpfile > \
/dev/null 2>&1
return $? ;;
*"execute:"*|execute)
! chgusr_exec $user $FIND $node > /dev/null 2>&1
return $? ;;
esac
else
case $acl_spec in
*:read_data:*|read_data)
! chgusr_exec $user $CAT $node > /dev/null 2>&1
return $? ;;
*:write_data:*|write_data)
! chgusr_exec $user $DD if=/usr/bin/ls of=$node > \
/dev/null 2>&1
return $? ;;
*"execute:"*|execute)
ZFS_ACL_ERR_STR=$(chgusr_exec $user $node 2>&1)
return $? ;;
--- 365,394 ----
fi
if [[ -d $node ]]; then
case $acl_spec in
*:read_data:*|read_data)
! chgusr_exec $user ls -l $node > /dev/null 2>&1
return $? ;;
*:write_data:*|write_data)
if [[ -f ${node}/tmpfile ]]; then
! log_must rm -f ${node}/tmpfile
fi
! chgusr_exec $user touch ${node}/tmpfile > \
/dev/null 2>&1
return $? ;;
*"execute:"*|execute)
! chgusr_exec $user find $node > /dev/null 2>&1
return $? ;;
esac
else
case $acl_spec in
*:read_data:*|read_data)
! chgusr_exec $user cat $node > /dev/null 2>&1
return $? ;;
*:write_data:*|write_data)
! chgusr_exec $user dd if=/usr/bin/ls of=$node > \
/dev/null 2>&1
return $? ;;
*"execute:"*|execute)
ZFS_ACL_ERR_STR=$(chgusr_exec $user $node 2>&1)
return $? ;;
*** 403,415 ****
typeset xattr
if (( ${#obj} == 0 )); then
return 1
fi
! for xattr in `$RUNAT $obj $LS | \
/usr/xpg4/bin/egrep -v -e SUNWattr_ro -e SUNWattr_rw` ; do
! $RUNAT $obj $SUM $xattr
done
}
#
# Get the owner of a file/directory
--- 407,419 ----
typeset xattr
if (( ${#obj} == 0 )); then
return 1
fi
! for xattr in `runat $obj ls | \
/usr/xpg4/bin/egrep -v -e SUNWattr_ro -e SUNWattr_rw` ; do
! runat $obj sum $xattr
done
}
#
# Get the owner of a file/directory
*** 422,437 ****
if [[ -z $node ]]; then
log_fail "node are not defined."
fi
if [[ -d $node ]]; then
! value=$($LS -dl $node | $AWK '{print $3}')
elif [[ -e $node ]]; then
! value=$($LS -l $node | $AWK '{print $3}')
fi
! $ECHO $value
}
#
# Get the group of a file/directory
#
--- 426,441 ----
if [[ -z $node ]]; then
log_fail "node are not defined."
fi
if [[ -d $node ]]; then
! value=$(ls -dl $node | awk '{print $3}')
elif [[ -e $node ]]; then
! value=$(ls -l $node | awk '{print $3}')
fi
! echo $value
}
#
# Get the group of a file/directory
#
*** 443,458 ****
if [[ -z $node ]]; then
log_fail "node are not defined."
fi
if [[ -d $node ]]; then
! value=$($LS -dl $node | $AWK '{print $4}')
elif [[ -e $node ]]; then
! value=$($LS -l $node | $AWK '{print $4}')
fi
! $ECHO $value
}
#
# Get the group name that a UID belongs to
--- 447,462 ----
if [[ -z $node ]]; then
log_fail "node are not defined."
fi
if [[ -d $node ]]; then
! value=$(ls -dl $node | awk '{print $4}')
elif [[ -e $node ]]; then
! value=$(ls -l $node | awk '{print $4}')
fi
! echo $value
}
#
# Get the group name that a UID belongs to
*** 469,479 ****
value=$(id $uid)
if [[ $? -eq 0 ]]; then
value=${value##*\(}
value=${value%%\)*}
! $ECHO $value
else
log_fail "Invalid UID (uid)."
fi
}
--- 473,483 ----
value=$(id $uid)
if [[ $? -eq 0 ]]; then
value=${value##*\(}
value=${value%%\)*}
! echo $value
else
log_fail "Invalid UID (uid)."
fi
}
*** 507,527 ****
typeset aarr_name=$3
[[ ! -d $dir ]] && return
typeset oldpwd=$PWD
cd $dir
! typeset files=$($LS file*)
typeset -i i=0
typeset -i n=0
while (( i < NUM_FILE )); do
typeset f=$(getitem $i $files)
! eval $farr_name[$i]=\$\(\$CKSUM $f\)
typeset -i j=0
while (( j < NUM_ATTR )); do
! eval $aarr_name[$n]=\$\(\$RUNAT \$f \$CKSUM \
attribute.$j\)
(( j += 1 ))
(( n += 1 ))
done
--- 511,531 ----
typeset aarr_name=$3
[[ ! -d $dir ]] && return
typeset oldpwd=$PWD
cd $dir
! typeset files=$(ls file*)
typeset -i i=0
typeset -i n=0
while (( i < NUM_FILE )); do
typeset f=$(getitem $i $files)
! eval $farr_name[$i]=\$\(\cksum $f\)
typeset -i j=0
while (( j < NUM_ATTR )); do
! eval $aarr_name[$n]=\$\(\runat \$f \cksum \
attribute.$j\)
(( j += 1 ))
(( n += 1 ))
done
*** 569,584 ****
function record_cksum #<outfile>
{
typeset dir=$1
typeset outfile=$2
! [[ ! -d ${outfile%/*} ]] && usr_exec $MKDIR -p ${outfile%/*}
! usr_exec cd $dir ; $FIND . -depth -type f -exec cksum {} \\\; | \
! $SORT > $outfile
! usr_exec cd $dir ; $FIND . -depth -type f -xattr -exec runat {} \
! cksum attribute* \\\; | $SORT >> $outfile
}
#
# The function create_files creates the directories and files that the script
# will operate on to test extended attribute functionality.
--- 573,588 ----
function record_cksum #<outfile>
{
typeset dir=$1
typeset outfile=$2
! [[ ! -d ${outfile%/*} ]] && usr_exec mkdir -p ${outfile%/*}
! usr_exec cd $dir ; find . -depth -type f -exec cksum {} \\\; | \
! sort > $outfile
! usr_exec cd $dir ; find . -depth -type f -xattr -exec runat {} \
! cksum attribute* \\\; | sort >> $outfile
}
#
# The function create_files creates the directories and files that the script
# will operate on to test extended attribute functionality.
*** 587,623 ****
#
function create_files #<directory>
{
typeset basedir=$1
! [[ ! -d $basedir ]] && usr_exec $MKDIR -m 777 $basedir
! [[ ! -d $RES_DIR ]] && usr_exec $MKDIR -m 777 $RES_DIR
! [[ ! -d $INI_DIR ]] && usr_exec $MKDIR -m 777 $INI_DIR
! [[ ! -d $TST_DIR ]] && usr_exec $MKDIR -m 777 $TST_DIR
! [[ ! -d $TMP_DIR ]] && usr_exec $MKDIR -m 777 $TMP_DIR
#
# Create the original file and its attribute files.
#
[[ ! -a $RES_DIR/file ]] && \
! usr_exec $FILE_WRITE -o create -f $RES_DIR/file \
-b 1024 -d 0 -c 1
[[ ! -a $RES_DIR/attribute ]] && \
! usr_exec $CP $RES_DIR/file $RES_DIR/attribute
typeset oldpwd=$PWD
cd $INI_DIR
typeset -i i=0
while (( i < NUM_FILE )); do
typeset dstfile=$INI_DIR/file.$$.$i
! usr_exec $CP $RES_DIR/file $dstfile
typeset -i j=0
while (( j < NUM_ATTR )); do
! usr_exec $RUNAT $dstfile \
! $CP $RES_DIR/attribute ./attribute.$j
(( j += 1 ))
done
(( i += 1 ))
done
--- 591,627 ----
#
function create_files #<directory>
{
typeset basedir=$1
! [[ ! -d $basedir ]] && usr_exec mkdir -m 777 $basedir
! [[ ! -d $RES_DIR ]] && usr_exec mkdir -m 777 $RES_DIR
! [[ ! -d $INI_DIR ]] && usr_exec mkdir -m 777 $INI_DIR
! [[ ! -d $TST_DIR ]] && usr_exec mkdir -m 777 $TST_DIR
! [[ ! -d $TMP_DIR ]] && usr_exec mkdir -m 777 $TMP_DIR
#
# Create the original file and its attribute files.
#
[[ ! -a $RES_DIR/file ]] && \
! usr_exec file_write -o create -f $RES_DIR/file \
-b 1024 -d 0 -c 1
[[ ! -a $RES_DIR/attribute ]] && \
! usr_exec cp $RES_DIR/file $RES_DIR/attribute
typeset oldpwd=$PWD
cd $INI_DIR
typeset -i i=0
while (( i < NUM_FILE )); do
typeset dstfile=$INI_DIR/file.$$.$i
! usr_exec cp $RES_DIR/file $dstfile
typeset -i j=0
while (( j < NUM_ATTR )); do
! usr_exec runat $dstfile \
! cp $RES_DIR/attribute ./attribute.$j
(( j += 1 ))
done
(( i += 1 ))
done