Changeset View
Changeset View
Standalone View
Standalone View
tests/sys/audit/file-attribute-access.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/param.h> | #include <sys/param.h> | ||||
#include <sys/extattr.h> | #include <sys/extattr.h> | ||||
#include <sys/ucred.h> | |||||
#include <sys/mount.h> | #include <sys/mount.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <sys/syscall.h> | #include <sys/syscall.h> | ||||
#include <sys/ucred.h> | |||||
#include <atf-c.h> | #include <atf-c.h> | ||||
#include <errno.h> | |||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <string.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 pid_t pid; | static pid_t pid; | ||||
static fhandle_t fht; | static fhandle_t fht; | ||||
Show All 39 Lines | ATF_TC_HEAD(stat_failure, tc) | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"stat(2) call"); | "stat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(stat_failure, tc) | ATF_TC_BODY(stat_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: file does not exist */ | /* Failure reason: file does not exist */ | ||||
ATF_REQUIRE_EQ(-1, stat(errpath, &statbuff)); | ATF_REQUIRE_ERRNO(ENOENT, stat(errpath, &statbuff) == -1); | ||||
check_audit(fds, failurereg, pipefd); | check_audit(fds, failurereg, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(stat_failure, tc) | ATF_TC_CLEANUP(stat_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 26 Lines | ATF_TC_HEAD(lstat_failure, tc) | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"lstat(2) call"); | "lstat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(lstat_failure, tc) | ATF_TC_BODY(lstat_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: symbolic link does not exist */ | /* Failure reason: symbolic link does not exist */ | ||||
ATF_REQUIRE_EQ(-1, lstat(errpath, &statbuff)); | ATF_REQUIRE_ERRNO(ENOENT, lstat(errpath, &statbuff) == -1); | ||||
check_audit(fds, failurereg, pipefd); | check_audit(fds, failurereg, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(lstat_failure, tc) | ATF_TC_CLEANUP(lstat_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 31 Lines | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"fstat(2) call"); | "fstat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(fstat_failure, tc) | ATF_TC_BODY(fstat_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
const char *regex = "fstat.*return,failure : Bad file descriptor"; | const char *regex = "fstat.*return,failure : Bad file descriptor"; | ||||
/* Failure reason: bad file descriptor */ | /* Failure reason: bad file descriptor */ | ||||
ATF_REQUIRE_EQ(-1, fstat(-1, &statbuff)); | ATF_REQUIRE_ERRNO(EBADF, fstat(-1, &statbuff) == -1); | ||||
check_audit(fds, regex, pipefd); | check_audit(fds, regex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(fstat_failure, tc) | ATF_TC_CLEANUP(fstat_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 27 Lines | ATF_TC_HEAD(fstatat_failure, tc) | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"fstatat(2) call"); | "fstatat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(fstatat_failure, tc) | ATF_TC_BODY(fstatat_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: symbolic link does not exist */ | /* Failure reason: symbolic link does not exist */ | ||||
ATF_REQUIRE_EQ(-1, fstatat(AT_FDCWD, path, &statbuff, | ATF_REQUIRE_ERRNO(ENOENT, | ||||
AT_SYMLINK_NOFOLLOW)); | fstatat(AT_FDCWD, path, &statbuff, AT_SYMLINK_NOFOLLOW) == -1); | ||||
check_audit(fds, failurereg, pipefd); | check_audit(fds, failurereg, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(fstatat_failure, tc) | ATF_TC_CLEANUP(fstatat_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 27 Lines | ATF_TC_HEAD(statfs_failure, tc) | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"statfs(2) call"); | "statfs(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(statfs_failure, tc) | ATF_TC_BODY(statfs_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: file does not exist */ | /* Failure reason: file does not exist */ | ||||
ATF_REQUIRE_EQ(-1, statfs(errpath, &statfsbuff)); | ATF_REQUIRE_ERRNO(ENOENT, statfs(errpath, &statfsbuff) == -1); | ||||
check_audit(fds, failurereg, pipefd); | check_audit(fds, failurereg, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(statfs_failure, tc) | ATF_TC_CLEANUP(statfs_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 33 Lines | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"fstatfs(2) call"); | "fstatfs(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(fstatfs_failure, tc) | ATF_TC_BODY(fstatfs_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
const char *regex = "fstatfs.*return,failure : Bad file descriptor"; | const char *regex = "fstatfs.*return,failure : Bad file descriptor"; | ||||
/* Failure reason: bad file descriptor */ | /* Failure reason: bad file descriptor */ | ||||
ATF_REQUIRE_EQ(-1, fstatfs(-1, &statfsbuff)); | ATF_REQUIRE_ERRNO(EBADF, fstatfs(-1, &statfsbuff) == -1); | ||||
check_audit(fds, regex, pipefd); | check_audit(fds, regex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(fstatfs_failure, tc) | ATF_TC_CLEANUP(fstatfs_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 28 Lines | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"getfsstat(2) call"); | "getfsstat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(getfsstat_failure, tc) | ATF_TC_BODY(getfsstat_failure, tc) | ||||
{ | { | ||||
const char *regex = "getfsstat.*return,failure : Invalid argument"; | const char *regex = "getfsstat.*return,failure : Invalid argument"; | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: Invalid value for mode */ | /* Failure reason: Invalid value for mode */ | ||||
ATF_REQUIRE_EQ(-1, getfsstat(NULL, 0, -1)); | ATF_REQUIRE_ERRNO(EINVAL, getfsstat(NULL, 0, -1) == -1); | ||||
check_audit(fds, regex, pipefd); | check_audit(fds, regex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(getfsstat_failure, tc) | ATF_TC_CLEANUP(getfsstat_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 28 Lines | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"lgetfh(2) call"); | "lgetfh(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(lgetfh_failure, tc) | ATF_TC_BODY(lgetfh_failure, tc) | ||||
{ | { | ||||
const char *regex = "lgetfh.*return,failure"; | const char *regex = "lgetfh.*return,failure"; | ||||
FILE *pipefd = setup(fds, "fa"); | FILE *pipefd = setup(fds, "fa"); | ||||
/* Failure reason: symbolic link does not exist */ | /* Failure reason: symbolic link does not exist */ | ||||
ATF_REQUIRE_EQ(-1, lgetfh(errpath, &fht)); | ATF_REQUIRE_ERRNO(ENOENT, lgetfh(errpath, &fht) == -1); | ||||
check_audit(fds, regex, pipefd); | check_audit(fds, regex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(lgetfh_failure, tc) | ATF_TC_CLEANUP(lgetfh_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 39 Lines | |||||
ATF_TC_BODY(fhopen_failure, tc) | ATF_TC_BODY(fhopen_failure, tc) | ||||
{ | { | ||||
const char *regex = "fhopen.*return,failure : Invalid argument"; | const char *regex = "fhopen.*return,failure : Invalid argument"; | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* | /* | ||||
* Failure reason: NULL does not represent any file handle | * Failure reason: NULL does not represent any file handle | ||||
* and O_CREAT is not allowed as the flag for fhopen(2) | * and O_CREAT is not allowed as the flag for fhopen(2) | ||||
*/ | */ | ||||
ATF_REQUIRE_EQ(-1, fhopen(NULL, O_CREAT)); | ATF_REQUIRE_ERRNO(EINVAL, fhopen(NULL, O_CREAT) == -1); | ||||
check_audit(fds, regex, pipefd); | check_audit(fds, regex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(fhopen_failure, tc) | ATF_TC_CLEANUP(fhopen_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 34 Lines | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"fhstat(2) call"); | "fhstat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(fhstat_failure, tc) | ATF_TC_BODY(fhstat_failure, tc) | ||||
{ | { | ||||
const char *regex = "fhstat.*return,failure : Bad address"; | const char *regex = "fhstat.*return,failure : Bad address"; | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: NULL does not represent any file handle */ | /* Failure reason: NULL does not represent any file handle */ | ||||
ATF_REQUIRE_EQ(-1, fhstat(NULL, NULL)); | ATF_REQUIRE_ERRNO(EFAULT, fhstat(NULL, NULL) == -1); | ||||
check_audit(fds, regex, pipefd); | check_audit(fds, regex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(fhstat_failure, tc) | ATF_TC_CLEANUP(fhstat_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 34 Lines | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"fhstatfs(2) call"); | "fhstatfs(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(fhstatfs_failure, tc) | ATF_TC_BODY(fhstatfs_failure, tc) | ||||
{ | { | ||||
const char *regex = "fhstatfs.*return,failure : Bad address"; | const char *regex = "fhstatfs.*return,failure : Bad address"; | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: NULL does not represent any file handle */ | /* Failure reason: NULL does not represent any file handle */ | ||||
ATF_REQUIRE_EQ(-1, fhstatfs(NULL, NULL)); | ATF_REQUIRE_ERRNO(EFAULT, fhstatfs(NULL, NULL) == -1); | ||||
check_audit(fds, regex, pipefd); | check_audit(fds, regex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(fhstatfs_failure, tc) | ATF_TC_CLEANUP(fhstatfs_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 27 Lines | ATF_TC_HEAD(access_failure, tc) | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"access(2) call"); | "access(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(access_failure, tc) | ATF_TC_BODY(access_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: file does not exist */ | /* Failure reason: file does not exist */ | ||||
ATF_REQUIRE_EQ(-1, access(errpath, F_OK)); | ATF_REQUIRE_ERRNO(ENOENT, access(errpath, F_OK) == -1); | ||||
check_audit(fds, failurereg, pipefd); | check_audit(fds, failurereg, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(access_failure, tc) | ATF_TC_CLEANUP(access_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 27 Lines | ATF_TC_HEAD(eaccess_failure, tc) | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"eaccess(2) call"); | "eaccess(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(eaccess_failure, tc) | ATF_TC_BODY(eaccess_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: file does not exist */ | /* Failure reason: file does not exist */ | ||||
ATF_REQUIRE_EQ(-1, eaccess(errpath, F_OK)); | ATF_REQUIRE_ERRNO(ENOENT, eaccess(errpath, F_OK) == -1); | ||||
check_audit(fds, failurereg, pipefd); | check_audit(fds, failurereg, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(eaccess_failure, tc) | ATF_TC_CLEANUP(eaccess_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 27 Lines | ATF_TC_HEAD(faccessat_failure, tc) | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"faccessat(2) call"); | "faccessat(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(faccessat_failure, tc) | ATF_TC_BODY(faccessat_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: file does not exist */ | /* Failure reason: file does not exist */ | ||||
ATF_REQUIRE_EQ(-1, faccessat(AT_FDCWD, errpath, F_OK, AT_EACCESS)); | ATF_REQUIRE_ERRNO(ENOENT, | ||||
faccessat(AT_FDCWD, errpath, F_OK, AT_EACCESS) == -1); | |||||
check_audit(fds, failurereg, pipefd); | check_audit(fds, failurereg, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(faccessat_failure, tc) | ATF_TC_CLEANUP(faccessat_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 28 Lines | ATF_TC_HEAD(pathconf_failure, tc) | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"pathconf(2) call"); | "pathconf(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(pathconf_failure, tc) | ATF_TC_BODY(pathconf_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: file does not exist */ | /* Failure reason: file does not exist */ | ||||
ATF_REQUIRE_EQ(-1, pathconf(errpath, _PC_NAME_MAX)); | ATF_REQUIRE_ERRNO(ENOENT, pathconf(errpath, _PC_NAME_MAX) == -1); | ||||
check_audit(fds, failurereg, pipefd); | check_audit(fds, failurereg, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(pathconf_failure, tc) | ATF_TC_CLEANUP(pathconf_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 27 Lines | ATF_TC_HEAD(lpathconf_failure, tc) | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"lpathconf(2) call"); | "lpathconf(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(lpathconf_failure, tc) | ATF_TC_BODY(lpathconf_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: symbolic link does not exist */ | /* Failure reason: symbolic link does not exist */ | ||||
ATF_REQUIRE_EQ(-1, lpathconf(errpath, _PC_SYMLINK_MAX)); | ATF_REQUIRE_ERRNO(ENOENT, lpathconf(errpath, _PC_SYMLINK_MAX) == -1); | ||||
check_audit(fds, failurereg, pipefd); | check_audit(fds, failurereg, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(lpathconf_failure, tc) | ATF_TC_CLEANUP(lpathconf_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 32 Lines | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"fpathconf(2) call"); | "fpathconf(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(fpathconf_failure, tc) | ATF_TC_BODY(fpathconf_failure, tc) | ||||
{ | { | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
const char *regex = "fpathconf.*return,failure : Bad file descriptor"; | const char *regex = "fpathconf.*return,failure : Bad file descriptor"; | ||||
/* Failure reason: Bad file descriptor */ | /* Failure reason: Bad file descriptor */ | ||||
ATF_REQUIRE_EQ(-1, fpathconf(-1, _PC_NAME_MAX)); | ATF_REQUIRE_ERRNO(EBADF, fpathconf(-1, _PC_NAME_MAX) == -1); | ||||
check_audit(fds, regex, pipefd); | check_audit(fds, regex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(fpathconf_failure, tc) | ATF_TC_CLEANUP(fpathconf_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
ATF_TC_WITH_CLEANUP(extattr_get_file_success); | ATF_TC_WITH_CLEANUP(extattr_get_file_success); | ||||
ATF_TC_HEAD(extattr_get_file_success, tc) | ATF_TC_HEAD(extattr_get_file_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 " | ||||
"extattr_get_file(2) call"); | "extattr_get_file(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(extattr_get_file_success, tc) | ATF_TC_BODY(extattr_get_file_success, tc) | ||||
{ | { | ||||
/* File needs to exist to call extattr_get_file(2) */ | /* File needs to exist to call extattr_get_file(2) */ | ||||
ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ||||
skip_if_extattr_not_supported(path); | |||||
/* Set an extended attribute to be retrieved later on */ | /* Set an extended attribute to be retrieved later on */ | ||||
ATF_REQUIRE_EQ(sizeof(buff), extattr_set_file(path, | REQUIRE_EXTATTR_RESULT(sizeof(buff), | ||||
EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); | extattr_set_file(path, EXTATTR_NAMESPACE_USER, name, buff, | ||||
sizeof(buff))); | |||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_get_file.*%s.*%s.*return,success", path, name); | "extattr_get_file.*%s.*%s.*return,success", path, name); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
ATF_REQUIRE_EQ(sizeof(buff), extattr_get_file(path, | REQUIRE_EXTATTR_RESULT(sizeof(buff), | ||||
EXTATTR_NAMESPACE_USER, name, NULL, 0)); | extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, NULL, 0)); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
close(filedesc); | close(filedesc); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_get_file_success, tc) | ATF_TC_CLEANUP(extattr_get_file_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 9 Lines | |||||
ATF_TC_BODY(extattr_get_file_failure, tc) | ATF_TC_BODY(extattr_get_file_failure, tc) | ||||
{ | { | ||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_get_file.*%s.*%s.*failure", path, name); | "extattr_get_file.*%s.*%s.*failure", path, name); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: file does not exist */ | /* Failure reason: file does not exist */ | ||||
ATF_REQUIRE_EQ(-1, extattr_get_file(path, | ATF_REQUIRE_ERRNO(ENOENT, | ||||
EXTATTR_NAMESPACE_USER, name, NULL, 0)); | extattr_get_file(path, EXTATTR_NAMESPACE_USER, name, NULL, 0) == | ||||
-1); | |||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_get_file_failure, tc) | ATF_TC_CLEANUP(extattr_get_file_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
ATF_TC_WITH_CLEANUP(extattr_get_fd_success); | ATF_TC_WITH_CLEANUP(extattr_get_fd_success); | ||||
ATF_TC_HEAD(extattr_get_fd_success, tc) | ATF_TC_HEAD(extattr_get_fd_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 " | ||||
"extattr_get_fd(2) call"); | "extattr_get_fd(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(extattr_get_fd_success, tc) | ATF_TC_BODY(extattr_get_fd_success, tc) | ||||
{ | { | ||||
/* File needs to exist to call extattr_get_fd(2) */ | /* File needs to exist to call extattr_get_fd(2) */ | ||||
ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ||||
skip_if_extattr_not_supported(path); | |||||
/* Set an extended attribute to be retrieved later on */ | /* Set an extended attribute to be retrieved later on */ | ||||
ATF_REQUIRE_EQ(sizeof(buff), extattr_set_file(path, | REQUIRE_EXTATTR_RESULT(sizeof(buff), | ||||
EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); | extattr_set_file(path, EXTATTR_NAMESPACE_USER, name, buff, | ||||
sizeof(buff))); | |||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_get_fd.*%s.*return,success", name); | "extattr_get_fd.*%s.*return,success", name); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
ATF_REQUIRE_EQ(sizeof(buff), extattr_get_fd(filedesc, | REQUIRE_EXTATTR_RESULT(sizeof(buff), | ||||
EXTATTR_NAMESPACE_USER, name, NULL, 0)); | extattr_get_fd(filedesc, EXTATTR_NAMESPACE_USER, name, NULL, 0)); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
close(filedesc); | close(filedesc); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_get_fd_success, tc) | ATF_TC_CLEANUP(extattr_get_fd_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 9 Lines | |||||
ATF_TC_BODY(extattr_get_fd_failure, tc) | ATF_TC_BODY(extattr_get_fd_failure, tc) | ||||
{ | { | ||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_get_fd.*%s.*return,failure : Bad file descriptor", name); | "extattr_get_fd.*%s.*return,failure : Bad file descriptor", name); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: Invalid file descriptor */ | /* Failure reason: Invalid file descriptor */ | ||||
ATF_REQUIRE_EQ(-1, extattr_get_fd(-1, | ATF_REQUIRE_ERRNO(EBADF, | ||||
EXTATTR_NAMESPACE_USER, name, NULL, 0)); | extattr_get_fd(-1, EXTATTR_NAMESPACE_USER, name, NULL, 0) == -1); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_get_fd_failure, tc) | ATF_TC_CLEANUP(extattr_get_fd_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
ATF_TC_WITH_CLEANUP(extattr_get_link_success); | ATF_TC_WITH_CLEANUP(extattr_get_link_success); | ||||
ATF_TC_HEAD(extattr_get_link_success, tc) | ATF_TC_HEAD(extattr_get_link_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 " | ||||
"extattr_get_link(2) call"); | "extattr_get_link(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(extattr_get_link_success, tc) | ATF_TC_BODY(extattr_get_link_success, tc) | ||||
{ | { | ||||
/* Symbolic link needs to exist to call extattr_get_link(2) */ | /* Symbolic link needs to exist to call extattr_get_link(2) */ | ||||
ATF_REQUIRE_EQ(0, symlink("symlink", path)); | ATF_REQUIRE_EQ(0, symlink("symlink", path)); | ||||
skip_if_extattr_not_supported("."); | |||||
/* Set an extended attribute to be retrieved later on */ | /* Set an extended attribute to be retrieved later on */ | ||||
ATF_REQUIRE_EQ(sizeof(buff), extattr_set_link(path, | REQUIRE_EXTATTR_RESULT(sizeof(buff), | ||||
EXTATTR_NAMESPACE_USER, name, buff, sizeof(buff))); | extattr_set_link(path, EXTATTR_NAMESPACE_USER, name, buff, | ||||
sizeof(buff))); | |||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_get_link.*%s.*%s.*return,success", path, name); | "extattr_get_link.*%s.*%s.*return,success", path, name); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
ATF_REQUIRE_EQ(sizeof(buff), extattr_get_link(path, | REQUIRE_EXTATTR_RESULT(sizeof(buff), | ||||
EXTATTR_NAMESPACE_USER, name, NULL, 0)); | extattr_get_link(path, EXTATTR_NAMESPACE_USER, name, NULL, 0)); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_get_link_success, tc) | ATF_TC_CLEANUP(extattr_get_link_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
ATF_TC_WITH_CLEANUP(extattr_get_link_failure); | ATF_TC_WITH_CLEANUP(extattr_get_link_failure); | ||||
ATF_TC_HEAD(extattr_get_link_failure, tc) | ATF_TC_HEAD(extattr_get_link_failure, tc) | ||||
{ | { | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"extattr_get_link(2) call"); | "extattr_get_link(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(extattr_get_link_failure, tc) | ATF_TC_BODY(extattr_get_link_failure, tc) | ||||
{ | { | ||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_get_link.*%s.*%s.*failure", path, name); | "extattr_get_link.*%s.*%s.*failure", path, name); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: symbolic link does not exist */ | /* Failure reason: symbolic link does not exist */ | ||||
ATF_REQUIRE_EQ(-1, extattr_get_link(path, | ATF_REQUIRE_ERRNO(ENOENT, | ||||
EXTATTR_NAMESPACE_USER, name, NULL, 0)); | extattr_get_link(path, EXTATTR_NAMESPACE_USER, name, NULL, 0)); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_get_link_failure, tc) | ATF_TC_CLEANUP(extattr_get_link_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
ATF_TC_WITH_CLEANUP(extattr_list_file_success); | ATF_TC_WITH_CLEANUP(extattr_list_file_success); | ||||
ATF_TC_HEAD(extattr_list_file_success, tc) | ATF_TC_HEAD(extattr_list_file_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 " | ||||
"extattr_list_file(2) call"); | "extattr_list_file(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(extattr_list_file_success, tc) | ATF_TC_BODY(extattr_list_file_success, tc) | ||||
{ | { | ||||
int readbuff; | ssize_t readbuff; | ||||
/* File needs to exist to call extattr_list_file(2) */ | /* File needs to exist to call extattr_list_file(2) */ | ||||
ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ||||
skip_if_extattr_not_supported(path); | |||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
ATF_REQUIRE((readbuff = extattr_list_file(path, | readbuff = REQUIRE_EXTATTR_SUCCESS( | ||||
EXTATTR_NAMESPACE_USER, NULL, 0)) != -1); | extattr_list_file(path, EXTATTR_NAMESPACE_USER, NULL, 0)); | ||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_list_file.*%s.*return,success,%d", path, readbuff); | "extattr_list_file.*%s.*return,success,%zd", path, readbuff); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_list_file_success, tc) | ATF_TC_CLEANUP(extattr_list_file_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
ATF_TC_WITH_CLEANUP(extattr_list_file_failure); | ATF_TC_WITH_CLEANUP(extattr_list_file_failure); | ||||
ATF_TC_HEAD(extattr_list_file_failure, tc) | ATF_TC_HEAD(extattr_list_file_failure, tc) | ||||
{ | { | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"extattr_list_file(2) call"); | "extattr_list_file(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(extattr_list_file_failure, tc) | ATF_TC_BODY(extattr_list_file_failure, tc) | ||||
{ | { | ||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_list_file.*%s.*return,failure", path); | "extattr_list_file.*%s.*return,failure", path); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: file does not exist */ | /* Failure reason: file does not exist */ | ||||
ATF_REQUIRE_EQ(-1, extattr_list_file(path, | ATF_REQUIRE_ERRNO(ENOENT, | ||||
EXTATTR_NAMESPACE_USER, NULL, 0)); | extattr_list_file(path, EXTATTR_NAMESPACE_USER, NULL, 0)); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_list_file_failure, tc) | ATF_TC_CLEANUP(extattr_list_file_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
ATF_TC_WITH_CLEANUP(extattr_list_fd_success); | ATF_TC_WITH_CLEANUP(extattr_list_fd_success); | ||||
ATF_TC_HEAD(extattr_list_fd_success, tc) | ATF_TC_HEAD(extattr_list_fd_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 " | ||||
"extattr_list_fd(2) call"); | "extattr_list_fd(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(extattr_list_fd_success, tc) | ATF_TC_BODY(extattr_list_fd_success, tc) | ||||
{ | { | ||||
int readbuff; | ssize_t readbuff; | ||||
/* File needs to exist to call extattr_list_fd(2) */ | /* File needs to exist to call extattr_list_fd(2) */ | ||||
ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ATF_REQUIRE((filedesc = open(path, O_CREAT, mode)) != -1); | ||||
skip_if_extattr_not_supported(path); | |||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
ATF_REQUIRE((readbuff = extattr_list_fd(filedesc, | readbuff = REQUIRE_EXTATTR_SUCCESS( | ||||
EXTATTR_NAMESPACE_USER, NULL, 0)) != -1); | extattr_list_fd(filedesc, EXTATTR_NAMESPACE_USER, NULL, 0)); | ||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_list_fd.*return,success,%d", readbuff); | "extattr_list_fd.*return,success,%zd", readbuff); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
close(filedesc); | close(filedesc); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_list_fd_success, tc) | ATF_TC_CLEANUP(extattr_list_fd_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
Show All 9 Lines | |||||
ATF_TC_BODY(extattr_list_fd_failure, tc) | ATF_TC_BODY(extattr_list_fd_failure, tc) | ||||
{ | { | ||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_list_fd.*return,failure : Bad file descriptor"); | "extattr_list_fd.*return,failure : Bad file descriptor"); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: Invalid file descriptor */ | /* Failure reason: Invalid file descriptor */ | ||||
ATF_REQUIRE_EQ(-1, | ATF_REQUIRE_ERRNO(EBADF, | ||||
extattr_list_fd(-1, EXTATTR_NAMESPACE_USER, NULL, 0)); | extattr_list_fd(-1, EXTATTR_NAMESPACE_USER, NULL, 0) == -1); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_list_fd_failure, tc) | ATF_TC_CLEANUP(extattr_list_fd_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
ATF_TC_WITH_CLEANUP(extattr_list_link_success); | ATF_TC_WITH_CLEANUP(extattr_list_link_success); | ||||
ATF_TC_HEAD(extattr_list_link_success, tc) | ATF_TC_HEAD(extattr_list_link_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 " | ||||
"extattr_list_link(2) call"); | "extattr_list_link(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(extattr_list_link_success, tc) | ATF_TC_BODY(extattr_list_link_success, tc) | ||||
{ | { | ||||
int readbuff; | ssize_t readbuff; | ||||
/* Symbolic link needs to exist to call extattr_list_link(2) */ | /* Symbolic link needs to exist to call extattr_list_link(2) */ | ||||
ATF_REQUIRE_EQ(0, symlink("symlink", path)); | ATF_REQUIRE_EQ(0, symlink("symlink", path)); | ||||
FILE *pipefd = setup(fds, auclass); | skip_if_extattr_not_supported("."); | ||||
ATF_REQUIRE((readbuff = extattr_list_link(path, | FILE *pipefd = setup(fds, auclass); | ||||
EXTATTR_NAMESPACE_USER, NULL, 0)) != -1); | readbuff = REQUIRE_EXTATTR_SUCCESS( | ||||
extattr_list_link(path, EXTATTR_NAMESPACE_USER, NULL, 0)); | |||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_list_link.*%s.*return,success,%d", path, readbuff); | "extattr_list_link.*%s.*return,success,%zd", path, readbuff); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_list_link_success, tc) | ATF_TC_CLEANUP(extattr_list_link_success, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
ATF_TC_WITH_CLEANUP(extattr_list_link_failure); | ATF_TC_WITH_CLEANUP(extattr_list_link_failure); | ||||
ATF_TC_HEAD(extattr_list_link_failure, tc) | ATF_TC_HEAD(extattr_list_link_failure, tc) | ||||
{ | { | ||||
atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " | ||||
"extattr_list_link(2) call"); | "extattr_list_link(2) call"); | ||||
} | } | ||||
ATF_TC_BODY(extattr_list_link_failure, tc) | ATF_TC_BODY(extattr_list_link_failure, tc) | ||||
{ | { | ||||
/* Prepare the regex to be checked in the audit record */ | /* Prepare the regex to be checked in the audit record */ | ||||
snprintf(extregex, sizeof(extregex), | snprintf(extregex, sizeof(extregex), | ||||
"extattr_list_link.*%s.*failure", path); | "extattr_list_link.*%s.*failure", path); | ||||
FILE *pipefd = setup(fds, auclass); | FILE *pipefd = setup(fds, auclass); | ||||
/* Failure reason: symbolic link does not exist */ | /* Failure reason: symbolic link does not exist */ | ||||
ATF_REQUIRE_EQ(-1, extattr_list_link(path, | ATF_REQUIRE_ERRNO(ENOENT, | ||||
EXTATTR_NAMESPACE_USER, NULL, 0)); | extattr_list_link(path, EXTATTR_NAMESPACE_USER, NULL, 0) == -1); | ||||
check_audit(fds, extregex, pipefd); | check_audit(fds, extregex, pipefd); | ||||
} | } | ||||
ATF_TC_CLEANUP(extattr_list_link_failure, tc) | ATF_TC_CLEANUP(extattr_list_link_failure, tc) | ||||
{ | { | ||||
cleanup(); | cleanup(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | ATF_TP_ADD_TCS(tp) | ||||
ATF_TP_ADD_TC(tp, extattr_get_link_failure); | ATF_TP_ADD_TC(tp, extattr_get_link_failure); | ||||
ATF_TP_ADD_TC(tp, extattr_list_file_success); | ATF_TP_ADD_TC(tp, extattr_list_file_success); | ||||
ATF_TP_ADD_TC(tp, extattr_list_file_failure); | ATF_TP_ADD_TC(tp, extattr_list_file_failure); | ||||
ATF_TP_ADD_TC(tp, extattr_list_fd_success); | ATF_TP_ADD_TC(tp, extattr_list_fd_success); | ||||
ATF_TP_ADD_TC(tp, extattr_list_fd_failure); | ATF_TP_ADD_TC(tp, extattr_list_fd_failure); | ||||
ATF_TP_ADD_TC(tp, extattr_list_link_success); | ATF_TP_ADD_TC(tp, extattr_list_link_success); | ||||
ATF_TP_ADD_TC(tp, extattr_list_link_failure); | ATF_TP_ADD_TC(tp, extattr_list_link_failure); | ||||
return (atf_no_error()); | return (atf_no_error()); | ||||
} | } |