Date: Mon, 28 May 2018 19:59:55 GMT From: aniketp@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r337257 - soc2018/aniketp/head/tests/sys/audit Message-ID: <201805281959.w4SJxtp2083449@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: aniketp Date: Mon May 28 19:59:53 2018 New Revision: 337257 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=337257 Log: Finish tests fort all auditable IPC system calls Modified: soc2018/aniketp/head/tests/sys/audit/inter-process.c Modified: soc2018/aniketp/head/tests/sys/audit/inter-process.c ============================================================================== --- soc2018/aniketp/head/tests/sys/audit/inter-process.c Mon May 28 14:21:00 2018 (r337256) +++ soc2018/aniketp/head/tests/sys/audit/inter-process.c Mon May 28 19:59:53 2018 (r337257) @@ -28,35 +28,42 @@ #include <sys/types.h> #include <sys/ipc.h> +#include <sys/mman.h> #include <sys/msg.h> #include <sys/shm.h> #include <sys/sem.h> #include <sys/stat.h> #include <atf-c.h> +#include <fcntl.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> #include "utils.h" struct msgstr { - long int mtype; - char mtext[128]; + long int mtype; + char mtext[128]; }; typedef struct msgstr msgstr_t; static union semun { - int val; - struct semid_ds *buf; - unsigned short *array; + int val; + struct semid_ds *buf; + unsigned short *array; } arg; +static int msqid, shmid, semid; +static ssize_t msgsize; +static mode_t mode = 0600; static struct pollfd fds[1]; static struct msqid_ds msgbuff; static struct shmid_ds shmbuff; static struct semid_ds sembuff; -static int msqid, shmid, semid; static char ipcregex[60]; +static char path[20] = "/fileforaudit"; static unsigned short semvals[40]; -static ssize_t msgsize; ATF_TC_WITH_CLEANUP(msgget_success); @@ -445,6 +452,7 @@ FILE *pipefd = setup(fds, "ip"); ATF_REQUIRE((int)(addr = shmat(shmid, NULL, 0)) != -1); + /* Check the presence of shared memory ID and process address in record */ snprintf(ipcregex, 60, "shmat.*Shared Memory " "IPC.*%d.*return,success,%d", shmid, (int)addr); @@ -1318,6 +1326,193 @@ } +ATF_TC_WITH_CLEANUP(shm_open_success); +ATF_TC_HEAD(shm_open_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "shm_open(2) call"); +} + +ATF_TC_BODY(shm_open_success, tc) +{ + /* Build an absolute path to a file in the test-case directory */ + char dirpath[50]; + ATF_REQUIRE(getcwd(dirpath, sizeof(dirpath)) != NULL); + ATF_REQUIRE(strncat(dirpath, path, sizeof(dirpath) - 1) != NULL); + + const char *regex = "shm_open.*fileforaudit.*return,success"; + FILE *pipefd = setup(fds, "ip"); + ATF_REQUIRE(shm_open(dirpath, O_CREAT | O_TRUNC | O_RDWR, 0600) != -1); + check_audit(fds, regex, pipefd); + ATF_REQUIRE_EQ(0, shm_unlink(dirpath)); +} + +ATF_TC_CLEANUP(shm_open_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(shm_open_failure); +ATF_TC_HEAD(shm_open_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "shm_open(2) call"); +} + +ATF_TC_BODY(shm_open_failure, tc) +{ + const char *regex = "shm_open.*fileforaudit.*return,failure"; + FILE *pipefd = setup(fds, "ip"); + ATF_REQUIRE_EQ(-1, shm_open(path, O_TRUNC | O_RDWR, 0600)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(shm_open_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(shm_unlink_success); +ATF_TC_HEAD(shm_unlink_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "shm_unlink(2) call"); +} + +ATF_TC_BODY(shm_unlink_success, tc) +{ + /* Build an absolute path to a file in the test-case directory */ + char dirpath[50]; + ATF_REQUIRE(getcwd(dirpath, sizeof(dirpath)) != NULL); + ATF_REQUIRE(strncat(dirpath, path, sizeof(dirpath) - 1) != NULL); + ATF_REQUIRE(shm_open(dirpath, O_CREAT | O_TRUNC | O_RDWR, 0600) != -1); + + const char *regex = "shm_unlink.*fileforaudit.*return,success"; + FILE *pipefd = setup(fds, "ip"); + ATF_REQUIRE_EQ(0, shm_unlink(dirpath)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(shm_unlink_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(shm_unlink_failure); +ATF_TC_HEAD(shm_unlink_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "shm_unlink(2) call"); +} + +ATF_TC_BODY(shm_unlink_failure, tc) +{ + const char *regex = "shm_unlink.*fileforaudit.*return,failure"; + FILE *pipefd = setup(fds, "ip"); + ATF_REQUIRE_EQ(-1, shm_unlink(path)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(shm_unlink_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(pipe_success); +ATF_TC_HEAD(pipe_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "pipe(2) call"); +} + +ATF_TC_BODY(pipe_success, tc) +{ + int filedesc[2]; + ATF_REQUIRE((filedesc[0] = open(path, O_CREAT, mode)) != -1); + ATF_REQUIRE((filedesc[1] = open(path, O_CREAT, mode)) != -1); + + pid_t pid = getpid(); + snprintf(ipcregex, 60, "pipe.*%d.*return,success", pid); + FILE *pipefd = setup(fds, "ip"); + ATF_REQUIRE_EQ(0, pipe(filedesc)); + check_audit(fds, ipcregex, pipefd); +} + +ATF_TC_CLEANUP(pipe_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(pipe_failure); +ATF_TC_HEAD(pipe_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "pipe(2) call"); +} + +ATF_TC_BODY(pipe_failure, tc) +{ + const char *regex = "pipe.*return,failure : Bad address"; + FILE *pipefd = setup(fds, "ip"); + ATF_REQUIRE_EQ(-1, pipe((int *)-1)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(pipe_failure, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(posix_openpt_success); +ATF_TC_HEAD(posix_openpt_success, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful " + "posix_openpt(2) call"); +} + +ATF_TC_BODY(posix_openpt_success, tc) +{ + int filedesc; + FILE *pipefd = setup(fds, "ip"); + ATF_REQUIRE((filedesc = posix_openpt(O_RDWR)) != -1); + /* Check for the presence of filedesc in the audit record */ + snprintf(ipcregex, 60, "posix_openpt.*return,success,%d", filedesc); + check_audit(fds, ipcregex, pipefd); +} + +ATF_TC_CLEANUP(posix_openpt_success, tc) +{ + cleanup(); +} + + +ATF_TC_WITH_CLEANUP(posix_openpt_failure); +ATF_TC_HEAD(posix_openpt_failure, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful " + "posix_openpt(2) call"); +} + +ATF_TC_BODY(posix_openpt_failure, tc) +{ + const char *regex = "posix_openpt.*return,failure : Invalid argument"; + FILE *pipefd = setup(fds, "ip"); + ATF_REQUIRE_EQ(-1, posix_openpt(-1)); + check_audit(fds, regex, pipefd); +} + +ATF_TC_CLEANUP(posix_openpt_failure, tc) +{ + cleanup(); +} + + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, msgget_success); @@ -1377,6 +1572,16 @@ ATF_TP_ADD_TC(tp, semctl_rmid_failure); ATF_TP_ADD_TC(tp, semctl_illegal_command); + ATF_TP_ADD_TC(tp, shm_open_success); + ATF_TP_ADD_TC(tp, shm_open_failure); + ATF_TP_ADD_TC(tp, shm_unlink_success); + ATF_TP_ADD_TC(tp, shm_unlink_failure); + + ATF_TP_ADD_TC(tp, pipe_success); + ATF_TP_ADD_TC(tp, pipe_failure); + ATF_TP_ADD_TC(tp, posix_openpt_success); + ATF_TP_ADD_TC(tp, posix_openpt_failure); + return (atf_no_error()); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201805281959.w4SJxtp2083449>