From owner-svn-src-head@freebsd.org Sun Jun 17 16:24:47 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5DEFD1000B44; Sun, 17 Jun 2018 16:24:47 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 0A7A87454D; Sun, 17 Jun 2018 16:24:47 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DB43F17BD4; Sun, 17 Jun 2018 16:24:46 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w5HGOk5O091039; Sun, 17 Jun 2018 16:24:46 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5HGOkbT091038; Sun, 17 Jun 2018 16:24:46 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201806171624.w5HGOkbT091038@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Sun, 17 Jun 2018 16:24:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335285 - head/tests/sys/audit X-SVN-Group: head X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: head/tests/sys/audit X-SVN-Commit-Revision: 335285 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jun 2018 16:24:47 -0000 Author: asomers Date: Sun Jun 17 16:24:46 2018 New Revision: 335285 URL: https://svnweb.freebsd.org/changeset/base/335285 Log: audit(4): Add tests for a few syscalls in the ad class The ad audit class is for administrative commands. This commit adds test for settimeofday, adjtime, and getfh. Submitted by: aniketp MFC after: 2 weeks Sponsored by: Google, Inc. (GSoC 2018) Differential Revision: https://reviews.freebsd.org/D15861 Added: head/tests/sys/audit/administrative.c (contents, props changed) Modified: head/tests/sys/audit/Makefile Modified: head/tests/sys/audit/Makefile ============================================================================== --- head/tests/sys/audit/Makefile Sun Jun 17 15:22:27 2018 (r335284) +++ head/tests/sys/audit/Makefile Sun Jun 17 16:24:46 2018 (r335285) @@ -12,6 +12,7 @@ ATF_TESTS_C+= file-read ATF_TESTS_C+= open ATF_TESTS_C+= network ATF_TESTS_C+= inter-process +ATF_TESTS_C+= administrative SRCS.file-attribute-access+= file-attribute-access.c SRCS.file-attribute-access+= utils.c @@ -33,6 +34,8 @@ SRCS.network+= network.c SRCS.network+= utils.c SRCS.inter-process+= inter-process.c SRCS.inter-process+= utils.c +SRCS.administrative+= administrative.c +SRCS.administrative+= utils.c TEST_METADATA+= timeout="30" TEST_METADATA+= required_user="root" Added: head/tests/sys/audit/administrative.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/audit/administrative.c Sun Jun 17 16:24:46 2018 (r335285) @@ -0,0 +1,214 @@ +/*- + * 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 + +#include "utils.h" + +static pid_t pid; +static int filedesc; +static mode_t mode = 0777; +static struct pollfd fds[1]; +static char adregex[60]; +static const char *auclass = "ad"; +static const char *path = "fileforaudit"; + + +ATF_TC_WITH_CLEANUP(settimeofday_success); +ATF_TC_HEAD(settimeofday_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "settimeofday(2) call"); +} + +ATF_TC_BODY(settimeofday_success, tc) +{ + pid = getpid(); + snprintf(adregex, sizeof(adregex), "settimeofday.*%d.*success", pid); + + struct timeval tp; + struct timezone tzp; + ATF_REQUIRE_EQ(0, gettimeofday(&tp, &tzp)); + + FILE *pipefd = setup(fds, auclass); + /* Setting the same time as obtained by gettimeofday(2) */ + ATF_REQUIRE_EQ(0, settimeofday(&tp, &tzp)); + check_audit(fds, adregex, pipefd); +} + +ATF_TC_CLEANUP(settimeofday_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(settimeofday_failure); +ATF_TC_HEAD(settimeofday_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "settimeofday(2) call"); +} + +ATF_TC_BODY(settimeofday_failure, tc) +{ + pid = getpid(); + snprintf(adregex, sizeof(adregex), "settimeofday.*%d.*failure", pid); + + struct timeval tp; + struct timezone tzp; + ATF_REQUIRE_EQ(0, gettimeofday(&tp, &tzp)); + + FILE *pipefd = setup(fds, auclass); + tp.tv_sec = -1; + /* Failure reason: Invalid value for tp.tv_sec; */ + ATF_REQUIRE_EQ(-1, settimeofday(&tp, &tzp)); + check_audit(fds, adregex, pipefd); +} + +ATF_TC_CLEANUP(settimeofday_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(adjtime_success); +ATF_TC_HEAD(adjtime_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "adjtime(2) call"); +} + +ATF_TC_BODY(adjtime_success, tc) +{ + pid = getpid(); + snprintf(adregex, sizeof(adregex), "adjtime.*%d.*return,success", pid); + + FILE *pipefd = setup(fds, auclass); + /* We don't want to change the system time, hence NULL */ + ATF_REQUIRE_EQ(0, adjtime(NULL,NULL)); + check_audit(fds, adregex, pipefd); +} + +ATF_TC_CLEANUP(adjtime_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(adjtime_failure); +ATF_TC_HEAD(adjtime_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "adjtime(2) call"); +} + +ATF_TC_BODY(adjtime_failure, tc) +{ + pid = getpid(); + snprintf(adregex, sizeof(adregex), "adjtime.*%d.*return,failure", pid); + + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE_EQ(-1, adjtime((struct timeval *)(-1), NULL)); + check_audit(fds, adregex, pipefd); +} + +ATF_TC_CLEANUP(adjtime_failure, tc) +{ + cleanup(); +} + + + +ATF_TC_WITH_CLEANUP(nfs_getfh_success); +ATF_TC_HEAD(nfs_getfh_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "getfh(2) call"); +} + +ATF_TC_BODY(nfs_getfh_success, tc) +{ + fhandle_t fhp; + pid = getpid(); + snprintf(adregex, sizeof(adregex), "nfs_getfh.*%d.*ret.*success", pid); + + /* File needs to exist to call getfh(2) */ + ATF_REQUIRE(filedesc = open(path, O_CREAT, mode) != -1); + FILE *pipefd = setup(fds, auclass); + ATF_REQUIRE_EQ(0, getfh(path, &fhp)); + check_audit(fds, adregex, pipefd); + close(filedesc); +} + +ATF_TC_CLEANUP(nfs_getfh_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(nfs_getfh_failure); +ATF_TC_HEAD(nfs_getfh_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "getfh(2) call"); +} + +ATF_TC_BODY(nfs_getfh_failure, tc) +{ + pid = getpid(); + snprintf(adregex, sizeof(adregex), "nfs_getfh.*%d.*ret.*failure", pid); + + FILE *pipefd = setup(fds, auclass); + /* Failure reason: file does not exist */ + ATF_REQUIRE_EQ(-1, getfh(path, NULL)); + check_audit(fds, adregex, pipefd); +} + +ATF_TC_CLEANUP(nfs_getfh_failure, tc) +{ + cleanup(); +} + + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, settimeofday_success); + ATF_TP_ADD_TC(tp, settimeofday_failure); + ATF_TP_ADD_TC(tp, adjtime_success); + ATF_TP_ADD_TC(tp, adjtime_failure); + + ATF_TP_ADD_TC(tp, nfs_getfh_success); + ATF_TP_ADD_TC(tp, nfs_getfh_failure); + + return (atf_no_error()); +}