1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-26 10:04:02 +03:00

swrap: Process control messages in recvmsg().

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Andreas Schneider <asn@samba.org>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
This commit is contained in:
Andreas Schneider 2014-06-03 14:57:35 +02:00 committed by Michael Adam
parent fb308daaa0
commit 1df0810583

View File

@ -3863,6 +3863,8 @@ static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, int flags)
struct socket_info *si;
struct msghdr msg;
struct iovec tmp;
size_t msg_ctrllen_filled;
size_t msg_ctrllen_left;
ssize_t ret;
int rc;
@ -3881,6 +3883,9 @@ static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, int flags)
msg.msg_iov = omsg->msg_iov; /* scatter/gather array */
msg.msg_iovlen = omsg->msg_iovlen; /* # elements in msg_iov */
#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
msg_ctrllen_filled = 0;
msg_ctrllen_left = omsg->msg_controllen;
msg.msg_control = omsg->msg_control; /* ancillary data, see below */
msg.msg_controllen = omsg->msg_controllen; /* ancillary data buffer len */
msg.msg_flags = omsg->msg_flags; /* flags on received message */
@ -3893,11 +3898,45 @@ static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, int flags)
ret = libc_recvmsg(s, &msg, flags);
rc = swrap_recvmsg_after(s, si, omsg, &from_addr, from_addrlen, ret);
msg.msg_name = omsg->msg_name;
msg.msg_namelen = omsg->msg_namelen;
#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
msg_ctrllen_filled += msg.msg_controllen;
msg_ctrllen_left -= msg.msg_controllen;
if (omsg->msg_control != NULL) {
uint8_t *p;
p = omsg->msg_control;
p += msg_ctrllen_filled;
msg.msg_control = p;
msg.msg_controllen = msg_ctrllen_left;
} else {
msg.msg_control = NULL;
msg.msg_controllen = 0;
}
#endif
rc = swrap_recvmsg_after(s, si, &msg, &from_addr, from_addrlen, ret);
if (rc != 0) {
return rc;
}
#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
if (omsg->msg_control != NULL) {
/* msg.msg_controllen = space left */
msg_ctrllen_left = msg.msg_controllen;
msg_ctrllen_filled = omsg->msg_controllen - msg_ctrllen_left;
}
/* Update the original message length */
omsg->msg_controllen = msg_ctrllen_filled;
omsg->msg_flags = msg.msg_flags;
#endif
omsg->msg_iovlen = msg.msg_iovlen;
return ret;
}