Index: etc/mtree/BSD.tests.dist =================================================================== --- etc/mtree/BSD.tests.dist +++ etc/mtree/BSD.tests.dist @@ -432,6 +432,8 @@ .. audit .. + auditpipe + .. capsicum .. cddl Index: tests/sys/Makefile =================================================================== --- tests/sys/Makefile +++ tests/sys/Makefile @@ -7,6 +7,7 @@ TESTS_SUBDIRS+= acl TESTS_SUBDIRS+= aio TESTS_SUBDIRS+= audit +TESTS_SUBDIRS+= auditpipe TESTS_SUBDIRS+= capsicum TESTS_SUBDIRS+= ${_cddl} TESTS_SUBDIRS+= fifo Index: tests/sys/auditpipe/Makefile =================================================================== --- /dev/null +++ tests/sys/auditpipe/Makefile @@ -0,0 +1,10 @@ +# $FreeBSD$ + +TESTSDIR= ${TESTSBASE}/sys/auditpipe + +ATF_TESTS_C= auditpipe_test + +TEST_METADATA+= required_user="root" +WARNS?= 6 + +.include Index: tests/sys/auditpipe/auditpipe_test.c =================================================================== --- /dev/null +++ tests/sys/auditpipe/auditpipe_test.c @@ -0,0 +1,165 @@ +/*- + * Copyright (c) 2018 Aniket Pandey + * + * 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 + +#include +#include + +#include +#include +#include + +static int filedesc; + +ATF_TC(auditpipe_get_qlen); +ATF_TC_HEAD(auditpipe_get_qlen, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_GET_QLEN works properly"); +} + +ATF_TC_BODY(auditpipe_get_qlen, tc) +{ + int qlen = -1; + filedesc = open("/dev/auditpipe", O_RDONLY); + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLEN, &qlen)); + ATF_REQUIRE(qlen != -1); + close(filedesc); +} + + +ATF_TC(auditpipe_get_qlimit); +ATF_TC_HEAD(auditpipe_get_qlimit, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_GET_QLIMIT works properly"); +} + +ATF_TC_BODY(auditpipe_get_qlimit, tc) +{ + int qlimit = -1; + filedesc = open("/dev/auditpipe", O_RDONLY); + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT, &qlimit)); + ATF_REQUIRE(qlimit != -1); + close(filedesc); +} + + +ATF_TC(auditpipe_set_qlimit); +ATF_TC_HEAD(auditpipe_set_qlimit, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_SET_QLIMIT works properly"); +} + +ATF_TC_BODY(auditpipe_set_qlimit, tc) +{ + /* + * Expected current value of QLIMIT is 128, choose 127 as it is not too + * disruptive in case something breaks and the system QLIMIT is modified + */ + int test_qlimit = 127; + int curr_qlimit, recv_qlimit; + + filedesc = open("/dev/auditpipe", O_RDONLY); + /* Retreive the current value, probably 128 */ + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT, &curr_qlimit)); + /* Set the test value as 127 */ + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_SET_QLIMIT, &test_qlimit)); + /* Receive modified value and check whether QLIMIT was set as 127 */ + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT, &recv_qlimit)); + ATF_REQUIRE_EQ(test_qlimit, recv_qlimit); + + /* Set the original value back */ + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_SET_QLIMIT, &curr_qlimit)); + close(filedesc); +} + + +ATF_TC(auditpipe_get_qlimit_min); +ATF_TC_HEAD(auditpipe_get_qlimit_min, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_GET_QLIMIT_MIN works properly"); +} + +ATF_TC_BODY(auditpipe_get_qlimit_min, tc) +{ + int qlim_min = -1; + filedesc = open("/dev/auditpipe", O_RDONLY); + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT_MIN, &qlim_min)); + ATF_REQUIRE(qlim_min != -1); + close(filedesc); +} + + +ATF_TC(auditpipe_get_qlimit_max); +ATF_TC_HEAD(auditpipe_get_qlimit_max, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_GET_QLIMIT_MAX works properly"); +} + +ATF_TC_BODY(auditpipe_get_qlimit_max, tc) +{ + int qlim_max = -1; + filedesc = open("/dev/auditpipe", O_RDONLY); + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_QLIMIT_MAX, &qlim_max)); + ATF_REQUIRE(qlim_max != -1); + close(filedesc); +} + + +ATF_TC(auditpipe_get_maxauditdata); +ATF_TC_HEAD(auditpipe_get_maxauditdata, tc) +{ + atf_tc_set_md_var(tc, "descr", "Verifies whether the auditpipe ioctl, " + "AUDITPIPE_GET_MAXAUDITDATA works properly"); +} + +ATF_TC_BODY(auditpipe_get_maxauditdata, tc) +{ + int audata = -1; + filedesc = open("/dev/auditpipe", O_RDONLY); + ATF_REQUIRE_EQ(0, ioctl(filedesc, AUDITPIPE_GET_MAXAUDITDATA, &audata)); + ATF_REQUIRE(audata != -1); + close(filedesc); +} + + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, auditpipe_get_qlen); + ATF_TP_ADD_TC(tp, auditpipe_get_qlimit); + ATF_TP_ADD_TC(tp, auditpipe_set_qlimit); + ATF_TP_ADD_TC(tp, auditpipe_get_qlimit_min); + ATF_TP_ADD_TC(tp, auditpipe_get_qlimit_max); + ATF_TP_ADD_TC(tp, auditpipe_get_maxauditdata); + + return (atf_no_error()); +}