Date: Mon, 18 Jun 2018 15:07:10 +0000 (UTC) From: Alan Somers <asomers@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335318 - head/tests/sys/audit Message-ID: <201806181507.w5IF7A3H094459@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: asomers Date: Mon Jun 18 15:07:10 2018 New Revision: 335318 URL: https://svnweb.freebsd.org/changeset/base/335318 Log: audit(4): add tests for extattr_set_file and friends Includes extattr_{set_file, _set_fd, _set_link, _delete_file, _delete_fd, _delete_link} Submitted by: aniketp MFC after: 2 weeks Sponsored by: Google, Inc. (GSoC 2018) Differential Revision: https://reviews.freebsd.org/D15867 Modified: head/tests/sys/audit/file-attribute-modify.c Modified: head/tests/sys/audit/file-attribute-modify.c ============================================================================== --- head/tests/sys/audit/file-attribute-modify.c Mon Jun 18 14:10:12 2018 (r335317) +++ head/tests/sys/audit/file-attribute-modify.c Mon Jun 18 15:07:10 2018 (r335318) @@ -25,6 +25,8 @@ * $FreeBSD$ */ +#include <sys/types.h> +#include <sys/extattr.h> #include <sys/file.h> #include <sys/stat.h> @@ -37,11 +39,13 @@ static pid_t pid; static uid_t uid = -1; static gid_t gid = -1; -static int filedesc; +static int filedesc, retval; static struct pollfd fds[1]; static mode_t mode = 0777; static char extregex[80]; +static const char *buff = "ezio"; static const char *auclass = "fm"; +static const char *name = "authorname"; static const char *path = "fileforaudit"; static const char *errpath = "adirhasnoname/fileforaudit"; static const char *successreg = "fileforaudit.*return,success"; @@ -685,6 +689,333 @@ ATF_TC_CLEANUP(lchflags_failure, tc) } +ATF_TC_WITH_CLEANUP(extattr_set_file_success); +ATF_TC_HEAD(extattr_set_file_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "extattr_set_file(2) call"); +} + +ATF_TC_BODY(extattr_set_file_success, tc) +{ + /* File needs to exist to call extattr_set_file(2) */ + ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_set_file.*%s.*%s.*return,success", path, name); + + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE_EQ(sizeof(buff), extattr_set_file(path, + EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); + check_audit(fds, extregex, pipefd); + close(filedesc); +} + +ATF_TC_CLEANUP(extattr_set_file_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(extattr_set_file_failure); +ATF_TC_HEAD(extattr_set_file_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "extattr_set_file(2) call"); +} + +ATF_TC_BODY(extattr_set_file_failure, tc) +{ + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_set_file.*%s.*%s.*failure", path, name); + + FILE *pipefd = setup(fds, auclass); + /* Failure reason: file does not exist */ + ATF_REQUIRE_EQ(-1, extattr_set_file(path, + EXTATTR_NAMESPACE_USER, name, NULL, 0)); + check_audit(fds, extregex, pipefd); +} + +ATF_TC_CLEANUP(extattr_set_file_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(extattr_set_fd_success); +ATF_TC_HEAD(extattr_set_fd_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "extattr_set_fd(2) call"); +} + +ATF_TC_BODY(extattr_set_fd_success, tc) +{ + /* File needs to exist to call extattr_set_fd(2) */ + ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); + + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_set_fd.*%s.*return,success", name); + + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE_EQ(sizeof(buff), extattr_set_fd(filedesc, + EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); + check_audit(fds, extregex, pipefd); + close(filedesc); +} + +ATF_TC_CLEANUP(extattr_set_fd_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(extattr_set_fd_failure); +ATF_TC_HEAD(extattr_set_fd_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "extattr_set_fd(2) call"); +} + +ATF_TC_BODY(extattr_set_fd_failure, tc) +{ + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_set_fd.*%s.*return,failure : Bad file descriptor", name); + + FILE *pipefd = setup(fds, auclass); + /* Failure reason: Invalid file descriptor */ + ATF_REQUIRE_EQ(-1, extattr_set_fd(-1, + EXTATTR_NAMESPACE_USER, name, NULL, 0)); + check_audit(fds, extregex, pipefd); +} + +ATF_TC_CLEANUP(extattr_set_fd_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(extattr_set_link_success); +ATF_TC_HEAD(extattr_set_link_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "extattr_set_link(2) call"); +} + +ATF_TC_BODY(extattr_set_link_success, tc) +{ + /* Symbolic link needs to exist to call extattr_set_link(2) */ + ATF_REQUIRE_EQ(0, symlink("symlink", path)); + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_set_link.*%s.*%s.*return,success", path, name); + + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE_EQ(sizeof(buff), extattr_set_link(path, + EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); + + check_audit(fds, extregex, pipefd); +} + +ATF_TC_CLEANUP(extattr_set_link_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(extattr_set_link_failure); +ATF_TC_HEAD(extattr_set_link_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "extattr_set_link(2) call"); +} + +ATF_TC_BODY(extattr_set_link_failure, tc) +{ + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_set_link.*%s.*%s.*failure", path, name); + FILE *pipefd = setup(fds, auclass); + /* Failure reason: symbolic link does not exist */ + ATF_REQUIRE_EQ(-1, extattr_set_link(path, + EXTATTR_NAMESPACE_USER, name, NULL, 0)); + check_audit(fds, extregex, pipefd); +} + +ATF_TC_CLEANUP(extattr_set_link_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(extattr_delete_file_success); +ATF_TC_HEAD(extattr_delete_file_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "extattr_delete_file(2) call"); +} + +ATF_TC_BODY(extattr_delete_file_success, tc) +{ + /* File needs to exist to call extattr_delete_file(2) */ + ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); + ATF_REQUIRE_EQ(sizeof(buff), extattr_set_file(path, + EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); + + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE((retval = extattr_delete_file(path, + EXTATTR_NAMESPACE_USER, name)) != -1); + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_delete_file.*%s.*return,success,%d", path, retval); + check_audit(fds, extregex, pipefd); + close(filedesc); +} + +ATF_TC_CLEANUP(extattr_delete_file_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(extattr_delete_file_failure); +ATF_TC_HEAD(extattr_delete_file_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "extattr_delete_file(2) call"); +} + +ATF_TC_BODY(extattr_delete_file_failure, tc) +{ + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_delete_file.*%s.*return,failure", path); + + FILE *pipefd = setup(fds, auclass); + /* Failure reason: file does not exist */ + ATF_REQUIRE_EQ(-1, extattr_delete_file(path, + EXTATTR_NAMESPACE_USER, name)); + check_audit(fds, extregex, pipefd); +} + +ATF_TC_CLEANUP(extattr_delete_file_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(extattr_delete_fd_success); +ATF_TC_HEAD(extattr_delete_fd_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "extattr_delete_fd(2) call"); +} + +ATF_TC_BODY(extattr_delete_fd_success, tc) +{ + /* File needs to exist to call extattr_delete_fd(2) */ + ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); + ATF_REQUIRE_EQ(sizeof(buff), extattr_set_file(path, + EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); + + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE((retval = extattr_delete_fd(filedesc, + EXTATTR_NAMESPACE_USER, name)) != -1); + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_delete_fd.*return,success,%d", retval); + check_audit(fds, extregex, pipefd); + close(filedesc); +} + +ATF_TC_CLEANUP(extattr_delete_fd_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(extattr_delete_fd_failure); +ATF_TC_HEAD(extattr_delete_fd_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "extattr_delete_fd(2) call"); +} + +ATF_TC_BODY(extattr_delete_fd_failure, tc) +{ + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_delete_fd.*return,failure : Bad file descriptor"); + + FILE *pipefd = setup(fds, auclass); + /* Failure reason: Invalid file descriptor */ + ATF_REQUIRE_EQ(-1, extattr_delete_fd(-1, EXTATTR_NAMESPACE_USER, name)); + check_audit(fds, extregex, pipefd); +} + +ATF_TC_CLEANUP(extattr_delete_fd_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(extattr_delete_link_success); +ATF_TC_HEAD(extattr_delete_link_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "extattr_delete_link(2) call"); +} + +ATF_TC_BODY(extattr_delete_link_success, tc) +{ + /* Symbolic link needs to exist to call extattr_delete_link(2) */ + ATF_REQUIRE_EQ(0, symlink("symlink", path)); + ATF_REQUIRE_EQ(sizeof(buff), extattr_set_link(path, + EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); + + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE((retval = extattr_delete_link(path, + EXTATTR_NAMESPACE_USER, name)) != -1); + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_delete_link.*%s.*return,success,%d", path, retval); + check_audit(fds, extregex, pipefd); +} + +ATF_TC_CLEANUP(extattr_delete_link_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(extattr_delete_link_failure); +ATF_TC_HEAD(extattr_delete_link_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "extattr_delete_link(2) call"); +} + +ATF_TC_BODY(extattr_delete_link_failure, tc) +{ + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, sizeof(extregex), + "extattr_delete_link.*%s.*failure", path); + FILE *pipefd = setup(fds, auclass); + /* Failure reason: symbolic link does not exist */ + ATF_REQUIRE_EQ(-1, extattr_delete_link(path, + EXTATTR_NAMESPACE_USER, name)); + check_audit(fds, extregex, pipefd); +} + +ATF_TC_CLEANUP(extattr_delete_link_failure, tc) +{ + cleanup(); +} + + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, flock_success); @@ -718,6 +1049,20 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, fchflags_failure); ATF_TP_ADD_TC(tp, lchflags_success); ATF_TP_ADD_TC(tp, lchflags_failure); + + ATF_TP_ADD_TC(tp, extattr_set_file_success); + ATF_TP_ADD_TC(tp, extattr_set_file_failure); + ATF_TP_ADD_TC(tp, extattr_set_fd_success); + ATF_TP_ADD_TC(tp, extattr_set_fd_failure); + ATF_TP_ADD_TC(tp, extattr_set_link_success); + ATF_TP_ADD_TC(tp, extattr_set_link_failure); + + ATF_TP_ADD_TC(tp, extattr_delete_file_success); + ATF_TP_ADD_TC(tp, extattr_delete_file_failure); + ATF_TP_ADD_TC(tp, extattr_delete_fd_success); + ATF_TP_ADD_TC(tp, extattr_delete_fd_failure); + ATF_TP_ADD_TC(tp, extattr_delete_link_success); + ATF_TP_ADD_TC(tp, extattr_delete_link_failure); return (atf_no_error()); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806181507.w5IF7A3H094459>