From owner-svn-soc-all@freebsd.org Tue May 22 13:27:15 2018 Return-Path: Delivered-To: svn-soc-all@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 91912EF5A38 for ; Tue, 22 May 2018 13:27:15 +0000 (UTC) (envelope-from aniketp@FreeBSD.org) Received: from mxrelay.ysv.freebsd.org (mxrelay.ysv.freebsd.org [IPv6:2001:1900:2254:206a::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.ysv.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2D8F57425C for ; Tue, 22 May 2018 13:27:15 +0000 (UTC) (envelope-from aniketp@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.ysv.freebsd.org (Postfix) with ESMTPS id 52D0E11266 for ; Tue, 22 May 2018 13:27:14 +0000 (UTC) (envelope-from aniketp@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id w4MDRE6h066369 for ; Tue, 22 May 2018 13:27:14 GMT (envelope-from aniketp@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id w4MDRD6f066314 for svn-soc-all@FreeBSD.org; Tue, 22 May 2018 13:27:13 GMT (envelope-from aniketp@FreeBSD.org) Date: Tue, 22 May 2018 13:27:13 GMT Message-Id: <201805221327.w4MDRD6f066314@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to aniketp@FreeBSD.org using -f From: aniketp@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r337245 - soc2018/aniketp/head/tests/sys/audit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 May 2018 13:27:15 -0000 Author: aniketp Date: Tue May 22 13:27:11 2018 New Revision: 337245 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=337245 Log: Complete all 83 tests for file-attribute-modify audit_class Modified: soc2018/aniketp/head/tests/sys/audit/file-attribute-modify.c Modified: soc2018/aniketp/head/tests/sys/audit/file-attribute-modify.c ============================================================================== --- soc2018/aniketp/head/tests/sys/audit/file-attribute-modify.c Mon May 21 19:37:09 2018 (r337244) +++ soc2018/aniketp/head/tests/sys/audit/file-attribute-modify.c Tue May 22 13:27:11 2018 (r337245) @@ -27,11 +27,16 @@ */ #include +#include #include +#include #include +#include #include #include +#include +#include #include #include "utils.h" @@ -40,7 +45,9 @@ static mode_t mode = 0777; static uid_t uid = -1; static gid_t gid = -1; +static char extregex[80]; static struct stat statbuff; +static const char *name = "authorname"; static const char *path = "fileforaudit"; static const char *errpath = "dirdoesnotexist/fileforaudit"; static const char *successreg = "fileforaudit.*return,success"; @@ -137,6 +144,57 @@ } +ATF_TC_WITH_CLEANUP(fsync_success); +ATF_TC_HEAD(fsync_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "fsync(2) call"); +} + +ATF_TC_BODY(fsync_success, tc) +{ + int filedesc; + char regex[30]; + + /* File needs to exist to call fsync(2) */ + ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); + ATF_REQUIRE_EQ(0, fstat(filedesc, &statbuff)); + /* Prepare the regex to be checked in the audit record */ + snprintf(regex, 30, "fsync.*%lu.*return,success", statbuff.st_ino); + + FILE *pipefd = setup(fds, "fm"); + ATF_REQUIRE_EQ(0, fsync(filedesc)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(fsync_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(fsync_failure); +ATF_TC_HEAD(fsync_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "fsync(2) call"); +} + +ATF_TC_BODY(fsync_failure, tc) +{ + const char *regex = "fsync.*return,failure : Bad file descriptor"; + FILE *pipefd = setup(fds, "fm"); + /* Failure reason: Invalid file descriptor */ + ATF_REQUIRE_EQ(-1, fsync(-1)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(fsync_failure, tc) +{ + cleanup(); +} + + ATF_TC_WITH_CLEANUP(chmod_success); ATF_TC_HEAD(chmod_success, tc) { @@ -859,6 +917,230 @@ } +ATF_TC_WITH_CLEANUP(mprotect_success); +ATF_TC_HEAD(mprotect_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "mprotect(2) call"); +} + +ATF_TC_BODY(mprotect_success, tc) +{ + const char *regex = "mprotect.*return,success"; + FILE *pipefd = setup(fds, "fm"); + ATF_REQUIRE_EQ(0, mprotect(NULL, 0, 0)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(mprotect_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(mprotect_failure); +ATF_TC_HEAD(mprotect_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "mprotect(2) call"); +} + +ATF_TC_BODY(mprotect_failure, tc) +{ + const char *regex = "mprotect.*return,failure : Invalid argument"; + FILE *pipefd = setup(fds, "fm"); + ATF_REQUIRE_EQ(-1, mprotect((void *)SIZE_MAX, -1, PROT_NONE)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(mprotect_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(undelete_failure); +ATF_TC_HEAD(undelete_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "undelete(2) call"); +} + +ATF_TC_BODY(undelete_failure, tc) +{ + const char *regex = "undelete.*return,failure"; + FILE *pipefd = setup(fds, "fm"); + ATF_REQUIRE_EQ(-1, undelete(errpath)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(undelete_failure, tc) +{ + cleanup(); +} + + +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) +{ + const char *buff = "ezio"; + /* File needs to exist to call extattr_set_file(2) */ + ATF_REQUIRE(open(path, O_CREAT, mode) != -1); + /* Prepare the regex to be checked in the audit record */ + snprintf(extregex, 80, "extattr_set_file.*%s.*%s.*return,success,%lu", \ + path, name, sizeof(buff)); + + FILE *pipefd = setup(fds, "fm"); + ATF_REQUIRE_EQ(sizeof(buff), extattr_set_file(path, \ + EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); + check_audit(fds, extregex, pipefd); +} + +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, 80, "extattr_set_file.*%s.*%s.*failure", path, name); + + FILE *pipefd = setup(fds, "fm"); + /* 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) +{ + int filedesc; + const char *buff = "ezio"; + /* 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, 80, "extattr_set_fd.*%s.*return,success", name); + FILE *pipefd = setup(fds, "fm"); + ATF_REQUIRE_EQ(sizeof(buff), extattr_set_fd(filedesc, \ + EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); + + check_audit(fds, extregex, pipefd); +} + +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, 80, "extattr_set_fd.*%s.*return,failure : " + "Bad file descriptor", name); + + FILE *pipefd = setup(fds, "fm"); + /* 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) +{ + const char *buff = "ezio"; + /* 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, 80, "extattr_set_link.*%s.*%s.*return,success,%lu", \ + path, name, sizeof(buff)); + + FILE *pipefd = setup(fds, "fm"); + 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, 80, "extattr_set_link.*%s.*%s.*failure", path, name); + FILE *pipefd = setup(fds, "fm"); + /* 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(open_read_creat_success); ATF_TC_HEAD(open_read_creat_success, tc) { @@ -1635,6 +1917,9 @@ ATF_TP_ADD_TC(tp, fcntl_success); ATF_TP_ADD_TC(tp, fcntl_failure); + ATF_TP_ADD_TC(tp, fsync_success); + ATF_TP_ADD_TC(tp, fsync_failure); + ATF_TP_ADD_TC(tp, chmod_success); ATF_TP_ADD_TC(tp, chmod_failure); ATF_TP_ADD_TC(tp, fchmod_success); @@ -1671,6 +1956,17 @@ ATF_TP_ADD_TC(tp, futimesat_success); ATF_TP_ADD_TC(tp, futimesat_failure); + ATF_TP_ADD_TC(tp, mprotect_success); + ATF_TP_ADD_TC(tp, mprotect_failure); + ATF_TP_ADD_TC(tp, undelete_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, open_read_creat_success); ATF_TP_ADD_TC(tp, open_read_creat_failure); ATF_TP_ADD_TC(tp, openat_read_creat_success);