#include "../lib/tsocket/tsocket.h"
#include "librpc/rpc/dcerpc_ep.h"
-#include "rpc_server/rpc_server.h"
+#include "librpc/rpc/dcesrv_core.h"
#include "rpc_server/rpc_sock_helper.h"
#include "lib/server_prefork.h"
#include "librpc/ndr/ndr_table.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_RPC_SRV
-NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(
- const struct ndr_interface_table *iface,
- struct dcerpc_binding_vector *bvec,
- uint16_t port,
- struct pf_listen_fd *listen_fd,
- int *listen_fd_size)
+NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(struct dcesrv_endpoint *e,
+ struct dcerpc_binding_vector *bvec,
+ struct pf_listen_fd *listen_fd,
+ int *listen_fd_size)
{
- uint32_t num_ifs = iface_count();
- uint32_t i;
- uint16_t p = port;
TALLOC_CTX *tmp_ctx;
NTSTATUS status = NT_STATUS_UNSUCCESSFUL;
int rc;
+ uint16_t port = 0;
+ char port_str[6];
+ const char *endpoint = NULL;
tmp_ctx = talloc_stackframe();
if (tmp_ctx == NULL) {
return NT_STATUS_NO_MEMORY;
}
+ endpoint = dcerpc_binding_get_string_option(e->ep_description,
+ "endpoint");
+ if (endpoint != NULL) {
+ port = atoi(endpoint);
+ }
+
if (lp_interfaces() && lp_bind_interfaces_only()) {
+ uint32_t num_ifs = iface_count();
+ uint32_t i;
+
/*
* We have been given an interfaces line, and been told to only
* bind to those interfaces. Create a socket per interface and
iface_n_sockaddr_storage(i);
struct tsocket_address *bind_addr;
const char *addr;
- int fd;
+ int fd = -1;
status = dcesrv_create_ncacn_ip_tcp_socket(ifss,
- &p,
+ &port,
&fd);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
listen_fd[*listen_fd_size].fd = fd;
- listen_fd[*listen_fd_size].fd_data = NULL;
+ listen_fd[*listen_fd_size].fd_data = e;
(*listen_fd_size)++;
if (bvec != NULL) {
+ struct dcesrv_if_list *if_list = NULL;
+
rc = tsocket_address_bsd_from_sockaddr(tmp_ctx,
(const struct sockaddr *)ifss,
sizeof(struct sockaddr_storage),
goto done;
}
- status = dcerpc_binding_vector_add_port(iface,
- bvec,
- addr,
- p);
- if (!NT_STATUS_IS_OK(status)) {
- close(fd);
- goto done;
+ for (if_list = e->interface_list; if_list; if_list = if_list->next) {
+ const struct ndr_interface_table *iface = NULL;
+ iface = ndr_table_by_syntax(&if_list->iface->syntax_id);
+ if (iface != NULL) {
+ status = dcerpc_binding_vector_add_port(iface,
+ bvec,
+ addr,
+ port);
+ if (!NT_STATUS_IS_OK(status)) {
+ close(fd);
+ goto done;
+ }
+ }
}
}
}
next_token_talloc(talloc_tos(), &sock_ptr, &sock_tok, " \t,");
) {
struct sockaddr_storage ss;
- int fd;
+ int fd = -1;
/* open an incoming socket */
if (!interpret_string_addr(&ss,
}
status = dcesrv_create_ncacn_ip_tcp_socket(&ss,
- &p,
+ &port,
&fd);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
listen_fd[*listen_fd_size].fd = fd;
- listen_fd[*listen_fd_size].fd_data = NULL;
+ listen_fd[*listen_fd_size].fd_data = e;
(*listen_fd_size)++;
if (bvec != NULL) {
- status = dcerpc_binding_vector_add_port(iface,
- bvec,
- sock_tok,
- p);
- if (!NT_STATUS_IS_OK(status)) {
- close(fd);
- goto done;
+ struct dcesrv_if_list *if_list = NULL;
+
+ for (if_list = e->interface_list; if_list; if_list = if_list->next) {
+ const struct ndr_interface_table *iface = NULL;
+ iface = ndr_table_by_syntax(&if_list->iface->syntax_id);
+ if (iface != NULL) {
+ status = dcerpc_binding_vector_add_port(iface,
+ bvec,
+ sock_tok,
+ port);
+ if (!NT_STATUS_IS_OK(status)) {
+ close(fd);
+ goto done;
+ }
+ }
}
}
}
}
+ /* Set the port in the endpoint */
+ snprintf(port_str, sizeof(port_str), "%u", port);
+
+ status = dcerpc_binding_set_string_option(e->ep_description,
+ "endpoint", port_str);
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_ERR("Failed to set binding endpoint '%s': %s\n",
+ port_str, nt_errstr(status));
+ goto done;
+ }
+
status = NT_STATUS_OK;
done:
talloc_free(tmp_ctx);