s3:rpc_server: Create ncalrpc socket through endpoint initialization
authorSamuel Cabrero <scabrero@suse.de>
Wed, 27 Feb 2019 17:32:45 +0000 (18:32 +0100)
committerSamuel Cabrero <scabrero@sn-devel-184>
Fri, 20 Mar 2020 15:36:34 +0000 (15:36 +0000)
Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/rpc_server/lsasd.c
source3/rpc_server/mdssd.c
source3/rpc_server/rpc_server.c
source3/rpc_server/rpc_server.h
source3/rpc_server/rpc_service_setup.c

index 904dd11888e1d0d268baa13aa36a08ca410aa19f..9628df7df4eed8aaaaf461ac14a7d4d983a24ac3 100644 (file)
@@ -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;
index e3b16a7a87a408e5a2736de1f03b82a35c753b92..85b2cd5f694e7fb539c8775078cc47372fbff8e4 100644 (file)
@@ -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;
index 1e05ae599f0557427641c70d3b0228afa5d6691a..d9777d12e9babc0fc547ef891ae6f323491f6504 100644 (file)
@@ -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));
index 4fc01c1ce39e481449e501c4f734633d80c8c448..b7154ab28eb8180580cf17a9ad5a53da14d8e513 100644 (file)
@@ -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,
index 1ac9bdf03c06e35bee0fd86733ff3f3532eec32b..fe8de1b0199ff4d451aaf5fde34b3fbb24ef6ad3 100644 (file)
@@ -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: