mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-25 11:47:43 +03:00
tests: review every instance of $?
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: John Kennedy <john.kennedy@delphix.com> Reviewed-by: Ryan Moeller <ryan@iXsystems.com> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #13259
This commit is contained in:
@@ -98,7 +98,7 @@ function compare_acls #<src> <tgt>
|
||||
get_acl $src > $tmpsrc
|
||||
get_acl $tgt > $tmptgt
|
||||
typeset -i ret=0
|
||||
diff $tmpsrc $tmptgt > /dev/null 2>&1
|
||||
cmp $tmpsrc $tmptgt > /dev/null
|
||||
ret=$?
|
||||
rm -f $tmpsrc $tmptgt
|
||||
|
||||
@@ -108,7 +108,7 @@ function compare_acls #<src> <tgt>
|
||||
|
||||
get_compact_acl $src > $tmpsrc
|
||||
get_compact_acl $tgt > $tmptgt
|
||||
diff $tmpsrc $tmptgt > /dev/null 2>&1
|
||||
cmp $tmpsrc $tmptgt > /dev/null
|
||||
ret=$?
|
||||
rm -f $tmpsrc $tmptgt
|
||||
|
||||
@@ -166,7 +166,7 @@ function compare_xattrs #<src> <tgt>
|
||||
get_xattr $src > $tmpsrc
|
||||
get_xattr $tgt > $tmptgt
|
||||
typeset -i ret=0
|
||||
diff $tmpsrc $tmptgt > /dev/null 2>&1
|
||||
cmp $tmpsrc $tmptgt > /dev/null
|
||||
ret=$?
|
||||
rm -f $tmpsrc $tmptgt
|
||||
|
||||
@@ -284,8 +284,7 @@ function get_ACE #<file or dir name> <specified number> <verbose|compact>
|
||||
;;
|
||||
esac
|
||||
|
||||
ls $args $file > $tmpfile
|
||||
(( $? != 0 )) && log_fail "FAIL: ls $args $file > $tmpfile"
|
||||
log_must eval "ls $args $file > $tmpfile"
|
||||
while read line; do
|
||||
[[ -z $line ]] && continue
|
||||
if [[ $args == -vd ]]; then
|
||||
@@ -306,8 +305,7 @@ function get_ACE #<file or dir name> <specified number> <verbose|compact>
|
||||
fi
|
||||
done < $tmpfile
|
||||
|
||||
rm -f $tmpfile
|
||||
(( $? != 0 )) && log_fail "FAIL: rm -f $tmpfile"
|
||||
log_must rm -f $tmpfile
|
||||
}
|
||||
|
||||
#
|
||||
@@ -362,30 +360,30 @@ function rwx_node #user node acl_spec|access
|
||||
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 $? ;;
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
@@ -459,9 +457,7 @@ function get_user_group #uid
|
||||
log_fail "UID not defined."
|
||||
fi
|
||||
|
||||
value=$(id $uid)
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
if value=$(id $uid); then
|
||||
value=${value##*\(}
|
||||
value=${value%%\)*}
|
||||
echo $value
|
||||
|
||||
@@ -57,40 +57,41 @@ log_onexit cleanup
|
||||
log_note "Testing access to FILE"
|
||||
log_must touch $TESTDIR/file.0
|
||||
log_must setfacl -m g:$ZFS_ACL_STAFF_GROUP:rw $TESTDIR/file.0
|
||||
getfacl $TESTDIR/file.0 2> /dev/null | grep -q \
|
||||
"^group:$ZFS_ACL_STAFF_GROUP:rw-$"
|
||||
if [ "$?" -eq "0" ]; then
|
||||
# Should be able to write to file
|
||||
log_must user_run $ZFS_ACL_STAFF1 \
|
||||
"echo 'echo test > /dev/null' > $TESTDIR/file.0"
|
||||
|
||||
# Since $TESTDIR is 777, create a new dir with controlled permissions
|
||||
# for testing that creating a new file is not allowed.
|
||||
log_must mkdir $TESTDIR/dir.0
|
||||
log_must chmod 700 $TESTDIR/dir.0
|
||||
log_must setfacl -m g:$ZFS_ACL_STAFF_GROUP:rw $TESTDIR/dir.0
|
||||
# Confirm permissions
|
||||
if ! ls -l $TESTDIR | grep "dir.0" | grep -q "drwxrw----+"; then
|
||||
msk=$(ls -l $TESTDIR | awk '/dir.0/ {print $1}')
|
||||
log_note "expected mask drwxrw----+ but found $msk"
|
||||
log_fail "Expected permissions were not set."
|
||||
fi
|
||||
getfacl $TESTDIR/dir.0 2> /dev/null | grep -q \
|
||||
"^group:$ZFS_ACL_STAFF_GROUP:rw-$"
|
||||
if [ "$?" -ne "0" ]; then
|
||||
acl=$(getfacl $TESTDIR/dir.0 2> /dev/null)
|
||||
log_note $acl
|
||||
log_fail "ACL group:$ZFS_ACL_STAFF_GROUP:rw- was not set."
|
||||
fi
|
||||
# Should NOT be able to create new file
|
||||
log_mustnot user_run $ZFS_ACL_STAFF1 "touch $TESTDIR/dir.0/file.1"
|
||||
|
||||
# Root should be able to run file, but not user
|
||||
chmod +x $TESTDIR/file.0
|
||||
log_must $TESTDIR/file.0
|
||||
log_mustnot user_run $ZFS_ACL_STAFF1 $TESTDIR/file.0
|
||||
|
||||
log_pass "POSIX ACL mode works on files"
|
||||
else
|
||||
if ! getfacl $TESTDIR/file.0 2> /dev/null |
|
||||
grep -qFx "group:$ZFS_ACL_STAFF_GROUP:rw-"
|
||||
then
|
||||
log_note "$(getfacl $TESTDIR/file.0 2> /dev/null)"
|
||||
log_fail "Group '$ZFS_ACL_STAFF_GROUP' does not have 'rw' as specified"
|
||||
fi
|
||||
|
||||
# Should be able to write to file
|
||||
log_must user_run $ZFS_ACL_STAFF1 \
|
||||
"echo 'echo test > /dev/null' > $TESTDIR/file.0"
|
||||
|
||||
# Since $TESTDIR is 777, create a new dir with controlled permissions
|
||||
# for testing that creating a new file is not allowed.
|
||||
log_must mkdir $TESTDIR/dir.0
|
||||
log_must chmod 700 $TESTDIR/dir.0
|
||||
log_must setfacl -m g:$ZFS_ACL_STAFF_GROUP:rw $TESTDIR/dir.0
|
||||
# Confirm permissions
|
||||
msk=$(ls -ld $TESTDIR/dir.0 | awk '{print $1}')
|
||||
if ! [ "$msk" = "drwxrw----+" ]; then
|
||||
log_note "expected mask drwxrw----+ but found $msk"
|
||||
log_fail "Expected permissions were not set."
|
||||
fi
|
||||
|
||||
if ! getfacl $TESTDIR/dir.0 2> /dev/null |
|
||||
grep -qFx "group:$ZFS_ACL_STAFF_GROUP:rw-"
|
||||
then
|
||||
log_note "$(getfacl $TESTDIR/dir.0 2> /dev/null)"
|
||||
log_fail "ACL group:$ZFS_ACL_STAFF_GROUP:rw- was not set."
|
||||
fi
|
||||
# Should NOT be able to create new file
|
||||
log_mustnot user_run $ZFS_ACL_STAFF1 "touch $TESTDIR/dir.0/file.1"
|
||||
|
||||
# Root should be able to run file, but not user
|
||||
chmod +x $TESTDIR/file.0
|
||||
log_must $TESTDIR/file.0
|
||||
log_mustnot user_run $ZFS_ACL_STAFF1 $TESTDIR/file.0
|
||||
|
||||
log_pass "POSIX ACL mode works on files"
|
||||
|
||||
@@ -58,9 +58,9 @@ if ! ls -l $TESTDIR | grep "dir.0" | grep -q "drwx-wx---+"; then
|
||||
log_note "expected mask drwx-wx---+ but found $msk"
|
||||
log_fail "Expected permissions were not set."
|
||||
fi
|
||||
getfacl $TESTDIR/dir.0 2> /dev/null | grep -q \
|
||||
"^group:$ZFS_ACL_STAFF_GROUP:-wx$"
|
||||
if [ "$?" -eq "0" ]; then
|
||||
if getfacl $TESTDIR/dir.0 2> /dev/null |
|
||||
grep -q "^group:$ZFS_ACL_STAFF_GROUP:-wx$"
|
||||
then
|
||||
# Should be able to create file in directory
|
||||
log_must user_run $ZFS_ACL_STAFF1 "touch $TESTDIR/dir.0/file.0"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user