Changeset View
Changeset View
Standalone View
Standalone View
head/tests/sys/audit/file-close.c
Show All 34 Lines | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include "utils.h" | #include "utils.h" | ||||
static pid_t pid; | static pid_t pid; | ||||
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 = "cl"; | static const char *auclass = "cl"; | ||||
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 *failurereg = "fileforaudit.*return,failure"; | static const char *failurereg = "fileforaudit.*return,failure"; | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
ATF_TC_HEAD(close_success, tc) | ATF_TC_HEAD(close_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 " | ||||
"close(2) call"); | "close(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(close_success, tc) | ATF_TC_BODY(close_success, tc) | ||||
{ | { | ||||
int filedesc; | |||||
/* File needs to exist to call close(2) */ | /* File needs to exist to call close(2) */ | ||||
ATF_REQUIRE((filedesc = open(path, O_CREAT | O_RDWR, mode)) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT | O_RDWR, mode)) != -1); | ||||
/* Call stat(2) to store the Inode number of 'path' */ | /* Call stat(2) to store the Inode number of 'path' */ | ||||
ATF_REQUIRE_EQ(0, stat(path, &statbuff)); | ATF_REQUIRE_EQ(0, stat(path, &statbuff)); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
ATF_REQUIRE_EQ(0, close(filedesc)); | ATF_REQUIRE_EQ(0, close(filedesc)); | ||||
/* intmax_t to support all architectures */ | /* intmax_t to support all architectures */ | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | |||||
ATF_TC_HEAD(revoke_success, tc) | ATF_TC_HEAD(revoke_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 " | ||||
"revoke(2) call"); | "revoke(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(revoke_success, tc) | ATF_TC_BODY(revoke_success, tc) | ||||
{ | { | ||||
int filedesc; | |||||
char *ptyname; | char *ptyname; | ||||
pid = getpid(); | pid = getpid(); | ||||
snprintf(extregex, sizeof(extregex), "revoke.*%d.*return,success", pid); | snprintf(extregex, sizeof(extregex), "revoke.*%d.*return,success", pid); | ||||
/* Obtain a pseudo terminal and get the path to slave device */ | /* Obtain a pseudo terminal and get the path to slave device */ | ||||
ATF_REQUIRE((filedesc = posix_openpt(O_RDWR | O_NOCTTY)) != -1); | ATF_REQUIRE((filedesc = posix_openpt(O_RDWR | O_NOCTTY)) != -1); | ||||
ATF_REQUIRE((ptyname = ptsname(filedesc)) != NULL); | ATF_REQUIRE((ptyname = ptsname(filedesc)) != NULL); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
ATF_REQUIRE_EQ(0, revoke(ptyname)); | ATF_REQUIRE_EQ(0, revoke(ptyname)); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
close(filedesc); | |||||
/* Close the file descriptor to pseudo terminal */ | |||||
ATF_REQUIRE_EQ(0, close(filedesc)); | |||||
} | } | ||||
ATF_TC_CLEANUP(revoke_success, tc) | ATF_TC_CLEANUP(revoke_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 35 Lines |