summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
*/