Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/audit/file-delete.c
Show All 29 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 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(rmdir_success); | ATF_TC_WITH_CLEANUP(rmdir_success); | ||||
ATF_TC_HEAD(rmdir_success, tc) | ATF_TC_HEAD(rmdir_success, tc) | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
ATF_TC_HEAD(rename_success, tc) | ATF_TC_HEAD(rename_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 " | ||||
"rename(2) call"); | "rename(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(rename_success, tc) | ATF_TC_BODY(rename_success, tc) | ||||
{ | { | ||||
ATF_REQUIRE(open(path, O_CREAT, mode) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ||||
FILE *pipefd = setup(fds, "fd"); | FILE *pipefd = setup(fds, "fd"); | ||||
ATF_REQUIRE_EQ(0, rename(path, "renamed")); | ATF_REQUIRE_EQ(0, rename(path, "renamed")); | ||||
check_audit(fds, successreg, pipefd); | check_audit(fds, successreg, pipefd); | ||||
/* Close the file descriptor of path */ | |||||
ATF_REQUIRE_EQ(0, close(filedesc)); | |||||
} | } | ||||
ATF_TC_CLEANUP(rename_success, tc) | ATF_TC_CLEANUP(rename_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 22 Lines | |||||
ATF_TC_HEAD(renameat_success, tc) | ATF_TC_HEAD(renameat_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 " | ||||
"renameat(2) call"); | "renameat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(renameat_success, tc) | ATF_TC_BODY(renameat_success, tc) | ||||
{ | { | ||||
ATF_REQUIRE(open(path, O_CREAT, mode) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ||||
FILE *pipefd = setup(fds, "fd"); | FILE *pipefd = setup(fds, "fd"); | ||||
ATF_REQUIRE_EQ(0, renameat(AT_FDCWD, path, AT_FDCWD, "renamed")); | ATF_REQUIRE_EQ(0, renameat(AT_FDCWD, path, AT_FDCWD, "renamed")); | ||||
check_audit(fds, successreg, pipefd); | check_audit(fds, successreg, pipefd); | ||||
/* Close the file descriptor of path */ | |||||
ATF_REQUIRE_EQ(0, close(filedesc)); | |||||
} | } | ||||
ATF_TC_CLEANUP(renameat_success, tc) | ATF_TC_CLEANUP(renameat_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 22 Lines | |||||
ATF_TC_HEAD(unlink_success, tc) | ATF_TC_HEAD(unlink_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 " | ||||
"unlink(2) call"); | "unlink(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(unlink_success, tc) | ATF_TC_BODY(unlink_success, tc) | ||||
{ | { | ||||
ATF_REQUIRE(open(path, O_CREAT, mode) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ||||
FILE *pipefd = setup(fds, "fd"); | FILE *pipefd = setup(fds, "fd"); | ||||
ATF_REQUIRE_EQ(0, unlink(path)); | ATF_REQUIRE_EQ(0, unlink(path)); | ||||
check_audit(fds, successreg, pipefd); | check_audit(fds, successreg, pipefd); | ||||
/* Close the file descriptor of path */ | |||||
ATF_REQUIRE_EQ(0, close(filedesc)); | |||||
} | } | ||||
ATF_TC_CLEANUP(unlink_success, tc) | ATF_TC_CLEANUP(unlink_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 80 Lines • Show Last 20 Lines |