[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Mon Jan 5 18:59:04 MST 2015


The branch, master has been updated
       via  a2670f1 winbind: Retry after SESSION_EXPIRED error in ping-dc
       via  0f6bf35 smbd: Properly handle EINTR in vfs_aio_fork
       via  4b1e6ae smbd: Use msghdr.[ch] in vfs_aio_fork
       via  8caa866 lib: Use msghdr_prep_recv_fds in unix_msg
       via  37af87e lib: Add msghdr_prep_recv_fds
       via  2beae2b lib: Use msghdr_extract_fds in unix_msg
       via  cd46f76 lib: Add msghdr_extract_fds
       via  9bd7e52 smbd: Use msghdr_prep_fds in vfs_aio_fork
       via  bd9b59a lib: Use msghdr in unix_msg
       via  190554c lib: Add msghdr.[ch]
       via  9859848 lib: unix_dgram_msg does not need "num_fds"
       via  9959fc9 torture3: Fix a typo
      from  8a2a598 s3:winbindd: improve logic to use CLDAP for a given domain.

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a2670f15dea27c10e3827216adf572f9c3894f85
Author: Christof Schmitt <cs at samba.org>
Date:   Fri Dec 19 12:24:53 2014 -0700

    winbind: Retry after SESSION_EXPIRED error in ping-dc
    
    Trying to establish a netlogon connection when the service ticket
    expires might fail with NT_STATUS_NETWORK_SESSION_EXPIRED. The
    underlying client code already marks the session as invalid, so retry
    the netlogon connect in this case.
    
    Signed-off-by: Christof Schmit <cs at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Tue Jan  6 02:58:57 CET 2015 on sn-devel-104

commit 0f6bf3575e587354fcd0dd274fa0d27210cc9ac6
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Dec 31 14:27:03 2014 +0100

    smbd: Properly handle EINTR in vfs_aio_fork
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 4b1e6ae5d393c3ac5e837b64f16bfbcf5267a2e0
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Dec 31 14:26:43 2014 +0100

    smbd: Use msghdr.[ch] in vfs_aio_fork
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 8caa866b08172dd5da5ef2cfadad4210c1dabf08
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Dec 31 14:19:13 2014 +0100

    lib: Use msghdr_prep_recv_fds in unix_msg
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 37af87e75e6efb7393f6e7572aaa4bef8f38920f
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Dec 31 14:18:59 2014 +0100

    lib: Add msghdr_prep_recv_fds
    
    This will prepare a msghdr for receiving fd's. Same pattern as before: First
    get the buffer size, then fill in msghdr.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 2beae2bfbce4e35361f0a559fa8d9508190f34ea
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Dec 31 13:33:48 2014 +0100

    lib: Use msghdr_extract_fds in unix_msg
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit cd46f7685b47bb40e2f794ec7380b8078627d87f
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Dec 31 13:14:41 2014 +0100

    lib: Add msghdr_extract_fds
    
    This is a copy of the extract_fd_array_from_msghdr routine in unix_msg.c, with
    a similar use pattern: First call it without an output array to get the length
    and then call it a second time to actually fill in the array.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 9bd7e52db0386b928a3d777e519ee23f2a0fedfb
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Dec 31 13:03:24 2014 +0100

    smbd: Use msghdr_prep_fds in vfs_aio_fork
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit bd9b59ae28e8128857e7d8308a23d09a547299e0
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 30 14:05:02 2014 +0000

    lib: Use msghdr in unix_msg
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 190554c402f23a9eff1f20670e66f7b94a36b396
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 30 13:36:46 2014 +0000

    lib: Add msghdr.[ch]
    
    This is a little set of routines to deal with the ugly fd-passing macros.
    
    This patch is the first step assisting the creation of msghrds for sending fds.
    Receiving fd helpers will follow later.
    
    The basic idea behind these routines is that they fill a variable-sized buffer.
    They are supposed to be called twice per msghdr preparation. First with a
    0-sized NULL output buffer to calculate the required bufsize, and then a second
    time filling in the buffer as such.
    
    This does not take care of the old msg_accrights way of passing file
    descriptors. CMSG/SCM_RIGHTS is standardized for quite a while now, and I
    believe this intreface can be made to also take care of msg_accrights if
    needed.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 98598485c3bb10638ee99f4b04768bd2e8683bb1
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 30 12:26:16 2014 +0100

    lib: unix_dgram_msg does not need "num_fds"
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

commit 9959fc9d72e40e69e87c76b9baee30fb11a4ae21
Author: Volker Lendecke <vl at samba.org>
Date:   Wed Dec 31 10:39:25 2014 +0100

    torture3: Fix a typo
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Ralph Boehme <slow at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 source3/lib/msghdr.c                  | 175 +++++++++++++++++++++++
 source3/lib/{iov_buf.h => msghdr.h}   |  28 ++--
 source3/lib/unix_msg/unix_msg.c       | 259 ++++++++++------------------------
 source3/lib/unix_msg/wscript_build    |   2 +-
 source3/modules/vfs_aio_fork.c        | 116 ++++++---------
 source3/torture/test_messaging_read.c |   2 +-
 source3/winbindd/winbindd_dual_srv.c  |   8 ++
 source3/wscript_build                 |   5 +
 8 files changed, 328 insertions(+), 267 deletions(-)
 create mode 100644 source3/lib/msghdr.c
 copy source3/lib/{iov_buf.h => msghdr.h} (53%)


Changeset truncated at 500 lines:

diff --git a/source3/lib/msghdr.c b/source3/lib/msghdr.c
new file mode 100644
index 0000000..9ed1444
--- /dev/null
+++ b/source3/lib/msghdr.c
@@ -0,0 +1,175 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Copyright (C) Volker Lendecke 2014
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include "lib/msghdr.h"
+#include "lib/iov_buf.h"
+#include <sys/socket.h>
+
+ssize_t msghdr_prep_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize,
+			const int *fds, size_t num_fds)
+{
+	size_t fds_size = sizeof(int) * MIN(num_fds, INT8_MAX);
+	size_t cmsg_len = CMSG_LEN(fds_size);
+	size_t cmsg_space = CMSG_SPACE(fds_size);
+	struct cmsghdr *cmsg;
+	void *fdptr;
+
+	if (num_fds == 0) {
+		if (msg != NULL) {
+			msg->msg_control = NULL;
+			msg->msg_controllen = 0;
+		}
+		return 0;
+	}
+	if (num_fds > INT8_MAX) {
+		return -1;
+	}
+	if (cmsg_space > bufsize) {
+		return cmsg_space;
+	}
+
+	msg->msg_control = buf;
+	msg->msg_controllen = cmsg_space;
+
+	cmsg = CMSG_FIRSTHDR(msg);
+	cmsg->cmsg_level = SOL_SOCKET;
+	cmsg->cmsg_type = SCM_RIGHTS;
+	cmsg->cmsg_len = cmsg_len;
+	fdptr = CMSG_DATA(cmsg);
+	memcpy(fdptr, fds, fds_size);
+	msg->msg_controllen = cmsg->cmsg_len;
+
+	return cmsg_space;
+}
+
+struct msghdr_buf {
+	struct msghdr msg;
+	struct sockaddr_storage addr;
+	struct iovec iov;
+	uint8_t buf[];
+};
+
+ssize_t msghdr_copy(struct msghdr_buf *msg, size_t msgsize,
+		    const void *addr, socklen_t addrlen,
+		    const struct iovec *iov, int iovcnt,
+		    const int *fds, size_t num_fds)
+{
+	size_t fd_len, iov_len, needed, bufsize;
+
+	bufsize = (msgsize > offsetof(struct msghdr_buf, buf)) ?
+		msgsize - offsetof(struct msghdr_buf, buf) : 0;
+
+	fd_len = msghdr_prep_fds(&msg->msg, msg->buf, bufsize, fds, num_fds);
+
+	if (bufsize >= fd_len) {
+		bufsize -= fd_len;
+	} else {
+		bufsize = 0;
+	}
+
+	if (msg != NULL) {
+
+		if (addr != NULL) {
+			if (addrlen > sizeof(struct sockaddr_storage)) {
+				errno = EMSGSIZE;
+				return -1;
+			}
+			memcpy(&msg->addr, addr, addrlen);
+			msg->msg.msg_name = &msg->addr;
+			msg->msg.msg_namelen = addrlen;
+		} else {
+			msg->msg.msg_name = NULL;
+			msg->msg.msg_namelen = 0;
+		}
+
+		msg->iov.iov_base = msg->buf + fd_len;
+		msg->iov.iov_len = iov_buf(
+			iov, iovcnt, msg->iov.iov_base, bufsize);
+		iov_len = msg->iov.iov_len;
+
+		msg->msg.msg_iov = &msg->iov;
+		msg->msg.msg_iovlen = 1;
+	} else {
+		iov_len = iov_buflen(iov, iovcnt);
+	}
+
+	needed = offsetof(struct msghdr_buf, buf) + fd_len;
+	if (needed < fd_len) {
+		return -1;
+	}
+	needed += iov_len;
+	if (needed < iov_len) {
+		return -1;
+	}
+
+	return needed;
+}
+
+struct msghdr *msghdr_buf_msghdr(struct msghdr_buf *msg)
+{
+	return &msg->msg;
+}
+
+size_t msghdr_prep_recv_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize,
+			    size_t num_fds)
+{
+	size_t ret = CMSG_SPACE(sizeof(int) * num_fds);
+
+	if (bufsize < ret) {
+		return ret;
+	}
+	if (msg != NULL) {
+		if (num_fds != 0) {
+			msg->msg_control = buf;
+			msg->msg_controllen = ret;
+		} else {
+			msg->msg_control = NULL;
+			msg->msg_controllen = 0;
+		}
+	}
+	return ret;
+}
+
+size_t msghdr_extract_fds(struct msghdr *msg, int *fds, size_t fds_size)
+{
+	struct cmsghdr *cmsg;
+	size_t num_fds;
+
+	for(cmsg = CMSG_FIRSTHDR(msg);
+	    cmsg != NULL;
+	    cmsg = CMSG_NXTHDR(msg, cmsg))
+	{
+		if ((cmsg->cmsg_type == SCM_RIGHTS) &&
+		    (cmsg->cmsg_level == SOL_SOCKET)) {
+			break;
+		}
+	}
+
+	if (cmsg == NULL) {
+		return 0;
+	}
+
+	num_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);
+
+	if ((num_fds != 0) && (fds_size >= num_fds)) {
+		memcpy(fds, CMSG_DATA(cmsg), num_fds * sizeof(int));
+	}
+
+	return num_fds;
+}
diff --git a/source3/lib/iov_buf.h b/source3/lib/msghdr.h
similarity index 53%
copy from source3/lib/iov_buf.h
copy to source3/lib/msghdr.h
index 8f0ca26..c1676d2 100644
--- a/source3/lib/iov_buf.h
+++ b/source3/lib/msghdr.h
@@ -1,6 +1,5 @@
 /*
  * Unix SMB/CIFS implementation.
- * Samba system utilities
  * Copyright (C) Volker Lendecke 2014
  *
  * This program is free software; you can redistribute it and/or modify
@@ -17,16 +16,27 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef __LIB_IOV_BUF_H__
-#define __LIB_IOV_BUF_H__
+#ifndef __LIB_MSGHDR_H__
+#define __LIB_MSGHDR_H__
 
-#include <unistd.h>
+#include <stddef.h>
 #include <stdint.h>
-#include <stdbool.h>
+#include <sys/uio.h>
+#include <sys/socket.h>
 
-ssize_t iov_buflen(const struct iovec *iov, int iovlen);
-ssize_t iov_buf(const struct iovec *iov, int iovcnt,
-		uint8_t *buf, size_t buflen);
-bool iov_advance(struct iovec **iov, int *iovcnt, size_t n);
+ssize_t msghdr_prep_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize,
+			const int *fds, size_t num_fds);
+
+struct msghdr_buf;
+
+ssize_t msghdr_copy(struct msghdr_buf *msg, size_t msgsize,
+		    const void *addr, socklen_t addrlen,
+		    const struct iovec *iov, int iovcnt,
+		    const int *fds, size_t num_fds);
+struct msghdr *msghdr_buf_msghdr(struct msghdr_buf *msg);
+
+size_t msghdr_prep_recv_fds(struct msghdr *msg, uint8_t *buf, size_t bufsize,
+			    size_t num_fds);
+size_t msghdr_extract_fds(struct msghdr *msg, int *fds, size_t num_fds);
 
 #endif
diff --git a/source3/lib/unix_msg/unix_msg.c b/source3/lib/unix_msg/unix_msg.c
index 78b29c2..51bb0c6 100644
--- a/source3/lib/unix_msg/unix_msg.c
+++ b/source3/lib/unix_msg/unix_msg.c
@@ -24,6 +24,7 @@
 #include "dlinklist.h"
 #include "pthreadpool/pthreadpool.h"
 #include "lib/iov_buf.h"
+#include "lib/msghdr.h"
 #include <fcntl.h>
 
 /*
@@ -43,9 +44,6 @@ struct unix_dgram_msg {
 	int sock;
 	ssize_t sent;
 	int sys_errno;
-	size_t num_fds;
-	struct msghdr msg;
-	struct iovec iov;
 };
 
 struct unix_dgram_send_queue {
@@ -137,30 +135,20 @@ static int prepare_socket(int sock)
 	return prepare_socket_cloexec(sock);
 }
 
-static void extract_fd_array_from_msghdr(struct msghdr *msg, int **fds,
-					 size_t *num_fds)
+static size_t unix_dgram_msg_size(void)
 {
-#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
-	struct cmsghdr *cmsg;
-
-	for(cmsg = CMSG_FIRSTHDR(msg);
-	    cmsg != NULL;
-	    cmsg = CMSG_NXTHDR(msg, cmsg))
-	{
-		void *data = CMSG_DATA(cmsg);
-
-		if (cmsg->cmsg_type != SCM_RIGHTS) {
-			continue;
-		}
-		if (cmsg->cmsg_level != SOL_SOCKET) {
-			continue;
-		}
+	size_t msgsize = sizeof(struct unix_dgram_msg);
+	msgsize = (msgsize + 15) & ~15; /* align to 16 */
+	return msgsize;
+}
 
-		*fds = (int *)data;
-		*num_fds = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof (int);
-		break;
-	}
-#endif
+static struct msghdr_buf *unix_dgram_msghdr(struct unix_dgram_msg *msg)
+{
+	/*
+	 * Not portable in C99, but "msg" is aligned and so is
+	 * unix_dgram_msg_size()
+	 */
+	return (struct msghdr_buf *)(((char *)msg) + unix_dgram_msg_size());
 }
 
 static void close_fd_array(int *fds, size_t num_fds)
@@ -177,16 +165,15 @@ static void close_fd_array(int *fds, size_t num_fds)
 	}
 }
 
-static void close_fd_array_cmsg(struct msghdr *msg)
+static void close_fd_array_dgram_msg(struct unix_dgram_msg *dmsg)
 {
-	int *fds = NULL;
-	size_t num_fds = 0;
+	struct msghdr_buf *hdr = unix_dgram_msghdr(dmsg);
+	struct msghdr *msg = msghdr_buf_msghdr(hdr);
+	size_t num_fds = msghdr_extract_fds(msg, NULL, 0);
+	int fds[num_fds];
 
-	extract_fd_array_from_msghdr(msg, &fds, &num_fds);
+	msghdr_extract_fds(msg, fds, num_fds);
 
-	/*
-	 * TODO: caveat - side-effect - changing msg ???
-	 */
 	close_fd_array(fds, num_fds);
 }
 
@@ -285,11 +272,8 @@ static void unix_dgram_recv_handler(struct poll_watch *w, int fd, short events,
 	int flags = 0;
 	struct msghdr msg;
 	struct iovec iov;
-#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
-	char buf[CMSG_SPACE(sizeof(int)*INT8_MAX)] = { 0, };
-#endif /* HAVE_STRUCT_MSGHDR_MSG_CONTROL */
-	int *fds = NULL;
-	size_t i, num_fds = 0;
+	size_t bufsize = msghdr_prep_recv_fds(NULL, NULL, 0, INT8_MAX);
+	uint8_t buf[bufsize];
 
 	iov = (struct iovec) {
 		.iov_base = (void *)ctx->recv_buf,
@@ -299,12 +283,10 @@ static void unix_dgram_recv_handler(struct poll_watch *w, int fd, short events,
 	msg = (struct msghdr) {
 		.msg_iov = &iov,
 		.msg_iovlen = 1,
-#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
-		.msg_control = buf,
-		.msg_controllen = sizeof(buf),
-#endif
 	};
 
+	msghdr_prep_recv_fds(&msg, buf, bufsize, INT8_MAX);
+
 #ifdef MSG_CMSG_CLOEXEC
 	flags |= MSG_CMSG_CLOEXEC;
 #endif
@@ -326,32 +308,26 @@ static void unix_dgram_recv_handler(struct poll_watch *w, int fd, short events,
 		return;
 	}
 
-	extract_fd_array_from_msghdr(&msg, &fds, &num_fds);
-
-	for (i = 0; i < num_fds; i++) {
-		int err;
-
-		err = prepare_socket_cloexec(fds[i]);
-		if (err != 0) {
-			goto cleanup_fds;
-		}
-	}
+	{
+		size_t num_fds = msghdr_extract_fds(&msg, NULL, 0);
+		int fds[num_fds];
+		int i;
 
-	ctx->recv_callback(ctx, ctx->recv_buf, received,
-			   fds, num_fds, ctx->private_data);
+		msghdr_extract_fds(&msg, fds, num_fds);
 
-	/*
-	 * Close those fds that the callback has not set to -1.
-	 */
-	close_fd_array(fds, num_fds);
+		for (i = 0; i < num_fds; i++) {
+			int err;
 
-	return;
-
-cleanup_fds:
-	close_fd_array(fds, num_fds);
+			err = prepare_socket_cloexec(fds[i]);
+			if (err != 0) {
+				close_fd_array(fds, num_fds);
+				num_fds = 0;
+			}
+		}
 
-	ctx->recv_callback(ctx, ctx->recv_buf, received,
-			   NULL, 0, ctx->private_data);
+		ctx->recv_callback(ctx, ctx->recv_buf, received,
+				   fds, num_fds, ctx->private_data);
+	}
 }
 
 static void unix_dgram_job_finished(struct poll_watch *w, int fd, short events,
@@ -449,7 +425,7 @@ static void unix_dgram_send_queue_free(struct unix_dgram_send_queue *q)
 		struct unix_dgram_msg *msg;
 		msg = q->msgs;
 		DLIST_REMOVE(q->msgs, msg);
-		close_fd_array_cmsg(&msg->msg);
+		close_fd_array_dgram_msg(msg);
 		free(msg);
 	}
 	close(q->sock);
@@ -471,55 +447,17 @@ static struct unix_dgram_send_queue *find_send_queue(
 }
 
 static int queue_msg(struct unix_dgram_send_queue *q,
-		     const struct iovec *iov, int iovlen,
+		     const struct iovec *iov, int iovcnt,
 		     const int *fds, size_t num_fds)
 {
 	struct unix_dgram_msg *msg;
-	ssize_t data_len;
-	uint8_t *data_buf;
-	size_t msglen = sizeof(struct unix_dgram_msg);
-	int i;
-	size_t tmp;
-	int ret = -1;
-#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
-	size_t fds_size = sizeof(int) * MIN(num_fds, INT8_MAX);
+	struct msghdr_buf *hdr;
+	size_t msglen, needed;
+	ssize_t msghdrlen;
 	int fds_copy[MIN(num_fds, INT8_MAX)];
-	size_t cmsg_len = CMSG_LEN(fds_size);
-	size_t cmsg_space = CMSG_SPACE(fds_size);
-	char *cmsg_buf;
-
-	/*
-	 * Note: No need to check for overflow here,
-	 * since cmsg will store <= INT8_MAX fds.
-	 */
-	msglen += cmsg_space;
-
-#endif /*  HAVE_STRUCT_MSGHDR_MSG_CONTROL */
-
-	if (num_fds > INT8_MAX) {
-		return EINVAL;
-	}
+	int i, ret;
 
-#ifndef HAVE_STRUCT_MSGHDR_MSG_CONTROL
-	if (num_fds > 0) {
-		return ENOSYS;
-	}
-#endif
-
-	data_len = iov_buflen(iov, iovlen);
-	if (data_len == -1) {
-		return EINVAL;
-	}
-
-	tmp = msglen + data_len;
-	if ((tmp < msglen) || (tmp < data_len)) {
-		/* overflow */
-		return EINVAL;
-	}
-	msglen = tmp;
-
-#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
-	for (i = 0; i < num_fds; i++) {
+	for (i=0; i<num_fds; i++) {
 		fds_copy[i] = -1;
 	}
 
@@ -530,68 +468,37 @@ static int queue_msg(struct unix_dgram_send_queue *q,
 			goto fail;
 		}
 	}
-#endif
 
-	msg = malloc(msglen);
-	if (msg == NULL) {
-		ret = ENOMEM;
+	msglen = unix_dgram_msg_size();
+
+	msghdrlen = msghdr_copy(NULL, 0, NULL, 0, iov, iovcnt,
+				fds_copy, num_fds);
+	if (msghdrlen == -1) {
+		ret = EMSGSIZE;
 		goto fail;
 	}
 
-	msg->sock = q->sock;
-	msg->num_fds = num_fds;
-
-	data_buf = (uint8_t *)(msg + 1);
-
-#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
-	if (num_fds > 0) {
-		cmsg_buf = (char *)data_buf;
-		memset(cmsg_buf, 0, cmsg_space);
-		data_buf += cmsg_space;
-	} else {
-		cmsg_buf = NULL;
-		cmsg_space = 0;
+	needed = msglen + msghdrlen;


-- 
Samba Shared Repository


More information about the samba-cvs mailing list