Date: Thu, 24 May 2018 23:20:47 GMT From: aniketp@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r337250 - soc2018/aniketp/head/tests/sys/audit Message-ID: <201805242320.w4ONKlK4017869@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: aniketp Date: Thu May 24 23:20:45 2018 New Revision: 337250 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=337250 Log: Replace hex format specifier by %x to match audit_record Added: soc2018/aniketp/head/tests/sys/audit/network.c Modified: soc2018/aniketp/head/tests/sys/audit/Makefile soc2018/aniketp/head/tests/sys/audit/ioctl.c Modified: soc2018/aniketp/head/tests/sys/audit/Makefile ============================================================================== --- soc2018/aniketp/head/tests/sys/audit/Makefile Thu May 24 13:51:53 2018 (r337249) +++ soc2018/aniketp/head/tests/sys/audit/Makefile Thu May 24 23:20:45 2018 (r337250) @@ -11,6 +11,7 @@ ATF_TESTS_C+= file-attribute-modify ATF_TESTS_C+= exec ATF_TESTS_C+= ioctl +ATF_TESTS_C+= network SRCS.file-create+= file-create.c SRCS.file-create+= utils.c @@ -30,6 +31,8 @@ SRCS.exec+= utils.c SRCS.ioctl+= ioctl.c SRCS.ioctl+= utils.c +SRCS.network+= network.c +SRCS.network+= utils.c TEST_METADATA.file-create+= timeout="30" TEST_METADATA.file-create+= required_user="root" @@ -49,6 +52,8 @@ TEST_METADATA.exec+= required_user="root" TEST_METADATA.ioctl+= timeout="30" TEST_METADATA.ioctl+= required_user="root" +TEST_METADATA.network+= timeout="30" +TEST_METADATA.network+= required_user="root" WARNS?= 6 Modified: soc2018/aniketp/head/tests/sys/audit/ioctl.c ============================================================================== --- soc2018/aniketp/head/tests/sys/audit/ioctl.c Thu May 24 13:51:53 2018 (r337249) +++ soc2018/aniketp/head/tests/sys/audit/ioctl.c Thu May 24 23:20:45 2018 (r337250) @@ -51,9 +51,10 @@ int filedesc; char regex[30]; + /* auditpipe(4) supports quite a few ioctl(2)s */ 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); + snprintf(regex, 30, "ioctl.*0x%x.*return,success", filedesc); FILE *pipefd = setup(fds, "io"); ATF_REQUIRE(ioctl(filedesc, AUDITPIPE_FLUSH) != -1); Added: soc2018/aniketp/head/tests/sys/audit/network.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2018/aniketp/head/tests/sys/audit/network.c Thu May 24 23:20:45 2018 (r337250) @@ -0,0 +1,93 @@ +/*- + * 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/socket.h> + +#include <atf-c.h> +#include <unistd.h> + +#include "utils.h" +#define ERROR (-1) + +static int sockfd; +static struct pollfd fds[1]; +static char regex[40]; + +ATF_TC_WITH_CLEANUP(socket_success); +ATF_TC_HEAD(socket_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "socket(2) call"); +} + +ATF_TC_BODY(socket_success, tc) +{ + FILE *pipefd = setup(fds, "nt"); + ATF_REQUIRE((sockfd = socket(PF_INET, SOCK_STREAM, 0)) != -1); + /* Check the presence of sockfd in audit record */ + snprintf(regex, 30, "socket.*return,success,%d", sockfd); + check_audit(fds, regex, pipefd); + close(sockfd); +} + +ATF_TC_CLEANUP(socket_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(socket_failure); +ATF_TC_HEAD(socket_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "socket(2) call"); +} + +ATF_TC_BODY(socket_failure, tc) +{ + FILE *pipefd = setup(fds, "nt"); + ATF_REQUIRE_EQ(-1, socket(ERROR, SOCK_STREAM, 0)); + /* Check the presence of hex(-1) in audit record */ + snprintf(regex, 40, "socket.*0x%x.*return,failure", ERROR); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(socket_failure, tc) +{ + cleanup(); +} + + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, socket_success); + ATF_TP_ADD_TC(tp, socket_failure); + + return (atf_no_error()); +} +
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201805242320.w4ONKlK4017869>