From fd099ae16a73ab9a6287968b15ba596b7cf89ee0 Mon Sep 17 00:00:00 2001 From: Samuel Cabrero Date: Wed, 27 Feb 2019 16:06:44 +0100 Subject: [PATCH] s3:rpc_server: Initialize mdssd connection endpoints Signed-off-by: Samuel Cabrero Reviewed-by: Andrew Bartlett --- source3/rpc_server/mdssd.c | 60 +++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 10 deletions(-) diff --git a/source3/rpc_server/mdssd.c b/source3/rpc_server/mdssd.c index 3c291554ee1..e3b16a7a87a 100644 --- a/source3/rpc_server/mdssd.c +++ b/source3/rpc_server/mdssd.c @@ -32,6 +32,7 @@ #include "librpc/rpc/dcesrv_core.h" #include "rpc_server/rpc_server.h" +#include "rpc_server/rpc_service_setup.h" #include "rpc_server/rpc_ep_register.h" #include "rpc_server/rpc_sock_helper.h" #include "rpc_server/rpc_modules.h" @@ -520,21 +521,23 @@ static void mdssd_check_children(struct tevent_context *ev_ctx, * start it up */ -static bool mdssd_create_sockets(struct tevent_context *ev_ctx, - struct messaging_context *msg_ctx, - struct pf_listen_fd *listen_fd, - int *listen_fd_size) +static NTSTATUS mdssd_create_sockets(struct tevent_context *ev_ctx, + struct messaging_context *msg_ctx, + struct dcesrv_context *dce_ctx, + struct pf_listen_fd *listen_fd, + int *listen_fd_size) { struct dcerpc_binding_vector *v, *v_orig; TALLOC_CTX *tmp_ctx; NTSTATUS status; int fd = -1; int rc; - bool ok = false; + uint32_t i; + struct dcesrv_endpoint *e = NULL; tmp_ctx = talloc_stackframe(); if (tmp_ctx == NULL) { - return false; + return NT_STATUS_NO_MEMORY; } status = dcerpc_binding_vector_new(tmp_ctx, &v_orig); @@ -542,6 +545,39 @@ static bool mdssd_create_sockets(struct tevent_context *ev_ctx, goto done; } + DBG_INFO("Initializing DCE/RPC connection endpoints\n"); + + for (e = dce_ctx->endpoint_list; e; e = e->next) { + status = dcesrv_create_endpoint_sockets(ev_ctx, + msg_ctx, + dce_ctx, + e, + v_orig, + listen_fd, + listen_fd_size); + if (!NT_STATUS_IS_OK(status)) { + char *ep_string = dcerpc_binding_string( + dce_ctx, e->ep_description); + DBG_ERR("Failed to create endpoint '%s': %s\n", + ep_string, nt_errstr(status)); + TALLOC_FREE(ep_string); + goto done; + } + } + + for (i = 0; i < *listen_fd_size; i++) { + rc = listen(listen_fd[i].fd, pf_mdssd_cfg.max_allowed_clients); + if (rc == -1) { + char *ep_string = dcerpc_binding_string( + dce_ctx, e->ep_description); + DBG_ERR("Failed to listen on endpoint '%s': %s\n", + ep_string, strerror(errno)); + status = map_nt_error_from_unix(errno); + TALLOC_FREE(ep_string); + goto done; + } + } + /* mdssvc */ status = dcesrv_create_ncacn_np_socket("mdssvc", &fd); if (!NT_STATUS_IS_OK(status)) { @@ -591,13 +627,13 @@ static bool mdssd_create_sockets(struct tevent_context *ev_ctx, goto done; } - ok = true; + status = NT_STATUS_OK; done: if (fd != -1) { close(fd); } talloc_free(tmp_ctx); - return ok; + return status; } void start_mdssd(struct tevent_context *ev_ctx, @@ -688,8 +724,12 @@ void start_mdssd(struct tevent_context *ev_ctx, exit(1); } - ok = mdssd_create_sockets(ev_ctx, msg_ctx, listen_fd, &listen_fd_size); - if (!ok) { + status = mdssd_create_sockets(ev_ctx, + msg_ctx, + dce_ctx, + listen_fd, + &listen_fd_size); + if (!NT_STATUS_IS_OK(status)) { exit(1); }