From: Samuel Cabrero Date: Wed, 27 Feb 2019 17:20:11 +0000 (+0100) Subject: s3:rpc_server: Setup ncalrpc sockets through endpoint initialization X-Git-Tag: ldb-2.2.0~1330 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d970fa83da200a8962c8acd579607b15166c5dc;p=thirdparty%2Fsamba.git s3:rpc_server: Setup ncalrpc sockets through endpoint initialization Signed-off-by: Samuel Cabrero Reviewed-by: Andrew Bartlett --- diff --git a/source3/rpc_server/epmd.c b/source3/rpc_server/epmd.c index baf99db5f60..cdcd87c1e6f 100644 --- a/source3/rpc_server/epmd.c +++ b/source3/rpc_server/epmd.c @@ -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")); diff --git a/source3/rpc_server/rpc_server.c b/source3/rpc_server/rpc_server.c index 2ba8cc0b53e..1e05ae599f0 100644 --- a/source3/rpc_server/rpc_server.c +++ b/source3/rpc_server/rpc_server.c @@ -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); diff --git a/source3/rpc_server/rpc_server.h b/source3/rpc_server/rpc_server.h index 68fff9563a1..4fc01c1ce39 100644 --- a/source3/rpc_server/rpc_server.h +++ b/source3/rpc_server/rpc_server.h @@ -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); diff --git a/source3/rpc_server/rpc_service_setup.c b/source3/rpc_server/rpc_service_setup.c index 00e34829ff0..1ac9bdf03c0 100644 --- a/source3/rpc_server/rpc_service_setup.c +++ b/source3/rpc_server/rpc_service_setup.c @@ -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: