socsvn commit: r337245 - soc2018/aniketp/head/tests/sys/audit

aniketp at FreeBSD.org aniketp at FreeBSD.org
Tue May 22 13:27:15 UTC 2018


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 <sys/stat.h>
+#include <sys/mman.h>
 #include <sys/time.h>
+#include <sys/types.h>
 #include <sys/syscall.h>
+#include <sys/extattr.h>
 
 #include <atf-c.h>
 #include <fcntl.h>
+#include <stdint.h>
+#include <stdlib.h>
 #include <unistd.h>
 
 #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);


More information about the svn-soc-all mailing list