Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 May 2018 11:58:33 GMT
From:      aniketp@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r337247 - soc2018/aniketp/head/tests/sys/audit
Message-ID:  <201805241158.w4OBwXlO072776@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: aniketp
Date: Thu May 24 11:58:32 2018
New Revision: 337247
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=337247

Log:
  Add 2 execve(2) test-cases for exec audit class
  

Added:
  soc2018/aniketp/head/tests/sys/audit/exec.c
Modified:
  soc2018/aniketp/head/tests/sys/audit/Makefile

Modified: soc2018/aniketp/head/tests/sys/audit/Makefile
==============================================================================
--- soc2018/aniketp/head/tests/sys/audit/Makefile	Wed May 23 11:36:06 2018	(r337246)
+++ soc2018/aniketp/head/tests/sys/audit/Makefile	Thu May 24 11:58:32 2018	(r337247)
@@ -6,8 +6,10 @@
 ATF_TESTS_C+=	file-delete
 ATF_TESTS_C+=	file-read
 ATF_TESTS_C+=	file-write
+ATF_TESTS_C+=	file-close
 ATF_TESTS_C+=	file-attribute-access
 ATF_TESTS_C+=	file-attribute-modify
+ATF_TESTS_C+=	exec
 
 SRCS.file-create+=	file-create.c
 SRCS.file-create+=	utils.c
@@ -17,10 +19,14 @@
 SRCS.file-read+=	utils.c
 SRCS.file-write+=	file-write.c
 SRCS.file-write+=	utils.c
+SRCS.file-close+=	file-close.c
+SRCS.file-close+=	utils.c
 SRCS.file-attribute-access+=	file-attribute-access.c
 SRCS.file-attribute-access+=	utils.c
 SRCS.file-attribute-modify+=	file-attribute-modify.c
 SRCS.file-attribute-modify+=	utils.c
+SRCS.exec+=	exec.c
+SRCS.exec+=	utils.c
 
 TEST_METADATA.file-create+= timeout="30"
 TEST_METADATA.file-create+= required_user="root"
@@ -30,10 +36,14 @@
 TEST_METADATA.file-read+= required_user="root"
 TEST_METADATA.file-write+= timeout="30"
 TEST_METADATA.file-write+= required_user="root"
+TEST_METADATA.file-close+= timeout="30"
+TEST_METADATA.file-close+= required_user="root"
 TEST_METADATA.file-attribute-access+= timeout="30"
 TEST_METADATA.file-attribute-access+= required_user="root"
 TEST_METADATA.file-attribute-modify+= timeout="30"
 TEST_METADATA.file-attribute-modify+= required_user="root"
+TEST_METADATA.exec+= timeout="30"
+TEST_METADATA.exec+= required_user="root"
 
 WARNS?=	6
 

Added: soc2018/aniketp/head/tests/sys/audit/exec.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2018/aniketp/head/tests/sys/audit/exec.c	Thu May 24 11:58:32 2018	(r337247)
@@ -0,0 +1,112 @@
+/*-
+ * 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/types.h>
+#include <sys/wait.h>
+
+#include <atf-c.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "utils.h"
+
+static pid_t pid;
+static int status;
+static struct pollfd fds[1];
+static char argument[] = "sample-argument";
+
+
+ATF_TC_WITH_CLEANUP(execve_success);
+ATF_TC_HEAD(execve_success, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+					"execve(2) call");
+}
+
+ATF_TC_BODY(execve_success, tc)
+{
+	char bin[] = "/usr/bin/true";
+
+	const char *regex = "execve.*sample-argument";
+	char *arg[] = {bin, argument, NULL};
+	FILE *pipefd = setup(fds, "ex");
+
+	ATF_REQUIRE((pid = fork()) != -1);
+	if (pid) {
+		ATF_REQUIRE(wait(&status) != -1);
+		check_audit(fds, regex, pipefd);
+	}
+	else {
+		ATF_REQUIRE(execve(bin, arg, NULL) != -1);
+	}
+}
+
+ATF_TC_CLEANUP(execve_success, tc)
+{
+	cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(execve_failure);
+ATF_TC_HEAD(execve_failure, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+					"execve(2) call");
+}
+
+ATF_TC_BODY(execve_failure, tc)
+{
+	char bin[] = "/does/not/exist";
+	const char *regex = "execve.*sample-argument.*return,failure";
+	char *arg[] = {bin, argument, NULL};
+	FILE *pipefd = setup(fds, "ex");
+
+	ATF_REQUIRE((pid = fork()) != -1);
+	if (pid) {
+		ATF_REQUIRE(wait(&status) != -1);
+		check_audit(fds, regex, pipefd);
+	}
+	else {
+		ATF_REQUIRE_EQ(-1, execve(bin, arg, NULL));
+	}
+}
+
+ATF_TC_CLEANUP(execve_failure, tc)
+{
+	cleanup();
+}
+
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, execve_success);
+	ATF_TP_ADD_TC(tp, execve_failure);
+
+	return (atf_no_error());
+}
+



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