socsvn commit: r337246 - soc2018/aniketp/head/tests/sys/audit
aniketp at FreeBSD.org
aniketp at FreeBSD.org
Wed May 23 11:36:12 UTC 2018
Author: aniketp
Date: Wed May 23 11:36:06 2018
New Revision: 337246
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=337246
Log:
Add 5 test-cases for 'cl' audit events
Added:
soc2018/aniketp/head/tests/sys/audit/file-close.c
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 Tue May 22 13:27:11 2018 (r337245)
+++ soc2018/aniketp/head/tests/sys/audit/file-attribute-modify.c Wed May 23 11:36:06 2018 (r337246)
@@ -1141,6 +1141,174 @@
}
+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)
+{
+ int readbuff;
+ const char *buff = "ezio";
+ /* File needs to exist to call extattr_delete_file(2) */
+ ATF_REQUIRE(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, "fm");
+ ATF_REQUIRE((readbuff = extattr_delete_file(path, \
+ EXTATTR_NAMESPACE_USER, name)) != -1);
+ /* Prepare the regex to be checked in the audit record */
+ snprintf(extregex, 80, "extattr_delete_file.*%s.*return,success,%d", \
+ path, readbuff);
+ check_audit(fds, extregex, pipefd);
+}
+
+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, 80, "extattr_delete_file.*%s.*return,failure", path);
+
+ FILE *pipefd = setup(fds, "fm");
+ /* 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)
+{
+ int filedesc, readbuff;
+ const char *buff = "ezio";
+
+ /* 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, "fm");
+ ATF_REQUIRE((readbuff = extattr_delete_fd(filedesc, \
+ EXTATTR_NAMESPACE_USER, name)) != -1);
+ /* Prepare the regex to be checked in the audit record */
+ snprintf(extregex, 80, "extattr_delete_fd.*return,success,%d", readbuff);
+ check_audit(fds, extregex, pipefd);
+}
+
+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, 80, "extattr_delete_fd.*return,failure : "
+ "Bad file descriptor");
+
+ FILE *pipefd = setup(fds, "fm");
+ /* 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)
+{
+ int readbuff;
+ const char *buff = "ezio";
+
+ /* 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, "fm");
+
+ ATF_REQUIRE((readbuff = extattr_delete_link(path, \
+ EXTATTR_NAMESPACE_USER, name)) != -1);
+ /* Prepare the regex to be checked in the audit record */
+ snprintf(extregex, 80, "extattr_delete_link.*%s.*return,success,%d", \
+ path, readbuff);
+ 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, 80, "extattr_delete_link.*%s.*failure", path);
+ FILE *pipefd = setup(fds, "fm");
+ /* 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_TC_WITH_CLEANUP(open_read_creat_success);
ATF_TC_HEAD(open_read_creat_success, tc)
{
@@ -1967,6 +2135,13 @@
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);
+
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);
Added: soc2018/aniketp/head/tests/sys/audit/file-close.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2018/aniketp/head/tests/sys/audit/file-close.c Wed May 23 11:36:06 2018 (r337246)
@@ -0,0 +1,173 @@
+/*-
+ * Copyright 2018 Aniket Pandey
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include <atf-c.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "utils.h"
+
+static struct pollfd fds[1];
+static mode_t mode = 0777;
+static char extregex[80];
+static struct stat statbuff;
+static const char *path = "fileforaudit";
+static const char *errpath = "dirdoesnotexist/fileforaudit";
+static const char *failurereg = "fileforaudit.*return,failure";
+
+
+ATF_TC_WITH_CLEANUP(munmap_success);
+ATF_TC_HEAD(munmap_success, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+ "munmap(2) call");
+}
+
+ATF_TC_BODY(munmap_success, tc)
+{
+ int pagesize = sysconf(_SC_PAGESIZE);
+ const char *regex = "munmap.*return,success";
+ char *addr = mmap(NULL, 4 * pagesize, PROT_READ , MAP_ANONYMOUS, -1, 0);
+ FILE *pipefd = setup(fds, "cl");
+ ATF_REQUIRE_EQ(0, munmap(addr, pagesize));
+ check_audit(fds, regex, pipefd);
+}
+
+ATF_TC_CLEANUP(munmap_success, tc)
+{
+ cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(munmap_failure);
+ATF_TC_HEAD(munmap_failure, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+ "munmap(2) call");
+}
+
+ATF_TC_BODY(munmap_failure, tc)
+{
+ const char *regex = "munmap.*return,failure : Invalid argument";
+ FILE *pipefd = setup(fds, "cl");
+ ATF_REQUIRE_EQ(-1, munmap((void *)SIZE_MAX, -1));
+ check_audit(fds, regex, pipefd);
+}
+
+ATF_TC_CLEANUP(munmap_failure, tc)
+{
+ cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(close_success);
+ATF_TC_HEAD(close_success, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+ "close(2) call");
+}
+
+ATF_TC_BODY(close_success, tc)
+{
+ int filedesc;
+ /* File needs to exist to call close(2) */
+ ATF_REQUIRE((filedesc = open(path, O_CREAT | O_RDWR, mode)) != -1);
+ /* Call stat(2) to store the Inode number of 'path' */
+ ATF_REQUIRE_EQ(0, stat(path, &statbuff));
+ FILE *pipefd = setup(fds, "cl");
+ ATF_REQUIRE_EQ(0, close(filedesc));
+
+ snprintf(extregex, 80, "close.*%lu.*return,success", statbuff.st_ino);
+ check_audit(fds, extregex, pipefd);
+}
+
+ATF_TC_CLEANUP(close_success, tc)
+{
+ cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(close_failure);
+ATF_TC_HEAD(close_failure, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+ "close(2) call");
+}
+
+ATF_TC_BODY(close_failure, tc)
+{
+ const char *regex = "close.*return,failure";
+ FILE *pipefd = setup(fds, "cl");
+ /* Failure reason: file does not exist */
+ ATF_REQUIRE_EQ(-1, close(-1));
+ check_audit(fds, regex, pipefd);
+}
+
+ATF_TC_CLEANUP(close_failure, tc)
+{
+ cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(revoke_failure);
+ATF_TC_HEAD(revoke_failure, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+ "revoke(2) call");
+}
+
+ATF_TC_BODY(revoke_failure, tc)
+{
+ FILE *pipefd = setup(fds, "cl");
+ /* Failure reason: file does not exist */
+ ATF_REQUIRE_EQ(-1, revoke(errpath));
+ check_audit(fds, failurereg, pipefd);
+}
+
+ATF_TC_CLEANUP(revoke_failure, tc)
+{
+ cleanup();
+}
+
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, munmap_success);
+ ATF_TP_ADD_TC(tp, munmap_failure);
+ ATF_TP_ADD_TC(tp, close_success);
+ ATF_TP_ADD_TC(tp, close_failure);
+ ATF_TP_ADD_TC(tp, revoke_failure);
+
+ return (atf_no_error());
+}
+
More information about the svn-soc-all
mailing list