From: Samuel Cabrero Date: Wed, 27 Feb 2019 17:32:45 +0000 (+0100) Subject: s3:rpc_server: Create ncalrpc socket through endpoint initialization X-Git-Tag: ldb-2.2.0~1329 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f8eb0e3569b7372763ce40ff43c9152ece4ecc6e;p=thirdparty%2Fsamba.git s3:rpc_server: Create ncalrpc socket through endpoint initialization Signed-off-by: Samuel Cabrero Reviewed-by: Andrew Bartlett --- diff --git a/source3/rpc_server/lsasd.c b/source3/rpc_server/lsasd.c index 904dd11888e..9628df7df4e 100644 --- a/source3/rpc_server/lsasd.c +++ b/source3/rpc_server/lsasd.c @@ -664,22 +664,6 @@ static NTSTATUS lsasd_create_sockets(struct tevent_context *ev_ctx, (*listen_fd_size)++; fd = -1; - status = dcesrv_create_ncalrpc_socket("lsarpc", &fd); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - rc = listen(fd, pf_lsasd_cfg.max_allowed_clients); - if (rc == -1) { - DEBUG(0, ("Failed to listen on lsarpc ncalrpc - %s\n", - strerror(errno))); - goto done; - } - listen_fd[*listen_fd_size].fd = fd; - listen_fd[*listen_fd_size].fd_data = NULL; - (*listen_fd_size)++; - fd = -1; - v = dcerpc_binding_vector_dup(tmp_ctx, v_orig); if (v == NULL) { goto done; @@ -722,22 +706,6 @@ static NTSTATUS lsasd_create_sockets(struct tevent_context *ev_ctx, (*listen_fd_size)++; fd = -1; - status = dcesrv_create_ncalrpc_socket("samr", &fd); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - rc = listen(fd, pf_lsasd_cfg.max_allowed_clients); - if (rc == -1) { - DEBUG(0, ("Failed to listen on samr ncalrpc - %s\n", - strerror(errno))); - goto done; - } - listen_fd[*listen_fd_size].fd = fd; - listen_fd[*listen_fd_size].fd_data = NULL; - (*listen_fd_size)++; - fd = -1; - v = dcerpc_binding_vector_dup(tmp_ctx, v_orig); if (v == NULL) { goto done; @@ -780,22 +748,6 @@ static NTSTATUS lsasd_create_sockets(struct tevent_context *ev_ctx, (*listen_fd_size)++; fd = -1; - status = dcesrv_create_ncalrpc_socket("netlogon", &fd); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - rc = listen(fd, pf_lsasd_cfg.max_allowed_clients); - if (rc == -1) { - DEBUG(0, ("Failed to listen on netlogon ncalrpc - %s\n", - strerror(errno))); - goto done; - } - listen_fd[*listen_fd_size].fd = fd; - listen_fd[*listen_fd_size].fd_data = NULL; - (*listen_fd_size)++; - fd = -1; - v = dcerpc_binding_vector_dup(tmp_ctx, v_orig); if (v == NULL) { goto done; diff --git a/source3/rpc_server/mdssd.c b/source3/rpc_server/mdssd.c index e3b16a7a87a..85b2cd5f694 100644 --- a/source3/rpc_server/mdssd.c +++ b/source3/rpc_server/mdssd.c @@ -593,20 +593,6 @@ static NTSTATUS mdssd_create_sockets(struct tevent_context *ev_ctx, (*listen_fd_size)++; fd = -1; - status = dcesrv_create_ncalrpc_socket("mdssvc", &fd); - if (!NT_STATUS_IS_OK(status)) { - goto done; - } - - rc = listen(fd, pf_mdssd_cfg.max_allowed_clients); - if (rc == -1) { - goto done; - } - listen_fd[*listen_fd_size].fd = fd; - listen_fd[*listen_fd_size].fd_data = NULL; - (*listen_fd_size)++; - fd = -1; - v = dcerpc_binding_vector_dup(tmp_ctx, v_orig); if (v == NULL) { goto done; diff --git a/source3/rpc_server/rpc_server.c b/source3/rpc_server/rpc_server.c index 1e05ae599f0..d9777d12e9b 100644 --- a/source3/rpc_server/rpc_server.c +++ b/source3/rpc_server/rpc_server.c @@ -476,13 +476,31 @@ static void dcesrv_ncalrpc_listener(struct tevent_context *ev, uint16_t flags, void *private_data); -NTSTATUS dcesrv_create_ncalrpc_socket(const char *name, int *out_fd) +NTSTATUS dcesrv_create_ncalrpc_socket(struct dcesrv_endpoint *e, int *out_fd) { int fd = -1; + const char *endpoint = NULL; NTSTATUS status; - if (name == NULL) { - name = "DEFAULT"; + endpoint = dcerpc_binding_get_string_option(e->ep_description, + "endpoint"); + if (endpoint == NULL) { + /* + * No identifier specified: use DEFAULT. + * + * TODO: DO NOT hardcode this value anywhere else. Rather, + * specify no endpoint and let the epmapper worry about it. + */ + endpoint = "DEFAULT"; + status = dcerpc_binding_set_string_option(e->ep_description, + "endpoint", + endpoint); + if (!NT_STATUS_IS_OK(status)) { + DBG_ERR("Failed to set ncalrpc 'endpoint' binding " + "string option to '%s': %s\n", + endpoint, nt_errstr(status)); + return status; + } } if (!directory_create_or_exist(lp_ncalrpc_dir(), 0755)) { @@ -492,16 +510,16 @@ NTSTATUS dcesrv_create_ncalrpc_socket(const char *name, int *out_fd) goto out; } - fd = create_pipe_sock(lp_ncalrpc_dir(), name, 0755); + fd = create_pipe_sock(lp_ncalrpc_dir(), endpoint, 0755); if (fd == -1) { status = map_nt_error_from_unix_common(errno); DBG_ERR("Failed to create ncalrpc socket '%s/%s': %s\n", - lp_ncalrpc_dir(), name, strerror(errno)); + lp_ncalrpc_dir(), endpoint, strerror(errno)); goto out; } DBG_DEBUG("Opened ncalrpc socket fd '%d' for '%s/%s'\n", - fd, lp_ncalrpc_dir(), name); + fd, lp_ncalrpc_dir(), endpoint); *out_fd = fd; @@ -522,7 +540,6 @@ NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx, struct tevent_fd *fde; int rc; NTSTATUS status; - const char *endpoint = NULL; /* Alloc in endpoint context. If the endpoint is freed (for example * when forked daemons reinit the dcesrv_context, the tevent_fd @@ -541,28 +558,7 @@ NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx, state->termination_fn = term_fn; state->termination_data = termination_data; - endpoint = dcerpc_binding_get_string_option(e->ep_description, - "endpoint"); - if (endpoint == NULL) { - /* - * No identifier specified: use DEFAULT. - * - * TODO: DO NOT hardcode this value anywhere else. Rather, - * specify no endpoint and let the epmapper worry about it. - */ - endpoint = "DEFAULT"; - status = dcerpc_binding_set_string_option(e->ep_description, - "endpoint", - endpoint); - if (!NT_STATUS_IS_OK(status)) { - DBG_ERR("Failed to set ncalrpc 'endpoint' binding " - "string option to '%s': %s\n", - endpoint, nt_errstr(status)); - goto out; - } - } - - status = dcesrv_create_ncalrpc_socket(endpoint, &state->fd); + status = dcesrv_create_ncalrpc_socket(e, &state->fd); if (!NT_STATUS_IS_OK(status)) { DBG_ERR("Failed to create ncalrpc socket: %s\n", nt_errstr(status)); @@ -571,6 +567,8 @@ NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx, rc = listen(state->fd, 5); if (rc < 0) { + const char *endpoint = dcerpc_binding_get_string_option( + e->ep_description, "endpoint"); status = map_nt_error_from_unix_common(errno); DBG_ERR("Failed to listen on ncalrpc socket %s: %s\n", endpoint, strerror(errno)); diff --git a/source3/rpc_server/rpc_server.h b/source3/rpc_server/rpc_server.h index 4fc01c1ce39..b7154ab28eb 100644 --- a/source3/rpc_server/rpc_server.h +++ b/source3/rpc_server/rpc_server.h @@ -93,7 +93,7 @@ NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx, dcerpc_ncacn_termination_fn term_fn, void *term_data); -NTSTATUS dcesrv_create_ncalrpc_socket(const char *name, int *out_fd); +NTSTATUS dcesrv_create_ncalrpc_socket(struct dcesrv_endpoint *e, int *fd); NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx, struct messaging_context *msg_ctx, struct dcesrv_context *dce_ctx, diff --git a/source3/rpc_server/rpc_service_setup.c b/source3/rpc_server/rpc_service_setup.c index 1ac9bdf03c0..fe8de1b0199 100644 --- a/source3/rpc_server/rpc_service_setup.c +++ b/source3/rpc_server/rpc_service_setup.c @@ -60,6 +60,7 @@ #include "rpc_server/spoolss/srv_spoolss_nt.h" #include "rpc_server/svcctl/srv_svcctl_nt.h" +#include "lib/server_prefork.h" #include "librpc/rpc/dcesrv_core.h" #include "librpc/rpc/dcerpc_ep.h" #include "rpc_server/rpc_sock_helper.h" @@ -127,6 +128,7 @@ NTSTATUS dcesrv_create_endpoint_sockets(struct tevent_context *ev_ctx, dcerpc_binding_get_transport(e->ep_description); char *binding = NULL; NTSTATUS status; + int out_fd; binding = dcerpc_binding_string(dce_ctx, e->ep_description); if (binding == NULL) { @@ -137,8 +139,12 @@ NTSTATUS dcesrv_create_endpoint_sockets(struct tevent_context *ev_ctx, switch (transport) { case NCALRPC: - /* TODO */ - status = NT_STATUS_OK; + status = dcesrv_create_ncalrpc_socket(e, &out_fd); + if (NT_STATUS_IS_OK(status)) { + listen_fds[*listen_fds_size].fd = out_fd; + listen_fds[*listen_fds_size].fd_data = e; + (*listen_fds_size)++; + } break; case NCACN_IP_TCP: