summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2011-05-12 12:33:01 +0200
committerAndrew Tridgell <tridge@samba.org>2011-06-06 12:26:09 +1000
commitd510687408c03291df767e0ccacebcd4a360646c (patch)
tree855f4f21cecab2d9091050ae92d1a2fce0073baa
parentdf632483f18923430a6da595d07c9f241438e766 (diff)
downloadsamba-d510687408c03291df767e0ccacebcd4a360646c.tar.gz
samba-d510687408c03291df767e0ccacebcd4a360646c.tar.bz2
samba-d510687408c03291df767e0ccacebcd4a360646c.zip
s4-ipv6: fixed stream_setup_socket() to handle IPv6
for IP we now detect the address family from the address, rather than requiring the caller to specify it.
-rw-r--r--source4/smbd/service_stream.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/source4/smbd/service_stream.c b/source4/smbd/service_stream.c
index a0e440f63c..cb084a0039 100644
--- a/source4/smbd/service_stream.c
+++ b/source4/smbd/service_stream.c
@@ -27,6 +27,7 @@
#include "cluster/cluster.h"
#include "param/param.h"
#include "../lib/tsocket/tsocket.h"
+#include "lib/util/util_net.h"
/* the range of ports to try for dcerpc over tcp endpoints */
#define SERVER_TCP_LOW_PORT 1024
@@ -271,12 +272,34 @@ NTSTATUS stream_setup_socket(TALLOC_CTX *mem_ctx,
struct socket_address *socket_address;
struct tevent_fd *fde;
int i;
+ struct sockaddr_storage ss;
stream_socket = talloc_zero(mem_ctx, struct stream_socket);
NT_STATUS_HAVE_NO_MEMORY(stream_socket);
- status = socket_create(family, SOCKET_TYPE_STREAM, &stream_socket->sock, 0);
- NT_STATUS_NOT_OK_RETURN(status);
+ if (strcmp(family, "ip") == 0) {
+ /* we will get the real family from the address itself */
+ if (!interpret_string_addr(&ss, sock_addr, 0)) {
+ talloc_free(stream_socket);
+ return NT_STATUS_INVALID_ADDRESS;
+ }
+
+ socket_address = socket_address_from_sockaddr_storage(stream_socket, &ss, port?*port:0);
+ NT_STATUS_HAVE_NO_MEMORY_AND_FREE(socket_address, stream_socket);
+
+ status = socket_create(socket_address->family, SOCKET_TYPE_STREAM, &stream_socket->sock, 0);
+ NT_STATUS_NOT_OK_RETURN(status);
+ } else {
+ status = socket_create(family, SOCKET_TYPE_STREAM, &stream_socket->sock, 0);
+ NT_STATUS_NOT_OK_RETURN(status);
+
+ /* this is for non-IP sockets, eg. unix domain sockets */
+ socket_address = socket_address_from_strings(stream_socket,
+ stream_socket->sock->backend_name,
+ sock_addr, 0);
+ NT_STATUS_HAVE_NO_MEMORY(socket_address);
+ }
+
talloc_steal(stream_socket, stream_socket->sock);
@@ -297,34 +320,19 @@ NTSTATUS stream_setup_socket(TALLOC_CTX *mem_ctx,
/* Some sockets don't have a port, or are just described from
* the string. We are indicating this by having port == NULL */
if (!port) {
- socket_address = socket_address_from_strings(stream_socket,
- stream_socket->sock->backend_name,
- sock_addr, 0);
- NT_STATUS_HAVE_NO_MEMORY(socket_address);
status = socket_listen(stream_socket->sock, socket_address, SERVER_LISTEN_BACKLOG, 0);
- talloc_free(socket_address);
-
} else if (*port == 0) {
for (i=SERVER_TCP_LOW_PORT;i<= SERVER_TCP_HIGH_PORT;i++) {
- socket_address = socket_address_from_strings(stream_socket,
- stream_socket->sock->backend_name,
- sock_addr, i);
- NT_STATUS_HAVE_NO_MEMORY(socket_address);
+ socket_address->port = i;
status = socket_listen(stream_socket->sock, socket_address,
SERVER_LISTEN_BACKLOG, 0);
- talloc_free(socket_address);
if (NT_STATUS_IS_OK(status)) {
*port = i;
break;
}
}
} else {
- socket_address = socket_address_from_strings(stream_socket,
- stream_socket->sock->backend_name,
- sock_addr, *port);
- NT_STATUS_HAVE_NO_MEMORY(socket_address);
status = socket_listen(stream_socket->sock, socket_address, SERVER_LISTEN_BACKLOG, 0);
- talloc_free(socket_address);
}
if (!NT_STATUS_IS_OK(status)) {
@@ -362,6 +370,7 @@ NTSTATUS stream_setup_socket(TALLOC_CTX *mem_ctx,
return NT_STATUS_OK;
}
+
/*
setup a connection title
*/