Date: Thu, 24 May 2018 13:51:54 GMT From: aniketp@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r337249 - soc2018/aniketp/head/tests/sys/audit Message-ID: <201805241351.w4ODps1N081365@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: aniketp Date: Thu May 24 13:51:53 2018 New Revision: 337249 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=337249 Log: Initial set of tests for ioctl(2) in "io" audit class Added: soc2018/aniketp/head/tests/sys/audit/ioctl.c Modified: soc2018/aniketp/head/tests/sys/audit/Makefile Modified: soc2018/aniketp/head/tests/sys/audit/Makefile ============================================================================== --- soc2018/aniketp/head/tests/sys/audit/Makefile Thu May 24 12:07:06 2018 (r337248) +++ soc2018/aniketp/head/tests/sys/audit/Makefile Thu May 24 13:51:53 2018 (r337249) @@ -10,6 +10,7 @@ ATF_TESTS_C+= file-attribute-access ATF_TESTS_C+= file-attribute-modify ATF_TESTS_C+= exec +ATF_TESTS_C+= ioctl SRCS.file-create+= file-create.c SRCS.file-create+= utils.c @@ -27,6 +28,8 @@ SRCS.file-attribute-modify+= utils.c SRCS.exec+= exec.c SRCS.exec+= utils.c +SRCS.ioctl+= ioctl.c +SRCS.ioctl+= utils.c TEST_METADATA.file-create+= timeout="30" TEST_METADATA.file-create+= required_user="root" @@ -44,6 +47,8 @@ TEST_METADATA.file-attribute-modify+= required_user="root" TEST_METADATA.exec+= timeout="30" TEST_METADATA.exec+= required_user="root" +TEST_METADATA.ioctl+= timeout="30" +TEST_METADATA.ioctl+= required_user="root" WARNS?= 6 Added: soc2018/aniketp/head/tests/sys/audit/ioctl.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2018/aniketp/head/tests/sys/audit/ioctl.c Thu May 24 13:51:53 2018 (r337249) @@ -0,0 +1,97 @@ +/*- + * 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/ioctl.h> + +#include <atf-c.h> +#include <fcntl.h> +#include <unistd.h> +#include <bsm/libbsm.h> +#include <security/audit/audit_ioctl.h> + +#include "utils.h" + +static struct pollfd fds[1]; + + +ATF_TC_WITH_CLEANUP(ioctl_success); +ATF_TC_HEAD(ioctl_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "ioctl(2) call"); +} + +ATF_TC_BODY(ioctl_success, tc) +{ + int filedesc; + char regex[30]; + + ATF_REQUIRE((filedesc = open("/dev/auditpipe", O_RDONLY)) != -1); + /* Prepare the regex to be checked in the audit record */ + snprintf(regex, 30, "ioctl.*0x%X.*return,success", filedesc); + + FILE *pipefd = setup(fds, "io"); + ATF_REQUIRE(ioctl(filedesc, AUDITPIPE_FLUSH) != -1); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(ioctl_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(ioctl_failure); +ATF_TC_HEAD(ioctl_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "ioctl(2) call"); +} + +ATF_TC_BODY(ioctl_failure, tc) +{ + const char *regex = "ioctl.*return,failure : Bad file descriptor"; + FILE *pipefd = setup(fds, "io"); + ATF_REQUIRE_EQ(-1, ioctl(-1, AUDITPIPE_FLUSH)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(ioctl_failure, tc) +{ + cleanup(); +} + + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, ioctl_success); + ATF_TP_ADD_TC(tp, ioctl_failure); + + return (atf_no_error()); +} +
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201805241351.w4ODps1N081365>