]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:rpc_server: Setup ncalrpc sockets through endpoint initialization
authorSamuel Cabrero <scabrero@suse.de>
Wed, 27 Feb 2019 17:20:11 +0000 (18:20 +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/epmd.c
source3/rpc_server/rpc_server.c
source3/rpc_server/rpc_server.h
source3/rpc_server/rpc_service_setup.c

index baf99db5f60268ca20c70af3d1edb29d5bc28cfd..cdcd87c1e6f4d01ba47120204c00f527107398b4 100644 (file)
@@ -238,16 +238,6 @@ void start_epmd(struct tevent_context *ev_ctx,
                }
        }
 
-       status = dcesrv_setup_ncalrpc_socket(ev_ctx,
-                                            msg_ctx,
-                                            "EPMAPPER",
-                                            srv_epmapper_delete_endpoints,
-                                            NULL);
-       if (!NT_STATUS_IS_OK(status)) {
-               DEBUG(0, ("Failed to open epmd ncalrpc pipe!\n"));
-               exit(1);
-       }
-
        status = dcesrv_setup_ncacn_np_socket("epmapper", ev_ctx, msg_ctx);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0, ("Failed to open epmd named pipe!\n"));
index 2ba8cc0b53e46181f782bcd7f43f3f425781c63d..1e05ae599f0557427641c70d3b0228afa5d6691a 100644 (file)
@@ -513,7 +513,8 @@ out:
 
 NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
                                     struct messaging_context *msg_ctx,
-                                    const char *name,
+                                    struct dcesrv_context *dce_ctx,
+                                    struct dcesrv_endpoint *e,
                                     dcerpc_ncacn_termination_fn term_fn,
                                     void *termination_data)
 {
@@ -521,29 +522,47 @@ NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
        struct tevent_fd *fde;
        int rc;
        NTSTATUS status;
+       const char *endpoint = NULL;
 
-       state = talloc_zero(ev_ctx, struct dcerpc_ncacn_listen_state);
+       /* Alloc in endpoint context. If the endpoint is freed (for example
+        * when forked daemons reinit the dcesrv_context, the tevent_fd
+        * listener will be stopped and the socket closed */
+       state = talloc_zero(e, struct dcerpc_ncacn_listen_state);
        if (state == NULL) {
                DBG_ERR("Out of memory\n");
                return NT_STATUS_NO_MEMORY;
        }
 
        state->fd = -1;
+       state->ev_ctx = ev_ctx;
+       state->msg_ctx = msg_ctx;
+       state->dce_ctx = talloc_reference(state, dce_ctx);
+       state->endpoint = e;
        state->termination_fn = term_fn;
        state->termination_data = termination_data;
 
-       if (name == NULL) {
-               name = "DEFAULT";
-       }
-
-       state->ep.name = talloc_strdup(state, name);
-       if (state->ep.name == NULL) {
-               DBG_ERR("Out of memory\n");
-               talloc_free(state);
-               return NT_STATUS_NO_MEMORY;
+       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(name, &state->fd);
+       status = dcesrv_create_ncalrpc_socket(endpoint, &state->fd);
        if (!NT_STATUS_IS_OK(status)) {
                DBG_ERR("Failed to create ncalrpc socket: %s\n",
                        nt_errstr(status));
@@ -554,13 +573,10 @@ NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
        if (rc < 0) {
                status = map_nt_error_from_unix_common(errno);
                DBG_ERR("Failed to listen on ncalrpc socket %s: %s\n",
-                       name, strerror(errno));
+                       endpoint, strerror(errno));
                goto out;
        }
 
-       state->ev_ctx = ev_ctx;
-       state->msg_ctx = msg_ctx;
-
        /* Set server socket to non-blocking for the accept. */
        set_blocking(state->fd, false);
 
@@ -610,6 +626,7 @@ static void dcesrv_ncalrpc_listener(struct tevent_context *ev,
        };
        int sd = -1;
        int rc;
+       const char *endpoint = NULL;
 
        sd = accept(state->fd, &addr.u.sa, &addr.sa_socklen);
        if (sd == -1) {
@@ -640,13 +657,21 @@ static void dcesrv_ncalrpc_listener(struct tevent_context *ev,
                return;
        }
 
+       endpoint = dcerpc_binding_get_string_option(
+                       state->endpoint->ep_description, "endpoint");
+       if (endpoint == NULL) {
+               DBG_ERR("Failed to get endpoint from binding description\n");
+               close(sd);
+               return;
+       }
+
        DBG_DEBUG("Accepted ncalrpc socket %s (fd: %d)\n",
                   addr.u.un.sun_path, sd);
 
        dcerpc_ncacn_accept(state->ev_ctx,
                            state->msg_ctx,
                            NCALRPC,
-                           state->ep.name,
+                           endpoint,
                            cli_addr, srv_addr, sd,
                            state->termination_fn,
                            state->termination_data);
index 68fff9563a1b8c0dd3c4476cebc5d10c3a213fec..4fc01c1ce39e481449e501c4f734633d80c8c448 100644 (file)
@@ -96,7 +96,8 @@ NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx,
 NTSTATUS dcesrv_create_ncalrpc_socket(const char *name, int *out_fd);
 NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
                                     struct messaging_context *msg_ctx,
-                                    const char *name,
+                                    struct dcesrv_context *dce_ctx,
+                                    struct dcesrv_endpoint *e,
                                     dcerpc_ncacn_termination_fn term_fn,
                                     void *termination_data);
 
index 00e34829ff03ccb00d8c0a181122f6302ae2b5d5..1ac9bdf03c06e35bee0fd86733ff3f3532eec32b 100644 (file)
@@ -210,8 +210,12 @@ NTSTATUS dcesrv_setup_endpoint_sockets(struct tevent_context *ev_ctx,
 
        switch (transport) {
        case NCALRPC:
-               /* TODO */
-               status = NT_STATUS_OK;
+               status = dcesrv_setup_ncalrpc_socket(ev_ctx,
+                                                    msg_ctx,
+                                                    dce_ctx,
+                                                    e,
+                                                    term_fn,
+                                                    term_data);
                break;
 
        case NCACN_IP_TCP: