From owner-svn-soc-all@freebsd.org Thu May 24 13:51:57 2018 Return-Path: Delivered-To: svn-soc-all@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 6521FEF1D8B for ; Thu, 24 May 2018 13:51:57 +0000 (UTC) (envelope-from aniketp@FreeBSD.org) Received: from mxrelay.ysv.freebsd.org (mxrelay.ysv.freebsd.org [IPv6:2001:1900:2254:206a::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.ysv.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F1E576CA5B for ; Thu, 24 May 2018 13:51:56 +0000 (UTC) (envelope-from aniketp@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.ysv.freebsd.org (Postfix) with ESMTPS id 437F1A7F5 for ; Thu, 24 May 2018 13:51:56 +0000 (UTC) (envelope-from aniketp@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id w4ODpuAU082781 for ; Thu, 24 May 2018 13:51:56 GMT (envelope-from aniketp@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id w4ODps1N081365 for svn-soc-all@FreeBSD.org; Thu, 24 May 2018 13:51:54 GMT (envelope-from aniketp@FreeBSD.org) Date: Thu, 24 May 2018 13:51:54 GMT Message-Id: <201805241351.w4ODps1N081365@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to aniketp@FreeBSD.org using -f From: aniketp@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r337249 - soc2018/aniketp/head/tests/sys/audit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 May 2018 13:51:57 -0000 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 + +#include +#include +#include +#include +#include + +#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()); +} +