diff options
author | dec05eba <dec05eba@protonmail.com> | 2023-11-18 13:55:27 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2023-11-18 13:55:27 +0100 |
commit | 2cbcde19f62970a8da308d5b128b2b2d7c725077 (patch) | |
tree | 3430722f0dbca95eb6d125ad0326317ade0a2914 /kms/client | |
parent | 7bc72696521895218cf3b84abb41b97b209e1b5a (diff) |
Properly send socketpair fd to kms server
Diffstat (limited to 'kms/client')
-rw-r--r-- | kms/client/kms_client.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/kms/client/kms_client.c b/kms/client/kms_client.c index 3e60c63..8e1dafb 100644 --- a/kms/client/kms_client.c +++ b/kms/client/kms_client.c @@ -53,11 +53,29 @@ static int send_msg_to_server(int server_fd, gsr_kms_request *request) { iov.iov_base = request; iov.iov_len = sizeof(*request); - struct msghdr request_message = {0}; - request_message.msg_iov = &iov; - request_message.msg_iovlen = 1; + struct msghdr response_message = {0}; + response_message.msg_iov = &iov; + response_message.msg_iovlen = 1; + + char cmsgbuf[CMSG_SPACE(sizeof(int) * 1)]; + memset(cmsgbuf, 0, sizeof(cmsgbuf)); + + if(request->new_connection_fd > 0) { + response_message.msg_control = cmsgbuf; + response_message.msg_controllen = sizeof(cmsgbuf); + + struct cmsghdr *cmsg = CMSG_FIRSTHDR(&response_message); + cmsg->cmsg_level = SOL_SOCKET; + cmsg->cmsg_type = SCM_RIGHTS; + cmsg->cmsg_len = CMSG_LEN(sizeof(int) * 1); + + int *fds = (int*)CMSG_DATA(cmsg); + fds[0] = request->new_connection_fd; + + response_message.msg_controllen = cmsg->cmsg_len; + } - return sendmsg(server_fd, &request_message, 0); + return sendmsg(server_fd, &response_message, 0); } static int recv_msg_from_server(int server_fd, gsr_kms_response *response) { |