Changeset View
Changeset View
Standalone View
Standalone View
head/tests/sys/audit/utils.c
Show All 21 Lines | |||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
#include <time.h> | #include <bsm/libbsm.h> | ||||
#include <security/audit/audit_ioctl.h> | |||||
#include <atf-c.h> | |||||
#include <errno.h> | #include <errno.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <atf-c.h> | |||||
#include <string.h> | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | |||||
#include <time.h> | |||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <bsm/libbsm.h> | |||||
#include <security/audit/audit_ioctl.h> | |||||
#include "utils.h" | #include "utils.h" | ||||
/* | /* | ||||
* Checks the presence of "auditregex" in auditpipe(4) after the | * Checks the presence of "auditregex" in auditpipe(4) after the | ||||
* corresponding system call has been triggered. | * corresponding system call has been triggered. | ||||
*/ | */ | ||||
static bool | static bool | ||||
Show All 27 Lines | while (bytes < reclen) { | ||||
} | } | ||||
/* Print the tokens as they are obtained, in the default form */ | /* Print the tokens as they are obtained, in the default form */ | ||||
au_print_flags_tok(memstream, &token, del, AU_OFLAG_NONE); | au_print_flags_tok(memstream, &token, del, AU_OFLAG_NONE); | ||||
bytes += token.len; | bytes += token.len; | ||||
} | } | ||||
free(buff); | free(buff); | ||||
fclose(memstream); | ATF_REQUIRE_EQ(0, fclose(memstream)); | ||||
return (atf_utils_grep_string("%s", membuff, auditregex)); | return (atf_utils_grep_string("%s", membuff, auditregex)); | ||||
} | } | ||||
/* | /* | ||||
* Override the system-wide audit mask settings in /etc/security/audit_control | * Override the system-wide audit mask settings in /etc/security/audit_control | ||||
* and set the auditpipe's maximum allowed queue length limit | * and set the auditpipe's maximum allowed queue length limit | ||||
*/ | */ | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 98 Lines • ▼ Show 20 Lines | |||||
check_audit_startup(struct pollfd fd[], const char *auditrgx, FILE *pipestream){ | check_audit_startup(struct pollfd fd[], const char *auditrgx, FILE *pipestream){ | ||||
check_auditpipe(fd, auditrgx, pipestream); | check_auditpipe(fd, auditrgx, pipestream); | ||||
} | } | ||||
void | void | ||||
check_audit(struct pollfd fd[], const char *auditrgx, FILE *pipestream) { | check_audit(struct pollfd fd[], const char *auditrgx, FILE *pipestream) { | ||||
check_auditpipe(fd, auditrgx, pipestream); | check_auditpipe(fd, auditrgx, pipestream); | ||||
/* Cleanup */ | /* Teardown: /dev/auditpipe's instance opened for this test-suite */ | ||||
fclose(pipestream); | ATF_REQUIRE_EQ(0, fclose(pipestream)); | ||||
close(fd[0].fd); | |||||
} | } | ||||
FILE | FILE | ||||
*setup(struct pollfd fd[], const char *name) | *setup(struct pollfd fd[], const char *name) | ||||
{ | { | ||||
au_mask_t fmask, nomask; | au_mask_t fmask, nomask; | ||||
fmask = get_audit_mask(name); | fmask = get_audit_mask(name); | ||||
nomask = get_audit_mask("no"); | nomask = get_audit_mask("no"); | ||||
FILE *pipestream; | FILE *pipestream; | ||||
fd[0].fd = open("/dev/auditpipe", O_RDONLY); | ATF_REQUIRE((fd[0].fd = open("/dev/auditpipe", O_RDONLY)) != -1); | ||||
ATF_REQUIRE((pipestream = fdopen(fd[0].fd, "r")) != NULL); | |||||
fd[0].events = POLLIN; | fd[0].events = POLLIN; | ||||
pipestream = fdopen(fd[0].fd, "r"); | |||||
/* Set local preselection audit_class as "no" for audit startup */ | /* Set local preselection audit_class as "no" for audit startup */ | ||||
set_preselect_mode(fd[0].fd, &nomask); | set_preselect_mode(fd[0].fd, &nomask); | ||||
ATF_REQUIRE_EQ(0, system("service auditd onestatus || \ | ATF_REQUIRE_EQ(0, system("service auditd onestatus || \ | ||||
{ service auditd onestart && touch started_auditd ; }")); | { service auditd onestart && touch started_auditd ; }")); | ||||
/* If 'started_auditd' exists, that means we started auditd(8) */ | /* If 'started_auditd' exists, that means we started auditd(8) */ | ||||
if (atf_utils_file_exists("started_auditd")) | if (atf_utils_file_exists("started_auditd")) | ||||
Show All 13 Lines |