16d203d2dSAlan Somers /*- 26d203d2dSAlan Somers * Copyright (c) 2018 Aniket Pandey 36d203d2dSAlan Somers * 46d203d2dSAlan Somers * Redistribution and use in source and binary forms, with or without 56d203d2dSAlan Somers * modification, are permitted provided that the following conditions 66d203d2dSAlan Somers * are met: 76d203d2dSAlan Somers * 1. Redistributions of source code must retain the above copyright 86d203d2dSAlan Somers * notice, this list of conditions and the following disclaimer. 96d203d2dSAlan Somers * 2. Redistributions in binary form must reproduce the above copyright 106d203d2dSAlan Somers * notice, this list of conditions and the following disclaimer in the 116d203d2dSAlan Somers * documentation and/or other materials provided with the distribution. 126d203d2dSAlan Somers * 136d203d2dSAlan Somers * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 146d203d2dSAlan Somers * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 156d203d2dSAlan Somers * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 166d203d2dSAlan Somers * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 176d203d2dSAlan Somers * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 186d203d2dSAlan Somers * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 196d203d2dSAlan Somers * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 206d203d2dSAlan Somers * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 216d203d2dSAlan Somers * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 226d203d2dSAlan Somers * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 236d203d2dSAlan Somers * SUCH DAMAGE. 246d203d2dSAlan Somers * 256d203d2dSAlan Somers * $FreeBSD$ 266d203d2dSAlan Somers */ 276d203d2dSAlan Somers 28*844fc5ebSAlan Somers #include <sys/types.h> 29*844fc5ebSAlan Somers #include <sys/extattr.h> 306d203d2dSAlan Somers #include <sys/file.h> 3128845213SAlan Somers #include <sys/stat.h> 326d203d2dSAlan Somers 336d203d2dSAlan Somers #include <atf-c.h> 346d203d2dSAlan Somers #include <fcntl.h> 356d203d2dSAlan Somers #include <unistd.h> 366d203d2dSAlan Somers 376d203d2dSAlan Somers #include "utils.h" 386d203d2dSAlan Somers 396d203d2dSAlan Somers static pid_t pid; 405c9a4738SAlan Somers static uid_t uid = -1; 415c9a4738SAlan Somers static gid_t gid = -1; 42*844fc5ebSAlan Somers static int filedesc, retval; 436d203d2dSAlan Somers static struct pollfd fds[1]; 446d203d2dSAlan Somers static mode_t mode = 0777; 456d203d2dSAlan Somers static char extregex[80]; 46*844fc5ebSAlan Somers static const char *buff = "ezio"; 476d203d2dSAlan Somers static const char *auclass = "fm"; 48*844fc5ebSAlan Somers static const char *name = "authorname"; 496d203d2dSAlan Somers static const char *path = "fileforaudit"; 5028845213SAlan Somers static const char *errpath = "adirhasnoname/fileforaudit"; 5128845213SAlan Somers static const char *successreg = "fileforaudit.*return,success"; 5228845213SAlan Somers static const char *failurereg = "fileforaudit.*return,failure"; 536d203d2dSAlan Somers 546d203d2dSAlan Somers 556d203d2dSAlan Somers ATF_TC_WITH_CLEANUP(flock_success); 566d203d2dSAlan Somers ATF_TC_HEAD(flock_success, tc) 576d203d2dSAlan Somers { 586d203d2dSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 596d203d2dSAlan Somers "flock(2) call"); 606d203d2dSAlan Somers } 616d203d2dSAlan Somers 626d203d2dSAlan Somers ATF_TC_BODY(flock_success, tc) 636d203d2dSAlan Somers { 646d203d2dSAlan Somers pid = getpid(); 656d203d2dSAlan Somers snprintf(extregex, sizeof(extregex), "flock.*%d.*return,success", pid); 666d203d2dSAlan Somers 676d203d2dSAlan Somers /* File needs to exist to call flock(2) */ 686d203d2dSAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 696d203d2dSAlan Somers FILE *pipefd = setup(fds, auclass); 706d203d2dSAlan Somers ATF_REQUIRE_EQ(0, flock(filedesc, LOCK_SH)); 716d203d2dSAlan Somers check_audit(fds, extregex, pipefd); 726d203d2dSAlan Somers close(filedesc); 736d203d2dSAlan Somers } 746d203d2dSAlan Somers 756d203d2dSAlan Somers ATF_TC_CLEANUP(flock_success, tc) 766d203d2dSAlan Somers { 776d203d2dSAlan Somers cleanup(); 786d203d2dSAlan Somers } 796d203d2dSAlan Somers 806d203d2dSAlan Somers 816d203d2dSAlan Somers ATF_TC_WITH_CLEANUP(flock_failure); 826d203d2dSAlan Somers ATF_TC_HEAD(flock_failure, tc) 836d203d2dSAlan Somers { 846d203d2dSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 856d203d2dSAlan Somers "flock(2) call"); 866d203d2dSAlan Somers } 876d203d2dSAlan Somers 886d203d2dSAlan Somers ATF_TC_BODY(flock_failure, tc) 896d203d2dSAlan Somers { 906d203d2dSAlan Somers const char *regex = "flock.*return,failure : Bad file descriptor"; 916d203d2dSAlan Somers FILE *pipefd = setup(fds, auclass); 926d203d2dSAlan Somers ATF_REQUIRE_EQ(-1, flock(-1, LOCK_SH)); 936d203d2dSAlan Somers check_audit(fds, regex, pipefd); 946d203d2dSAlan Somers } 956d203d2dSAlan Somers 966d203d2dSAlan Somers ATF_TC_CLEANUP(flock_failure, tc) 976d203d2dSAlan Somers { 986d203d2dSAlan Somers cleanup(); 996d203d2dSAlan Somers } 1006d203d2dSAlan Somers 1016d203d2dSAlan Somers 1026d203d2dSAlan Somers ATF_TC_WITH_CLEANUP(fcntl_success); 1036d203d2dSAlan Somers ATF_TC_HEAD(fcntl_success, tc) 1046d203d2dSAlan Somers { 1056d203d2dSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 1066d203d2dSAlan Somers "fcntl(2) call"); 1076d203d2dSAlan Somers } 1086d203d2dSAlan Somers 1096d203d2dSAlan Somers ATF_TC_BODY(fcntl_success, tc) 1106d203d2dSAlan Somers { 1116d203d2dSAlan Somers int flagstatus; 1126d203d2dSAlan Somers /* File needs to exist to call fcntl(2) */ 1136d203d2dSAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 1146d203d2dSAlan Somers FILE *pipefd = setup(fds, auclass); 1156d203d2dSAlan Somers 1166d203d2dSAlan Somers /* Retrieve the status flags of 'filedesc' and store it in flagstatus */ 1176d203d2dSAlan Somers ATF_REQUIRE((flagstatus = fcntl(filedesc, F_GETFL, 0)) != -1); 1186d203d2dSAlan Somers snprintf(extregex, sizeof(extregex), 1196d203d2dSAlan Somers "fcntl.*return,success,%d", flagstatus); 1206d203d2dSAlan Somers check_audit(fds, extregex, pipefd); 1216d203d2dSAlan Somers close(filedesc); 1226d203d2dSAlan Somers } 1236d203d2dSAlan Somers 1246d203d2dSAlan Somers ATF_TC_CLEANUP(fcntl_success, tc) 1256d203d2dSAlan Somers { 1266d203d2dSAlan Somers cleanup(); 1276d203d2dSAlan Somers } 1286d203d2dSAlan Somers 1296d203d2dSAlan Somers 1306d203d2dSAlan Somers ATF_TC_WITH_CLEANUP(fcntl_failure); 1316d203d2dSAlan Somers ATF_TC_HEAD(fcntl_failure, tc) 1326d203d2dSAlan Somers { 1336d203d2dSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 1346d203d2dSAlan Somers "fcntl(2) call"); 1356d203d2dSAlan Somers } 1366d203d2dSAlan Somers 1376d203d2dSAlan Somers ATF_TC_BODY(fcntl_failure, tc) 1386d203d2dSAlan Somers { 1396d203d2dSAlan Somers const char *regex = "fcntl.*return,failure : Bad file descriptor"; 1406d203d2dSAlan Somers FILE *pipefd = setup(fds, auclass); 1416d203d2dSAlan Somers ATF_REQUIRE_EQ(-1, fcntl(-1, F_GETFL, 0)); 1426d203d2dSAlan Somers check_audit(fds, regex, pipefd); 1436d203d2dSAlan Somers } 1446d203d2dSAlan Somers 1456d203d2dSAlan Somers ATF_TC_CLEANUP(fcntl_failure, tc) 1466d203d2dSAlan Somers { 1476d203d2dSAlan Somers cleanup(); 1486d203d2dSAlan Somers } 1496d203d2dSAlan Somers 1506d203d2dSAlan Somers 1516d203d2dSAlan Somers ATF_TC_WITH_CLEANUP(fsync_success); 1526d203d2dSAlan Somers ATF_TC_HEAD(fsync_success, tc) 1536d203d2dSAlan Somers { 1546d203d2dSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 1556d203d2dSAlan Somers "fsync(2) call"); 1566d203d2dSAlan Somers } 1576d203d2dSAlan Somers 1586d203d2dSAlan Somers ATF_TC_BODY(fsync_success, tc) 1596d203d2dSAlan Somers { 1606d203d2dSAlan Somers pid = getpid(); 1616d203d2dSAlan Somers snprintf(extregex, sizeof(extregex), "fsync.*%d.*return,success", pid); 1626d203d2dSAlan Somers 1636d203d2dSAlan Somers /* File needs to exist to call fsync(2) */ 1646d203d2dSAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 1656d203d2dSAlan Somers FILE *pipefd = setup(fds, auclass); 1666d203d2dSAlan Somers ATF_REQUIRE_EQ(0, fsync(filedesc)); 1676d203d2dSAlan Somers check_audit(fds, extregex, pipefd); 1686d203d2dSAlan Somers close(filedesc); 1696d203d2dSAlan Somers } 1706d203d2dSAlan Somers 1716d203d2dSAlan Somers ATF_TC_CLEANUP(fsync_success, tc) 1726d203d2dSAlan Somers { 1736d203d2dSAlan Somers cleanup(); 1746d203d2dSAlan Somers } 1756d203d2dSAlan Somers 1766d203d2dSAlan Somers 1776d203d2dSAlan Somers ATF_TC_WITH_CLEANUP(fsync_failure); 1786d203d2dSAlan Somers ATF_TC_HEAD(fsync_failure, tc) 1796d203d2dSAlan Somers { 1806d203d2dSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 1816d203d2dSAlan Somers "fsync(2) call"); 1826d203d2dSAlan Somers } 1836d203d2dSAlan Somers 1846d203d2dSAlan Somers ATF_TC_BODY(fsync_failure, tc) 1856d203d2dSAlan Somers { 1866d203d2dSAlan Somers const char *regex = "fsync.*return,failure : Bad file descriptor"; 1876d203d2dSAlan Somers FILE *pipefd = setup(fds, auclass); 1886d203d2dSAlan Somers /* Failure reason: Invalid file descriptor */ 1896d203d2dSAlan Somers ATF_REQUIRE_EQ(-1, fsync(-1)); 1906d203d2dSAlan Somers check_audit(fds, regex, pipefd); 1916d203d2dSAlan Somers } 1926d203d2dSAlan Somers 1936d203d2dSAlan Somers ATF_TC_CLEANUP(fsync_failure, tc) 1946d203d2dSAlan Somers { 1956d203d2dSAlan Somers cleanup(); 1966d203d2dSAlan Somers } 1976d203d2dSAlan Somers 1986d203d2dSAlan Somers 19928845213SAlan Somers ATF_TC_WITH_CLEANUP(chmod_success); 20028845213SAlan Somers ATF_TC_HEAD(chmod_success, tc) 20128845213SAlan Somers { 20228845213SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 20328845213SAlan Somers "chmod(2) call"); 20428845213SAlan Somers } 20528845213SAlan Somers 20628845213SAlan Somers ATF_TC_BODY(chmod_success, tc) 20728845213SAlan Somers { 20828845213SAlan Somers /* File needs to exist to call chmod(2) */ 20928845213SAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 21028845213SAlan Somers FILE *pipefd = setup(fds, auclass); 21128845213SAlan Somers ATF_REQUIRE_EQ(0, chmod(path, mode)); 21228845213SAlan Somers check_audit(fds, successreg, pipefd); 21328845213SAlan Somers close(filedesc); 21428845213SAlan Somers } 21528845213SAlan Somers 21628845213SAlan Somers ATF_TC_CLEANUP(chmod_success, tc) 21728845213SAlan Somers { 21828845213SAlan Somers cleanup(); 21928845213SAlan Somers } 22028845213SAlan Somers 22128845213SAlan Somers 22228845213SAlan Somers ATF_TC_WITH_CLEANUP(chmod_failure); 22328845213SAlan Somers ATF_TC_HEAD(chmod_failure, tc) 22428845213SAlan Somers { 22528845213SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 22628845213SAlan Somers "chmod(2) call"); 22728845213SAlan Somers } 22828845213SAlan Somers 22928845213SAlan Somers ATF_TC_BODY(chmod_failure, tc) 23028845213SAlan Somers { 23128845213SAlan Somers FILE *pipefd = setup(fds, auclass); 23228845213SAlan Somers /* Failure reason: file does not exist */ 23328845213SAlan Somers ATF_REQUIRE_EQ(-1, chmod(errpath, mode)); 23428845213SAlan Somers check_audit(fds, failurereg, pipefd); 23528845213SAlan Somers } 23628845213SAlan Somers 23728845213SAlan Somers ATF_TC_CLEANUP(chmod_failure, tc) 23828845213SAlan Somers { 23928845213SAlan Somers cleanup(); 24028845213SAlan Somers } 24128845213SAlan Somers 24228845213SAlan Somers 24328845213SAlan Somers ATF_TC_WITH_CLEANUP(fchmod_success); 24428845213SAlan Somers ATF_TC_HEAD(fchmod_success, tc) 24528845213SAlan Somers { 24628845213SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 24728845213SAlan Somers "fchmod(2) call"); 24828845213SAlan Somers } 24928845213SAlan Somers 25028845213SAlan Somers ATF_TC_BODY(fchmod_success, tc) 25128845213SAlan Somers { 25228845213SAlan Somers pid = getpid(); 25328845213SAlan Somers snprintf(extregex, sizeof(extregex), "fchmod.*%d.*return,success", pid); 25428845213SAlan Somers 25528845213SAlan Somers /* File needs to exist to call fchmod(2) */ 25628845213SAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 25728845213SAlan Somers FILE *pipefd = setup(fds, auclass); 25828845213SAlan Somers ATF_REQUIRE_EQ(0, fchmod(filedesc, mode)); 25928845213SAlan Somers check_audit(fds, extregex, pipefd); 26028845213SAlan Somers close(filedesc); 26128845213SAlan Somers } 26228845213SAlan Somers 26328845213SAlan Somers ATF_TC_CLEANUP(fchmod_success, tc) 26428845213SAlan Somers { 26528845213SAlan Somers cleanup(); 26628845213SAlan Somers } 26728845213SAlan Somers 26828845213SAlan Somers 26928845213SAlan Somers ATF_TC_WITH_CLEANUP(fchmod_failure); 27028845213SAlan Somers ATF_TC_HEAD(fchmod_failure, tc) 27128845213SAlan Somers { 27228845213SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 27328845213SAlan Somers "fchmod(2) call"); 27428845213SAlan Somers } 27528845213SAlan Somers 27628845213SAlan Somers ATF_TC_BODY(fchmod_failure, tc) 27728845213SAlan Somers { 27828845213SAlan Somers const char *regex = "fchmod.*return,failure : Bad file descriptor"; 27928845213SAlan Somers FILE *pipefd = setup(fds, auclass); 28028845213SAlan Somers /* Failure reason: Invalid file descriptor */ 28128845213SAlan Somers ATF_REQUIRE_EQ(-1, fchmod(-1, mode)); 28228845213SAlan Somers check_audit(fds, regex, pipefd); 28328845213SAlan Somers } 28428845213SAlan Somers 28528845213SAlan Somers ATF_TC_CLEANUP(fchmod_failure, tc) 28628845213SAlan Somers { 28728845213SAlan Somers cleanup(); 28828845213SAlan Somers } 28928845213SAlan Somers 29028845213SAlan Somers 29128845213SAlan Somers ATF_TC_WITH_CLEANUP(lchmod_success); 29228845213SAlan Somers ATF_TC_HEAD(lchmod_success, tc) 29328845213SAlan Somers { 29428845213SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 29528845213SAlan Somers "lchmod(2) call"); 29628845213SAlan Somers } 29728845213SAlan Somers 29828845213SAlan Somers ATF_TC_BODY(lchmod_success, tc) 29928845213SAlan Somers { 30028845213SAlan Somers /* Symbolic link needs to exist to call lchmod(2) */ 30128845213SAlan Somers ATF_REQUIRE_EQ(0, symlink("symlink", path)); 30228845213SAlan Somers FILE *pipefd = setup(fds, auclass); 30328845213SAlan Somers ATF_REQUIRE_EQ(0, lchmod(path, mode)); 30428845213SAlan Somers check_audit(fds, successreg, pipefd); 30528845213SAlan Somers } 30628845213SAlan Somers 30728845213SAlan Somers ATF_TC_CLEANUP(lchmod_success, tc) 30828845213SAlan Somers { 30928845213SAlan Somers cleanup(); 31028845213SAlan Somers } 31128845213SAlan Somers 31228845213SAlan Somers 31328845213SAlan Somers ATF_TC_WITH_CLEANUP(lchmod_failure); 31428845213SAlan Somers ATF_TC_HEAD(lchmod_failure, tc) 31528845213SAlan Somers { 31628845213SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 31728845213SAlan Somers "lchmod(2) call"); 31828845213SAlan Somers } 31928845213SAlan Somers 32028845213SAlan Somers ATF_TC_BODY(lchmod_failure, tc) 32128845213SAlan Somers { 32228845213SAlan Somers FILE *pipefd = setup(fds, auclass); 32328845213SAlan Somers /* Failure reason: file does not exist */ 32428845213SAlan Somers ATF_REQUIRE_EQ(-1, lchmod(errpath, mode)); 32528845213SAlan Somers check_audit(fds, failurereg, pipefd); 32628845213SAlan Somers } 32728845213SAlan Somers 32828845213SAlan Somers ATF_TC_CLEANUP(lchmod_failure, tc) 32928845213SAlan Somers { 33028845213SAlan Somers cleanup(); 33128845213SAlan Somers } 33228845213SAlan Somers 33328845213SAlan Somers 33428845213SAlan Somers ATF_TC_WITH_CLEANUP(fchmodat_success); 33528845213SAlan Somers ATF_TC_HEAD(fchmodat_success, tc) 33628845213SAlan Somers { 33728845213SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 33828845213SAlan Somers "fchmodat(2) call"); 33928845213SAlan Somers } 34028845213SAlan Somers 34128845213SAlan Somers ATF_TC_BODY(fchmodat_success, tc) 34228845213SAlan Somers { 34328845213SAlan Somers /* File needs to exist to call fchmodat(2) */ 34428845213SAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 34528845213SAlan Somers FILE *pipefd = setup(fds, auclass); 34628845213SAlan Somers ATF_REQUIRE_EQ(0, fchmodat(AT_FDCWD, path, mode, 0)); 34728845213SAlan Somers check_audit(fds, successreg, pipefd); 34828845213SAlan Somers close(filedesc); 34928845213SAlan Somers } 35028845213SAlan Somers 35128845213SAlan Somers ATF_TC_CLEANUP(fchmodat_success, tc) 35228845213SAlan Somers { 35328845213SAlan Somers cleanup(); 35428845213SAlan Somers } 35528845213SAlan Somers 35628845213SAlan Somers 35728845213SAlan Somers ATF_TC_WITH_CLEANUP(fchmodat_failure); 35828845213SAlan Somers ATF_TC_HEAD(fchmodat_failure, tc) 35928845213SAlan Somers { 36028845213SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 36128845213SAlan Somers "fchmodat(2) call"); 36228845213SAlan Somers } 36328845213SAlan Somers 36428845213SAlan Somers ATF_TC_BODY(fchmodat_failure, tc) 36528845213SAlan Somers { 36628845213SAlan Somers FILE *pipefd = setup(fds, auclass); 36728845213SAlan Somers /* Failure reason: file does not exist */ 36828845213SAlan Somers ATF_REQUIRE_EQ(-1, fchmodat(AT_FDCWD, errpath, mode, 0)); 36928845213SAlan Somers check_audit(fds, failurereg, pipefd); 37028845213SAlan Somers } 37128845213SAlan Somers 37228845213SAlan Somers ATF_TC_CLEANUP(fchmodat_failure, tc) 37328845213SAlan Somers { 37428845213SAlan Somers cleanup(); 37528845213SAlan Somers } 37628845213SAlan Somers 37728845213SAlan Somers 3785c9a4738SAlan Somers ATF_TC_WITH_CLEANUP(chown_success); 3795c9a4738SAlan Somers ATF_TC_HEAD(chown_success, tc) 3805c9a4738SAlan Somers { 3815c9a4738SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 3825c9a4738SAlan Somers "chown(2) call"); 3835c9a4738SAlan Somers } 3845c9a4738SAlan Somers 3855c9a4738SAlan Somers ATF_TC_BODY(chown_success, tc) 3865c9a4738SAlan Somers { 3875c9a4738SAlan Somers /* File needs to exist to call chown(2) */ 3885c9a4738SAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 3895c9a4738SAlan Somers FILE *pipefd = setup(fds, auclass); 3905c9a4738SAlan Somers ATF_REQUIRE_EQ(0, chown(path, uid, gid)); 3915c9a4738SAlan Somers check_audit(fds, successreg, pipefd); 3925c9a4738SAlan Somers close(filedesc); 3935c9a4738SAlan Somers } 3945c9a4738SAlan Somers 3955c9a4738SAlan Somers ATF_TC_CLEANUP(chown_success, tc) 3965c9a4738SAlan Somers { 3975c9a4738SAlan Somers cleanup(); 3985c9a4738SAlan Somers } 3995c9a4738SAlan Somers 4005c9a4738SAlan Somers 4015c9a4738SAlan Somers ATF_TC_WITH_CLEANUP(chown_failure); 4025c9a4738SAlan Somers ATF_TC_HEAD(chown_failure, tc) 4035c9a4738SAlan Somers { 4045c9a4738SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 4055c9a4738SAlan Somers "chown(2) call"); 4065c9a4738SAlan Somers } 4075c9a4738SAlan Somers 4085c9a4738SAlan Somers ATF_TC_BODY(chown_failure, tc) 4095c9a4738SAlan Somers { 4105c9a4738SAlan Somers FILE *pipefd = setup(fds, auclass); 4115c9a4738SAlan Somers /* Failure reason: file does not exist */ 4125c9a4738SAlan Somers ATF_REQUIRE_EQ(-1, chown(errpath, uid, gid)); 4135c9a4738SAlan Somers check_audit(fds, failurereg, pipefd); 4145c9a4738SAlan Somers } 4155c9a4738SAlan Somers 4165c9a4738SAlan Somers ATF_TC_CLEANUP(chown_failure, tc) 4175c9a4738SAlan Somers { 4185c9a4738SAlan Somers cleanup(); 4195c9a4738SAlan Somers } 4205c9a4738SAlan Somers 4215c9a4738SAlan Somers 4225c9a4738SAlan Somers ATF_TC_WITH_CLEANUP(fchown_success); 4235c9a4738SAlan Somers ATF_TC_HEAD(fchown_success, tc) 4245c9a4738SAlan Somers { 4255c9a4738SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 4265c9a4738SAlan Somers "fchown(2) call"); 4275c9a4738SAlan Somers } 4285c9a4738SAlan Somers 4295c9a4738SAlan Somers ATF_TC_BODY(fchown_success, tc) 4305c9a4738SAlan Somers { 4315c9a4738SAlan Somers pid = getpid(); 4325c9a4738SAlan Somers snprintf(extregex, sizeof(extregex), "fchown.*%d.*return,success", pid); 4335c9a4738SAlan Somers 4345c9a4738SAlan Somers /* File needs to exist to call fchown(2) */ 4355c9a4738SAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 4365c9a4738SAlan Somers FILE *pipefd = setup(fds, auclass); 4375c9a4738SAlan Somers ATF_REQUIRE_EQ(0, fchown(filedesc, uid, gid)); 4385c9a4738SAlan Somers check_audit(fds, extregex, pipefd); 4395c9a4738SAlan Somers close(filedesc); 4405c9a4738SAlan Somers } 4415c9a4738SAlan Somers 4425c9a4738SAlan Somers ATF_TC_CLEANUP(fchown_success, tc) 4435c9a4738SAlan Somers { 4445c9a4738SAlan Somers cleanup(); 4455c9a4738SAlan Somers } 4465c9a4738SAlan Somers 4475c9a4738SAlan Somers 4485c9a4738SAlan Somers ATF_TC_WITH_CLEANUP(fchown_failure); 4495c9a4738SAlan Somers ATF_TC_HEAD(fchown_failure, tc) 4505c9a4738SAlan Somers { 4515c9a4738SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 4525c9a4738SAlan Somers "fchown(2) call"); 4535c9a4738SAlan Somers } 4545c9a4738SAlan Somers 4555c9a4738SAlan Somers ATF_TC_BODY(fchown_failure, tc) 4565c9a4738SAlan Somers { 4575c9a4738SAlan Somers const char *regex = "fchown.*return,failure : Bad file descriptor"; 4585c9a4738SAlan Somers FILE *pipefd = setup(fds, auclass); 4595c9a4738SAlan Somers /* Failure reason: Invalid file descriptor */ 4605c9a4738SAlan Somers ATF_REQUIRE_EQ(-1, fchown(-1, uid, gid)); 4615c9a4738SAlan Somers check_audit(fds, regex, pipefd); 4625c9a4738SAlan Somers } 4635c9a4738SAlan Somers 4645c9a4738SAlan Somers ATF_TC_CLEANUP(fchown_failure, tc) 4655c9a4738SAlan Somers { 4665c9a4738SAlan Somers cleanup(); 4675c9a4738SAlan Somers } 4685c9a4738SAlan Somers 4695c9a4738SAlan Somers 4705c9a4738SAlan Somers ATF_TC_WITH_CLEANUP(lchown_success); 4715c9a4738SAlan Somers ATF_TC_HEAD(lchown_success, tc) 4725c9a4738SAlan Somers { 4735c9a4738SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 4745c9a4738SAlan Somers "lchown(2) call"); 4755c9a4738SAlan Somers } 4765c9a4738SAlan Somers 4775c9a4738SAlan Somers ATF_TC_BODY(lchown_success, tc) 4785c9a4738SAlan Somers { 4795c9a4738SAlan Somers /* Symbolic link needs to exist to call lchown(2) */ 4805c9a4738SAlan Somers ATF_REQUIRE_EQ(0, symlink("symlink", path)); 4815c9a4738SAlan Somers FILE *pipefd = setup(fds, auclass); 4825c9a4738SAlan Somers ATF_REQUIRE_EQ(0, lchown(path, uid, gid)); 4835c9a4738SAlan Somers check_audit(fds, successreg, pipefd); 4845c9a4738SAlan Somers } 4855c9a4738SAlan Somers 4865c9a4738SAlan Somers ATF_TC_CLEANUP(lchown_success, tc) 4875c9a4738SAlan Somers { 4885c9a4738SAlan Somers cleanup(); 4895c9a4738SAlan Somers } 4905c9a4738SAlan Somers 4915c9a4738SAlan Somers 4925c9a4738SAlan Somers ATF_TC_WITH_CLEANUP(lchown_failure); 4935c9a4738SAlan Somers ATF_TC_HEAD(lchown_failure, tc) 4945c9a4738SAlan Somers { 4955c9a4738SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 4965c9a4738SAlan Somers "lchown(2) call"); 4975c9a4738SAlan Somers } 4985c9a4738SAlan Somers 4995c9a4738SAlan Somers ATF_TC_BODY(lchown_failure, tc) 5005c9a4738SAlan Somers { 5015c9a4738SAlan Somers FILE *pipefd = setup(fds, auclass); 5025c9a4738SAlan Somers /* Failure reason: Symbolic link does not exist */ 5035c9a4738SAlan Somers ATF_REQUIRE_EQ(-1, lchown(errpath, uid, gid)); 5045c9a4738SAlan Somers check_audit(fds, failurereg, pipefd); 5055c9a4738SAlan Somers } 5065c9a4738SAlan Somers 5075c9a4738SAlan Somers ATF_TC_CLEANUP(lchown_failure, tc) 5085c9a4738SAlan Somers { 5095c9a4738SAlan Somers cleanup(); 5105c9a4738SAlan Somers } 5115c9a4738SAlan Somers 5125c9a4738SAlan Somers 5135c9a4738SAlan Somers ATF_TC_WITH_CLEANUP(fchownat_success); 5145c9a4738SAlan Somers ATF_TC_HEAD(fchownat_success, tc) 5155c9a4738SAlan Somers { 5165c9a4738SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 5175c9a4738SAlan Somers "fchownat(2) call"); 5185c9a4738SAlan Somers } 5195c9a4738SAlan Somers 5205c9a4738SAlan Somers ATF_TC_BODY(fchownat_success, tc) 5215c9a4738SAlan Somers { 5225c9a4738SAlan Somers /* File needs to exist to call fchownat(2) */ 5235c9a4738SAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 5245c9a4738SAlan Somers FILE *pipefd = setup(fds, auclass); 5255c9a4738SAlan Somers ATF_REQUIRE_EQ(0, fchownat(AT_FDCWD, path, uid, gid, 0)); 5265c9a4738SAlan Somers check_audit(fds, successreg, pipefd); 5275c9a4738SAlan Somers close(filedesc); 5285c9a4738SAlan Somers } 5295c9a4738SAlan Somers 5305c9a4738SAlan Somers ATF_TC_CLEANUP(fchownat_success, tc) 5315c9a4738SAlan Somers { 5325c9a4738SAlan Somers cleanup(); 5335c9a4738SAlan Somers } 5345c9a4738SAlan Somers 5355c9a4738SAlan Somers 5365c9a4738SAlan Somers ATF_TC_WITH_CLEANUP(fchownat_failure); 5375c9a4738SAlan Somers ATF_TC_HEAD(fchownat_failure, tc) 5385c9a4738SAlan Somers { 5395c9a4738SAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 5405c9a4738SAlan Somers "fchownat(2) call"); 5415c9a4738SAlan Somers } 5425c9a4738SAlan Somers 5435c9a4738SAlan Somers ATF_TC_BODY(fchownat_failure, tc) 5445c9a4738SAlan Somers { 5455c9a4738SAlan Somers FILE *pipefd = setup(fds, auclass); 5465c9a4738SAlan Somers /* Failure reason: file does not exist */ 5475c9a4738SAlan Somers ATF_REQUIRE_EQ(-1, fchownat(AT_FDCWD, errpath, uid, gid, 0)); 5485c9a4738SAlan Somers check_audit(fds, failurereg, pipefd); 5495c9a4738SAlan Somers } 5505c9a4738SAlan Somers 5515c9a4738SAlan Somers ATF_TC_CLEANUP(fchownat_failure, tc) 5525c9a4738SAlan Somers { 5535c9a4738SAlan Somers cleanup(); 5545c9a4738SAlan Somers } 5555c9a4738SAlan Somers 5565c9a4738SAlan Somers 55768e520feSAlan Somers ATF_TC_WITH_CLEANUP(chflags_success); 55868e520feSAlan Somers ATF_TC_HEAD(chflags_success, tc) 55968e520feSAlan Somers { 56068e520feSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 56168e520feSAlan Somers "chflags(2) call"); 56268e520feSAlan Somers } 56368e520feSAlan Somers 56468e520feSAlan Somers ATF_TC_BODY(chflags_success, tc) 56568e520feSAlan Somers { 56668e520feSAlan Somers /* File needs to exist to call chflags(2) */ 56768e520feSAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 56868e520feSAlan Somers FILE *pipefd = setup(fds, auclass); 56968e520feSAlan Somers ATF_REQUIRE_EQ(0, chflags(path, UF_OFFLINE)); 57068e520feSAlan Somers check_audit(fds, successreg, pipefd); 57168e520feSAlan Somers close(filedesc); 57268e520feSAlan Somers } 57368e520feSAlan Somers 57468e520feSAlan Somers ATF_TC_CLEANUP(chflags_success, tc) 57568e520feSAlan Somers { 57668e520feSAlan Somers cleanup(); 57768e520feSAlan Somers } 57868e520feSAlan Somers 57968e520feSAlan Somers 58068e520feSAlan Somers ATF_TC_WITH_CLEANUP(chflags_failure); 58168e520feSAlan Somers ATF_TC_HEAD(chflags_failure, tc) 58268e520feSAlan Somers { 58368e520feSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 58468e520feSAlan Somers "chflags(2) call"); 58568e520feSAlan Somers } 58668e520feSAlan Somers 58768e520feSAlan Somers ATF_TC_BODY(chflags_failure, tc) 58868e520feSAlan Somers { 58968e520feSAlan Somers FILE *pipefd = setup(fds, auclass); 59068e520feSAlan Somers /* Failure reason: file does not exist */ 59168e520feSAlan Somers ATF_REQUIRE_EQ(-1, chflags(errpath, UF_OFFLINE)); 59268e520feSAlan Somers check_audit(fds, failurereg, pipefd); 59368e520feSAlan Somers } 59468e520feSAlan Somers 59568e520feSAlan Somers ATF_TC_CLEANUP(chflags_failure, tc) 59668e520feSAlan Somers { 59768e520feSAlan Somers cleanup(); 59868e520feSAlan Somers } 59968e520feSAlan Somers 60068e520feSAlan Somers 60168e520feSAlan Somers ATF_TC_WITH_CLEANUP(fchflags_success); 60268e520feSAlan Somers ATF_TC_HEAD(fchflags_success, tc) 60368e520feSAlan Somers { 60468e520feSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 60568e520feSAlan Somers "fchflags(2) call"); 60668e520feSAlan Somers } 60768e520feSAlan Somers 60868e520feSAlan Somers ATF_TC_BODY(fchflags_success, tc) 60968e520feSAlan Somers { 61068e520feSAlan Somers pid = getpid(); 61168e520feSAlan Somers snprintf(extregex, sizeof(extregex), "fchflags.*%d.*ret.*success", pid); 61268e520feSAlan Somers /* File needs to exist to call fchflags(2) */ 61368e520feSAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 61468e520feSAlan Somers 61568e520feSAlan Somers FILE *pipefd = setup(fds, auclass); 61668e520feSAlan Somers ATF_REQUIRE_EQ(0, fchflags(filedesc, UF_OFFLINE)); 61768e520feSAlan Somers check_audit(fds, extregex, pipefd); 61868e520feSAlan Somers close(filedesc); 61968e520feSAlan Somers } 62068e520feSAlan Somers 62168e520feSAlan Somers ATF_TC_CLEANUP(fchflags_success, tc) 62268e520feSAlan Somers { 62368e520feSAlan Somers cleanup(); 62468e520feSAlan Somers } 62568e520feSAlan Somers 62668e520feSAlan Somers 62768e520feSAlan Somers ATF_TC_WITH_CLEANUP(fchflags_failure); 62868e520feSAlan Somers ATF_TC_HEAD(fchflags_failure, tc) 62968e520feSAlan Somers { 63068e520feSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 63168e520feSAlan Somers "fchflags(2) call"); 63268e520feSAlan Somers } 63368e520feSAlan Somers 63468e520feSAlan Somers ATF_TC_BODY(fchflags_failure, tc) 63568e520feSAlan Somers { 63668e520feSAlan Somers const char *regex = "fchflags.*return,failure : Bad file descriptor"; 63768e520feSAlan Somers FILE *pipefd = setup(fds, auclass); 63868e520feSAlan Somers /* Failure reason: Invalid file descriptor */ 63968e520feSAlan Somers ATF_REQUIRE_EQ(-1, fchflags(-1, UF_OFFLINE)); 64068e520feSAlan Somers check_audit(fds, regex, pipefd); 64168e520feSAlan Somers } 64268e520feSAlan Somers 64368e520feSAlan Somers ATF_TC_CLEANUP(fchflags_failure, tc) 64468e520feSAlan Somers { 64568e520feSAlan Somers cleanup(); 64668e520feSAlan Somers } 64768e520feSAlan Somers 64868e520feSAlan Somers 64968e520feSAlan Somers ATF_TC_WITH_CLEANUP(lchflags_success); 65068e520feSAlan Somers ATF_TC_HEAD(lchflags_success, tc) 65168e520feSAlan Somers { 65268e520feSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 65368e520feSAlan Somers "lchflags(2) call"); 65468e520feSAlan Somers } 65568e520feSAlan Somers 65668e520feSAlan Somers ATF_TC_BODY(lchflags_success, tc) 65768e520feSAlan Somers { 65868e520feSAlan Somers /* Symbolic link needs to exist to call lchflags(2) */ 65968e520feSAlan Somers ATF_REQUIRE_EQ(0, symlink("symlink", path)); 66068e520feSAlan Somers FILE *pipefd = setup(fds, auclass); 66168e520feSAlan Somers ATF_REQUIRE_EQ(0, lchflags(path, UF_OFFLINE)); 66268e520feSAlan Somers check_audit(fds, successreg, pipefd); 66368e520feSAlan Somers } 66468e520feSAlan Somers 66568e520feSAlan Somers ATF_TC_CLEANUP(lchflags_success, tc) 66668e520feSAlan Somers { 66768e520feSAlan Somers cleanup(); 66868e520feSAlan Somers } 66968e520feSAlan Somers 67068e520feSAlan Somers 67168e520feSAlan Somers ATF_TC_WITH_CLEANUP(lchflags_failure); 67268e520feSAlan Somers ATF_TC_HEAD(lchflags_failure, tc) 67368e520feSAlan Somers { 67468e520feSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 67568e520feSAlan Somers "lchflags(2) call"); 67668e520feSAlan Somers } 67768e520feSAlan Somers 67868e520feSAlan Somers ATF_TC_BODY(lchflags_failure, tc) 67968e520feSAlan Somers { 68068e520feSAlan Somers FILE *pipefd = setup(fds, auclass); 68168e520feSAlan Somers /* Failure reason: Symbolic link does not exist */ 68268e520feSAlan Somers ATF_REQUIRE_EQ(-1, lchflags(errpath, UF_OFFLINE)); 68368e520feSAlan Somers check_audit(fds, failurereg, pipefd); 68468e520feSAlan Somers } 68568e520feSAlan Somers 68668e520feSAlan Somers ATF_TC_CLEANUP(lchflags_failure, tc) 68768e520feSAlan Somers { 68868e520feSAlan Somers cleanup(); 68968e520feSAlan Somers } 69068e520feSAlan Somers 69168e520feSAlan Somers 692*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_set_file_success); 693*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_set_file_success, tc) 694*844fc5ebSAlan Somers { 695*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 696*844fc5ebSAlan Somers "extattr_set_file(2) call"); 697*844fc5ebSAlan Somers } 698*844fc5ebSAlan Somers 699*844fc5ebSAlan Somers ATF_TC_BODY(extattr_set_file_success, tc) 700*844fc5ebSAlan Somers { 701*844fc5ebSAlan Somers /* File needs to exist to call extattr_set_file(2) */ 702*844fc5ebSAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 703*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 704*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 705*844fc5ebSAlan Somers "extattr_set_file.*%s.*%s.*return,success", path, name); 706*844fc5ebSAlan Somers 707*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 708*844fc5ebSAlan Somers ATF_REQUIRE_EQ(sizeof(buff), extattr_set_file(path, 709*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); 710*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 711*844fc5ebSAlan Somers close(filedesc); 712*844fc5ebSAlan Somers } 713*844fc5ebSAlan Somers 714*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_set_file_success, tc) 715*844fc5ebSAlan Somers { 716*844fc5ebSAlan Somers cleanup(); 717*844fc5ebSAlan Somers } 718*844fc5ebSAlan Somers 719*844fc5ebSAlan Somers 720*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_set_file_failure); 721*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_set_file_failure, tc) 722*844fc5ebSAlan Somers { 723*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 724*844fc5ebSAlan Somers "extattr_set_file(2) call"); 725*844fc5ebSAlan Somers } 726*844fc5ebSAlan Somers 727*844fc5ebSAlan Somers ATF_TC_BODY(extattr_set_file_failure, tc) 728*844fc5ebSAlan Somers { 729*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 730*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 731*844fc5ebSAlan Somers "extattr_set_file.*%s.*%s.*failure", path, name); 732*844fc5ebSAlan Somers 733*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 734*844fc5ebSAlan Somers /* Failure reason: file does not exist */ 735*844fc5ebSAlan Somers ATF_REQUIRE_EQ(-1, extattr_set_file(path, 736*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name, NULL, 0)); 737*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 738*844fc5ebSAlan Somers } 739*844fc5ebSAlan Somers 740*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_set_file_failure, tc) 741*844fc5ebSAlan Somers { 742*844fc5ebSAlan Somers cleanup(); 743*844fc5ebSAlan Somers } 744*844fc5ebSAlan Somers 745*844fc5ebSAlan Somers 746*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_set_fd_success); 747*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_set_fd_success, tc) 748*844fc5ebSAlan Somers { 749*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 750*844fc5ebSAlan Somers "extattr_set_fd(2) call"); 751*844fc5ebSAlan Somers } 752*844fc5ebSAlan Somers 753*844fc5ebSAlan Somers ATF_TC_BODY(extattr_set_fd_success, tc) 754*844fc5ebSAlan Somers { 755*844fc5ebSAlan Somers /* File needs to exist to call extattr_set_fd(2) */ 756*844fc5ebSAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 757*844fc5ebSAlan Somers 758*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 759*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 760*844fc5ebSAlan Somers "extattr_set_fd.*%s.*return,success", name); 761*844fc5ebSAlan Somers 762*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 763*844fc5ebSAlan Somers ATF_REQUIRE_EQ(sizeof(buff), extattr_set_fd(filedesc, 764*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); 765*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 766*844fc5ebSAlan Somers close(filedesc); 767*844fc5ebSAlan Somers } 768*844fc5ebSAlan Somers 769*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_set_fd_success, tc) 770*844fc5ebSAlan Somers { 771*844fc5ebSAlan Somers cleanup(); 772*844fc5ebSAlan Somers } 773*844fc5ebSAlan Somers 774*844fc5ebSAlan Somers 775*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_set_fd_failure); 776*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_set_fd_failure, tc) 777*844fc5ebSAlan Somers { 778*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 779*844fc5ebSAlan Somers "extattr_set_fd(2) call"); 780*844fc5ebSAlan Somers } 781*844fc5ebSAlan Somers 782*844fc5ebSAlan Somers ATF_TC_BODY(extattr_set_fd_failure, tc) 783*844fc5ebSAlan Somers { 784*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 785*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 786*844fc5ebSAlan Somers "extattr_set_fd.*%s.*return,failure : Bad file descriptor", name); 787*844fc5ebSAlan Somers 788*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 789*844fc5ebSAlan Somers /* Failure reason: Invalid file descriptor */ 790*844fc5ebSAlan Somers ATF_REQUIRE_EQ(-1, extattr_set_fd(-1, 791*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name, NULL, 0)); 792*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 793*844fc5ebSAlan Somers } 794*844fc5ebSAlan Somers 795*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_set_fd_failure, tc) 796*844fc5ebSAlan Somers { 797*844fc5ebSAlan Somers cleanup(); 798*844fc5ebSAlan Somers } 799*844fc5ebSAlan Somers 800*844fc5ebSAlan Somers 801*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_set_link_success); 802*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_set_link_success, tc) 803*844fc5ebSAlan Somers { 804*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 805*844fc5ebSAlan Somers "extattr_set_link(2) call"); 806*844fc5ebSAlan Somers } 807*844fc5ebSAlan Somers 808*844fc5ebSAlan Somers ATF_TC_BODY(extattr_set_link_success, tc) 809*844fc5ebSAlan Somers { 810*844fc5ebSAlan Somers /* Symbolic link needs to exist to call extattr_set_link(2) */ 811*844fc5ebSAlan Somers ATF_REQUIRE_EQ(0, symlink("symlink", path)); 812*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 813*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 814*844fc5ebSAlan Somers "extattr_set_link.*%s.*%s.*return,success", path, name); 815*844fc5ebSAlan Somers 816*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 817*844fc5ebSAlan Somers ATF_REQUIRE_EQ(sizeof(buff), extattr_set_link(path, 818*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); 819*844fc5ebSAlan Somers 820*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 821*844fc5ebSAlan Somers } 822*844fc5ebSAlan Somers 823*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_set_link_success, tc) 824*844fc5ebSAlan Somers { 825*844fc5ebSAlan Somers cleanup(); 826*844fc5ebSAlan Somers } 827*844fc5ebSAlan Somers 828*844fc5ebSAlan Somers 829*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_set_link_failure); 830*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_set_link_failure, tc) 831*844fc5ebSAlan Somers { 832*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 833*844fc5ebSAlan Somers "extattr_set_link(2) call"); 834*844fc5ebSAlan Somers } 835*844fc5ebSAlan Somers 836*844fc5ebSAlan Somers ATF_TC_BODY(extattr_set_link_failure, tc) 837*844fc5ebSAlan Somers { 838*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 839*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 840*844fc5ebSAlan Somers "extattr_set_link.*%s.*%s.*failure", path, name); 841*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 842*844fc5ebSAlan Somers /* Failure reason: symbolic link does not exist */ 843*844fc5ebSAlan Somers ATF_REQUIRE_EQ(-1, extattr_set_link(path, 844*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name, NULL, 0)); 845*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 846*844fc5ebSAlan Somers } 847*844fc5ebSAlan Somers 848*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_set_link_failure, tc) 849*844fc5ebSAlan Somers { 850*844fc5ebSAlan Somers cleanup(); 851*844fc5ebSAlan Somers } 852*844fc5ebSAlan Somers 853*844fc5ebSAlan Somers 854*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_delete_file_success); 855*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_delete_file_success, tc) 856*844fc5ebSAlan Somers { 857*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 858*844fc5ebSAlan Somers "extattr_delete_file(2) call"); 859*844fc5ebSAlan Somers } 860*844fc5ebSAlan Somers 861*844fc5ebSAlan Somers ATF_TC_BODY(extattr_delete_file_success, tc) 862*844fc5ebSAlan Somers { 863*844fc5ebSAlan Somers /* File needs to exist to call extattr_delete_file(2) */ 864*844fc5ebSAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 865*844fc5ebSAlan Somers ATF_REQUIRE_EQ(sizeof(buff), extattr_set_file(path, 866*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); 867*844fc5ebSAlan Somers 868*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 869*844fc5ebSAlan Somers ATF_REQUIRE((retval = extattr_delete_file(path, 870*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name)) != -1); 871*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 872*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 873*844fc5ebSAlan Somers "extattr_delete_file.*%s.*return,success,%d", path, retval); 874*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 875*844fc5ebSAlan Somers close(filedesc); 876*844fc5ebSAlan Somers } 877*844fc5ebSAlan Somers 878*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_delete_file_success, tc) 879*844fc5ebSAlan Somers { 880*844fc5ebSAlan Somers cleanup(); 881*844fc5ebSAlan Somers } 882*844fc5ebSAlan Somers 883*844fc5ebSAlan Somers 884*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_delete_file_failure); 885*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_delete_file_failure, tc) 886*844fc5ebSAlan Somers { 887*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 888*844fc5ebSAlan Somers "extattr_delete_file(2) call"); 889*844fc5ebSAlan Somers } 890*844fc5ebSAlan Somers 891*844fc5ebSAlan Somers ATF_TC_BODY(extattr_delete_file_failure, tc) 892*844fc5ebSAlan Somers { 893*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 894*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 895*844fc5ebSAlan Somers "extattr_delete_file.*%s.*return,failure", path); 896*844fc5ebSAlan Somers 897*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 898*844fc5ebSAlan Somers /* Failure reason: file does not exist */ 899*844fc5ebSAlan Somers ATF_REQUIRE_EQ(-1, extattr_delete_file(path, 900*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name)); 901*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 902*844fc5ebSAlan Somers } 903*844fc5ebSAlan Somers 904*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_delete_file_failure, tc) 905*844fc5ebSAlan Somers { 906*844fc5ebSAlan Somers cleanup(); 907*844fc5ebSAlan Somers } 908*844fc5ebSAlan Somers 909*844fc5ebSAlan Somers 910*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_delete_fd_success); 911*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_delete_fd_success, tc) 912*844fc5ebSAlan Somers { 913*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 914*844fc5ebSAlan Somers "extattr_delete_fd(2) call"); 915*844fc5ebSAlan Somers } 916*844fc5ebSAlan Somers 917*844fc5ebSAlan Somers ATF_TC_BODY(extattr_delete_fd_success, tc) 918*844fc5ebSAlan Somers { 919*844fc5ebSAlan Somers /* File needs to exist to call extattr_delete_fd(2) */ 920*844fc5ebSAlan Somers ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); 921*844fc5ebSAlan Somers ATF_REQUIRE_EQ(sizeof(buff), extattr_set_file(path, 922*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); 923*844fc5ebSAlan Somers 924*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 925*844fc5ebSAlan Somers ATF_REQUIRE((retval = extattr_delete_fd(filedesc, 926*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name)) != -1); 927*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 928*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 929*844fc5ebSAlan Somers "extattr_delete_fd.*return,success,%d", retval); 930*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 931*844fc5ebSAlan Somers close(filedesc); 932*844fc5ebSAlan Somers } 933*844fc5ebSAlan Somers 934*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_delete_fd_success, tc) 935*844fc5ebSAlan Somers { 936*844fc5ebSAlan Somers cleanup(); 937*844fc5ebSAlan Somers } 938*844fc5ebSAlan Somers 939*844fc5ebSAlan Somers 940*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_delete_fd_failure); 941*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_delete_fd_failure, tc) 942*844fc5ebSAlan Somers { 943*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 944*844fc5ebSAlan Somers "extattr_delete_fd(2) call"); 945*844fc5ebSAlan Somers } 946*844fc5ebSAlan Somers 947*844fc5ebSAlan Somers ATF_TC_BODY(extattr_delete_fd_failure, tc) 948*844fc5ebSAlan Somers { 949*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 950*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 951*844fc5ebSAlan Somers "extattr_delete_fd.*return,failure : Bad file descriptor"); 952*844fc5ebSAlan Somers 953*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 954*844fc5ebSAlan Somers /* Failure reason: Invalid file descriptor */ 955*844fc5ebSAlan Somers ATF_REQUIRE_EQ(-1, extattr_delete_fd(-1, EXTATTR_NAMESPACE_USER, name)); 956*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 957*844fc5ebSAlan Somers } 958*844fc5ebSAlan Somers 959*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_delete_fd_failure, tc) 960*844fc5ebSAlan Somers { 961*844fc5ebSAlan Somers cleanup(); 962*844fc5ebSAlan Somers } 963*844fc5ebSAlan Somers 964*844fc5ebSAlan Somers 965*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_delete_link_success); 966*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_delete_link_success, tc) 967*844fc5ebSAlan Somers { 968*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " 969*844fc5ebSAlan Somers "extattr_delete_link(2) call"); 970*844fc5ebSAlan Somers } 971*844fc5ebSAlan Somers 972*844fc5ebSAlan Somers ATF_TC_BODY(extattr_delete_link_success, tc) 973*844fc5ebSAlan Somers { 974*844fc5ebSAlan Somers /* Symbolic link needs to exist to call extattr_delete_link(2) */ 975*844fc5ebSAlan Somers ATF_REQUIRE_EQ(0, symlink("symlink", path)); 976*844fc5ebSAlan Somers ATF_REQUIRE_EQ(sizeof(buff), extattr_set_link(path, 977*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); 978*844fc5ebSAlan Somers 979*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 980*844fc5ebSAlan Somers ATF_REQUIRE((retval = extattr_delete_link(path, 981*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name)) != -1); 982*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 983*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 984*844fc5ebSAlan Somers "extattr_delete_link.*%s.*return,success,%d", path, retval); 985*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 986*844fc5ebSAlan Somers } 987*844fc5ebSAlan Somers 988*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_delete_link_success, tc) 989*844fc5ebSAlan Somers { 990*844fc5ebSAlan Somers cleanup(); 991*844fc5ebSAlan Somers } 992*844fc5ebSAlan Somers 993*844fc5ebSAlan Somers 994*844fc5ebSAlan Somers ATF_TC_WITH_CLEANUP(extattr_delete_link_failure); 995*844fc5ebSAlan Somers ATF_TC_HEAD(extattr_delete_link_failure, tc) 996*844fc5ebSAlan Somers { 997*844fc5ebSAlan Somers atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " 998*844fc5ebSAlan Somers "extattr_delete_link(2) call"); 999*844fc5ebSAlan Somers } 1000*844fc5ebSAlan Somers 1001*844fc5ebSAlan Somers ATF_TC_BODY(extattr_delete_link_failure, tc) 1002*844fc5ebSAlan Somers { 1003*844fc5ebSAlan Somers /* Prepare the regex to be checked in the audit record */ 1004*844fc5ebSAlan Somers snprintf(extregex, sizeof(extregex), 1005*844fc5ebSAlan Somers "extattr_delete_link.*%s.*failure", path); 1006*844fc5ebSAlan Somers FILE *pipefd = setup(fds, auclass); 1007*844fc5ebSAlan Somers /* Failure reason: symbolic link does not exist */ 1008*844fc5ebSAlan Somers ATF_REQUIRE_EQ(-1, extattr_delete_link(path, 1009*844fc5ebSAlan Somers EXTATTR_NAMESPACE_USER, name)); 1010*844fc5ebSAlan Somers check_audit(fds, extregex, pipefd); 1011*844fc5ebSAlan Somers } 1012*844fc5ebSAlan Somers 1013*844fc5ebSAlan Somers ATF_TC_CLEANUP(extattr_delete_link_failure, tc) 1014*844fc5ebSAlan Somers { 1015*844fc5ebSAlan Somers cleanup(); 1016*844fc5ebSAlan Somers } 1017*844fc5ebSAlan Somers 1018*844fc5ebSAlan Somers 10196d203d2dSAlan Somers ATF_TP_ADD_TCS(tp) 10206d203d2dSAlan Somers { 10216d203d2dSAlan Somers ATF_TP_ADD_TC(tp, flock_success); 10226d203d2dSAlan Somers ATF_TP_ADD_TC(tp, flock_failure); 10236d203d2dSAlan Somers ATF_TP_ADD_TC(tp, fcntl_success); 10246d203d2dSAlan Somers ATF_TP_ADD_TC(tp, fcntl_failure); 10256d203d2dSAlan Somers ATF_TP_ADD_TC(tp, fsync_success); 10266d203d2dSAlan Somers ATF_TP_ADD_TC(tp, fsync_failure); 10276d203d2dSAlan Somers 102828845213SAlan Somers ATF_TP_ADD_TC(tp, chmod_success); 102928845213SAlan Somers ATF_TP_ADD_TC(tp, chmod_failure); 103028845213SAlan Somers ATF_TP_ADD_TC(tp, fchmod_success); 103128845213SAlan Somers ATF_TP_ADD_TC(tp, fchmod_failure); 103228845213SAlan Somers ATF_TP_ADD_TC(tp, lchmod_success); 103328845213SAlan Somers ATF_TP_ADD_TC(tp, lchmod_failure); 103428845213SAlan Somers ATF_TP_ADD_TC(tp, fchmodat_success); 103528845213SAlan Somers ATF_TP_ADD_TC(tp, fchmodat_failure); 103628845213SAlan Somers 10375c9a4738SAlan Somers ATF_TP_ADD_TC(tp, chown_success); 10385c9a4738SAlan Somers ATF_TP_ADD_TC(tp, chown_failure); 10395c9a4738SAlan Somers ATF_TP_ADD_TC(tp, fchown_success); 10405c9a4738SAlan Somers ATF_TP_ADD_TC(tp, fchown_failure); 10415c9a4738SAlan Somers ATF_TP_ADD_TC(tp, lchown_success); 10425c9a4738SAlan Somers ATF_TP_ADD_TC(tp, lchown_failure); 10435c9a4738SAlan Somers ATF_TP_ADD_TC(tp, fchownat_success); 10445c9a4738SAlan Somers ATF_TP_ADD_TC(tp, fchownat_failure); 10455c9a4738SAlan Somers 104668e520feSAlan Somers ATF_TP_ADD_TC(tp, chflags_success); 104768e520feSAlan Somers ATF_TP_ADD_TC(tp, chflags_failure); 104868e520feSAlan Somers ATF_TP_ADD_TC(tp, fchflags_success); 104968e520feSAlan Somers ATF_TP_ADD_TC(tp, fchflags_failure); 105068e520feSAlan Somers ATF_TP_ADD_TC(tp, lchflags_success); 105168e520feSAlan Somers ATF_TP_ADD_TC(tp, lchflags_failure); 105268e520feSAlan Somers 1053*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_set_file_success); 1054*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_set_file_failure); 1055*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_set_fd_success); 1056*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_set_fd_failure); 1057*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_set_link_success); 1058*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_set_link_failure); 1059*844fc5ebSAlan Somers 1060*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_delete_file_success); 1061*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_delete_file_failure); 1062*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_delete_fd_success); 1063*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_delete_fd_failure); 1064*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_delete_link_success); 1065*844fc5ebSAlan Somers ATF_TP_ADD_TC(tp, extattr_delete_link_failure); 1066*844fc5ebSAlan Somers 10676d203d2dSAlan Somers return (atf_no_error()); 10686d203d2dSAlan Somers } 1069