From owner-svn-src-head@freebsd.org Sat Jun 16 18:29:25 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 EE1C3101E89A; Sat, 16 Jun 2018 18:29:24 +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 A22A86AB1E; Sat, 16 Jun 2018 18:29:24 +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 833E81F7B; Sat, 16 Jun 2018 18:29:24 +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 w5GITO59016964; Sat, 16 Jun 2018 18:29:24 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w5GITOT3016963; Sat, 16 Jun 2018 18:29:24 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201806161829.w5GITOT3016963@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Sat, 16 Jun 2018 18:29:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r335261 - 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: 335261 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: Sat, 16 Jun 2018 18:29:25 -0000 Author: asomers Date: Sat Jun 16 18:29:24 2018 New Revision: 335261 URL: https://svnweb.freebsd.org/changeset/base/335261 Log: audit(4): add tests for pathconf(2) and friends pathconf, lpathconf, and fpathconf are included Submitted by: aniketp MFC after: 2 weeks Sponsored by: Google, Inc. (GSoC 2018) Differential Revision: https://reviews.freebsd.org/D15842 Modified: head/tests/sys/audit/file-attribute-access.c Modified: head/tests/sys/audit/file-attribute-access.c ============================================================================== --- head/tests/sys/audit/file-attribute-access.c Sat Jun 16 18:22:35 2018 (r335260) +++ head/tests/sys/audit/file-attribute-access.c Sat Jun 16 18:29:24 2018 (r335261) @@ -661,6 +661,144 @@ ATF_TC_CLEANUP(faccessat_failure, tc) } +ATF_TC_WITH_CLEANUP(pathconf_success); +ATF_TC_HEAD(pathconf_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "pathconf(2) call"); +} + +ATF_TC_BODY(pathconf_success, tc) +{ + /* File needs to exist to call pathconf(2) */ + ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); + FILE *pipefd = setup(fds, auclass); + /* Get the maximum number of bytes of filename */ + ATF_REQUIRE(pathconf(path, _PC_NAME_MAX) != -1); + check_audit(fds, successreg, pipefd); + close(filedesc); +} + +ATF_TC_CLEANUP(pathconf_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(pathconf_failure); +ATF_TC_HEAD(pathconf_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "pathconf(2) call"); +} + +ATF_TC_BODY(pathconf_failure, tc) +{ + FILE *pipefd = setup(fds, auclass); + /* Failure reason: file does not exist */ + ATF_REQUIRE_EQ(-1, pathconf(errpath, _PC_NAME_MAX)); + check_audit(fds, failurereg, pipefd); +} + +ATF_TC_CLEANUP(pathconf_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(lpathconf_success); +ATF_TC_HEAD(lpathconf_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "lpathconf(2) call"); +} + +ATF_TC_BODY(lpathconf_success, tc) +{ + /* Symbolic link needs to exist to call lpathconf(2) */ + ATF_REQUIRE_EQ(0, symlink("symlink", path)); + FILE *pipefd = setup(fds, auclass); + /* Get the maximum number of bytes of symlink's name */ + ATF_REQUIRE(lpathconf(path, _PC_SYMLINK_MAX) != -1); + check_audit(fds, successreg, pipefd); +} + +ATF_TC_CLEANUP(lpathconf_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(lpathconf_failure); +ATF_TC_HEAD(lpathconf_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "lpathconf(2) call"); +} + +ATF_TC_BODY(lpathconf_failure, tc) +{ + FILE *pipefd = setup(fds, auclass); + /* Failure reason: symbolic link does not exist */ + ATF_REQUIRE_EQ(-1, lpathconf(errpath, _PC_SYMLINK_MAX)); + check_audit(fds, failurereg, pipefd); +} + +ATF_TC_CLEANUP(lpathconf_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(fpathconf_success); +ATF_TC_HEAD(fpathconf_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "fpathconf(2) call"); +} + +ATF_TC_BODY(fpathconf_success, tc) +{ + pid = getpid(); + snprintf(extregex, sizeof(extregex), "fpathconf.*%d.*success", pid); + + /* File needs to exist to call fpathconf(2) */ + ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); + FILE *pipefd = setup(fds, auclass); + /* Get the maximum number of bytes of filename */ + ATF_REQUIRE(fpathconf(filedesc, _PC_NAME_MAX) != -1); + check_audit(fds, extregex, pipefd); + close(filedesc); +} + +ATF_TC_CLEANUP(fpathconf_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(fpathconf_failure); +ATF_TC_HEAD(fpathconf_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "fpathconf(2) call"); +} + +ATF_TC_BODY(fpathconf_failure, tc) +{ + FILE *pipefd = setup(fds, auclass); + const char *regex = "fpathconf.*return,failure : Bad file descriptor"; + /* Failure reason: Bad file descriptor */ + ATF_REQUIRE_EQ(-1, fpathconf(-1, _PC_NAME_MAX)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(fpathconf_failure, tc) +{ + cleanup(); +} + + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, stat_success); @@ -693,6 +831,13 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, eaccess_failure); ATF_TP_ADD_TC(tp, faccessat_success); ATF_TP_ADD_TC(tp, faccessat_failure); + + ATF_TP_ADD_TC(tp, pathconf_success); + ATF_TP_ADD_TC(tp, pathconf_failure); + ATF_TP_ADD_TC(tp, lpathconf_success); + ATF_TP_ADD_TC(tp, lpathconf_failure); + ATF_TP_ADD_TC(tp, fpathconf_success); + ATF_TP_ADD_TC(tp, fpathconf_failure); return (atf_no_error()); }