From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from relay.sgi.com (relay2.corp.sgi.com [137.38.102.29]) by oss.sgi.com (Postfix) with ESMTP id 0C9247F37 for ; Wed, 18 Nov 2015 08:18:09 -0600 (CST) Received: from cuda.sgi.com (cuda3.sgi.com [192.48.176.15]) by relay2.corp.sgi.com (Postfix) with ESMTP id F1A34304039 for ; Wed, 18 Nov 2015 06:18:08 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by cuda.sgi.com with ESMTP id tFg2Gpr1vTuaOUZQ (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 18 Nov 2015 06:18:03 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 34BE1C049D4F for ; Wed, 18 Nov 2015 14:18:03 +0000 (UTC) From: Andreas Gruenbacher Subject: [XFSTESTS 5/6] Add richacl tests Date: Wed, 18 Nov 2015 15:17:48 +0100 Message-Id: <1447856269-7872-6-git-send-email-agruenba@redhat.com> In-Reply-To: <1447856269-7872-1-git-send-email-agruenba@redhat.com> References: <1447856269-7872-1-git-send-email-agruenba@redhat.com> List-Id: XFS Filesystem from SGI List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: xfs-bounces@oss.sgi.com Sender: xfs-bounces@oss.sgi.com To: xfs@oss.sgi.com Cc: Andreas Gruenbacher Add the Rich Access Control List tests from the richacl package. The new tests require TEST_DEV and TEST_DIR to be set. When the check script is run, it first makes sure that the test filesystem has richacls enabled or disabled as appropriate: with the -richacl option, richacls must be enabled; without the -richacl option, richacls must be disabled. If TEST_DEV has incorrect richacl support, the TEST_DEV filesystem is recreated. The -richacl option currently selects the tests in the richacl group to be run. Additional test groups or tests can be specified on the command line, e.g., ./check -richacl -g quick (Eventually, the -richacl option will be changed to only skip tests which are incompatible with richacls.) Signed-off-by: Andreas Gruenbacher --- .gitignore | 1 + check | 39 +++++++- common/rc | 23 ++++- src/Makefile | 2 +- src/require-richacls.c | 35 +++++++ tests/richacl/001-apply-masks | 1 + tests/richacl/002-auto-inheritance | 1 + tests/richacl/003-basic | 1 + tests/richacl/004-chmod | 1 + tests/richacl/005-chown | 1 + tests/richacl/006-create | 1 + tests/richacl/007-ctime | 1 + tests/richacl/008-delete | 1 + tests/richacl/009-setrichacl-modify | 1 + tests/richacl/010-write-vs-append | 1 + tests/richacl/Makefile | 44 +++++++++ tests/richacl/apply-masks | 163 ++++++++++++++++++++++++++++++ tests/richacl/auto-inheritance | 191 ++++++++++++++++++++++++++++++++++++ tests/richacl/basic | 97 ++++++++++++++++++ tests/richacl/chmod | 40 ++++++++ tests/richacl/chown | 42 ++++++++ tests/richacl/create | 36 +++++++ tests/richacl/ctime | 35 +++++++ tests/richacl/delete | 89 +++++++++++++++++ tests/richacl/group | 15 +++ tests/richacl/setrichacl-modify | 57 +++++++++++ tests/richacl/test-lib.sh | 149 ++++++++++++++++++++++++++++ tests/richacl/write-vs-append | 54 ++++++++++ 28 files changed, 1114 insertions(+), 8 deletions(-) create mode 100644 src/require-richacls.c create mode 120000 tests/richacl/001-apply-masks create mode 120000 tests/richacl/002-auto-inheritance create mode 120000 tests/richacl/003-basic create mode 120000 tests/richacl/004-chmod create mode 120000 tests/richacl/005-chown create mode 120000 tests/richacl/006-create create mode 120000 tests/richacl/007-ctime create mode 120000 tests/richacl/008-delete create mode 120000 tests/richacl/009-setrichacl-modify create mode 120000 tests/richacl/010-write-vs-append create mode 100644 tests/richacl/Makefile create mode 100755 tests/richacl/apply-masks create mode 100755 tests/richacl/auto-inheritance create mode 100755 tests/richacl/basic create mode 100755 tests/richacl/chmod create mode 100755 tests/richacl/chown create mode 100755 tests/richacl/create create mode 100755 tests/richacl/ctime create mode 100755 tests/richacl/delete create mode 100644 tests/richacl/group create mode 100755 tests/richacl/setrichacl-modify create mode 100644 tests/richacl/test-lib.sh create mode 100755 tests/richacl/write-vs-append diff --git a/.gitignore b/.gitignore index 7c25c41..d7ff600 100644 --- a/.gitignore +++ b/.gitignore @@ -116,6 +116,7 @@ /src/cloner /src/renameat2 /src/t_rename_overwrite +/src/require-richacls # dmapi/ binaries /dmapi/src/common/cmd/read_invis diff --git a/check b/check index 5ecc12b..89b6d8a 100755 --- a/check +++ b/check @@ -60,7 +60,7 @@ then exit 1 fi -SRC_GROUPS="generic shared" +SRC_GROUPS="generic shared richacl" export SRC_DIR="tests" usage() @@ -71,6 +71,7 @@ check options -nfs test NFS -cifs test CIFS -tmpfs test TMPFS + -richacl test Rich Access Control Lists -l line mode diff -udiff show unified diff (default) -n show me, do not run tests @@ -220,6 +221,11 @@ while [ $# -gt 0 ]; do -cifs) FSTYP=cifs ;; -tmpfs) FSTYP=tmpfs ;; + -richacl) + RICHACL=1 + GROUP_LIST="$GROUP_LIST richacl" + ;; + -g) group=$2 ; shift ; GROUP_LIST="$GROUP_LIST ${group//,/ }" ;; @@ -417,6 +423,34 @@ else trap "_wrapup; exit \$status" 0 1 2 3 15 fi +# Check if the filesystem on a block device is compatible with how the test +# suite is being run. Currently, we use this to check if the filesystem +# has richacl support when needed. +_dev_is_compatible() { + local dev=$1 HAS_RICHACL= + + case "$FSTYP" in + xfs) + if xfs_db -r -c version "$dev" | grep -qw RICHACL; then + HAS_RICHACL=1 + fi + ;; + + ext2|ext3|ext4) + if tune2fs -l "$dev" | grep -q '^Filesystem features.*\'; then + HAS_RICHACL=1 + fi + ;; + + *) + # Other filesystems don't currently have richacl support; there + # is no point in recreating them. + HAS_RICHACL=$RICHACL + ;; + esac + [ "$HAS_RICHACL" = "$RICHACL" ] +} + for section in $HOST_OPTIONS_SECTIONS; do OLD_FSTYP=$FSTYP OLD_MOUNT_OPTIONS=$MOUNT_OPTIONS @@ -446,7 +480,8 @@ for section in $HOST_OPTIONS_SECTIONS; do echo "SECTION -- $section" fi - if $RECREATE_TEST_DEV || [ "$OLD_FSTYP" != "$FSTYP" ]; then + if $RECREATE_TEST_DEV || [ "$OLD_FSTYP" != "$FSTYP" ] || + ! _dev_is_compatible "$TEST_DEV"; then echo "RECREATING -- $FSTYP on $TEST_DEV" umount $TEST_DEV 2> /dev/null if ! _test_mkfs >$tmp.err 2>&1 diff --git a/common/rc b/common/rc index ce6ae3d..0dd8e4f 100644 --- a/common/rc +++ b/common/rc @@ -559,6 +559,19 @@ _scratch_mkfs_ext4() _test_mkfs() { + local OPT=$MKFS_OPTIONS + + if [ -n "$RICHACL" ]; then + case "$FSTYP" in + xfs) + OPT="$OPT -m richacl=1" + ;; + ext2|ext3|ext4) + OPT="$OPT -O richacl" + ;; + esac + fi + case $FSTYP in nfs*) # do nothing for nfs @@ -567,19 +580,19 @@ _test_mkfs() # do nothing for cifs ;; udf) - $MKFS_UDF_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null + $MKFS_UDF_PROG $OPT $* $TEST_DEV > /dev/null ;; btrfs) - $MKFS_BTRFS_PROG $MKFS_OPTIONS $* $TEST_DEV > /dev/null + $MKFS_BTRFS_PROG $OPT $* $TEST_DEV > /dev/null ;; xfs) - $MKFS_PROG -t $FSTYP -- -f $MKFS_OPTIONS $* $TEST_DEV + $MKFS_PROG -t $FSTYP -- -f $OPT $* $TEST_DEV ;; ext2|ext3|ext4) - $MKFS_PROG -t $FSTYP -- -F $MKFS_OPTIONS $* $TEST_DEV + $MKFS_PROG -t $FSTYP -- -F $OPT $* $TEST_DEV ;; *) - yes | $MKFS_PROG -t $FSTYP -- $MKFS_OPTIONS $* $TEST_DEV + yes | $MKFS_PROG -t $FSTYP -- $OPT $* $TEST_DEV ;; esac } diff --git a/src/Makefile b/src/Makefile index 4781736..7908f3c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,7 +19,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ bulkstat_unlink_test_modified t_dir_offset t_futimens t_immutable \ stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \ seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \ - renameat2 t_getcwd e4compact + renameat2 t_getcwd e4compact require-richacls SUBDIRS = diff --git a/src/require-richacls.c b/src/require-richacls.c new file mode 100644 index 0000000..dce984f --- /dev/null +++ b/src/require-richacls.c @@ -0,0 +1,35 @@ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE +#endif +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + int ret; + + ret = getxattr(".", "system.richacl", NULL, 0); + if (ret < 0 && errno != ENODATA) { + char cwd[PATH_MAX]; + + if (!getcwd(cwd, sizeof(cwd))) + strcpy(cwd, "."); + if (errno == ENOTSUP) { + printf("This test requires a filesystem with richacl " + "support at %s\n", + cwd); + return 77; + } else { + perror(cwd); + return 1; + } + } + return 0; +} diff --git a/tests/richacl/001-apply-masks b/tests/richacl/001-apply-masks new file mode 120000 index 0000000..256bb2b --- /dev/null +++ b/tests/richacl/001-apply-masks @@ -0,0 +1 @@ +apply-masks \ No newline at end of file diff --git a/tests/richacl/002-auto-inheritance b/tests/richacl/002-auto-inheritance new file mode 120000 index 0000000..98472fc --- /dev/null +++ b/tests/richacl/002-auto-inheritance @@ -0,0 +1 @@ +auto-inheritance \ No newline at end of file diff --git a/tests/richacl/003-basic b/tests/richacl/003-basic new file mode 120000 index 0000000..ea5233d --- /dev/null +++ b/tests/richacl/003-basic @@ -0,0 +1 @@ +basic \ No newline at end of file diff --git a/tests/richacl/004-chmod b/tests/richacl/004-chmod new file mode 120000 index 0000000..8acd9e4 --- /dev/null +++ b/tests/richacl/004-chmod @@ -0,0 +1 @@ +chmod \ No newline at end of file diff --git a/tests/richacl/005-chown b/tests/richacl/005-chown new file mode 120000 index 0000000..6fb0fcd --- /dev/null +++ b/tests/richacl/005-chown @@ -0,0 +1 @@ +chown \ No newline at end of file diff --git a/tests/richacl/006-create b/tests/richacl/006-create new file mode 120000 index 0000000..f4ab424 --- /dev/null +++ b/tests/richacl/006-create @@ -0,0 +1 @@ +create \ No newline at end of file diff --git a/tests/richacl/007-ctime b/tests/richacl/007-ctime new file mode 120000 index 0000000..3ddadee --- /dev/null +++ b/tests/richacl/007-ctime @@ -0,0 +1 @@ +ctime \ No newline at end of file diff --git a/tests/richacl/008-delete b/tests/richacl/008-delete new file mode 120000 index 0000000..bbd98f4 --- /dev/null +++ b/tests/richacl/008-delete @@ -0,0 +1 @@ +delete \ No newline at end of file diff --git a/tests/richacl/009-setrichacl-modify b/tests/richacl/009-setrichacl-modify new file mode 120000 index 0000000..e3ebe54 --- /dev/null +++ b/tests/richacl/009-setrichacl-modify @@ -0,0 +1 @@ +setrichacl-modify \ No newline at end of file diff --git a/tests/richacl/010-write-vs-append b/tests/richacl/010-write-vs-append new file mode 120000 index 0000000..f19a074 --- /dev/null +++ b/tests/richacl/010-write-vs-append @@ -0,0 +1 @@ +write-vs-append \ No newline at end of file diff --git a/tests/richacl/Makefile b/tests/richacl/Makefile new file mode 100644 index 0000000..46662c5 --- /dev/null +++ b/tests/richacl/Makefile @@ -0,0 +1,44 @@ +# +# Copyright (C) 2015 Red Hat, Inc. +# + +# TOPDIR = .. +# include $(TOPDIR)/include/builddefs +# +# TESTS = apply-masks basic chmod chown create delete setrichacl-modify \ +# write-vs-append ctime auto-inheritance +# +# LSRCFILES = test-lib.sh $(TESTS) +# +# default install install-dev install-lib: +# +# include $(BUILDRULES) + +#$(TARGETS): +# @echo " [CC] $@" +# $(Q)$(LTLINK) $@.c -o $@ $(CFLAGS) $(LDFLAGS) $(LDLIBS) + +#TESTS_ENVIRONMENT = \ +# abs_top_builddir=$(abs_top_builddir); \ +# export abs_top_builddir; +# +# +# +# +# + +TOPDIR = ../.. +include $(TOPDIR)/include/builddefs + +TARGET_DIR = $(PKG_LIB_DIR)/$(TESTS_DIR)/richacl + +include $(BUILDRULES) + +install: + $(INSTALL) -m 755 -d $(TARGET_DIR) + $(INSTALL) -m 755 [0-9]?? $(TESTS) $(TARGET_DIR) + $(INSTALL) -m 644 group $(TARGET_DIR) + #$(INSTALL) -m 644 [0-9]??.* $(TARGET_DIR) + +# Nothing. +install-dev install-lib: diff --git a/tests/richacl/apply-masks b/tests/richacl/apply-masks new file mode 100755 index 0000000..7a99cf9 --- /dev/null +++ b/tests/richacl/apply-masks @@ -0,0 +1,163 @@ +#! /bin/sh + +. ${0%/*}/test-lib.sh + +require_richacls +use_tmpdir + +ncheck "touch x" +ncheck "setrichacl --set 'owner@:rwp::allow group@:rwp::allow everyone@:r::allow' x" +check "getrichacl x" < acl.txt" +check "cat acl.txt" <&2 + exit 77 + fi +} + +require_richacls() { + $here/src/require-richacls || exit $? + if ! type -f getrichacl setrichacl > /dev/null; then + echo "This test requires the getrichacl and setrichacl utilities" >&2 + exit 77 + fi +} + +require_getfattr() { + if ! type -f getfattr > /dev/null ; then + echo "This test requires the getfattr utility" >&2 + exit 77 + fi +} + +_RUNAS= +runas() { + _start_test -1 runas "$*" + if [ $# = 0 ]; then + _RUNAS= + else + _RUNAS="$here/src/runas $* --" + fi + echo "ok" +} + +if diff -u -L expected -L got /dev/null /dev/null 2> /dev/null; then + eval '_compare() { + diff -u -L expected -L got "$1" "$2" + }' +else + eval '_compare() { + echo "expected:" + cat "$1" + echo "got:" + cat "$2" + }' +fi + +_check() { + local frame=$1 + shift + _start_test "$frame" "$*" + expected=`cat` + if got=`set +x; eval "$_RUNAS $*" 3>&2 &1` && \ + test "$expected" = "$got" ; then + echo "ok" + checks_succeeded="$checks_succeeded + 1" + else + echo "FAILED" + if test "$expected" != "$got" ; then + echo "$expected" > expected~ + echo "$got" > got~ + _compare expected~ got~ + rm -f expected~ got~ + fi + checks_failed="$checks_failed + 1" + fi +} + +check() { + _check 0 "$@" +} + +ncheck() { + _check 0 "$@" < /dev/null +} + +parent_check() { + _check 1 "$@" +} + +parent_ncheck() { + _check 1 "$@" < /dev/null +} + +cleanup() { + status=$? + checks_succeeded=`expr $checks_succeeded` + checks_failed=`expr $checks_failed` + checks_total=`expr $checks_succeeded + $checks_failed` + if test $checks_total -gt 0 ; then + if test $checks_failed -gt 0 && test $status -eq 0 ; then + status=1 + fi + echo "$checks_total tests ($checks_succeeded passed," \ + "$checks_failed failed)" + fi + if test -n "$tmpdir" ; then + chmod -R u+rwx "$tmpdir" 2>/dev/null + cd / && rm -rf "$tmpdir" + fi + exit $status +} + +if test -z "`echo -n`"; then + if eval 'test -n "${BASH_LINENO[0]}" 2>/dev/null'; then + eval ' + _start_test() { + local frame=$1 + shift + printf "[${BASH_LINENO[2+frame]}] $* -- " + }' + else + eval ' + _start_test() { + shift + printf "* $* -- " + }' + fi +else + eval ' + _start_test() { + shift + printf "* $*\\n" + }' +fi + +if ! type cat > /dev/null 2> /dev/null; then + echo "This test requires the cat utility" >&2 + exit 77 +fi + +export PATH=$here/src:$PATH + +[ -z "$TEST_DIR" ] || cd "$TEST_DIR" + +checks_succeeded=0 +checks_failed=0 +trap cleanup 0 diff --git a/tests/richacl/write-vs-append b/tests/richacl/write-vs-append new file mode 100755 index 0000000..4528f3a --- /dev/null +++ b/tests/richacl/write-vs-append @@ -0,0 +1,54 @@ +#! /bin/sh + +. ${0%/*}/test-lib.sh + +require_runas +require_richacls +use_tmpdir + +export LC_ALL=C + +ncheck "touch a b c d e f" +ncheck "setrichacl --set 'owner@:rwp::allow' a" +ncheck "setrichacl --set 'owner@:rwp::allow 99:w::allow' b" +ncheck "setrichacl --set 'owner@:rwp::allow 99:p::allow' c" +ncheck "setrichacl --set 'owner@:rwp::allow 99:wp::allow' d" +ncheck "setrichacl --set '99:a::deny owner@:rwp::allow 99:w::allow' e" +ncheck "setrichacl --set '99:w::deny owner@:rwp::allow 99:p::allow' f" + +runas -u 99 -g 99 +check "sh -c 'echo a > a' || :" < b' || :" +check "sh -c 'echo c > c' || :" < d' || :" +ncheck "sh -c 'echo e > e' || :" +check "sh -c 'echo f > f' || :" <> a' || :" <> b' || :" <> c' || :" +ncheck "sh -c 'echo D >> d' || :" +check "sh -c 'echo E >> e' || :" <> f' || :" + +runas +check "cat a b c d e f" <