Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Jun 2018 15:32:02 +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: r335207 - head/tests/sys/audit
Message-ID:  <201806151532.w5FFW2Qg086076@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Fri Jun 15 15:32:02 2018
New Revision: 335207
URL: https://svnweb.freebsd.org/changeset/base/335207

Log:
  audit(4): add tests for access(2), chmod(2), and friends
  
  access(2), eaccess(2), faccessat(2), chmod(2), fchmod(2), lchmod(2), and
  fchmodat(2).
  
  Submitted by:	aniketp
  MFC after:	2 weeks
  Sponsored by:	Google, Inc. (GSoC 2018)
  Differential Revision:	https://reviews.freebsd.org/D15805
  Differential Revision:	https://reviews.freebsd.org/D15808

Modified:
  head/tests/sys/audit/file-attribute-access.c
  head/tests/sys/audit/file-attribute-modify.c

Modified: head/tests/sys/audit/file-attribute-access.c
==============================================================================
--- head/tests/sys/audit/file-attribute-access.c	Fri Jun 15 15:28:31 2018	(r335206)
+++ head/tests/sys/audit/file-attribute-access.c	Fri Jun 15 15:32:02 2018	(r335207)
@@ -529,6 +529,138 @@ ATF_TC_CLEANUP(fhstatfs_failure, tc)
 }
 
 
+ATF_TC_WITH_CLEANUP(access_success);
+ATF_TC_HEAD(access_success, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+					"access(2) call");
+}
+
+ATF_TC_BODY(access_success, tc)
+{
+	/* File needs to exist to call access(2) */
+	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
+	FILE *pipefd = setup(fds, auclass);
+	ATF_REQUIRE_EQ(0, access(path, F_OK));
+	check_audit(fds, successreg, pipefd);
+	close(filedesc);
+}
+
+ATF_TC_CLEANUP(access_success, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(access_failure);
+ATF_TC_HEAD(access_failure, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+					"access(2) call");
+}
+
+ATF_TC_BODY(access_failure, tc)
+{
+	FILE *pipefd = setup(fds, auclass);
+	/* Failure reason: file does not exist */
+	ATF_REQUIRE_EQ(-1, access(errpath, F_OK));
+	check_audit(fds, failurereg, pipefd);
+}
+
+ATF_TC_CLEANUP(access_failure, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(eaccess_success);
+ATF_TC_HEAD(eaccess_success, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+					"eaccess(2) call");
+}
+
+ATF_TC_BODY(eaccess_success, tc)
+{
+	/* File needs to exist to call eaccess(2) */
+	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
+	FILE *pipefd = setup(fds, auclass);
+	ATF_REQUIRE_EQ(0, eaccess(path, F_OK));
+	check_audit(fds, successreg, pipefd);
+	close(filedesc);
+}
+
+ATF_TC_CLEANUP(eaccess_success, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(eaccess_failure);
+ATF_TC_HEAD(eaccess_failure, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+					"eaccess(2) call");
+}
+
+ATF_TC_BODY(eaccess_failure, tc)
+{
+	FILE *pipefd = setup(fds, auclass);
+	/* Failure reason: file does not exist */
+	ATF_REQUIRE_EQ(-1, eaccess(errpath, F_OK));
+	check_audit(fds, failurereg, pipefd);
+}
+
+ATF_TC_CLEANUP(eaccess_failure, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(faccessat_success);
+ATF_TC_HEAD(faccessat_success, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+					"faccessat(2) call");
+}
+
+ATF_TC_BODY(faccessat_success, tc)
+{
+	/* File needs to exist to call faccessat(2) */
+	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
+	FILE *pipefd = setup(fds, auclass);
+	ATF_REQUIRE_EQ(0, faccessat(AT_FDCWD, path, F_OK, AT_EACCESS));
+	check_audit(fds, successreg, pipefd);
+	close(filedesc);
+}
+
+ATF_TC_CLEANUP(faccessat_success, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(faccessat_failure);
+ATF_TC_HEAD(faccessat_failure, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+					"faccessat(2) call");
+}
+
+ATF_TC_BODY(faccessat_failure, tc)
+{
+	FILE *pipefd = setup(fds, auclass);
+	/* Failure reason: file does not exist */
+	ATF_REQUIRE_EQ(-1, faccessat(AT_FDCWD, errpath, F_OK, AT_EACCESS));
+	check_audit(fds, failurereg, pipefd);
+}
+
+ATF_TC_CLEANUP(faccessat_failure, tc)
+{
+	cleanup();
+}
+
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, stat_success);
@@ -554,6 +686,13 @@ ATF_TP_ADD_TCS(tp)
 	ATF_TP_ADD_TC(tp, fhstat_failure);
 	ATF_TP_ADD_TC(tp, fhstatfs_success);
 	ATF_TP_ADD_TC(tp, fhstatfs_failure);
+
+	ATF_TP_ADD_TC(tp, access_success);
+	ATF_TP_ADD_TC(tp, access_failure);
+	ATF_TP_ADD_TC(tp, eaccess_success);
+	ATF_TP_ADD_TC(tp, eaccess_failure);
+	ATF_TP_ADD_TC(tp, faccessat_success);
+	ATF_TP_ADD_TC(tp, faccessat_failure);
 
 	return (atf_no_error());
 }

Modified: head/tests/sys/audit/file-attribute-modify.c
==============================================================================
--- head/tests/sys/audit/file-attribute-modify.c	Fri Jun 15 15:28:31 2018	(r335206)
+++ head/tests/sys/audit/file-attribute-modify.c	Fri Jun 15 15:32:02 2018	(r335207)
@@ -26,6 +26,7 @@
  */
 
 #include <sys/file.h>
+#include <sys/stat.h>
 
 #include <atf-c.h>
 #include <fcntl.h>
@@ -40,6 +41,9 @@ static mode_t mode = 0777;
 static char extregex[80];
 static const char *auclass = "fm";
 static const char *path = "fileforaudit";
+static const char *errpath = "adirhasnoname/fileforaudit";
+static const char *successreg = "fileforaudit.*return,success";
+static const char *failurereg = "fileforaudit.*return,failure";
 
 
 ATF_TC_WITH_CLEANUP(flock_success);
@@ -186,6 +190,185 @@ ATF_TC_CLEANUP(fsync_failure, tc)
 }
 
 
+ATF_TC_WITH_CLEANUP(chmod_success);
+ATF_TC_HEAD(chmod_success, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+					"chmod(2) call");
+}
+
+ATF_TC_BODY(chmod_success, tc)
+{
+	/* File needs to exist to call chmod(2) */
+	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
+	FILE *pipefd = setup(fds, auclass);
+	ATF_REQUIRE_EQ(0, chmod(path, mode));
+	check_audit(fds, successreg, pipefd);
+	close(filedesc);
+}
+
+ATF_TC_CLEANUP(chmod_success, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(chmod_failure);
+ATF_TC_HEAD(chmod_failure, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+					"chmod(2) call");
+}
+
+ATF_TC_BODY(chmod_failure, tc)
+{
+	FILE *pipefd = setup(fds, auclass);
+	/* Failure reason: file does not exist */
+	ATF_REQUIRE_EQ(-1, chmod(errpath, mode));
+	check_audit(fds, failurereg, pipefd);
+}
+
+ATF_TC_CLEANUP(chmod_failure, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(fchmod_success);
+ATF_TC_HEAD(fchmod_success, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+					"fchmod(2) call");
+}
+
+ATF_TC_BODY(fchmod_success, tc)
+{
+	pid = getpid();
+	snprintf(extregex, sizeof(extregex), "fchmod.*%d.*return,success", pid);
+
+	/* File needs to exist to call fchmod(2) */
+	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
+	FILE *pipefd = setup(fds, auclass);
+	ATF_REQUIRE_EQ(0, fchmod(filedesc, mode));
+	check_audit(fds, extregex, pipefd);
+	close(filedesc);
+}
+
+ATF_TC_CLEANUP(fchmod_success, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(fchmod_failure);
+ATF_TC_HEAD(fchmod_failure, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+					"fchmod(2) call");
+}
+
+ATF_TC_BODY(fchmod_failure, tc)
+{
+	const char *regex = "fchmod.*return,failure : Bad file descriptor";
+	FILE *pipefd = setup(fds, auclass);
+	/* Failure reason: Invalid file descriptor */
+	ATF_REQUIRE_EQ(-1, fchmod(-1, mode));
+	check_audit(fds, regex, pipefd);
+}
+
+ATF_TC_CLEANUP(fchmod_failure, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(lchmod_success);
+ATF_TC_HEAD(lchmod_success, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+					"lchmod(2) call");
+}
+
+ATF_TC_BODY(lchmod_success, tc)
+{
+	/* Symbolic link needs to exist to call lchmod(2) */
+	ATF_REQUIRE_EQ(0, symlink("symlink", path));
+	FILE *pipefd = setup(fds, auclass);
+	ATF_REQUIRE_EQ(0, lchmod(path, mode));
+	check_audit(fds, successreg, pipefd);
+}
+
+ATF_TC_CLEANUP(lchmod_success, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(lchmod_failure);
+ATF_TC_HEAD(lchmod_failure, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+					"lchmod(2) call");
+}
+
+ATF_TC_BODY(lchmod_failure, tc)
+{
+	FILE *pipefd = setup(fds, auclass);
+	/* Failure reason: file does not exist */
+	ATF_REQUIRE_EQ(-1, lchmod(errpath, mode));
+	check_audit(fds, failurereg, pipefd);
+}
+
+ATF_TC_CLEANUP(lchmod_failure, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(fchmodat_success);
+ATF_TC_HEAD(fchmodat_success, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+					"fchmodat(2) call");
+}
+
+ATF_TC_BODY(fchmodat_success, tc)
+{
+	/* File needs to exist to call fchmodat(2) */
+	ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1);
+	FILE *pipefd = setup(fds, auclass);
+	ATF_REQUIRE_EQ(0, fchmodat(AT_FDCWD, path, mode, 0));
+	check_audit(fds, successreg, pipefd);
+	close(filedesc);
+}
+
+ATF_TC_CLEANUP(fchmodat_success, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(fchmodat_failure);
+ATF_TC_HEAD(fchmodat_failure, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+					"fchmodat(2) call");
+}
+
+ATF_TC_BODY(fchmodat_failure, tc)
+{
+	FILE *pipefd = setup(fds, auclass);
+	/* Failure reason: file does not exist */
+	ATF_REQUIRE_EQ(-1, fchmodat(AT_FDCWD, errpath, mode, 0));
+	check_audit(fds, failurereg, pipefd);
+}
+
+ATF_TC_CLEANUP(fchmodat_failure, tc)
+{
+	cleanup();
+}
+
+
 ATF_TP_ADD_TCS(tp)
 {
 	ATF_TP_ADD_TC(tp, flock_success);
@@ -194,6 +377,15 @@ ATF_TP_ADD_TCS(tp)
 	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);
+	ATF_TP_ADD_TC(tp, fchmod_failure);
+	ATF_TP_ADD_TC(tp, lchmod_success);
+	ATF_TP_ADD_TC(tp, lchmod_failure);
+	ATF_TP_ADD_TC(tp, fchmodat_success);
+	ATF_TP_ADD_TC(tp, fchmodat_failure);
 
 	return (atf_no_error());
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806151532.w5FFW2Qg086076>