From owner-svn-src-head@freebsd.org Mon Jun 18 15:07:11 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 77EC3100D3B3; Mon, 18 Jun 2018 15:07:11 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2D22483674; Mon, 18 Jun 2018 15:07:11 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 09C2E25B17; Mon, 18 Jun 2018 15:07:11 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5IF7AUG094460; Mon, 18 Jun 2018 15:07:10 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5IF7A3H094459; Mon, 18 Jun 2018 15:07:10 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201806181507.w5IF7A3H094459@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Mon, 18 Jun 2018 15:07:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335318 - head/tests/sys/audit X-SVN-Group: head X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: head/tests/sys/audit X-SVN-Commit-Revision: 335318 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jun 2018 15:07:11 -0000 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 +#include #include #include @@ -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()); }