Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F170628126
D15853.id43907.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D15853.id43907.diff
View Options
Index: tests/sys/audit/network.c
===================================================================
--- tests/sys/audit/network.c
+++ tests/sys/audit/network.c
@@ -38,7 +38,7 @@
#define SERVER_PATH "server"
-static int sockfd;
+static int sockfd, sockfd2;
static socklen_t len;
static struct pollfd fds[1];
static char extregex[80];
@@ -392,6 +392,220 @@
}
+ATF_TC_WITH_CLEANUP(connect_success);
+ATF_TC_HEAD(connect_success, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+ "connect(2) call");
+}
+
+ATF_TC_BODY(connect_success, tc)
+{
+ struct sockaddr_un server;
+ assign_address(&server);
+ len = sizeof(struct sockaddr_un);
+
+ /* Server Socket: Assign address and listen for connection */
+ ATF_REQUIRE((sockfd = socket(PF_UNIX, SOCK_STREAM, 0)) != -1);
+ /* Non-blocking server socket */
+ ATF_REQUIRE(fcntl(sockfd, F_SETFL, O_NONBLOCK) != -1);
+ /* Bind to the specified address and wait for connection */
+ ATF_REQUIRE_EQ(0, bind(sockfd, (struct sockaddr *)&server, len));
+ ATF_REQUIRE_EQ(0, listen(sockfd, 1));
+
+ /* Set up "blocking" client socket */
+ ATF_REQUIRE((sockfd2 = socket(PF_UNIX, SOCK_STREAM, 0)) != -1);
+
+ /* Audit record must contain AF_UNIX address path & sockfd2 */
+ snprintf(extregex, sizeof(extregex),
+ "connect.*0x%x.*%s.*success", sockfd2, SERVER_PATH);
+
+ FILE *pipefd = setup(fds, auclass);
+ ATF_REQUIRE_EQ(0, connect(sockfd2, (struct sockaddr *)&server, len));
+ check_audit(fds, extregex, pipefd);
+
+ /* Close all socket descriptors */
+ close_sockets(2, sockfd, sockfd2);
+}
+
+ATF_TC_CLEANUP(connect_success, tc)
+{
+ cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(connect_failure);
+ATF_TC_HEAD(connect_failure, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+ "connect(2) call");
+}
+
+ATF_TC_BODY(connect_failure, tc)
+{
+ /* Preliminary socket setup */
+ struct sockaddr_un server;
+ assign_address(&server);
+ len = sizeof(struct sockaddr_un);
+
+ /* Audit record must contain AF_UNIX address path */
+ snprintf(extregex, sizeof(extregex),
+ "connect.*%s.*return,failure", SERVER_PATH);
+
+ FILE *pipefd = setup(fds, auclass);
+ /* Failure reason: Invalid socket descriptor */
+ ATF_REQUIRE_EQ(-1, connect(0, (struct sockaddr *)&server, len));
+ check_audit(fds, extregex, pipefd);
+}
+
+ATF_TC_CLEANUP(connect_failure, tc)
+{
+ cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(connectat_success);
+ATF_TC_HEAD(connectat_success, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+ "connectat(2) call");
+}
+
+ATF_TC_BODY(connectat_success, tc)
+{
+ struct sockaddr_un server;
+ assign_address(&server);
+ len = sizeof(struct sockaddr_un);
+
+ /* Server Socket: Assign address and listen for connection */
+ ATF_REQUIRE((sockfd = socket(PF_UNIX, SOCK_STREAM, 0)) != -1);
+ /* Non-blocking server socket */
+ ATF_REQUIRE(fcntl(sockfd, F_SETFL, O_NONBLOCK) != -1);
+ /* Bind to the specified address and wait for connection */
+ ATF_REQUIRE_EQ(0, bind(sockfd, (struct sockaddr *)&server, len));
+ ATF_REQUIRE_EQ(0, listen(sockfd, 1));
+
+ /* Set up "blocking" client socket */
+ ATF_REQUIRE((sockfd2 = socket(PF_UNIX, SOCK_STREAM, 0)) != -1);
+
+ /* Audit record must contain sockfd2 */
+ snprintf(extregex, sizeof(extregex),
+ "connectat.*0x%x.*return,success", sockfd2);
+
+ FILE *pipefd = setup(fds, auclass);
+ ATF_REQUIRE_EQ(0, connectat(AT_FDCWD, sockfd2,
+ (struct sockaddr *)&server, len));
+ check_audit(fds, extregex, pipefd);
+
+ /* Close all socket descriptors */
+ close_sockets(2, sockfd, sockfd2);
+}
+
+ATF_TC_CLEANUP(connectat_success, tc)
+{
+ cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(connectat_failure);
+ATF_TC_HEAD(connectat_failure, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+ "connectat(2) call");
+}
+
+ATF_TC_BODY(connectat_failure, tc)
+{
+ /* Preliminary socket setup */
+ struct sockaddr_un server;
+ assign_address(&server);
+ len = sizeof(struct sockaddr_un);
+ snprintf(extregex, sizeof(extregex), "connectat.*%s", invalregex);
+
+ FILE *pipefd = setup(fds, auclass);
+ /* Failure reason: Invalid socket descriptor */
+ ATF_REQUIRE_EQ(-1, connectat(AT_FDCWD, 0,
+ (struct sockaddr *)&server, len));
+ check_audit(fds, extregex, pipefd);
+}
+
+ATF_TC_CLEANUP(connectat_failure, tc)
+{
+ cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(accept_success);
+ATF_TC_HEAD(accept_success, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of a successful "
+ "accept(2) call");
+}
+
+ATF_TC_BODY(accept_success, tc)
+{
+ int clientfd;
+ struct sockaddr_un server, client;
+ assign_address(&server);
+ len = sizeof(struct sockaddr_un);
+
+ /* Server Socket: Assign address and listen for connection */
+ ATF_REQUIRE((sockfd = socket(PF_UNIX, SOCK_STREAM, 0)) != -1);
+ /* Non-blocking server socket */
+ ATF_REQUIRE(fcntl(sockfd, F_SETFL, O_NONBLOCK) != -1);
+ /* Bind to the specified address and wait for connection */
+ ATF_REQUIRE_EQ(0, bind(sockfd, (struct sockaddr *)&server, len));
+ ATF_REQUIRE_EQ(0, listen(sockfd, 1));
+
+ /* Set up "blocking" client socket */
+ ATF_REQUIRE((sockfd2 = socket(PF_UNIX, SOCK_STREAM, 0)) != -1);
+ ATF_REQUIRE_EQ(0, connect(sockfd2, (struct sockaddr *)&server, len));
+
+ FILE *pipefd = setup(fds, auclass);
+ ATF_REQUIRE((clientfd = accept(sockfd,
+ (struct sockaddr *)&client, &len)) != -1);
+
+ /* Audit record must contain clientfd & sockfd */
+ snprintf(extregex, sizeof(extregex),
+ "accept.*0x%x.*return,success,%d", sockfd, clientfd);
+ check_audit(fds, extregex, pipefd);
+
+ /* Close all socket descriptors */
+ close_sockets(3, sockfd, sockfd2, clientfd);
+}
+
+ATF_TC_CLEANUP(accept_success, tc)
+{
+ cleanup();
+}
+
+
+ATF_TC_WITH_CLEANUP(accept_failure);
+ATF_TC_HEAD(accept_failure, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "Tests the audit of an unsuccessful "
+ "accept(2) call");
+}
+
+ATF_TC_BODY(accept_failure, tc)
+{
+ /* Preliminary socket setup */
+ struct sockaddr_un client;
+ len = sizeof(struct sockaddr_un);
+ snprintf(extregex, sizeof(extregex), "accept.*%s", invalregex);
+
+ FILE *pipefd = setup(fds, auclass);
+ /* Failure reason: Invalid socket descriptor */
+ ATF_REQUIRE_EQ(-1, accept(0, (struct sockaddr *)&client, &len));
+ check_audit(fds, extregex, pipefd);
+}
+
+ATF_TC_CLEANUP(accept_failure, tc)
+{
+ cleanup();
+}
+
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, socket_success);
@@ -408,5 +622,12 @@
ATF_TP_ADD_TC(tp, listen_success);
ATF_TP_ADD_TC(tp, listen_failure);
+ ATF_TP_ADD_TC(tp, connect_success);
+ ATF_TP_ADD_TC(tp, connect_failure);
+ ATF_TP_ADD_TC(tp, connectat_success);
+ ATF_TP_ADD_TC(tp, connectat_failure);
+ ATF_TP_ADD_TC(tp, accept_success);
+ ATF_TP_ADD_TC(tp, accept_failure);
+
return (atf_no_error());
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Sep 6, 5:21 PM (19 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38424365
Default Alt Text
D15853.id43907.diff (6 KB)
Attached To
Mode
D15853: audit(4): Add tests for connect(2), connectat(2) and accept(2)
Attached
Detach File
Event Timeline
Log In to Comment