Changeset View
Changeset View
Standalone View
Standalone View
head/tests/sys/audit/file-write.c
Show All 26 Lines | |||||
#include <atf-c.h> | #include <atf-c.h> | ||||
#include <fcntl.h> | #include <fcntl.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 off_t offlen = 0; | static off_t offlen = 0; | ||||
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(truncate_success); | ATF_TC_WITH_CLEANUP(truncate_success); | ||||
ATF_TC_HEAD(truncate_success, tc) | ATF_TC_HEAD(truncate_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 " | ||||
"truncate(2) call"); | "truncate(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(truncate_success, tc) | ATF_TC_BODY(truncate_success, tc) | ||||
{ | { | ||||
/* File needs to exist to call truncate(2) */ | /* File needs to exist to call truncate(2) */ | ||||
ATF_REQUIRE(open(path, O_CREAT, mode) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ||||
FILE *pipefd = setup(fds, "fw"); | FILE *pipefd = setup(fds, "fw"); | ||||
ATF_REQUIRE_EQ(0, truncate(path, offlen)); | ATF_REQUIRE_EQ(0, truncate(path, offlen)); | ||||
check_audit(fds, successreg, pipefd); | check_audit(fds, successreg, pipefd); | ||||
close(filedesc); | |||||
} | } | ||||
ATF_TC_CLEANUP(truncate_success, tc) | ATF_TC_CLEANUP(truncate_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 22 Lines | |||||
ATF_TC_HEAD(ftruncate_success, tc) | ATF_TC_HEAD(ftruncate_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 " | ||||
"ftruncate(2) call"); | "ftruncate(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(ftruncate_success, tc) | ATF_TC_BODY(ftruncate_success, tc) | ||||
{ | { | ||||
int filedesc; | |||||
const char *regex = "ftruncate.*return,success"; | const char *regex = "ftruncate.*return,success"; | ||||
/* Valid file descriptor needs to exist to call ftruncate(2) */ | /* Valid file descriptor needs to exist to call ftruncate(2) */ | ||||
ATF_REQUIRE((filedesc = open(path, O_CREAT | O_RDWR)) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT | O_RDWR)) != -1); | ||||
FILE *pipefd = setup(fds, "fw"); | FILE *pipefd = setup(fds, "fw"); | ||||
ATF_REQUIRE_EQ(0, ftruncate(filedesc, offlen)); | ATF_REQUIRE_EQ(0, ftruncate(filedesc, offlen)); | ||||
check_audit(fds, regex, pipefd); | check_audit(fds, regex, pipefd); | ||||
close(filedesc); | |||||
} | } | ||||
ATF_TC_CLEANUP(ftruncate_success, tc) | ATF_TC_CLEANUP(ftruncate_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 31 Lines |