summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2020-06-29 09:39:22 +0200
committerAndreas Schneider <asn@samba.org>2021-02-02 10:23:33 +0100
commitc740bbe30affb7b94c6cca5f65a4e9047a1119ec (patch)
treea842d85f45ab3fdcf3006ebb0b08b94986bb897b
parentde819958b00b48f285a1f31bfee1f8bee8e16827 (diff)
downloadsocket_wrapper-c740bbe30affb7b94c6cca5f65a4e9047a1119ec.tar.gz
socket_wrapper-c740bbe30affb7b94c6cca5f65a4e9047a1119ec.tar.xz
socket_wrapper-c740bbe30affb7b94c6cca5f65a4e9047a1119ec.zip
swrap: let swrap_sendmsg_before_unix() create a copy of msg_tmp.msg_control
With fd-passing we'll have to modify the content of it. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
-rw-r--r--src/socket_wrapper.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/socket_wrapper.c b/src/socket_wrapper.c
index a0eef9d..fa18a09 100644
--- a/src/socket_wrapper.c
+++ b/src/socket_wrapper.c
@@ -5151,13 +5151,56 @@ static int swrap_sendmsg_filter_cmsg_sol_socket(const struct cmsghdr *cmsg,
static int swrap_sendmsg_before_unix(const struct msghdr *_msg_in,
struct msghdr *msg_tmp)
{
+#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
+ struct msghdr *msg_in = discard_const_p(struct msghdr, _msg_in);
+ struct cmsghdr *cmsg = NULL;
+ uint8_t *cm_data = NULL;
+ size_t cm_data_space = 0;
+ int rc = -1;
+
+ *msg_tmp = *msg_in;
+
+ /* Nothing to do */
+ if (msg_in->msg_controllen == 0 || msg_in->msg_control == NULL) {
+ return 0;
+ }
+
+ for (cmsg = CMSG_FIRSTHDR(msg_in);
+ cmsg != NULL;
+ cmsg = CMSG_NXTHDR(msg_in, cmsg)) {
+ switch (cmsg->cmsg_level) {
+ default:
+ rc = swrap_sendmsg_copy_cmsg(cmsg,
+ &cm_data,
+ &cm_data_space);
+ break;
+ }
+ if (rc < 0) {
+ int saved_errno = errno;
+ SAFE_FREE(cm_data);
+ errno = saved_errno;
+ return rc;
+ }
+ }
+
+ msg_tmp->msg_controllen = cm_data_space;
+ msg_tmp->msg_control = cm_data;
+
+ return 0;
+#else /* HAVE_STRUCT_MSGHDR_MSG_CONTROL */
*msg_tmp = *_msg_in;
return 0;
+#endif /* ! HAVE_STRUCT_MSGHDR_MSG_CONTROL */
}
static ssize_t swrap_sendmsg_after_unix(struct msghdr *msg_tmp,
ssize_t ret)
{
+#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
+ int saved_errno = errno;
+ SAFE_FREE(msg_tmp->msg_control);
+ errno = saved_errno;
+#endif /* HAVE_STRUCT_MSGHDR_MSG_CONTROL */
return ret;
}