Changeset View
Changeset View
Standalone View
Standalone View
head/tests/sys/audit/file-attribute-access.c
Show All 30 Lines | |||||
#include <atf-c.h> | #include <atf-c.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "utils.h" | #include "utils.h" | ||||
static struct pollfd fds[1]; | static struct pollfd fds[1]; | ||||
static mode_t mode = 0777; | static mode_t mode = 0777; | ||||
static int filedesc; | |||||
static char extregex[80]; | static char extregex[80]; | ||||
static struct stat statbuff; | static struct stat statbuff; | ||||
static const char *auclass = "fa"; | static const char *auclass = "fa"; | ||||
static const char *path = "fileforaudit"; | static const char *path = "fileforaudit"; | ||||
static const char *errpath = "dirdoesnotexist/fileforaudit"; | static const char *errpath = "dirdoesnotexist/fileforaudit"; | ||||
static const char *successreg = "fileforaudit.*return,success"; | static const char *successreg = "fileforaudit.*return,success"; | ||||
static const char *failurereg = "fileforaudit.*return,failure"; | static const char *failurereg = "fileforaudit.*return,failure"; | ||||
ATF_TC_WITH_CLEANUP(stat_success); | ATF_TC_WITH_CLEANUP(stat_success); | ||||
ATF_TC_HEAD(stat_success, tc) | ATF_TC_HEAD(stat_success, tc) | ||||
{ | { | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " | ||||
"stat(2) call"); | "stat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(stat_success, tc) | ATF_TC_BODY(stat_success, tc) | ||||
{ | { | ||||
/* File needs to exist to call stat(2) */ | /* File needs to exist to call stat(2) */ | ||||
ATF_REQUIRE(open(path, O_CREAT, mode) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
ATF_REQUIRE_EQ(0, stat(path, &statbuff)); | ATF_REQUIRE_EQ(0, stat(path, &statbuff)); | ||||
check_audit(fds, successreg, pipefd); | check_audit(fds, successreg, pipefd); | ||||
close(filedesc); | |||||
} | } | ||||
ATF_TC_CLEANUP(stat_success, tc) | ATF_TC_CLEANUP(stat_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
ATF_TC_HEAD(fstat_success, tc) | ATF_TC_HEAD(fstat_success, tc) | ||||
{ | { | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " | ||||
"fstat(2) call"); | "fstat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(fstat_success, tc) | ATF_TC_BODY(fstat_success, tc) | ||||
{ | { | ||||
int filedesc; | |||||
/* File needs to exist to call fstat(2) */ | /* File needs to exist to call fstat(2) */ | ||||
ATF_REQUIRE((filedesc = open(path, O_CREAT | O_RDWR, mode)) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT | O_RDWR, mode)) != -1); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
ATF_REQUIRE_EQ(0, fstat(filedesc, &statbuff)); | ATF_REQUIRE_EQ(0, fstat(filedesc, &statbuff)); | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"fstat.*%jd.*return,success", (intmax_t)statbuff.st_ino); | "fstat.*%jd.*return,success", (intmax_t)statbuff.st_ino); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
close(filedesc); | |||||
} | } | ||||
ATF_TC_CLEANUP(fstat_success, tc) | ATF_TC_CLEANUP(fstat_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |