summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/replace/libreplace_network.m44
-rw-r--r--lib/socket_wrapper/socket_wrapper.c56
-rw-r--r--lib/talloc/talloc.h2
-rw-r--r--lib/tsocket/tsocket_bsd.c48
-rw-r--r--lib/util/fault.m42
-rw-r--r--lib/util/tevent_ntstatus.c10
-rw-r--r--lib/util/tevent_ntstatus.h1
7 files changed, 92 insertions, 31 deletions
diff --git a/lib/replace/libreplace_network.m4 b/lib/replace/libreplace_network.m4
index 3bac72d136..2af02312ab 100644
--- a/lib/replace/libreplace_network.m4
+++ b/lib/replace/libreplace_network.m4
@@ -170,7 +170,7 @@ fi
# The following tests need LIBS="${LIBREPLACE_NETWORK_LIBS}"
old_LIBS=$LIBS
LIBS="${LIBREPLACE_NETWORK_LIBS}"
-SAVE_CPPFLAGS="$CPPFLAGS"
+libreplace_SAVE_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS -I$libreplacedir"
AC_CHECK_FUNCS(socketpair,[],[LIBREPLACE_NETWORK_OBJS="${LIBREPLACE_NETWORK_OBJS} socketpair.o"])
@@ -381,7 +381,7 @@ if test x"$libreplace_cv_HAVE_IPV6" = x"yes"; then
fi
LIBS=$old_LIBS
-CPPFLAGS="$SAVE_CPPFLAGS"
+CPPFLAGS="$libreplace_SAVE_CPPFLAGS"
LIBREPLACEOBJ="${LIBREPLACEOBJ} ${LIBREPLACE_NETWORK_OBJS}"
diff --git a/lib/socket_wrapper/socket_wrapper.c b/lib/socket_wrapper/socket_wrapper.c
index 44082e78a1..553827b192 100644
--- a/lib/socket_wrapper/socket_wrapper.c
+++ b/lib/socket_wrapper/socket_wrapper.c
@@ -218,6 +218,7 @@ struct socket_info
int bcast;
int is_server;
int connected;
+ int defer_connect;
char *path;
char *tmp_path;
@@ -1686,10 +1687,15 @@ _PUBLIC_ int swrap_connect(int s, const struct sockaddr *serv_addr, socklen_t ad
ret = sockaddr_convert_to_un(si, (const struct sockaddr *)serv_addr, addrlen, &un_addr, 0, NULL);
if (ret == -1) return -1;
- swrap_dump_packet(si, serv_addr, SWRAP_CONNECT_SEND, NULL, 0);
+ if (si->type == SOCK_DGRAM) {
+ si->defer_connect = 1;
+ ret = 0;
+ } else {
+ swrap_dump_packet(si, serv_addr, SWRAP_CONNECT_SEND, NULL, 0);
- ret = real_connect(s, (struct sockaddr *)&un_addr,
- sizeof(struct sockaddr_un));
+ ret = real_connect(s, (struct sockaddr *)&un_addr,
+ sizeof(struct sockaddr_un));
+ }
/* to give better errors */
if (ret == -1 && errno == ENOENT) {
@@ -1917,7 +1923,22 @@ _PUBLIC_ ssize_t swrap_sendto(int s, const void *buf, size_t len, int flags, con
return len;
}
-
+
+ if (si->defer_connect) {
+ ret = real_connect(s, (struct sockaddr *)&un_addr,
+ sizeof(un_addr));
+
+ /* to give better errors */
+ if (ret == -1 && errno == ENOENT) {
+ errno = EHOSTUNREACH;
+ }
+
+ if (ret == -1) {
+ return ret;
+ }
+ si->defer_connect = 0;
+ }
+
ret = real_sendto(s, buf, len, flags, (struct sockaddr *)&un_addr, sizeof(un_addr));
break;
default:
@@ -2002,6 +2023,33 @@ _PUBLIC_ ssize_t swrap_send(int s, const void *buf, size_t len, int flags)
len = MIN(len, 1500);
+ if (si->defer_connect) {
+ struct sockaddr_un un_addr;
+ int bcast = 0;
+
+ if (si->bound == 0) {
+ ret = swrap_auto_bind(si, si->family);
+ if (ret == -1) return -1;
+ }
+
+ ret = sockaddr_convert_to_un(si, si->peername, si->peername_len,
+ &un_addr, 0, &bcast);
+ if (ret == -1) return -1;
+
+ ret = real_connect(s, (struct sockaddr *)&un_addr,
+ sizeof(un_addr));
+
+ /* to give better errors */
+ if (ret == -1 && errno == ENOENT) {
+ errno = EHOSTUNREACH;
+ }
+
+ if (ret == -1) {
+ return ret;
+ }
+ si->defer_connect = 0;
+ }
+
ret = real_send(s, buf, len, flags);
if (ret == -1) {
diff --git a/lib/talloc/talloc.h b/lib/talloc/talloc.h
index 5c8d5c5fe2..f87564a13b 100644
--- a/lib/talloc/talloc.h
+++ b/lib/talloc/talloc.h
@@ -94,7 +94,7 @@ typedef void TALLOC_CTX;
#define talloc_array(ctx, type, count) (type *)_talloc_array(ctx, sizeof(type), count, #type)
#define talloc_array_size(ctx, size, count) _talloc_array(ctx, size, count, __location__)
#define talloc_array_ptrtype(ctx, ptr, count) (_TALLOC_TYPEOF(ptr))talloc_array_size(ctx, sizeof(*(ptr)), count)
-#define talloc_array_length(ctx) ((ctx) ? talloc_get_size(ctx)/sizeof(*ctx) : 0)
+#define talloc_array_length(ctx) (talloc_get_size(ctx)/sizeof(*ctx))
#define talloc_realloc(ctx, p, type, count) (type *)_talloc_realloc_array(ctx, p, sizeof(type), count, #type)
#define talloc_realloc_size(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__)
diff --git a/lib/tsocket/tsocket_bsd.c b/lib/tsocket/tsocket_bsd.c
index 2811882fed..3d13dfd47d 100644
--- a/lib/tsocket/tsocket_bsd.c
+++ b/lib/tsocket/tsocket_bsd.c
@@ -44,11 +44,11 @@ struct tsocket_address_bsd {
bool broadcast;
union {
struct sockaddr sa;
- struct sockaddr_in sin;
+ struct sockaddr_in in;
#ifdef HAVE_IPV6
- struct sockaddr_in6 sin6;
+ struct sockaddr_in6 in6;
#endif
- struct sockaddr_un sun;
+ struct sockaddr_un un;
struct sockaddr_storage ss;
} u;
};
@@ -204,14 +204,14 @@ char *tsocket_address_inet_addr_string(const struct tsocket_address *addr,
switch (bsda->u.sa.sa_family) {
case AF_INET:
- str = inet_ntop(bsda->u.sin.sin_family,
- &bsda->u.sin.sin_addr,
+ str = inet_ntop(bsda->u.in.sin_family,
+ &bsda->u.in.sin_addr,
addr_str, sizeof(addr_str));
break;
#ifdef HAVE_IPV6
case AF_INET6:
- str = inet_ntop(bsda->u.sin6.sin6_family,
- &bsda->u.sin6.sin6_addr,
+ str = inet_ntop(bsda->u.in6.sin6_family,
+ &bsda->u.in6.sin6_addr,
addr_str, sizeof(addr_str));
break;
#endif
@@ -240,11 +240,11 @@ uint16_t tsocket_address_inet_port(const struct tsocket_address *addr)
switch (bsda->u.sa.sa_family) {
case AF_INET:
- port = ntohs(bsda->u.sin.sin_port);
+ port = ntohs(bsda->u.in.sin_port);
break;
#ifdef HAVE_IPV6
case AF_INET6:
- port = ntohs(bsda->u.sin6.sin6_port);
+ port = ntohs(bsda->u.in6.sin6_port);
break;
#endif
default:
@@ -268,11 +268,11 @@ int tsocket_address_inet_set_port(struct tsocket_address *addr,
switch (bsda->u.sa.sa_family) {
case AF_INET:
- bsda->u.sin.sin_port = htons(port);
+ bsda->u.in.sin_port = htons(port);
break;
#ifdef HAVE_IPV6
case AF_INET6:
- bsda->u.sin6.sin6_port = htons(port);
+ bsda->u.in6.sin6_port = htons(port);
break;
#endif
default:
@@ -301,21 +301,21 @@ int _tsocket_address_unix_from_path(TALLOC_CTX *mem_ctx,
struct tsocket_address **_addr,
const char *location)
{
- struct sockaddr_un sun;
- void *p = &sun;
+ struct sockaddr_un un;
+ void *p = &un;
int ret;
if (!path) {
path = "";
}
- ZERO_STRUCT(sun);
- sun.sun_family = AF_UNIX;
- strncpy(sun.sun_path, path, sizeof(sun.sun_path));
+ ZERO_STRUCT(un);
+ un.sun_family = AF_UNIX;
+ strncpy(un.sun_path, path, sizeof(un.sun_path));
ret = _tsocket_address_bsd_from_sockaddr(mem_ctx,
(struct sockaddr *)p,
- sizeof(sun),
+ sizeof(un),
_addr,
location);
@@ -336,7 +336,7 @@ char *tsocket_address_unix_path(const struct tsocket_address *addr,
switch (bsda->u.sa.sa_family) {
case AF_UNIX:
- str = bsda->u.sun.sun_path;
+ str = bsda->u.un.sun_path;
break;
default:
errno = EINVAL;
@@ -359,7 +359,7 @@ static char *tsocket_address_bsd_string(const struct tsocket_address *addr,
switch (bsda->u.sa.sa_family) {
case AF_UNIX:
return talloc_asprintf(mem_ctx, "unix:%s",
- bsda->u.sun.sun_path);
+ bsda->u.un.sun_path);
case AF_INET:
prefix = "ipv4";
break;
@@ -469,27 +469,27 @@ static int tsocket_address_bsd_create_socket(const struct tsocket_address *addr,
errno = EINVAL;
return -1;
}
- if (bsda->u.sun.sun_path[0] != 0) {
+ if (bsda->u.un.sun_path[0] != 0) {
do_bind = true;
}
break;
case AF_INET:
- if (bsda->u.sin.sin_port != 0) {
+ if (bsda->u.in.sin_port != 0) {
do_reuseaddr = true;
do_bind = true;
}
- if (bsda->u.sin.sin_addr.s_addr == INADDR_ANY) {
+ if (bsda->u.in.sin_addr.s_addr == INADDR_ANY) {
do_bind = true;
}
break;
#ifdef HAVE_IPV6
case AF_INET6:
- if (bsda->u.sin6.sin6_port != 0) {
+ if (bsda->u.in6.sin6_port != 0) {
do_reuseaddr = true;
do_bind = true;
}
if (memcmp(&in6addr_any,
- &bsda->u.sin6.sin6_addr,
+ &bsda->u.in6.sin6_addr,
sizeof(in6addr_any)) != 0) {
do_bind = true;
}
diff --git a/lib/util/fault.m4 b/lib/util/fault.m4
index bac553a158..c22976998e 100644
--- a/lib/util/fault.m4
+++ b/lib/util/fault.m4
@@ -9,6 +9,8 @@ if test x"$ac_cv_header_execinfo_h" = x"yes" -a x"$ac_cv_func_ext_backtrace" = x
EXECINFO_CPPFLAGS="$CPPFLAGS"
EXECINFO_LDFLAGS="$LDFLAGS"
LIB_REMOVE_USR_LIB(EXECINFO_LDFLAGS)
+ CFLAGS_REMOVE_USR_INCLUDE(EXECINFO_CFLAGS)
+ CFLAGS_REMOVE_USR_INCLUDE(EXECINFO_CPPFLAGS)
else
SMB_ENABLE(EXECINFO,NO)
fi
diff --git a/lib/util/tevent_ntstatus.c b/lib/util/tevent_ntstatus.c
index 1a34e9c749..4e4339989a 100644
--- a/lib/util/tevent_ntstatus.c
+++ b/lib/util/tevent_ntstatus.c
@@ -49,3 +49,13 @@ bool tevent_req_is_nterror(struct tevent_req *req, NTSTATUS *status)
}
return true;
}
+
+NTSTATUS tevent_req_simple_recv_ntstatus(struct tevent_req *req)
+{
+ NTSTATUS status;
+
+ if (tevent_req_is_nterror(req, &status)) {
+ return status;
+ }
+ return NT_STATUS_OK;
+}
diff --git a/lib/util/tevent_ntstatus.h b/lib/util/tevent_ntstatus.h
index 84c275fb13..d7194a9b73 100644
--- a/lib/util/tevent_ntstatus.h
+++ b/lib/util/tevent_ntstatus.h
@@ -28,5 +28,6 @@
bool tevent_req_nterror(struct tevent_req *req, NTSTATUS status);
bool tevent_req_is_nterror(struct tevent_req *req, NTSTATUS *pstatus);
+NTSTATUS tevent_req_simple_recv_ntstatus(struct tevent_req *req);
#endif