mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
smbd: Use msghdr_prep_fds in vfs_aio_fork
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
This commit is contained in:
parent
bd9b59ae28
commit
9bd7e52db0
@ -28,6 +28,7 @@
|
||||
#include "lib/util/tevent_unix.h"
|
||||
#include "lib/sys_rw.h"
|
||||
#include "lib/sys_rw_data.h"
|
||||
#include "lib/msghdr.h"
|
||||
|
||||
#if !defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) && !defined(HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS)
|
||||
# error Can not pass file descriptors
|
||||
@ -221,39 +222,17 @@ static ssize_t read_fd(int fd, void *ptr, size_t nbytes, int *recvfd)
|
||||
static ssize_t write_fd(int fd, void *ptr, size_t nbytes, int sendfd)
|
||||
{
|
||||
struct msghdr msg;
|
||||
struct iovec iov[1];
|
||||
|
||||
#ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL
|
||||
union {
|
||||
struct cmsghdr cm;
|
||||
char control[CMSG_SPACE(sizeof(int))];
|
||||
} control_un;
|
||||
struct cmsghdr *cmptr;
|
||||
|
||||
ZERO_STRUCT(msg);
|
||||
ZERO_STRUCT(control_un);
|
||||
|
||||
msg.msg_control = control_un.control;
|
||||
msg.msg_controllen = sizeof(control_un.control);
|
||||
|
||||
cmptr = CMSG_FIRSTHDR(&msg);
|
||||
cmptr->cmsg_len = CMSG_LEN(sizeof(int));
|
||||
cmptr->cmsg_level = SOL_SOCKET;
|
||||
cmptr->cmsg_type = SCM_RIGHTS;
|
||||
memcpy(CMSG_DATA(cmptr), &sendfd, sizeof(sendfd));
|
||||
#else
|
||||
ZERO_STRUCT(msg);
|
||||
msg.msg_accrights = (caddr_t) &sendfd;
|
||||
msg.msg_accrightslen = sizeof(int);
|
||||
#endif
|
||||
size_t bufsize = msghdr_prep_fds(NULL, NULL, 0, &sendfd, 1);
|
||||
uint8_t buf[bufsize];
|
||||
struct iovec iov;
|
||||
|
||||
msghdr_prep_fds(&msg, buf, bufsize, &sendfd, 1);
|
||||
msg.msg_name = NULL;
|
||||
msg.msg_namelen = 0;
|
||||
|
||||
ZERO_STRUCT(iov);
|
||||
iov[0].iov_base = (void *)ptr;
|
||||
iov[0].iov_len = nbytes;
|
||||
msg.msg_iov = iov;
|
||||
iov.iov_base = (void *)ptr;
|
||||
iov.iov_len = nbytes;
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
return (sendmsg(fd, &msg, 0));
|
||||
|
Loading…
Reference in New Issue
Block a user