Changeset View
Standalone View
tests/sys/audit/open.c
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 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 o_mode = 0777; | static mode_t o_mode = 0777; | ||||
static int filedesc; | |||||
static char extregex[80]; | static char extregex[80]; | ||||
static const char *path = "fileforaudit"; | static const char *path = "fileforaudit"; | ||||
static const char *errpath = "adirhasnoname/fileforaudit"; | static const char *errpath = "adirhasnoname/fileforaudit"; | ||||
/* | /* | ||||
* Define test-cases for success and failure modes of both open(2) and openat(2) | * Define test-cases for success and failure modes of both open(2) and openat(2) | ||||
*/ | */ | ||||
#define OPEN_AT_TC_DEFINE(mode, regex, flag, class) \ | #define OPEN_AT_TC_DEFINE(mode, regex, flag, class) \ | ||||
asomers: Mixing whitespace changes with functional changes is hard to review. Could you please revert… | |||||
Not Done Inline ActionsIt doesn't matter in this case, but in general it's a good idea to release resources in the LIFO order as opposed to FIFO order. That way you never have an invalid combination of resources open. asomers: It doesn't matter in this case, but in general it's a good idea to release resources in the… | |||||
ATF_TC_WITH_CLEANUP(open_ ## mode ## _success); \ | ATF_TC_WITH_CLEANUP(open_ ## mode ## _success); \ | ||||
ATF_TC_HEAD(open_ ## mode ## _success, tc) \ | ATF_TC_HEAD(open_ ## mode ## _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 " \ | ||||
"open(2) call with flags = %s", #flag); \ | "open(2) call with flags = %s", #flag); \ | ||||
} \ | } \ | ||||
ATF_TC_BODY(open_ ## mode ## _success, tc) \ | ATF_TC_BODY(open_ ## mode ## _success, tc) \ | ||||
{ \ | { \ | ||||
snprintf(extregex, sizeof(extregex), \ | snprintf(extregex, sizeof(extregex), \ | ||||
"open.*%s.*fileforaudit.*return,success", regex); \ | "open.*%s.*fileforaudit.*return,success", regex); \ | ||||
/* File needs to exist for successful open(2) invocation */ \ | /* File needs to exist for successful open(2) invocation */ \ | ||||
ATF_REQUIRE(open(path, O_CREAT, o_mode) != -1); \ | ATF_REQUIRE((filedesc = open(path, O_CREAT, o_mode)) != -1); \ | ||||
FILE *pipefd = setup(fds, class); \ | FILE *pipefd = setup(fds, class); \ | ||||
ATF_REQUIRE(syscall(SYS_open, path, flag) != -1); \ | ATF_REQUIRE(syscall(SYS_open, path, flag) != -1); \ | ||||
check_audit(fds, extregex, pipefd); \ | check_audit(fds, extregex, pipefd); \ | ||||
/* Close the file descriptor of path */ \ | |||||
Not Done Inline Actions@asomers , formatting the backslashes to be at the limit of 80 character line (which looks better) took quite a bit of hard work. Undoing them would be really cumbersome. Can you please review in the current state? I've only added these lines in open.c 55: static int filedesc; [Global] 79: close(filedesc); 119: close(filedesc); 120: close(filedesc2); And modified the respective open() statements to store the return value in filedesc. aniketp: @asomers , formatting the backslashes to be at the limit of 80 character line (which looks… | |||||
Not Done Inline ActionsCould you revert everything else then and submit a style-only change? It's not just about ease-of-review. It's also important for future programmers who try to figure out what this change did and why it did it. And yourself is included among those future programmers; a year from now you won't be able to remember what you did. asomers: Could you revert everything else then and submit a style-only change? It's not just about ease… | |||||
ATF_REQUIRE_EQ(0, close(filedesc)); \ | |||||
} \ | } \ | ||||
ATF_TC_CLEANUP(open_ ## mode ## _success, tc) \ | ATF_TC_CLEANUP(open_ ## mode ## _success, tc) \ | ||||
{ \ | { \ | ||||
cleanup(); \ | cleanup(); \ | ||||
} \ | } \ | ||||
ATF_TC_WITH_CLEANUP(open_ ## mode ## _failure); \ | ATF_TC_WITH_CLEANUP(open_ ## mode ## _failure); \ | ||||
ATF_TC_HEAD(open_ ## mode ## _failure, tc) \ | ATF_TC_HEAD(open_ ## mode ## _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 " \ | ||||
"open(2) call with flags = %s", #flag); \ | "open(2) call with flags = %s", #flag); \ | ||||
} \ | } \ | ||||
ATF_TC_BODY(open_ ## mode ## _failure, tc) \ | ATF_TC_BODY(open_ ## mode ## _failure, tc) \ | ||||
{ \ | { \ | ||||
snprintf(extregex, sizeof(extregex), \ | snprintf(extregex, sizeof(extregex), \ | ||||
"open.*%s.*fileforaudit.*return,failure", regex); \ | "open.*%s.*fileforaudit.*return,failure", regex); \ | ||||
FILE *pipefd = setup(fds, class); \ | FILE *pipefd = setup(fds, class); \ | ||||
ATF_REQUIRE_EQ(-1, syscall(SYS_open, errpath, flag)); \ | ATF_REQUIRE_EQ(-1, syscall(SYS_open, errpath, flag)); \ | ||||
check_audit(fds, extregex, pipefd); \ | check_audit(fds, extregex, pipefd); \ | ||||
} \ | } \ | ||||
ATF_TC_CLEANUP(open_ ## mode ## _failure, tc) \ | ATF_TC_CLEANUP(open_ ## mode ## _failure, tc) \ | ||||
{ \ | { \ | ||||
cleanup(); \ | cleanup(); \ | ||||
} \ | } \ | ||||
ATF_TC_WITH_CLEANUP(openat_ ## mode ## _success); \ | ATF_TC_WITH_CLEANUP(openat_ ## mode ## _success); \ | ||||
ATF_TC_HEAD(openat_ ## mode ## _success, tc) \ | ATF_TC_HEAD(openat_ ## mode ## _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 " \ | ||||
"openat(2) call with flags = %s", #flag); \ | "openat(2) call with flags = %s", #flag); \ | ||||
} \ | } \ | ||||
ATF_TC_BODY(openat_ ## mode ## _success, tc) \ | ATF_TC_BODY(openat_ ## mode ## _success, tc) \ | ||||
{ \ | { \ | ||||
int filedesc2; \ | |||||
snprintf(extregex, sizeof(extregex), \ | snprintf(extregex, sizeof(extregex), \ | ||||
"openat.*%s.*fileforaudit.*return,success", regex); \ | "openat.*%s.*fileforaudit.*return,success", regex); \ | ||||
/* File needs to exist for successful openat(2) invocation */ \ | /* File needs to exist for successful openat(2) invocation */ \ | ||||
ATF_REQUIRE(open(path, O_CREAT, o_mode) != -1); \ | ATF_REQUIRE((filedesc = open(path, O_CREAT, o_mode)) != -1); \ | ||||
FILE *pipefd = setup(fds, class); \ | FILE *pipefd = setup(fds, class); \ | ||||
ATF_REQUIRE(openat(AT_FDCWD, path, flag) != -1); \ | ATF_REQUIRE((filedesc2 = openat(AT_FDCWD, path, flag)) != -1); \ | ||||
check_audit(fds, extregex, pipefd); \ | check_audit(fds, extregex, pipefd); \ | ||||
/* Close the file descriptors of path */ \ | |||||
ATF_REQUIRE_EQ(0, close(filedesc)); \ | |||||
ATF_REQUIRE_EQ(0, close(filedesc2)); \ | |||||
} \ | } \ | ||||
ATF_TC_CLEANUP(openat_ ## mode ## _success, tc) \ | ATF_TC_CLEANUP(openat_ ## mode ## _success, tc) \ | ||||
{ \ | { \ | ||||
cleanup(); \ | cleanup(); \ | ||||
} \ | } \ | ||||
ATF_TC_WITH_CLEANUP(openat_ ## mode ## _failure); \ | ATF_TC_WITH_CLEANUP(openat_ ## mode ## _failure); \ | ||||
ATF_TC_HEAD(openat_ ## mode ## _failure, tc) \ | ATF_TC_HEAD(openat_ ## mode ## _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 " \ | ||||
"openat(2) call with flags = %s", #flag); \ | "openat(2) call with flags = %s", #flag); \ | ||||
} \ | } \ | ||||
ATF_TC_BODY(openat_ ## mode ## _failure, tc) \ | ATF_TC_BODY(openat_ ## mode ## _failure, tc) \ | ||||
{ \ | { \ | ||||
snprintf(extregex, sizeof(extregex), \ | snprintf(extregex, sizeof(extregex), \ | ||||
"openat.*%s.*fileforaudit.*return,failure", regex); \ | "openat.*%s.*fileforaudit.*return,failure", regex); \ | ||||
FILE *pipefd = setup(fds, class); \ | FILE *pipefd = setup(fds, class); \ | ||||
ATF_REQUIRE_EQ(-1, openat(AT_FDCWD, errpath, flag)); \ | ATF_REQUIRE_EQ(-1, openat(AT_FDCWD, errpath, flag)); \ | ||||
check_audit(fds, extregex, pipefd); \ | check_audit(fds, extregex, pipefd); \ | ||||
} \ | } \ | ||||
ATF_TC_CLEANUP(openat_ ## mode ## _failure, tc) \ | ATF_TC_CLEANUP(openat_ ## mode ## _failure, tc) \ | ||||
{ \ | { \ | ||||
cleanup(); \ | cleanup(); \ | ||||
} | } | ||||
/* | /* | ||||
* Add both success and failure modes of open(2) and openat(2) | * Add both success and failure modes of open(2) and openat(2) | ||||
*/ | */ | ||||
#define OPEN_AT_TC_ADD(tp, mode) \ | #define OPEN_AT_TC_ADD(tp, mode) \ | ||||
do { \ | do { \ | ||||
ATF_TP_ADD_TC(tp, open_ ## mode ## _success); \ | ATF_TP_ADD_TC(tp, open_ ## mode ## _success); \ | ||||
ATF_TP_ADD_TC(tp, open_ ## mode ## _failure); \ | ATF_TP_ADD_TC(tp, open_ ## mode ## _failure); \ | ||||
ATF_TP_ADD_TC(tp, openat_ ## mode ## _success); \ | ATF_TP_ADD_TC(tp, openat_ ## mode ## _success); \ | ||||
ATF_TP_ADD_TC(tp, openat_ ## mode ## _failure); \ | ATF_TP_ADD_TC(tp, openat_ ## mode ## _failure); \ | ||||
} while (0) | } while (0) | ||||
/* | /* | ||||
* Each of the 12 OPEN_AT_TC_DEFINE statement is a group of 4 test-cases | * Each of the 12 OPEN_AT_TC_DEFINE statement is a group of 4 test-cases | ||||
* corresponding to separate audit events for open(2) and openat(2) | * corresponding to separate audit events for open(2) and openat(2) | ||||
*/ | */ | ||||
OPEN_AT_TC_DEFINE(read, "read", O_RDONLY, "fr") | OPEN_AT_TC_DEFINE(read, "read", O_RDONLY, "fr") | ||||
Show All 35 Lines |
Mixing whitespace changes with functional changes is hard to review. Could you please revert the whitespace changes for now?