1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

s3:rpc_server: Setup ncalrpc sockets through endpoint initialization

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Samuel Cabrero 2019-02-27 18:20:11 +01:00 committed by Samuel Cabrero
parent a6b718b6ec
commit 1d970fa83d
4 changed files with 50 additions and 30 deletions

View 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"));

View 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";
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;
}
}
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;
}
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);

View 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);

View 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: