The Samba-Bugzilla – Attachment 10505 Details for
Bug 10965
Missing eventfd prototype check in socket_wrapper for newer glibc
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Complete backport of socket_wrapper 1.1.2 to v4-2-test
tmp42.diff.txt (text/plain), 82.98 KB, created by
Stefan Metzmacher
on 2014-12-08 16:46:14 UTC
(
hide
)
Description:
Complete backport of socket_wrapper 1.1.2 to v4-2-test
Filename:
MIME Type:
Creator:
Stefan Metzmacher
Created:
2014-12-08 16:46:14 UTC
Size:
82.98 KB
patch
obsolete
>From f08c3cb8e81cf39c7fb7970a997c5b2388198398 Mon Sep 17 00:00:00 2001 >From: Michael Adam <obnox@samba.org> >Date: Thu, 2 Oct 2014 07:00:44 +0200 >Subject: [PATCH 01/27] swrap: fix build when neither HAVE_STRUCT_IN_PKTINFO > nor IP_RECVDSTADDR is defined > >Signed-off-by: Michael Adam <obnox@samba.org> >Reviewed-by: Andreas Schneider <asn@samba.org> >(cherry picked from commit a7a47796fd7ca1fa830a8c2644042c311b9796da) >--- > lib/socket_wrapper/socket_wrapper.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 67303eb..44b1f0b 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -3410,8 +3410,7 @@ static int swrap_msghdr_add_pktinfo(struct socket_info *si, > { > /* Add packet info */ > switch (si->pktinfo) { >-#if defined(IP_PKTINFO) >-/* && (defined(HAVE_STRUCT_IN_PKTINFO) || defined(IP_RECVDSTADDR)) */ >+#if defined(IP_PKTINFO) && (defined(HAVE_STRUCT_IN_PKTINFO) || defined(IP_RECVDSTADDR)) > case AF_INET: { > struct sockaddr_in *sin; > #if defined(HAVE_STRUCT_IN_PKTINFO) >-- >1.9.1 > > >From 2d2a6c98c01da3d1f55ee96d1a74da4e022d8850 Mon Sep 17 00:00:00 2001 >From: Michael Adam <obnox@samba.org> >Date: Thu, 2 Oct 2014 07:01:34 +0200 >Subject: [PATCH 02/27] swrap: fix discard const warning in > swrap_remove_stale() > >Signed-off-by: Michael Adam <obnox@samba.org> >Reviewed-by: Andreas Schneider <asn@samba.org> >(cherry picked from commit bebbd289859cff50d63cdbe76d214b67fd33e3f8) >--- > lib/socket_wrapper/socket_wrapper.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 44b1f0b..f216d76 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -1394,14 +1394,14 @@ static int sockaddr_convert_to_un(struct socket_info *si, > > switch (in_addr->sa_family) { > case AF_UNSPEC: { >- struct sockaddr_in *sin; >+ const struct sockaddr_in *sin; > if (si->family != AF_INET) { > break; > } > if (in_len < sizeof(struct sockaddr_in)) { > break; > } >- sin = (struct sockaddr_in *)in_addr; >+ sin = (const struct sockaddr_in *)in_addr; > if(sin->sin_addr.s_addr != htonl(INADDR_ANY)) { > break; > } >-- >1.9.1 > > >From 1507f8e804f2abbe30c93ed8812919b08da2e2fb Mon Sep 17 00:00:00 2001 >From: Michael Adam <obnox@samba.org> >Date: Thu, 2 Oct 2014 07:02:36 +0200 >Subject: [PATCH 03/27] swrap: fix discard const warning in swrap_bind() > >Signed-off-by: Michael Adam <obnox@samba.org> >Reviewed-by: Andreas Schneider <asn@samba.org> >(cherry picked from commit f6fe9a997d2f5a1c504ea53886e00cfb33ec76d0) >--- > lib/socket_wrapper/socket_wrapper.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index f216d76..ef71c5e 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -2846,7 +2846,7 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) > break; > } > >- sin = (struct sockaddr_in *)myaddr; >+ sin = (const struct sockaddr_in *)myaddr; > > if (sin->sin_family != AF_INET) { > bind_error = EAFNOSUPPORT; >-- >1.9.1 > > >From 87b2b2d245e5d735f329a99ceb7ef9dd97ba460f Mon Sep 17 00:00:00 2001 >From: Michael Adam <obnox@samba.org> >Date: Thu, 2 Oct 2014 07:03:22 +0200 >Subject: [PATCH 04/27] swrap: fix another discard const warning in > swrap_bind() > >Signed-off-by: Michael Adam <obnox@samba.org> >Reviewed-by: Andreas Schneider <asn@samba.org> >(cherry picked from commit 616364378da073f841d46fb299c81adb05d5222d) >--- > lib/socket_wrapper/socket_wrapper.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index ef71c5e..903eec2 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -2869,7 +2869,7 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) > break; > } > >- sin6 = (struct sockaddr_in6 *)myaddr; >+ sin6 = (const struct sockaddr_in6 *)myaddr; > > if (sin6->sin6_family != AF_INET6) { > bind_error = EAFNOSUPPORT; >-- >1.9.1 > > >From 2d2eed14e34370bf7c2c76b081c3a7f513a8ff43 Mon Sep 17 00:00:00 2001 >From: Jakub Hrozek <jakub.hrozek@gmail.com> >Date: Thu, 2 Oct 2014 07:05:35 +0200 >Subject: [PATCH 05/27] Provide a compatible declaration of CMSG_ALIGN > >Some platforms (like OSX) do support some of the CMGS macros, but don't >have a CMSG_ALIGN macro of their own. > >Signed-off-by: Jakub Hrozek <jakub.hrozek@gmail.com> >Reviewed-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Michael Adam <obnox@samba.org> >(cherry picked from commit 95c9917c8638f1eb5480e851c8dfbb808f1687bd) >--- > lib/socket_wrapper/socket_wrapper.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 903eec2..930ab58 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -3336,7 +3336,7 @@ int ioctl(int s, unsigned long int r, ...) > # ifdef _ALIGN /* BSD */ > #define CMSG_ALIGN _ALIGN > # else >-#error NO_CMSG_ALIGN >+#define CMSG_ALIGN(len) (((len) + sizeof(size_t) - 1) & ~(sizeof(size_t) - 1)) > # endif /* _ALIGN */ > #endif /* CMSG_ALIGN */ > >-- >1.9.1 > > >From 7a5f65375a4d1a3ffbe6fc27712699c556c8e587 Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:09:33 +0200 >Subject: [PATCH 06/27] swrap: Fix type punning warnings. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 2be25abcb13353c26712ec8bc50f65ad53d390d4) >--- > lib/socket_wrapper/socket_wrapper.c | 202 +++++++++++++++++++++++------------- > 1 file changed, 127 insertions(+), 75 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 930ab58..d5ab3c9 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -210,6 +210,19 @@ enum swrap_dbglvl_e { > * without changing the format above */ > #define MAX_WRAPPED_INTERFACES 40 > >+struct swrap_address { >+ socklen_t sa_socklen; >+ union { >+ struct sockaddr s; >+ struct sockaddr_in in; >+#ifdef HAVE_IPV6 >+ struct sockaddr_in6 in6; >+#endif >+ struct sockaddr_un un; >+ struct sockaddr_storage ss; >+ } sa; >+}; >+ > struct socket_info_fd { > struct socket_info_fd *prev, *next; > int fd; >@@ -2466,10 +2479,12 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > struct socket_info *parent_si, *child_si; > struct socket_info_fd *child_fi; > int fd; >- struct sockaddr_un un_addr; >- socklen_t un_addrlen = sizeof(un_addr); >- struct sockaddr_un un_my_addr; >- socklen_t un_my_addrlen = sizeof(un_my_addr); >+ struct swrap_address un_addr = { >+ .sa_socklen = sizeof(struct sockaddr_un), >+ }; >+ struct swrap_address un_my_addr = { >+ .sa_socklen = sizeof(struct sockaddr_un), >+ }; > struct sockaddr *my_addr; > socklen_t my_addrlen, len; > int ret; >@@ -2494,10 +2509,7 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > return -1; > } > >- memset(&un_addr, 0, sizeof(un_addr)); >- memset(&un_my_addr, 0, sizeof(un_my_addr)); >- >- ret = libc_accept(s, (struct sockaddr *)(void *)&un_addr, &un_addrlen); >+ ret = libc_accept(s, &un_addr.sa.s, &un_addr.sa_socklen); > if (ret == -1) { > if (errno == ENOTSOCK) { > /* Remove stale fds */ >@@ -2510,8 +2522,12 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > fd = ret; > > len = my_addrlen; >- ret = sockaddr_convert_from_un(parent_si, &un_addr, un_addrlen, >- parent_si->family, my_addr, &len); >+ ret = sockaddr_convert_from_un(parent_si, >+ &un_addr.sa.un, >+ un_addr.sa_socklen, >+ parent_si->family, >+ my_addr, >+ &len); > if (ret == -1) { > free(my_addr); > close(fd); >@@ -2553,8 +2569,8 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > } > > ret = libc_getsockname(fd, >- (struct sockaddr *)(void *)&un_my_addr, >- &un_my_addrlen); >+ &un_my_addr.sa.s, >+ &un_my_addr.sa_socklen); > if (ret == -1) { > free(child_fi); > free(child_si); >@@ -2564,8 +2580,12 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > } > > len = my_addrlen; >- ret = sockaddr_convert_from_un(child_si, &un_my_addr, un_my_addrlen, >- child_si->family, my_addr, &len); >+ ret = sockaddr_convert_from_un(child_si, >+ &un_my_addr.sa.un, >+ un_my_addr.sa_socklen, >+ child_si->family, >+ my_addr, >+ &len); > if (ret == -1) { > free(child_fi); > free(child_si); >@@ -2576,7 +2596,7 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > > SWRAP_LOG(SWRAP_LOG_TRACE, > "accept() path=%s, fd=%d", >- un_my_addr.sun_path, s); >+ un_my_addr.sa.un.sun_path, s); > > child_si->myname_len = len; > child_si->myname = sockaddr_dup(my_addr, len); >@@ -2613,7 +2633,9 @@ static int autobind_start; > */ > static int swrap_auto_bind(int fd, struct socket_info *si, int family) > { >- struct sockaddr_un un_addr; >+ struct swrap_address un_addr = { >+ .sa_socklen = sizeof(struct sockaddr_un), >+ }; > int i; > char type; > int ret; >@@ -2627,7 +2649,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family) > autobind_start += 10000; > } > >- un_addr.sun_family = AF_UNIX; >+ un_addr.sa.un.sun_family = AF_UNIX; > > switch (family) { > case AF_INET: { >@@ -2697,16 +2719,15 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family) > > for (i = 0; i < SOCKET_MAX_SOCKETS; i++) { > port = autobind_start + i; >- snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), >+ snprintf(un_addr.sa.un.sun_path, un_addr.sa_socklen, > "%s/"SOCKET_FORMAT, socket_wrapper_dir(), > type, socket_wrapper_default_iface(), port); >- if (stat(un_addr.sun_path, &st) == 0) continue; >+ if (stat(un_addr.sa.un.sun_path, &st) == 0) continue; > >- ret = libc_bind(fd, (struct sockaddr *)(void *)&un_addr, >- sizeof(un_addr)); >+ ret = libc_bind(fd, &un_addr.sa.s, un_addr.sa_socklen); > if (ret == -1) return ret; > >- si->tmp_path = strdup(un_addr.sun_path); >+ si->tmp_path = strdup(un_addr.sa.un.sun_path); > si->bound = 1; > autobind_start = port + 1; > break; >@@ -2736,7 +2757,9 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr, > socklen_t addrlen) > { > int ret; >- struct sockaddr_un un_addr; >+ struct swrap_address un_addr = { >+ .sa_socklen = sizeof(struct sockaddr_un), >+ }; > struct socket_info *si = find_socket_info(s); > int bcast = 0; > >@@ -2755,7 +2778,7 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr, > } > > ret = sockaddr_convert_to_un(si, serv_addr, >- addrlen, &un_addr, 0, &bcast); >+ addrlen, &un_addr.sa.un, 0, &bcast); > if (ret == -1) return -1; > > if (bcast) { >@@ -2770,13 +2793,13 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr, > swrap_dump_packet(si, serv_addr, SWRAP_CONNECT_SEND, NULL, 0); > > ret = libc_connect(s, >- (struct sockaddr *)(void *)&un_addr, >- sizeof(struct sockaddr_un)); >+ &un_addr.sa.s, >+ un_addr.sa_socklen); > } > > SWRAP_LOG(SWRAP_LOG_TRACE, > "connect() path=%s, fd=%d", >- un_addr.sun_path, s); >+ un_addr.un.sun_path, s); > > > /* to give better errors */ >@@ -2827,7 +2850,9 @@ int connect(int s, const struct sockaddr *serv_addr, socklen_t addrlen) > static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) > { > int ret; >- struct sockaddr_un un_addr; >+ struct swrap_address un_addr = { >+ .sa_socklen = sizeof(struct sockaddr_un), >+ }; > struct socket_info *si = find_socket_info(s); > int bind_error = 0; > #if 0 /* FIXME */ >@@ -2900,17 +2925,21 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) > si->myname_len = addrlen; > si->myname = sockaddr_dup(myaddr, addrlen); > >- ret = sockaddr_convert_to_un(si, myaddr, addrlen, &un_addr, 1, &si->bcast); >+ ret = sockaddr_convert_to_un(si, >+ myaddr, >+ addrlen, >+ &un_addr.sa.un, >+ 1, >+ &si->bcast); > if (ret == -1) return -1; > >- unlink(un_addr.sun_path); >+ unlink(un_addr.sa.un.sun_path); > >- ret = libc_bind(s, (struct sockaddr *)(void *)&un_addr, >- sizeof(struct sockaddr_un)); >+ ret = libc_bind(s, &un_addr.sa.s, un_addr.sa_socklen); > > SWRAP_LOG(SWRAP_LOG_TRACE, > "bind() path=%s, fd=%d", >- un_addr.sun_path, s); >+ un_addr.sa_un.sun_path, s); > > if (ret == 0) { > si->bound = 1; >@@ -2933,7 +2962,9 @@ static int swrap_getsockname(int s, struct sockaddr *name, socklen_t *addrlen); > > static int swrap_bindresvport_sa(int sd, struct sockaddr *sa) > { >- struct sockaddr_storage myaddr; >+ struct swrap_address myaddr = { >+ .sa_socklen = sizeof(struct sockaddr_storage), >+ }; > socklen_t salen; > static uint16_t port; > uint16_t i; >@@ -2949,16 +2980,16 @@ static int swrap_bindresvport_sa(int sd, struct sockaddr *sa) > } > > if (sa == NULL) { >- salen = sizeof(struct sockaddr); >- sa = (struct sockaddr *)&myaddr; >+ salen = myaddr.sa_socklen; >+ sa = &myaddr.sa.s; > >- rc = swrap_getsockname(sd, (struct sockaddr *)&myaddr, &salen); >+ rc = swrap_getsockname(sd, &myaddr.sa.s, &salen); > if (rc < 0) { > return -1; > } > > af = sa->sa_family; >- memset(&myaddr, 0, salen); >+ memset(&myaddr.sa.ss, 0, salen); > } else { > af = sa->sa_family; > } >@@ -2966,7 +2997,7 @@ static int swrap_bindresvport_sa(int sd, struct sockaddr *sa) > for (i = 0; i < SWRAP_NPORTS; i++, port++) { > switch(af) { > case AF_INET: { >- struct sockaddr_in *sinp = (struct sockaddr_in *)sa; >+ struct sockaddr_in *sinp = (struct sockaddr_in *)(void *)sa; > > salen = sizeof(struct sockaddr_in); > sinp->sin_port = htons(port); >@@ -3368,7 +3399,8 @@ static void swrap_msghdr_add_cmsghdr(struct msghdr *msg, > size_t cmlen = CMSG_LEN(len); > size_t cmspace = CMSG_SPACE(len); > uint8_t cmbuf[cmspace]; >- struct cmsghdr *cm = (struct cmsghdr *)cmbuf; >+ void *cast_ptr = (void *)cmbuf; >+ struct cmsghdr *cm = (struct cmsghdr *)cast_ptr; > uint8_t *p; > > memset(cmbuf, 0, cmspace); >@@ -4025,12 +4057,14 @@ done: > static ssize_t swrap_recvfrom(int s, void *buf, size_t len, int flags, > struct sockaddr *from, socklen_t *fromlen) > { >- struct sockaddr_un from_addr; >- socklen_t from_addrlen = sizeof(from_addr); >+ struct swrap_address from_addr = { >+ .sa_socklen = sizeof(struct sockaddr_un), >+ }; > ssize_t ret; > struct socket_info *si = find_socket_info(s); >- struct sockaddr_storage ss; >- socklen_t ss_len = sizeof(ss); >+ struct swrap_address saddr = { >+ .sa_socklen = sizeof(struct sockaddr_storage), >+ }; > struct msghdr msg; > struct iovec tmp; > int tret; >@@ -4052,8 +4086,8 @@ static ssize_t swrap_recvfrom(int s, void *buf, size_t len, int flags, > msg.msg_name = from; /* optional address */ > msg.msg_namelen = *fromlen; /* size of address */ > } else { >- msg.msg_name = (struct sockaddr *)(void *)&ss; /* optional address */ >- msg.msg_namelen = ss_len; /* size of address */ >+ msg.msg_name = &saddr.sa.s; /* optional address */ >+ msg.msg_namelen = saddr.sa_socklen; /* size of address */ > } > msg.msg_iov = &tmp; /* scatter/gather array */ > msg.msg_iovlen = 1; /* # elements in msg_iov */ >@@ -4071,14 +4105,12 @@ static ssize_t swrap_recvfrom(int s, void *buf, size_t len, int flags, > buf = msg.msg_iov[0].iov_base; > len = msg.msg_iov[0].iov_len; > >- /* irix 6.4 forgets to null terminate the sun_path string :-( */ >- memset(&from_addr, 0, sizeof(from_addr)); > ret = libc_recvfrom(s, > buf, > len, > flags, >- (struct sockaddr *)(void *)&from_addr, >- &from_addrlen); >+ &from_addr.sa.s, >+ &from_addr.sa_socklen); > if (ret == -1) { > return ret; > } >@@ -4086,8 +4118,8 @@ static ssize_t swrap_recvfrom(int s, void *buf, size_t len, int flags, > tret = swrap_recvmsg_after(s, > si, > &msg, >- &from_addr, >- from_addrlen, >+ &from_addr.sa.un, >+ from_addr.sa_socklen, > ret); > if (tret != 0) { > return tret; >@@ -4120,7 +4152,9 @@ static ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, > { > struct msghdr msg; > struct iovec tmp; >- struct sockaddr_un un_addr; >+ struct swrap_address un_addr = { >+ .sa_socklen = sizeof(struct sockaddr_un), >+ }; > const struct sockaddr_un *to_un = NULL; > ssize_t ret; > int rc; >@@ -4145,7 +4179,14 @@ static ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, > msg.msg_flags = 0; /* flags on received message */ > #endif > >- rc = swrap_sendmsg_before(s, si, &msg, &tmp, &un_addr, &to_un, &to, &bcast); >+ rc = swrap_sendmsg_before(s, >+ si, >+ &msg, >+ &tmp, >+ &un_addr.sa.un, >+ &to_un, >+ &to, >+ &bcast); > if (rc < 0) { > return -1; > } >@@ -4162,17 +4203,19 @@ static ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, > type = SOCKET_TYPE_CHAR_UDP; > > for(iface=0; iface <= MAX_WRAPPED_INTERFACES; iface++) { >- snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s/"SOCKET_FORMAT, >+ snprintf(un_addr.sa.un.sun_path, >+ sizeof(un_addr.sa.un.sun_path), >+ "%s/"SOCKET_FORMAT, > socket_wrapper_dir(), type, iface, prt); >- if (stat(un_addr.sun_path, &st) != 0) continue; >+ if (stat(un_addr.sa.un.sun_path, &st) != 0) continue; > > /* ignore the any errors in broadcast sends */ > libc_sendto(s, > buf, > len, > flags, >- (struct sockaddr *)(void *)&un_addr, >- sizeof(un_addr)); >+ &un_addr.sa.s, >+ un_addr.sa_socklen); > } > > swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len); >@@ -4206,8 +4249,9 @@ static ssize_t swrap_recv(int s, void *buf, size_t len, int flags) > { > struct socket_info *si; > struct msghdr msg; >- struct sockaddr_storage ss; >- socklen_t ss_len = sizeof(ss); >+ struct swrap_address saddr = { >+ .sa_socklen = sizeof(struct sockaddr_storage), >+ }; > struct iovec tmp; > ssize_t ret; > int tret; >@@ -4221,8 +4265,8 @@ static ssize_t swrap_recv(int s, void *buf, size_t len, int flags) > tmp.iov_len = len; > > ZERO_STRUCT(msg); >- msg.msg_name = (struct sockaddr *)(void *)&ss; /* optional address */ >- msg.msg_namelen = ss_len; /* size of address */ >+ msg.msg_name = &saddr.sa.s; /* optional address */ >+ msg.msg_namelen = saddr.sa_socklen; /* size of address */ > msg.msg_iov = &tmp; /* scatter/gather array */ > msg.msg_iovlen = 1; /* # elements in msg_iov */ > #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL >@@ -4263,8 +4307,9 @@ static ssize_t swrap_read(int s, void *buf, size_t len) > struct socket_info *si; > struct msghdr msg; > struct iovec tmp; >- struct sockaddr_storage ss; >- socklen_t ss_len = sizeof(ss); >+ struct swrap_address saddr = { >+ .sa_socklen = sizeof(struct sockaddr_storage), >+ }; > ssize_t ret; > int tret; > >@@ -4277,8 +4322,8 @@ static ssize_t swrap_read(int s, void *buf, size_t len) > tmp.iov_len = len; > > ZERO_STRUCT(msg); >- msg.msg_name = (struct sockaddr *)(void *)&ss; /* optional address */ >- msg.msg_namelen = ss_len; /* size of address */ >+ msg.msg_name = &saddr.sa.ss; /* optional address */ >+ msg.msg_namelen = saddr.sa_socklen; /* size of address */ > msg.msg_iov = &tmp; /* scatter/gather array */ > msg.msg_iovlen = 1; /* # elements in msg_iov */ > #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL >@@ -4370,8 +4415,9 @@ ssize_t send(int s, const void *buf, size_t len, int flags) > > static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, int flags) > { >- struct sockaddr_un from_addr; >- socklen_t from_addrlen = sizeof(from_addr); >+ struct swrap_address from_addr = { >+ .sa_socklen = sizeof(struct sockaddr_un), >+ }; > struct socket_info *si; > struct msghdr msg; > struct iovec tmp; >@@ -4392,8 +4438,8 @@ static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, int flags) > tmp.iov_len = 0; > > ZERO_STRUCT(msg); >- msg.msg_name = (struct sockaddr *)&from_addr; /* optional address */ >- msg.msg_namelen = from_addrlen; /* size of address */ >+ msg.msg_name = &from_addr.sa; /* optional address */ >+ msg.msg_namelen = from_addr.sa_socklen; /* size of address */ > 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 >@@ -4433,7 +4479,12 @@ static ssize_t swrap_recvmsg(int s, struct msghdr *omsg, int flags) > } > #endif > >- rc = swrap_recvmsg_after(s, si, &msg, &from_addr, from_addrlen, ret); >+ rc = swrap_recvmsg_after(s, >+ si, >+ &msg, >+ &from_addr.sa.un, >+ from_addr.sa_socklen, >+ ret); > if (rc != 0) { > return rc; > } >@@ -4581,8 +4632,9 @@ static ssize_t swrap_readv(int s, const struct iovec *vector, int count) > struct socket_info *si; > struct msghdr msg; > struct iovec tmp; >- struct sockaddr_storage ss; >- socklen_t ss_len = sizeof(ss); >+ struct swrap_address saddr = { >+ .sa_socklen = sizeof(struct sockaddr_storage) >+ }; > ssize_t ret; > int rc; > >@@ -4595,8 +4647,8 @@ static ssize_t swrap_readv(int s, const struct iovec *vector, int count) > tmp.iov_len = 0; > > ZERO_STRUCT(msg); >- msg.msg_name = (struct sockaddr *)(void *)&ss; /* optional address */ >- msg.msg_namelen = ss_len; /* size of address */ >+ msg.msg_name = &saddr.sa.s; /* optional address */ >+ msg.msg_namelen = saddr.sa_socklen; /* size of address */ > msg.msg_iov = discard_const_p(struct iovec, vector); /* scatter/gather array */ > msg.msg_iovlen = count; /* # elements in msg_iov */ > #ifdef HAVE_STRUCT_MSGHDR_MSG_CONTROL >-- >1.9.1 > > >From c268c4fa83a4f0a46873110b96954f9adbd0f44f Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:11:49 +0200 >Subject: [PATCH 07/27] swrap: Rename socket_wrapper_pcap_file(). > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit c626aad36a9757d584b9f10f0ba55dda72499c50) >--- > lib/socket_wrapper/socket_wrapper.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index d5ab3c9..41dc07d 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -1610,7 +1610,7 @@ union swrap_packet_payload { > SWRAP_PACKET_IP_SIZE + \ > SWRAP_PACKET_PAYLOAD_SIZE) > >-static const char *socket_wrapper_pcap_file(void) >+static const char *swrap_pcap_init_file(void) > { > static int initialized = 0; > static const char *s = NULL; >@@ -2209,7 +2209,7 @@ static void swrap_dump_packet(struct socket_info *si, > size_t packet_len = 0; > int fd; > >- file_name = socket_wrapper_pcap_file(); >+ file_name = swrap_pcap_init_file(); > if (!file_name) { > return; > } >-- >1.9.1 > > >From 3980e387a10f05b13fecaa579da7355526217802 Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:13:10 +0200 >Subject: [PATCH 08/27] swrap: Rename swrap_packet_init(). > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit e64ea9cb79b804c299d0213b2cca207fb000a3b8) >--- > lib/socket_wrapper/socket_wrapper.c | 37 ++++++++++++++++++++++--------------- > 1 file changed, 22 insertions(+), 15 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 41dc07d..b66fa8a 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -1672,17 +1672,17 @@ static const char *swrap_pcap_init_file(void) > return s; > } > >-static uint8_t *swrap_packet_init(struct timeval *tval, >- const struct sockaddr *src, >- const struct sockaddr *dest, >- int socket_type, >- const uint8_t *payload, >- size_t payload_len, >- unsigned long tcp_seqno, >- unsigned long tcp_ack, >- unsigned char tcp_ctl, >- int unreachable, >- size_t *_packet_len) >+static uint8_t *swrap_pcap_packet_init(struct timeval *tval, >+ const struct sockaddr *src, >+ const struct sockaddr *dest, >+ int socket_type, >+ const uint8_t *payload, >+ size_t payload_len, >+ unsigned long tcp_seqno, >+ unsigned long tcp_ack, >+ unsigned char tcp_ctl, >+ int unreachable, >+ size_t *_packet_len) > { > uint8_t *base; > uint8_t *buf; >@@ -2193,10 +2193,17 @@ static uint8_t *swrap_marshall_packet(struct socket_info *si, > > swrapGetTimeOfDay(&tv); > >- return swrap_packet_init(&tv, src_addr, dest_addr, si->type, >- (const uint8_t *)buf, len, >- tcp_seqno, tcp_ack, tcp_ctl, unreachable, >- packet_len); >+ return swrap_pcap_packet_init(&tv, >+ src_addr, >+ dest_addr, >+ si->type, >+ (const uint8_t *)buf, >+ len, >+ tcp_seqno, >+ tcp_ack, >+ tcp_ctl, >+ unreachable, >+ packet_len); > } > > static void swrap_dump_packet(struct socket_info *si, >-- >1.9.1 > > >From c839d66e5335e2cdf71f3ca935a03f4df721dc23 Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:14:04 +0200 >Subject: [PATCH 09/27] swrap: Rename swrap_marshall_packet(). > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 7d4c6cf25d5f424156fa0a6f90673744c5eba18e) >--- > lib/socket_wrapper/socket_wrapper.c | 21 +++++++++++++-------- > 1 file changed, 13 insertions(+), 8 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index b66fa8a..be48e18 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -1935,11 +1935,11 @@ static int swrap_get_pcap_fd(const char *fname) > return fd; > } > >-static uint8_t *swrap_marshall_packet(struct socket_info *si, >- const struct sockaddr *addr, >- enum swrap_packet_type type, >- const void *buf, size_t len, >- size_t *packet_len) >+static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, >+ const struct sockaddr *addr, >+ enum swrap_packet_type type, >+ const void *buf, size_t len, >+ size_t *packet_len) > { > const struct sockaddr *src_addr; > const struct sockaddr *dest_addr; >@@ -2073,7 +2073,7 @@ static uint8_t *swrap_marshall_packet(struct socket_info *si, > src_addr = si->peername; > > if (si->type == SOCK_DGRAM) { >- return swrap_marshall_packet(si, si->peername, >+ return swrap_pcap_marshall_packet(si, si->peername, > SWRAP_SENDTO_UNREACH, > buf, len, packet_len); > } >@@ -2221,8 +2221,13 @@ static void swrap_dump_packet(struct socket_info *si, > return; > } > >- packet = swrap_marshall_packet(si, addr, type, buf, len, &packet_len); >- if (!packet) { >+ packet = swrap_pcap_marshall_packet(si, >+ addr, >+ type, >+ buf, >+ len, >+ &packet_len); >+ if (packet == NULL) { > return; > } > >-- >1.9.1 > > >From c2b14c5ce25d7445f1fa569e977e23b83d88cf00 Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:14:44 +0200 >Subject: [PATCH 10/27] swrap: Rename swrap_pcap_get_fd(). > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 79e545b304db8b3fa6fcb21a6f1e023e0ae0f3b4) >--- > lib/socket_wrapper/socket_wrapper.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index be48e18..a721b94 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -1906,7 +1906,7 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval, > return base; > } > >-static int swrap_get_pcap_fd(const char *fname) >+static int swrap_pcap_get_fd(const char *fname) > { > static int fd = -1; > >@@ -2231,7 +2231,7 @@ static void swrap_dump_packet(struct socket_info *si, > return; > } > >- fd = swrap_get_pcap_fd(file_name); >+ fd = swrap_pcap_get_fd(file_name); > if (fd != -1) { > if (write(fd, packet, packet_len) != (ssize_t)packet_len) { > free(packet); >-- >1.9.1 > > >From 0034e2b32f6b025fd0da4862aff14ff55c12bd64 Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:15:38 +0200 >Subject: [PATCH 11/27] swrap: Rename swrap_pcap_dump_packet(). > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 9da1ff9ad1d7983bd11693263f3dfcd1ed9685d4) >--- > lib/socket_wrapper/socket_wrapper.c | 58 ++++++++++++++++++------------------- > 1 file changed, 29 insertions(+), 29 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index a721b94..b6f86eb 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -2206,10 +2206,10 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > packet_len); > } > >-static void swrap_dump_packet(struct socket_info *si, >- const struct sockaddr *addr, >- enum swrap_packet_type type, >- const void *buf, size_t len) >+static void swrap_pcap_dump_packet(struct socket_info *si, >+ const struct sockaddr *addr, >+ enum swrap_packet_type type, >+ const void *buf, size_t len) > { > const char *file_name; > uint8_t *packet; >@@ -2617,9 +2617,9 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > SWRAP_DLIST_ADD(sockets, child_si); > > if (addr != NULL) { >- swrap_dump_packet(child_si, addr, SWRAP_ACCEPT_SEND, NULL, 0); >- swrap_dump_packet(child_si, addr, SWRAP_ACCEPT_RECV, NULL, 0); >- swrap_dump_packet(child_si, addr, SWRAP_ACCEPT_ACK, NULL, 0); >+ swrap_pcap_dump_packet(child_si, addr, SWRAP_ACCEPT_SEND, NULL, 0); >+ swrap_pcap_dump_packet(child_si, addr, SWRAP_ACCEPT_RECV, NULL, 0); >+ swrap_pcap_dump_packet(child_si, addr, SWRAP_ACCEPT_ACK, NULL, 0); > } > > return fd; >@@ -2802,7 +2802,7 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr, > si->defer_connect = 1; > ret = 0; > } else { >- swrap_dump_packet(si, serv_addr, SWRAP_CONNECT_SEND, NULL, 0); >+ swrap_pcap_dump_packet(si, serv_addr, SWRAP_CONNECT_SEND, NULL, 0); > > ret = libc_connect(s, > &un_addr.sa.s, >@@ -2841,10 +2841,10 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr, > si->bindname_len = 0; > } > >- swrap_dump_packet(si, serv_addr, SWRAP_CONNECT_RECV, NULL, 0); >- swrap_dump_packet(si, serv_addr, SWRAP_CONNECT_ACK, NULL, 0); >+ swrap_pcap_dump_packet(si, serv_addr, SWRAP_CONNECT_RECV, NULL, 0); >+ swrap_pcap_dump_packet(si, serv_addr, SWRAP_CONNECT_ACK, NULL, 0); > } else { >- swrap_dump_packet(si, serv_addr, SWRAP_CONNECT_UNREACH, NULL, 0); >+ swrap_pcap_dump_packet(si, serv_addr, SWRAP_CONNECT_UNREACH, NULL, 0); > } > > return ret; >@@ -3339,9 +3339,9 @@ static int swrap_vioctl(int s, unsigned long int r, va_list va) > value = *((int *)va_arg(ap, int *)); > > if (rc == -1 && errno != EAGAIN && errno != ENOBUFS) { >- swrap_dump_packet(si, NULL, SWRAP_PENDING_RST, NULL, 0); >+ swrap_pcap_dump_packet(si, NULL, SWRAP_PENDING_RST, NULL, 0); > } else if (value == 0) { /* END OF FILE */ >- swrap_dump_packet(si, NULL, SWRAP_PENDING_RST, NULL, 0); >+ swrap_pcap_dump_packet(si, NULL, SWRAP_PENDING_RST, NULL, 0); > } > break; > } >@@ -3844,10 +3844,10 @@ static void swrap_sendmsg_after(int fd, > switch (si->type) { > case SOCK_STREAM: > if (ret == -1) { >- swrap_dump_packet(si, NULL, SWRAP_SEND, buf, len); >- swrap_dump_packet(si, NULL, SWRAP_SEND_RST, NULL, 0); >+ swrap_pcap_dump_packet(si, NULL, SWRAP_SEND, buf, len); >+ swrap_pcap_dump_packet(si, NULL, SWRAP_SEND_RST, NULL, 0); > } else { >- swrap_dump_packet(si, NULL, SWRAP_SEND, buf, len); >+ swrap_pcap_dump_packet(si, NULL, SWRAP_SEND, buf, len); > } > break; > >@@ -3856,10 +3856,10 @@ static void swrap_sendmsg_after(int fd, > to = si->peername; > } > if (ret == -1) { >- swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len); >- swrap_dump_packet(si, to, SWRAP_SENDTO_UNREACH, buf, len); >+ swrap_pcap_dump_packet(si, to, SWRAP_SENDTO, buf, len); >+ swrap_pcap_dump_packet(si, to, SWRAP_SENDTO_UNREACH, buf, len); > } else { >- swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len); >+ swrap_pcap_dump_packet(si, to, SWRAP_SENDTO, buf, len); > } > break; > } >@@ -4003,11 +4003,11 @@ static int swrap_recvmsg_after(int fd, > switch (si->type) { > case SOCK_STREAM: > if (ret == -1 && saved_errno != EAGAIN && saved_errno != ENOBUFS) { >- swrap_dump_packet(si, NULL, SWRAP_RECV_RST, NULL, 0); >+ swrap_pcap_dump_packet(si, NULL, SWRAP_RECV_RST, NULL, 0); > } else if (ret == 0) { /* END OF FILE */ >- swrap_dump_packet(si, NULL, SWRAP_RECV_RST, NULL, 0); >+ swrap_pcap_dump_packet(si, NULL, SWRAP_RECV_RST, NULL, 0); > } else if (ret > 0) { >- swrap_dump_packet(si, NULL, SWRAP_RECV, buf, ret); >+ swrap_pcap_dump_packet(si, NULL, SWRAP_RECV, buf, ret); > } > break; > >@@ -4027,13 +4027,13 @@ static int swrap_recvmsg_after(int fd, > goto done; > } > >- swrap_dump_packet(si, >+ swrap_pcap_dump_packet(si, > msg->msg_name, > SWRAP_RECVFROM, > buf, > ret); > } else { >- swrap_dump_packet(si, >+ swrap_pcap_dump_packet(si, > msg->msg_name, > SWRAP_RECV, > buf, >@@ -4230,7 +4230,7 @@ static ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, > un_addr.sa_socklen); > } > >- swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len); >+ swrap_pcap_dump_packet(si, to, SWRAP_SENDTO, buf, len); > > return len; > } >@@ -4617,7 +4617,7 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr *omsg, int flags) > libc_sendmsg(s, &msg, flags); > } > >- swrap_dump_packet(si, to, SWRAP_SENDTO, buf, len); >+ swrap_pcap_dump_packet(si, to, SWRAP_SENDTO, buf, len); > free(buf); > > return len; >@@ -4773,14 +4773,14 @@ static int swrap_close(int fd) > SWRAP_DLIST_REMOVE(sockets, si); > > if (si->myname && si->peername) { >- swrap_dump_packet(si, NULL, SWRAP_CLOSE_SEND, NULL, 0); >+ swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_SEND, NULL, 0); > } > > ret = libc_close(fd); > > if (si->myname && si->peername) { >- swrap_dump_packet(si, NULL, SWRAP_CLOSE_RECV, NULL, 0); >- swrap_dump_packet(si, NULL, SWRAP_CLOSE_ACK, NULL, 0); >+ swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_RECV, NULL, 0); >+ swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_ACK, NULL, 0); > } > > if (si->bindname != NULL) { >-- >1.9.1 > > >From 189b955af99c9f6860be11d6e9423871971e513c Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:16:25 +0200 >Subject: [PATCH 12/27] swrap: Use a sockaddr_un for the unix path in > socket_info. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 4402ba10b5afc57e72b45ce640c14764d5f0f2c7) >--- > lib/socket_wrapper/socket_wrapper.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index b6f86eb..b5c5b46 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -242,7 +242,8 @@ struct socket_info > int defer_connect; > int pktinfo; > >- char *tmp_path; >+ /* The unix path so we can unlink it on close() */ >+ struct sockaddr_un un_addr; > > struct sockaddr *bindname; > socklen_t bindname_len; >@@ -2739,7 +2740,8 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family) > ret = libc_bind(fd, &un_addr.sa.s, un_addr.sa_socklen); > if (ret == -1) return ret; > >- si->tmp_path = strdup(un_addr.sa.un.sun_path); >+ si->un_addr = un_addr.sa.un; >+ > si->bound = 1; > autobind_start = port + 1; > break; >@@ -4789,9 +4791,9 @@ static int swrap_close(int fd) > > if (si->myname) free(si->myname); > if (si->peername) free(si->peername); >- if (si->tmp_path) { >- unlink(si->tmp_path); >- free(si->tmp_path); >+ >+ if (si->un_addr.sun_path[0] != '\0') { >+ unlink(si->un_addr.sun_path); > } > free(si); > >-- >1.9.1 > > >From ea6244dd5fe190622d4b01278031d2073813167c Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:17:10 +0200 >Subject: [PATCH 13/27] swrap: Use swrap_address in the socket_info struct. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 889747486560e71d27c5a5255c825c4ebd62f8f9) >--- > lib/socket_wrapper/socket_wrapper.c | 216 ++++++++++++++++++------------------ > 1 file changed, 109 insertions(+), 107 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index b5c5b46..f39a151 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -245,14 +245,9 @@ struct socket_info > /* The unix path so we can unlink it on close() */ > struct sockaddr_un un_addr; > >- struct sockaddr *bindname; >- socklen_t bindname_len; >- >- struct sockaddr *myname; >- socklen_t myname_len; >- >- struct sockaddr *peername; >- socklen_t peername_len; >+ struct swrap_address bindname; >+ struct swrap_address myname; >+ struct swrap_address peername; > > struct { > unsigned long pck_snd; >@@ -834,15 +829,15 @@ static struct sockaddr *sockaddr_dup(const void *data, socklen_t len) > return ret; > } > >-static void set_port(int family, int prt, struct sockaddr *addr) >+static void set_port(int family, int prt, struct swrap_address *addr) > { > switch (family) { > case AF_INET: >- ((struct sockaddr_in *)addr)->sin_port = htons(prt); >+ addr->sa.in.sin_port = htons(prt); > break; > #ifdef HAVE_IPV6 > case AF_INET6: >- ((struct sockaddr_in6 *)addr)->sin6_port = htons(prt); >+ addr->sa.in6.sin6_port = htons(prt); > break; > #endif > } >@@ -1158,7 +1153,7 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in > } > > /* Store the bind address for connect() */ >- if (si->bindname == NULL) { >+ if (si->bindname.sa_socklen == 0) { > struct sockaddr_in bind_in; > socklen_t blen = sizeof(struct sockaddr_in); > >@@ -1167,8 +1162,8 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in > bind_in.sin_port = in->sin_port; > bind_in.sin_addr.s_addr = htonl(0x7F000000 | iface); > >- si->bindname = sockaddr_dup(&bind_in, blen); >- si->bindname_len = blen; >+ si->bindname.sa_socklen = blen; >+ memcpy(&si->bindname.sa.in, &bind_in, blen); > } > > break; >@@ -1209,7 +1204,7 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in > } > > /* Store the bind address for connect() */ >- if (si->bindname == NULL) { >+ if (si->bindname.sa_socklen == 0) { > struct sockaddr_in6 bind_in; > socklen_t blen = sizeof(struct sockaddr_in6); > >@@ -1220,8 +1215,8 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in > bind_in.sin6_addr = *swrap_ipv6(); > bind_in.sin6_addr.s6_addr[15] = iface; > >- si->bindname = sockaddr_dup(&bind_in, blen); >- si->bindname_len = blen; >+ memcpy(&si->bindname.sa.in6, &bind_in, blen); >+ si->bindname.sa_socklen = blen; > } > > break; >@@ -1248,8 +1243,8 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in > socket_wrapper_dir(), type, iface, prt); > if (stat(un->sun_path, &st) == 0) continue; > >- set_port(si->family, prt, si->myname); >- set_port(si->family, prt, si->bindname); >+ set_port(si->family, prt, &si->myname); >+ set_port(si->family, prt, &si->bindname); > > break; > } >@@ -1966,7 +1961,7 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > case SWRAP_CONNECT_SEND: > if (si->type != SOCK_STREAM) return NULL; > >- src_addr = si->myname; >+ src_addr = &si->myname.sa.s; > dest_addr = addr; > > tcp_seqno = si->io.pck_snd; >@@ -1980,7 +1975,7 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > case SWRAP_CONNECT_RECV: > if (si->type != SOCK_STREAM) return NULL; > >- dest_addr = si->myname; >+ dest_addr = &si->myname.sa.s; > src_addr = addr; > > tcp_seqno = si->io.pck_rcv; >@@ -1994,8 +1989,8 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > case SWRAP_CONNECT_UNREACH: > if (si->type != SOCK_STREAM) return NULL; > >- dest_addr = si->myname; >- src_addr = addr; >+ dest_addr = &si->myname.sa.s; >+ src_addr = addr; > > /* Unreachable: resend the data of SWRAP_CONNECT_SEND */ > tcp_seqno = si->io.pck_snd - 1; >@@ -2008,7 +2003,7 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > case SWRAP_CONNECT_ACK: > if (si->type != SOCK_STREAM) return NULL; > >- src_addr = si->myname; >+ src_addr = &si->myname.sa.s; > dest_addr = addr; > > tcp_seqno = si->io.pck_snd; >@@ -2020,7 +2015,7 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > case SWRAP_ACCEPT_SEND: > if (si->type != SOCK_STREAM) return NULL; > >- dest_addr = si->myname; >+ dest_addr = &si->myname.sa.s; > src_addr = addr; > > tcp_seqno = si->io.pck_rcv; >@@ -2034,7 +2029,7 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > case SWRAP_ACCEPT_RECV: > if (si->type != SOCK_STREAM) return NULL; > >- src_addr = si->myname; >+ src_addr = &si->myname.sa.s; > dest_addr = addr; > > tcp_seqno = si->io.pck_snd; >@@ -2048,7 +2043,7 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > case SWRAP_ACCEPT_ACK: > if (si->type != SOCK_STREAM) return NULL; > >- dest_addr = si->myname; >+ dest_addr = &si->myname.sa.s; > src_addr = addr; > > tcp_seqno = si->io.pck_rcv; >@@ -2058,8 +2053,8 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > break; > > case SWRAP_SEND: >- src_addr = si->myname; >- dest_addr = si->peername; >+ src_addr = &si->myname.sa.s; >+ dest_addr = &si->peername.sa.s; > > tcp_seqno = si->io.pck_snd; > tcp_ack = si->io.pck_rcv; >@@ -2070,13 +2065,16 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > break; > > case SWRAP_SEND_RST: >- dest_addr = si->myname; >- src_addr = si->peername; >+ dest_addr = &si->myname.sa.s; >+ src_addr = &si->peername.sa.s; > > if (si->type == SOCK_DGRAM) { >- return swrap_pcap_marshall_packet(si, si->peername, >- SWRAP_SENDTO_UNREACH, >- buf, len, packet_len); >+ return swrap_pcap_marshall_packet(si, >+ &si->peername.sa.s, >+ SWRAP_SENDTO_UNREACH, >+ buf, >+ len, >+ packet_len); > } > > tcp_seqno = si->io.pck_rcv; >@@ -2086,8 +2084,8 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > break; > > case SWRAP_PENDING_RST: >- dest_addr = si->myname; >- src_addr = si->peername; >+ dest_addr = &si->myname.sa.s; >+ src_addr = &si->peername.sa.s; > > if (si->type == SOCK_DGRAM) { > return NULL; >@@ -2100,8 +2098,8 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > break; > > case SWRAP_RECV: >- dest_addr = si->myname; >- src_addr = si->peername; >+ dest_addr = &si->myname.sa.s; >+ src_addr = &si->peername.sa.s; > > tcp_seqno = si->io.pck_rcv; > tcp_ack = si->io.pck_snd; >@@ -2112,8 +2110,8 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > break; > > case SWRAP_RECV_RST: >- dest_addr = si->myname; >- src_addr = si->peername; >+ dest_addr = &si->myname.sa.s; >+ src_addr = &si->peername.sa.s; > > if (si->type == SOCK_DGRAM) { > return NULL; >@@ -2126,7 +2124,7 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > break; > > case SWRAP_SENDTO: >- src_addr = si->myname; >+ src_addr = &si->myname.sa.s; > dest_addr = addr; > > si->io.pck_snd += len; >@@ -2134,7 +2132,7 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > break; > > case SWRAP_SENDTO_UNREACH: >- dest_addr = si->myname; >+ dest_addr = &si->myname.sa.s; > src_addr = addr; > > unreachable = 1; >@@ -2142,7 +2140,7 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > break; > > case SWRAP_RECVFROM: >- dest_addr = si->myname; >+ dest_addr = &si->myname.sa.s; > src_addr = addr; > > si->io.pck_rcv += len; >@@ -2152,8 +2150,8 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > case SWRAP_CLOSE_SEND: > if (si->type != SOCK_STREAM) return NULL; > >- src_addr = si->myname; >- dest_addr = si->peername; >+ src_addr = &si->myname.sa.s; >+ dest_addr = &si->peername.sa.s; > > tcp_seqno = si->io.pck_snd; > tcp_ack = si->io.pck_rcv; >@@ -2166,8 +2164,8 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > case SWRAP_CLOSE_RECV: > if (si->type != SOCK_STREAM) return NULL; > >- dest_addr = si->myname; >- src_addr = si->peername; >+ dest_addr = &si->myname.sa.s; >+ src_addr = &si->peername.sa.s; > > tcp_seqno = si->io.pck_rcv; > tcp_ack = si->io.pck_snd; >@@ -2180,8 +2178,8 @@ static uint8_t *swrap_pcap_marshall_packet(struct socket_info *si, > case SWRAP_CLOSE_ACK: > if (si->type != SOCK_STREAM) return NULL; > >- src_addr = si->myname; >- dest_addr = si->peername; >+ src_addr = &si->myname.sa.s; >+ dest_addr = &si->peername.sa.s; > > tcp_seqno = si->io.pck_snd; > tcp_ack = si->io.pck_rcv; >@@ -2374,8 +2372,8 @@ static int swrap_socket(int family, int type, int protocol) > .sin_family = AF_INET, > }; > >- si->myname_len = sizeof(struct sockaddr_in); >- si->myname = sockaddr_dup(&sin, si->myname_len); >+ si->myname.sa_socklen = sizeof(struct sockaddr_in); >+ memcpy(&si->myname.sa.in, &sin, si->myname.sa_socklen); > break; > } > case AF_INET6: { >@@ -2383,8 +2381,8 @@ static int swrap_socket(int family, int type, int protocol) > .sin6_family = AF_INET6, > }; > >- si->myname_len = sizeof(struct sockaddr_in6); >- si->myname = sockaddr_dup(&sin6, si->myname_len); >+ si->myname.sa_socklen = sizeof(struct sockaddr_in6); >+ memcpy(&si->myname.sa.in6, &sin6, si->myname.sa_socklen); > break; > } > default: >@@ -2395,9 +2393,6 @@ static int swrap_socket(int family, int type, int protocol) > > fi = (struct socket_info_fd *)calloc(1, sizeof(struct socket_info_fd)); > if (fi == NULL) { >- if (si->myname != NULL) { >- free (si->myname); >- } > free(si); > errno = ENOMEM; > return -1; >@@ -2570,8 +2565,8 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > child_si->is_server = 1; > child_si->connected = 1; > >- child_si->peername_len = len; >- child_si->peername = sockaddr_dup(my_addr, len); >+ child_si->peername.sa_socklen = len; >+ memcpy(&child_si->peername.sa.s, my_addr, len); > > if (addr != NULL && addrlen != NULL) { > size_t copy_len = MIN(*addrlen, len); >@@ -2611,8 +2606,8 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > "accept() path=%s, fd=%d", > un_my_addr.sa.un.sun_path, s); > >- child_si->myname_len = len; >- child_si->myname = sockaddr_dup(my_addr, len); >+ child_si->myname.sa_socklen = len; >+ memcpy(&child_si->myname.sa.s, my_addr, len); > free(my_addr); > > SWRAP_DLIST_ADD(sockets, child_si); >@@ -2685,9 +2680,10 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family) > in.sin_addr.s_addr = htonl(127<<24 | > socket_wrapper_default_iface()); > >- free(si->myname); >- si->myname_len = sizeof(in); >- si->myname = sockaddr_dup(&in, si->myname_len); >+ si->myname = (struct swrap_address) { >+ .sa_socklen = sizeof(in), >+ }; >+ memcpy(&si->myname.sa.in, &in, si->myname.sa_socklen); > break; > } > #ifdef HAVE_IPV6 >@@ -2715,9 +2711,11 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family) > in6.sin6_family = AF_INET6; > in6.sin6_addr = *swrap_ipv6(); > in6.sin6_addr.s6_addr[15] = socket_wrapper_default_iface(); >- free(si->myname); >- si->myname_len = sizeof(in6); >- si->myname = sockaddr_dup(&in6, si->myname_len); >+ >+ si->myname = (struct swrap_address) { >+ .sa_socklen = sizeof(in6), >+ }; >+ memcpy(&si->myname.sa.in6, &in6, si->myname.sa_socklen); > break; > } > #endif >@@ -2758,7 +2756,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family) > } > > si->family = family; >- set_port(si->family, port, si->myname); >+ set_port(si->family, port, &si->myname); > > return 0; > } >@@ -2822,8 +2820,11 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr, > } > > if (ret == 0) { >- si->peername_len = addrlen; >- si->peername = sockaddr_dup(serv_addr, addrlen); >+ si->peername = (struct swrap_address) { >+ .sa_socklen = addrlen, >+ }; >+ >+ memcpy(&si->peername.sa.ss, serv_addr, addrlen); > si->connected = 1; > > /* >@@ -2833,14 +2834,19 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr, > * but here we have to update the name so getsockname() > * returns correct information. > */ >- if (si->bindname != NULL) { >- free(si->myname); >- >- si->myname = si->bindname; >- si->myname_len = si->bindname_len; >- >- si->bindname = NULL; >- si->bindname_len = 0; >+ if (si->bindname.sa_socklen > 0) { >+ si->myname = (struct swrap_address) { >+ .sa_socklen = si->bindname.sa_socklen, >+ }; >+ >+ memcpy(&si->myname.sa.ss, >+ &si->bindname.sa.ss, >+ si->bindname.sa_socklen); >+ >+ /* Cleanup bindname */ >+ si->bindname = (struct swrap_address) { >+ .sa_socklen = 0, >+ }; > } > > swrap_pcap_dump_packet(si, serv_addr, SWRAP_CONNECT_RECV, NULL, 0); >@@ -2935,9 +2941,8 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) > } > #endif > >- free(si->myname); >- si->myname_len = addrlen; >- si->myname = sockaddr_dup(myaddr, addrlen); >+ si->myname.sa_socklen = addrlen; >+ memcpy(&si->myname.sa.ss, myaddr, addrlen); > > ret = sockaddr_convert_to_un(si, > myaddr, >@@ -3118,19 +3123,19 @@ static int swrap_getpeername(int s, struct sockaddr *name, socklen_t *addrlen) > return libc_getpeername(s, name, addrlen); > } > >- if (!si->peername) >+ if (si->peername.sa_socklen == 0) > { > errno = ENOTCONN; > return -1; > } > >- len = MIN(*addrlen, si->peername_len); >+ len = MIN(*addrlen, si->peername.sa_socklen); > if (len == 0) { > return 0; > } > >- memcpy(name, si->peername, len); >- *addrlen = si->peername_len; >+ memcpy(name, &si->peername.sa.ss, len); >+ *addrlen = si->peername.sa_socklen; > > return 0; > } >@@ -3157,13 +3162,13 @@ static int swrap_getsockname(int s, struct sockaddr *name, socklen_t *addrlen) > return libc_getsockname(s, name, addrlen); > } > >- len = MIN(*addrlen, si->myname_len); >+ len = MIN(*addrlen, si->myname.sa_socklen); > if (len == 0) { > return 0; > } > >- memcpy(name, si->myname, len); >- *addrlen = si->myname_len; >+ memcpy(name, &si->myname.sa.ss, len); >+ *addrlen = si->myname.sa_socklen; > > return 0; > } >@@ -3465,13 +3470,13 @@ static int swrap_msghdr_add_pktinfo(struct socket_info *si, > struct in_addr pkt; > #endif > >- if (si->bindname_len == sizeof(struct sockaddr_in)) { >- sin = (struct sockaddr_in*)si->bindname; >+ if (si->bindname.sa_socklen == sizeof(struct sockaddr_in)) { >+ sin = &si->bindname.sa.in; > } else { >- if (si->myname_len != sizeof(struct sockaddr_in)) { >+ if (si->myname.sa_socklen != sizeof(struct sockaddr_in)) { > return 0; > } >- sin = (struct sockaddr_in*)si->myname; >+ sin = &si->myname.sa.in; > } > > ZERO_STRUCT(pkt); >@@ -3495,13 +3500,13 @@ static int swrap_msghdr_add_pktinfo(struct socket_info *si, > struct sockaddr_in6 *sin6; > struct in6_pktinfo pkt6; > >- if (si->bindname_len == sizeof(struct sockaddr_in6)) { >- sin6 = (struct sockaddr_in6*)si->bindname; >+ if (si->bindname.sa_socklen == sizeof(struct sockaddr_in6)) { >+ sin6 = &si->bindname.sa.in6; > } else { >- if (si->myname_len != sizeof(struct sockaddr_in6)) { >+ if (si->myname.sa_socklen != sizeof(struct sockaddr_in6)) { > return 0; > } >- sin6 = (struct sockaddr_in6*)si->myname; >+ sin6 = &si->myname.sa.in6; > } > > ZERO_STRUCT(pkt6); >@@ -3743,8 +3748,12 @@ static ssize_t swrap_sendmsg_before(int fd, > break; > } > >- ret = sockaddr_convert_to_un(si, si->peername, si->peername_len, >- tmp_un, 0, NULL); >+ ret = sockaddr_convert_to_un(si, >+ &si->peername.sa.s, >+ si->peername.sa_socklen, >+ tmp_un, >+ 0, >+ NULL); > if (ret == -1) return -1; > > ret = libc_connect(fd, >@@ -3855,7 +3864,7 @@ static void swrap_sendmsg_after(int fd, > > case SOCK_DGRAM: > if (si->connected) { >- to = si->peername; >+ to = &si->peername.sa.s; > } > if (ret == -1) { > swrap_pcap_dump_packet(si, to, SWRAP_SENDTO, buf, len); >@@ -4774,24 +4783,17 @@ static int swrap_close(int fd) > > SWRAP_DLIST_REMOVE(sockets, si); > >- if (si->myname && si->peername) { >+ if (si->myname.sa_socklen > 0 && si->peername.sa_socklen > 0) { > swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_SEND, NULL, 0); > } > > ret = libc_close(fd); > >- if (si->myname && si->peername) { >+ if (si->myname.sa_socklen > 0 && si->peername.sa_socklen > 0) { > swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_RECV, NULL, 0); > swrap_pcap_dump_packet(si, NULL, SWRAP_CLOSE_ACK, NULL, 0); > } > >- if (si->bindname != NULL) { >- free(si->bindname); >- } >- >- if (si->myname) free(si->myname); >- if (si->peername) free(si->peername); >- > if (si->un_addr.sun_path[0] != '\0') { > unlink(si->un_addr.sun_path); > } >-- >1.9.1 > > >From 058fe1e4af26ba0b0b42baae197952ec6f345e8c Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:17:42 +0200 >Subject: [PATCH 14/27] swrap: Remove unused sockaddr_dup() function. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 891e837c3c0ca3db2ae2d59d04296aa67eb25d3a) >--- > lib/socket_wrapper/socket_wrapper.c | 7 ------- > 1 file changed, 7 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index f39a151..fd0980f 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -822,13 +822,6 @@ static const struct in6_addr *swrap_ipv6(void) > } > #endif > >-static struct sockaddr *sockaddr_dup(const void *data, socklen_t len) >-{ >- struct sockaddr *ret = (struct sockaddr *)malloc(len); >- memcpy(ret, data, len); >- return ret; >-} >- > static void set_port(int family, int prt, struct swrap_address *addr) > { > switch (family) { >-- >1.9.1 > > >From d85ee1fded106228dfcd86a92c83d687d381f0b6 Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:18:14 +0200 >Subject: [PATCH 15/27] swrap: Use swrap_address in swrap_accept(). > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit f8584abfef0974a19547927258369b04e03d6336) >--- > lib/socket_wrapper/socket_wrapper.c | 51 +++++++++++++++++-------------------- > 1 file changed, 23 insertions(+), 28 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index fd0980f..9649004 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -2486,8 +2486,12 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > struct swrap_address un_my_addr = { > .sa_socklen = sizeof(struct sockaddr_un), > }; >- struct sockaddr *my_addr; >- socklen_t my_addrlen, len; >+ struct swrap_address in_addr = { >+ .sa_socklen = sizeof(struct sockaddr_storage), >+ }; >+ struct swrap_address in_my_addr = { >+ .sa_socklen = sizeof(struct sockaddr_storage), >+ }; > int ret; > > parent_si = find_socket_info(s); >@@ -2499,38 +2503,30 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > * assume out sockaddr have the same size as the in parent > * socket family > */ >- my_addrlen = socket_length(parent_si->family); >- if (my_addrlen <= 0) { >+ in_addr.sa_socklen = socket_length(parent_si->family); >+ if (in_addr.sa_socklen <= 0) { > errno = EINVAL; > return -1; > } > >- my_addr = (struct sockaddr *)malloc(my_addrlen); >- if (my_addr == NULL) { >- return -1; >- } >- > ret = libc_accept(s, &un_addr.sa.s, &un_addr.sa_socklen); > if (ret == -1) { > if (errno == ENOTSOCK) { > /* Remove stale fds */ > swrap_remove_stale(s); > } >- free(my_addr); > return ret; > } > > fd = ret; > >- len = my_addrlen; > ret = sockaddr_convert_from_un(parent_si, > &un_addr.sa.un, > un_addr.sa_socklen, > parent_si->family, >- my_addr, >- &len); >+ &in_addr.sa.s, >+ &in_addr.sa_socklen); > if (ret == -1) { >- free(my_addr); > close(fd); > return ret; > } >@@ -2541,7 +2537,6 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > child_fi = (struct socket_info_fd *)calloc(1, sizeof(struct socket_info_fd)); > if (child_fi == NULL) { > free(child_si); >- free(my_addr); > close(fd); > errno = ENOMEM; > return -1; >@@ -2558,15 +2553,17 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > child_si->is_server = 1; > child_si->connected = 1; > >- child_si->peername.sa_socklen = len; >- memcpy(&child_si->peername.sa.s, my_addr, len); >+ child_si->peername = (struct swrap_address) { >+ .sa_socklen = in_addr.sa_socklen, >+ }; >+ memcpy(&child_si->peername.sa.ss, &in_addr.sa.ss, in_addr.sa_socklen); > > if (addr != NULL && addrlen != NULL) { >- size_t copy_len = MIN(*addrlen, len); >+ size_t copy_len = MIN(*addrlen, in_addr.sa_socklen); > if (copy_len > 0) { >- memcpy(addr, my_addr, copy_len); >+ memcpy(addr, &in_addr.sa.ss, copy_len); > } >- *addrlen = len; >+ *addrlen = in_addr.sa_socklen; > } > > ret = libc_getsockname(fd, >@@ -2575,22 +2572,19 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > if (ret == -1) { > free(child_fi); > free(child_si); >- free(my_addr); > close(fd); > return ret; > } > >- len = my_addrlen; > ret = sockaddr_convert_from_un(child_si, > &un_my_addr.sa.un, > un_my_addr.sa_socklen, > child_si->family, >- my_addr, >- &len); >+ &in_my_addr.sa.s, >+ &in_my_addr.sa_socklen); > if (ret == -1) { > free(child_fi); > free(child_si); >- free(my_addr); > close(fd); > return ret; > } >@@ -2599,9 +2593,10 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > "accept() path=%s, fd=%d", > un_my_addr.sa.un.sun_path, s); > >- child_si->myname.sa_socklen = len; >- memcpy(&child_si->myname.sa.s, my_addr, len); >- free(my_addr); >+ child_si->myname = (struct swrap_address) { >+ .sa_socklen = in_my_addr.sa_socklen, >+ }; >+ memcpy(&child_si->myname.sa.ss, &in_my_addr.sa.ss, in_my_addr.sa_socklen); > > SWRAP_DLIST_ADD(sockets, child_si); > >-- >1.9.1 > > >From ef828d5f3b4efe5ba7ffa9a5dd6709ce13e7f31a Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:18:48 +0200 >Subject: [PATCH 16/27] swrap: Wrap fopen to detect stale file descriptors. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 9731516e7f87cc16412eb830840d0393e8a4f823) >--- > lib/socket_wrapper/socket_wrapper.c | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 9649004..574f5ba 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -337,6 +337,7 @@ struct swrap_libc_fns { > socklen_t addrlen); > int (*libc_dup)(int fd); > int (*libc_dup2)(int oldfd, int newfd); >+ FILE *(*libc_fopen)(const char *name, const char *mode); > #ifdef HAVE_EVENTFD > int (*libc_eventfd)(int count, int flags); > #endif >@@ -645,6 +646,13 @@ static int libc_listen(int sockfd, int backlog) > return swrap.fns.libc_listen(sockfd, backlog); > } > >+static FILE *libc_fopen(const char *name, const char *mode) >+{ >+ swrap_load_lib_function(SWRAP_LIBC, fopen); >+ >+ return swrap.fns.libc_fopen(name, mode); >+} >+ > static int libc_vopen(const char *pathname, int flags, va_list ap) > { > long int mode = 0; >@@ -3066,6 +3074,29 @@ int listen(int s, int backlog) > } > > /**************************************************************************** >+ * FOPEN >+ ***************************************************************************/ >+ >+static FILE *swrap_fopen(const char *name, const char *mode) >+{ >+ FILE *fp; >+ >+ fp = libc_fopen(name, mode); >+ if (fp != NULL) { >+ int fd = fileno(fp); >+ >+ swrap_remove_stale(fd); >+ } >+ >+ return fp; >+} >+ >+FILE *fopen(const char *name, const char *mode) >+{ >+ return swrap_fopen(name, mode); >+} >+ >+/**************************************************************************** > * OPEN > ***************************************************************************/ > >-- >1.9.1 > > >From b462572709e1b23fd5bfc7fc6dbec8daaf1d8da9 Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:20:15 +0200 >Subject: [PATCH 17/27] swrap: Update copyright notice. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit a5046865661f814bab8af7f84f8ebd81a62067b7) >--- > lib/socket_wrapper/socket_wrapper.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 574f5ba..7225b3e 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -1,7 +1,7 @@ > /* >- * Copyright (C) Jelmer Vernooij 2005,2008 <jelmer@samba.org> >- * Copyright (C) Stefan Metzmacher 2006-2009 <metze@samba.org> >- * Copyright (C) Andreas Schneider 2013 <asn@samba.org> >+ * Copyright (c) 2005-2008 Jelmer Vernooij <jelmer@samba.org> >+ * Copyright (C) 2006-2014 Stefan Metzmacher <metze@samba.org> >+ * Copyright (C) 2013-2014 Andreas Schneider <asn@samba.org> > * > * All rights reserved. > * >-- >1.9.1 > > >From de3133660f67b16c468de9664b973710be4e23ab Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:20:53 +0200 >Subject: [PATCH 18/27] swrap: Fix whitespace errors. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 9ba259e68aa755037a1a720da3662fe07a0a7ee4) >--- > lib/socket_wrapper/socket_wrapper.c | 32 ++++++++++++++++---------------- > 1 file changed, 16 insertions(+), 16 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 7225b3e..1b3352b 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -980,7 +980,7 @@ static int convert_in_un_remote(struct socket_info *si, const struct sockaddr *i > > switch (inaddr->sa_family) { > case AF_INET: { >- const struct sockaddr_in *in = >+ const struct sockaddr_in *in = > (const struct sockaddr_in *)(const void *)inaddr; > unsigned int addr = ntohl(in->sin_addr.s_addr); > char u_type = '\0'; >@@ -1027,7 +1027,7 @@ static int convert_in_un_remote(struct socket_info *si, const struct sockaddr *i > } > #ifdef HAVE_IPV6 > case AF_INET6: { >- const struct sockaddr_in6 *in = >+ const struct sockaddr_in6 *in = > (const struct sockaddr_in6 *)(const void *)inaddr; > struct in6_addr cmp1, cmp2; > >@@ -1074,14 +1074,14 @@ static int convert_in_un_remote(struct socket_info *si, const struct sockaddr *i > } > > if (is_bcast) { >- snprintf(un->sun_path, sizeof(un->sun_path), "%s/EINVAL", >+ snprintf(un->sun_path, sizeof(un->sun_path), "%s/EINVAL", > socket_wrapper_dir()); > SWRAP_LOG(SWRAP_LOG_DEBUG, "un path [%s]", un->sun_path); > /* the caller need to do more processing */ > return 0; > } > >- snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, >+ snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, > socket_wrapper_dir(), type, iface, prt); > SWRAP_LOG(SWRAP_LOG_DEBUG, "un path [%s]", un->sun_path); > >@@ -1101,7 +1101,7 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in > > switch (si->family) { > case AF_INET: { >- const struct sockaddr_in *in = >+ const struct sockaddr_in *in = > (const struct sockaddr_in *)(const void *)inaddr; > unsigned int addr = ntohl(in->sin_addr.s_addr); > char u_type = '\0'; >@@ -1171,7 +1171,7 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in > } > #ifdef HAVE_IPV6 > case AF_INET6: { >- const struct sockaddr_in6 *in = >+ const struct sockaddr_in6 *in = > (const struct sockaddr_in6 *)(const void *)inaddr; > struct in6_addr cmp1, cmp2; > >@@ -1240,7 +1240,7 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in > if (prt == 0) { > /* handle auto-allocation of ephemeral ports */ > for (prt = 5001; prt < 10000; prt++) { >- snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, >+ snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, > socket_wrapper_dir(), type, iface, prt); > if (stat(un->sun_path, &st) == 0) continue; > >@@ -1255,7 +1255,7 @@ static int convert_in_un_alloc(struct socket_info *si, const struct sockaddr *in > } > } > >- snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, >+ snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, > socket_wrapper_dir(), type, iface, prt); > SWRAP_LOG(SWRAP_LOG_DEBUG, "un path [%s]", un->sun_path); > return 0; >@@ -1450,8 +1450,8 @@ static int sockaddr_convert_to_un(struct socket_info *si, > return -1; > } > >-static int sockaddr_convert_from_un(const struct socket_info *si, >- const struct sockaddr_un *in_addr, >+static int sockaddr_convert_from_un(const struct socket_info *si, >+ const struct sockaddr_un *in_addr, > socklen_t un_addrlen, > int family, > struct sockaddr *out_addr, >@@ -1459,7 +1459,7 @@ static int sockaddr_convert_from_un(const struct socket_info *si, > { > int ret; > >- if (out_addr == NULL || out_addrlen == NULL) >+ if (out_addr == NULL || out_addrlen == NULL) > return 0; > > if (un_addrlen == 0) { >@@ -1624,7 +1624,7 @@ static const char *swrap_pcap_init_file(void) > /* > * TODO: don't use the structs use plain buffer offsets > * and PUSH_U8(), PUSH_U16() and PUSH_U32() >- * >+ * > * for now make sure we disable PCAP support > * if the struct has alignment! > */ >@@ -2507,7 +2507,7 @@ static int swrap_accept(int s, struct sockaddr *addr, socklen_t *addrlen) > return libc_accept(s, addr, addrlen); > } > >- /* >+ /* > * assume out sockaddr have the same size as the in parent > * socket family > */ >@@ -2664,7 +2664,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family) > type = SOCKET_TYPE_CHAR_TCP; > break; > case SOCK_DGRAM: >- type = SOCKET_TYPE_CHAR_UDP; >+ type = SOCKET_TYPE_CHAR_UDP; > break; > default: > errno = ESOCKTNOSUPPORT; >@@ -2673,7 +2673,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family) > > memset(&in, 0, sizeof(in)); > in.sin_family = AF_INET; >- in.sin_addr.s_addr = htonl(127<<24 | >+ in.sin_addr.s_addr = htonl(127<<24 | > socket_wrapper_default_iface()); > > si->myname = (struct swrap_address) { >@@ -2696,7 +2696,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family) > type = SOCKET_TYPE_CHAR_TCP_V6; > break; > case SOCK_DGRAM: >- type = SOCKET_TYPE_CHAR_UDP_V6; >+ type = SOCKET_TYPE_CHAR_UDP_V6; > break; > default: > errno = ESOCKTNOSUPPORT; >-- >1.9.1 > > >From db44ea8e6b9b7f47a92615a9299cc77dc4c382b5 Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:22:13 +0200 >Subject: [PATCH 19/27] swrap: Fix access to struct members in log messages. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit b3c72e151f5dc479e600118dbdca2fdc006dbd83) >--- > lib/socket_wrapper/socket_wrapper.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 1b3352b..430904d 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -2807,7 +2807,7 @@ static int swrap_connect(int s, const struct sockaddr *serv_addr, > > SWRAP_LOG(SWRAP_LOG_TRACE, > "connect() path=%s, fd=%d", >- un_addr.un.sun_path, s); >+ un_addr.sa.un.sun_path, s); > > > /* to give better errors */ >@@ -2954,7 +2954,7 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) > > SWRAP_LOG(SWRAP_LOG_TRACE, > "bind() path=%s, fd=%d", >- un_addr.sa_un.sun_path, s); >+ un_addr.sa.un.sun_path, s); > > if (ret == 0) { > si->bound = 1; >-- >1.9.1 > > >From cd2fdf72a32f136bc2827cf494cff72f8307028c Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:22:59 +0200 >Subject: [PATCH 20/27] swrap: Fix type punning warnings when loading > functions. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 088db7f7b561c1b87a890359c67b551bc1a48593) >--- > lib/socket_wrapper/socket_wrapper.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 430904d..88183c1 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -520,8 +520,9 @@ static void *_swrap_load_lib_function(enum swrap_lib lib, const char *fn_name) > > #define swrap_load_lib_function(lib, fn_name) \ > if (swrap.fns.libc_##fn_name == NULL) { \ >+ void *swrap_cast_ptr = _swrap_load_lib_function(lib, #fn_name); \ > *(void **) (&swrap.fns.libc_##fn_name) = \ >- _swrap_load_lib_function(lib, #fn_name); \ >+ swrap_cast_ptr; \ > } > > >-- >1.9.1 > > >From 6b7f83844e67e50fcaff235bec9febe13862cb02 Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:23:25 +0200 >Subject: [PATCH 21/27] swrap: Silence alignment warnings. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 872e1ae0ef22f659f52241c753f7f9b1b6f5b279) >--- > lib/socket_wrapper/socket_wrapper.c | 32 ++++++++++++++++---------------- > 1 file changed, 16 insertions(+), 16 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 88183c1..13b24a0 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -1412,7 +1412,7 @@ static int sockaddr_convert_to_un(struct socket_info *si, > if (in_len < sizeof(struct sockaddr_in)) { > break; > } >- sin = (const struct sockaddr_in *)in_addr; >+ sin = (const struct sockaddr_in *)(const void *)in_addr; > if(sin->sin_addr.s_addr != htonl(INADDR_ANY)) { > break; > } >@@ -1707,16 +1707,16 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval, > > switch (src->sa_family) { > case AF_INET: >- src_in = (const struct sockaddr_in *)src; >- dest_in = (const struct sockaddr_in *)dest; >+ src_in = (const struct sockaddr_in *)(const void *)src; >+ dest_in = (const struct sockaddr_in *)(const void *)dest; > src_port = src_in->sin_port; > dest_port = dest_in->sin_port; > ip_hdr_len = sizeof(ip->v4); > break; > #ifdef HAVE_IPV6 > case AF_INET6: >- src_in6 = (const struct sockaddr_in6 *)src; >- dest_in6 = (const struct sockaddr_in6 *)dest; >+ src_in6 = (const struct sockaddr_in6 *)(const void *)src; >+ dest_in6 = (const struct sockaddr_in6 *)(const void *)dest; > src_port = src_in6->sin6_port; > dest_port = dest_in6->sin6_port; > ip_hdr_len = sizeof(ip->v6); >@@ -1778,14 +1778,14 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval, > > buf = base; > >- frame = (struct swrap_packet_frame *)buf; >+ frame = (struct swrap_packet_frame *)(void *)buf; > frame->seconds = tval->tv_sec; > frame->micro_seconds = tval->tv_usec; > frame->recorded_length = wire_len - icmp_truncate_len; > frame->full_length = wire_len - icmp_truncate_len; > buf += SWRAP_PACKET_FRAME_SIZE; > >- ip = (union swrap_packet_ip *)buf; >+ ip = (union swrap_packet_ip *)(void *)buf; > switch (src->sa_family) { > case AF_INET: > ip->v4.ver_hdrlen = 0x45; /* version 4 and 5 * 32 bit words */ >@@ -1816,7 +1816,7 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval, > } > > if (unreachable) { >- pay = (union swrap_packet_payload *)buf; >+ pay = (union swrap_packet_payload *)(void *)buf; > switch (src->sa_family) { > case AF_INET: > pay->icmp4.type = 0x03; /* destination unreachable */ >@@ -1826,7 +1826,7 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval, > buf += SWRAP_PACKET_PAYLOAD_ICMP4_SIZE; > > /* set the ip header in the ICMP payload */ >- ip = (union swrap_packet_ip *)buf; >+ ip = (union swrap_packet_ip *)(void *)buf; > ip->v4.ver_hdrlen = 0x45; /* version 4 and 5 * 32 bit words */ > ip->v4.tos = 0x00; > ip->v4.packet_length = htons(wire_len - icmp_hdr_len); >@@ -1852,7 +1852,7 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval, > buf += SWRAP_PACKET_PAYLOAD_ICMP6_SIZE; > > /* set the ip header in the ICMP payload */ >- ip = (union swrap_packet_ip *)buf; >+ ip = (union swrap_packet_ip *)(void *)buf; > ip->v6.ver_prio = 0x60; /* version 4 and 5 * 32 bit words */ > ip->v6.flow_label_high = 0x00; > ip->v6.flow_label_low = 0x0000; >@@ -1869,7 +1869,7 @@ static uint8_t *swrap_pcap_packet_init(struct timeval *tval, > } > } > >- pay = (union swrap_packet_payload *)buf; >+ pay = (union swrap_packet_payload *)(void *)buf; > > switch (socket_type) { > case SOCK_STREAM: >@@ -2888,7 +2888,7 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) > break; > } > >- sin = (const struct sockaddr_in *)myaddr; >+ sin = (const struct sockaddr_in *)(const void *)myaddr; > > if (sin->sin_family != AF_INET) { > bind_error = EAFNOSUPPORT; >@@ -2911,7 +2911,7 @@ static int swrap_bind(int s, const struct sockaddr *myaddr, socklen_t addrlen) > break; > } > >- sin6 = (const struct sockaddr_in6 *)myaddr; >+ sin6 = (const struct sockaddr_in6 *)(const void *)myaddr; > > if (sin6->sin6_family != AF_INET6) { > bind_error = EAFNOSUPPORT; >@@ -3020,7 +3020,7 @@ static int swrap_bindresvport_sa(int sd, struct sockaddr *sa) > break; > } > case AF_INET6: { >- struct sockaddr_in6 *sin6p = (struct sockaddr_in6 *)sa; >+ struct sockaddr_in6 *sin6p = (struct sockaddr_in6 *)(void *)sa; > > salen = sizeof(struct sockaddr_in6); > sin6p->sin6_port = htons(port); >@@ -4240,7 +4240,7 @@ static ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, > if (bcast) { > struct stat st; > unsigned int iface; >- unsigned int prt = ntohs(((const struct sockaddr_in *)to)->sin_port); >+ unsigned int prt = ntohs(((const struct sockaddr_in *)(const void *)to)->sin_port); > char type; > > type = SOCKET_TYPE_CHAR_UDP; >@@ -4604,7 +4604,7 @@ static ssize_t swrap_sendmsg(int s, const struct msghdr *omsg, int flags) > if (bcast) { > struct stat st; > unsigned int iface; >- unsigned int prt = ntohs(((const struct sockaddr_in *)to)->sin_port); >+ unsigned int prt = ntohs(((const struct sockaddr_in *)(const void *)to)->sin_port); > char type; > size_t i, len = 0; > uint8_t *buf; >-- >1.9.1 > > >From 2d88d3f0db3c82f2dfa44b161516e112b5831c20 Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:23:53 +0200 >Subject: [PATCH 22/27] swrap: Include the function name in the debug output. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 2efd5b242928c2e048b5421d52e35dd2e13dca15) >--- > lib/socket_wrapper/socket_wrapper.c | 26 ++++++++++++++------------ > 1 file changed, 14 insertions(+), 12 deletions(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 13b24a0..e0942ed 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -272,10 +272,12 @@ void swrap_destructor(void) DESTRUCTOR_ATTRIBUTE; > # define SWRAP_LOG(...) > #else > >-static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *format, ...) PRINTF_ATTRIBUTE(2, 3); >-# define SWRAP_LOG(dbglvl, ...) swrap_log((dbglvl), __VA_ARGS__) >+static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *func, const char *format, ...) PRINTF_ATTRIBUTE(3, 4); >+# define SWRAP_LOG(dbglvl, ...) swrap_log((dbglvl), __func__, __VA_ARGS__) > >-static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *format, ...) >+static void swrap_log(enum swrap_dbglvl_e dbglvl, >+ const char *func, >+ const char *format, ...) > { > char buffer[1024]; > va_list va; >@@ -295,23 +297,23 @@ static void swrap_log(enum swrap_dbglvl_e dbglvl, const char *format, ...) > switch (dbglvl) { > case SWRAP_LOG_ERROR: > fprintf(stderr, >- "SWRAP_ERROR(%d): %s\n", >- (int)getpid(), buffer); >+ "SWRAP_ERROR(%d) - %s: %s\n", >+ (int)getpid(), func, buffer); > break; > case SWRAP_LOG_WARN: > fprintf(stderr, >- "SWRAP_WARN(%d): %s\n", >- (int)getpid(), buffer); >+ "SWRAP_WARN(%d) - %s: %s\n", >+ (int)getpid(), func, buffer); > break; > case SWRAP_LOG_DEBUG: > fprintf(stderr, >- "SWRAP_DEBUG(%d): %s\n", >- (int)getpid(), buffer); >+ "SWRAP_DEBUG(%d) - %s: %s\n", >+ (int)getpid(), func, buffer); > break; > case SWRAP_LOG_TRACE: > fprintf(stderr, >- "SWRAP_TRACE(%d): %s\n", >- (int)getpid(), buffer); >+ "SWRAP_TRACE(%d) - %s: %s\n", >+ (int)getpid(), func, buffer); > break; > } > } >@@ -2727,7 +2729,7 @@ static int swrap_auto_bind(int fd, struct socket_info *si, int family) > > for (i = 0; i < SOCKET_MAX_SOCKETS; i++) { > port = autobind_start + i; >- snprintf(un_addr.sa.un.sun_path, un_addr.sa_socklen, >+ snprintf(un_addr.sa.un.sun_path, sizeof(un_addr.sa.un.sun_path), > "%s/"SOCKET_FORMAT, socket_wrapper_dir(), > type, socket_wrapper_default_iface(), port); > if (stat(un_addr.sa.un.sun_path, &st) == 0) continue; >-- >1.9.1 > > >From 2f2dda19eb59bed33531f31f0fa762b6b04d545b Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:24:27 +0200 >Subject: [PATCH 23/27] swrap: Implement fcntl() to catch F_DUPFD. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 8efc0952adda9273e90ffbbc0c691c9ff4b9b947) >--- > lib/socket_wrapper/socket_wrapper.c | 87 ++++++++++++++++++++++++++++++++++++- > 1 file changed, 86 insertions(+), 1 deletion(-) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index e0942ed..8a7b572 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -339,6 +339,7 @@ struct swrap_libc_fns { > socklen_t addrlen); > int (*libc_dup)(int fd); > int (*libc_dup2)(int oldfd, int newfd); >+ int (*libc_fcntl)(int fd, int cmd, ...); > FILE *(*libc_fopen)(const char *name, const char *mode); > #ifdef HAVE_EVENTFD > int (*libc_eventfd)(int count, int flags); >@@ -591,6 +592,28 @@ static int libc_eventfd(int count, int flags) > } > #endif > >+static int libc_vfcntl(int fd, int cmd, va_list ap) >+{ >+ long int args[4]; >+ int rc; >+ int i; >+ >+ swrap_load_lib_function(SWRAP_LIBC, fcntl); >+ >+ for (i = 0; i < 4; i++) { >+ args[i] = va_arg(ap, long int); >+ } >+ >+ rc = swrap.fns.libc_fcntl(fd, >+ cmd, >+ args[0], >+ args[1], >+ args[2], >+ args[3]); >+ >+ return rc; >+} >+ > static int libc_getpeername(int sockfd, > struct sockaddr *addr, > socklen_t *addrlen) >@@ -4918,7 +4941,69 @@ int dup2(int fd, int newfd) > } > > /**************************** >- * DUP2 >+ * FCNTL >+ ***************************/ >+ >+static int swrap_vfcntl(int fd, int cmd, va_list va) >+{ >+ struct socket_info_fd *fi; >+ struct socket_info *si; >+ int rc; >+ >+ si = find_socket_info(fd); >+ if (si == NULL) { >+ rc = libc_vfcntl(fd, cmd, va); >+ >+ return rc; >+ } >+ >+ switch (cmd) { >+ case F_DUPFD: >+ fi = (struct socket_info_fd *)calloc(1, sizeof(struct socket_info_fd)); >+ if (fi == NULL) { >+ errno = ENOMEM; >+ return -1; >+ } >+ >+ fi->fd = libc_vfcntl(fd, cmd, va); >+ if (fi->fd == -1) { >+ int saved_errno = errno; >+ free(fi); >+ errno = saved_errno; >+ return -1; >+ } >+ >+ /* Make sure we don't have an entry for the fd */ >+ swrap_remove_stale(fi->fd); >+ >+ SWRAP_DLIST_ADD(si->fds, fi); >+ >+ rc = fi->fd; >+ break; >+ default: >+ rc = libc_vfcntl(fd, cmd, va); >+ break; >+ } >+ >+ return rc; >+} >+ >+int fcntl(int fd, int cmd, ...) >+{ >+ va_list va; >+ int rc; >+ >+ va_start(va, cmd); >+ >+ rc = swrap_vfcntl(fd, cmd, va); >+ >+ va_end(va); >+ >+ return rc; >+} >+ >+/**************************** >+ * EVENTFD > ***************************/ > > #ifdef HAVE_EVENTFD >-- >1.9.1 > > >From 5a1061b4e3a6f7fea4bc90542cf142368699757a Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:24:55 +0200 >Subject: [PATCH 24/27] swrap: Add a trace message for swrap_socket(). > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 539fa2c04f6220e72a63ab492fae298c86b00954) >--- > lib/socket_wrapper/socket_wrapper.c | 5 +++++ > 1 file changed, 5 insertions(+) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 8a7b572..6a495b9 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -2430,6 +2430,11 @@ static int swrap_socket(int family, int type, int protocol) > SWRAP_DLIST_ADD(si->fds, fi); > SWRAP_DLIST_ADD(sockets, si); > >+ SWRAP_LOG(SWRAP_LOG_TRACE, >+ "Created %s socket for protocol %s", >+ si->family == AF_INET ? "IPv4" : "IPv6", >+ si->type == SOCK_DGRAM ? "UDP" : "TCP"); >+ > return fd; > } > >-- >1.9.1 > > >From 2691752033f63c4c68309dc24e557dd15de8d9ec Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:25:32 +0200 >Subject: [PATCH 25/27] swrap: Add support for eventfd with unsigned count > variable. > >The prototype in glibc 2.20.90 changed. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit afe2f47c0fd17c215857e800296de795d48c004d) >--- > lib/socket_wrapper/socket_wrapper.c | 4 ++++ > 1 file changed, 4 insertions(+) > >diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c >index 6a495b9..d5c343d 100644 >--- a/lib/socket_wrapper/socket_wrapper.c >+++ b/lib/socket_wrapper/socket_wrapper.c >@@ -5024,7 +5024,11 @@ static int swrap_eventfd(int count, int flags) > return fd; > } > >+#ifdef HAVE_EVENTFD_UNSIGNED_INT >+int eventfd(unsigned int count, int flags) >+#else > int eventfd(int count, int flags) >+#endif > { > return swrap_eventfd(count, flags); > } >-- >1.9.1 > > >From 123f94c9f2c47b8fee8f1acdd351c278e732d9aa Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Thu, 2 Oct 2014 07:26:35 +0200 >Subject: [PATCH 26/27] swrap: Bump version to 1.1.2. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Matthieu Patou <mat@matws.net> > >Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> >Autobuild-Date(master): Thu Oct 2 12:00:14 CEST 2014 on sn-devel-104 > >(cherry picked from commit 47f307d112a4eaec0d375ee1604c13ed7449b3c4) >--- > lib/socket_wrapper/wscript | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > >diff --git a/lib/socket_wrapper/wscript b/lib/socket_wrapper/wscript >index de5bedd..279f577 100644 >--- a/lib/socket_wrapper/wscript >+++ b/lib/socket_wrapper/wscript >@@ -2,7 +2,7 @@ > > import os > >-VERSION="1.1.1" >+VERSION="1.1.2" > > def configure(conf): > if conf.CHECK_BUNDLED_SYSTEM('socket_wrapper', minversion=VERSION, set_target=False): >-- >1.9.1 > > >From 9a37fd656d56b31791d1e274f1e9219bf124531a Mon Sep 17 00:00:00 2001 >From: Andreas Schneider <asn@samba.org> >Date: Wed, 26 Nov 2014 10:18:34 +0100 >Subject: [PATCH 27/27] socket_wrapper: Add missing prototype check for > eventfd. > >BUG: https://bugzilla.samba.org/show_bug.cgi?id=10965 > >Newer glibc versions use and unsinged integer for the count instead of >an integer. > >Signed-off-by: Andreas Schneider <asn@samba.org> >Reviewed-by: Stefan Metzmacher <metze@samba.org> >(cherry picked from commit 78e8bafb322ec69c5ff4b32a5e1c5679c9dea6bf) >--- > lib/socket_wrapper/wscript | 5 +++++ > 1 file changed, 5 insertions(+) > >diff --git a/lib/socket_wrapper/wscript b/lib/socket_wrapper/wscript >index 279f577..91d23d1 100644 >--- a/lib/socket_wrapper/wscript >+++ b/lib/socket_wrapper/wscript >@@ -88,6 +88,11 @@ def configure(conf): > 'int ioctl(int s, int r, ...)', > define='HAVE_IOCTL_INT', headers='unistd.h sys/ioctl.h') > >+ if conf.CONFIG_SET("HAVE_EVENTFD"): >+ conf.CHECK_C_PROTOTYPE('eventfd', >+ 'int eventfd(unsigned int count, int flags)', >+ define='HAVE_EVENTFD_UNSIGNED_INT', headers='sys/eventfd.h') >+ > # Create full path to socket_wrapper > srcdir = os.path.realpath(conf.srcdir) > libsocket_wrapper_so_path = srcdir + '/bin/default/lib/socket_wrapper/libsocket-wrapper.so' >-- >1.9.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Flags:
asn
:
review+
Actions:
View
Attachments on
bug 10965
:
10475
|
10504
| 10505