1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

s3:rpc_server: Create ncacn_np 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 19:13:57 +01:00 committed by Samuel Cabrero
parent 64a70a9610
commit 9a6a5a50f1
6 changed files with 37 additions and 121 deletions

View File

@ -628,22 +628,6 @@ static NTSTATUS spoolssd_create_sockets(struct tevent_context *ev_ctx,
}
}
status = dcesrv_create_ncacn_np_socket(SPOOLSS_PIPE_NAME, &fd);
if (!NT_STATUS_IS_OK(status)) {
goto done;
}
rc = listen(fd, pf_spoolss_cfg.max_allowed_clients);
if (rc == -1) {
DBG_ERR("Failed to listen on spoolss pipe - %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;
if (epm_mode != RPC_SERVICE_MODE_DISABLED &&
(lp_parm_bool(-1, "rpc_server", "register_embedded_np", false))) {
status = dcerpc_binding_vector_add_np_default(&ndr_table_spoolss, v);

View File

@ -632,38 +632,6 @@ static NTSTATUS lsasd_create_sockets(struct tevent_context *ev_ctx,
}
/* LSARPC */
status = dcesrv_create_ncacn_np_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 pipe - %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;
status = dcesrv_create_ncacn_np_socket("lsass", &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 lsass pipe - %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;
@ -690,22 +658,6 @@ static NTSTATUS lsasd_create_sockets(struct tevent_context *ev_ctx,
}
/* SAMR */
status = dcesrv_create_ncacn_np_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 pipe - %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;
@ -732,22 +684,6 @@ static NTSTATUS lsasd_create_sockets(struct tevent_context *ev_ctx,
}
/* NETLOGON */
status = dcesrv_create_ncacn_np_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 samr pipe - %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;

View File

@ -579,20 +579,6 @@ static NTSTATUS mdssd_create_sockets(struct tevent_context *ev_ctx,
}
/* mdssvc */
status = dcesrv_create_ncacn_np_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;

View File

@ -104,11 +104,34 @@ static void dcesrv_ncacn_np_listener(struct tevent_context *ev,
uint16_t flags,
void *private_data);
NTSTATUS dcesrv_create_ncacn_np_socket(const char *pipe_name, int *out_fd)
NTSTATUS dcesrv_create_ncacn_np_socket(struct dcesrv_endpoint *e, int *out_fd)
{
char *np_dir = NULL;
int fd = -1;
NTSTATUS status;
const char *endpoint;
char *endpoint_normalized = NULL;
char *p = NULL;
endpoint = dcerpc_binding_get_string_option(e->ep_description,
"endpoint");
if (endpoint == NULL) {
DBG_ERR("Endpoint mandatory for named pipes\n");
return NT_STATUS_INVALID_PARAMETER;
}
/* The endpoint string from IDL can be mixed uppercase and case is
* normalized by smbd on connection */
endpoint_normalized = strlower_talloc(talloc_tos(), endpoint);
if (endpoint_normalized == NULL) {
return NT_STATUS_NO_MEMORY;
}
/* The endpoint string from IDL can be prefixed by \pipe\ */
p = endpoint_normalized;
if (strncmp(p, "\\pipe\\", 6) == 0) {
p += 6;
}
/*
* As lp_ncalrpc_dir() should have 0755, but
@ -136,22 +159,23 @@ NTSTATUS dcesrv_create_ncacn_np_socket(const char *pipe_name, int *out_fd)
goto out;
}
fd = create_pipe_sock(np_dir, pipe_name, 0700);
fd = create_pipe_sock(np_dir, p, 0700);
if (fd == -1) {
status = map_nt_error_from_unix_common(errno);
DBG_ERR("Failed to create ncacn_np socket! '%s/%s': %s\n",
np_dir, pipe_name, strerror(errno));
np_dir, p, strerror(errno));
goto out;
}
DBG_DEBUG("Opened pipe socket fd %d for %s\n", fd, pipe_name);
DBG_DEBUG("Opened pipe socket fd %d for %s\n", fd, p);
*out_fd = fd;
status = NT_STATUS_OK;
out:
talloc_free(np_dir);
TALLOC_FREE(endpoint_normalized);
TALLOC_FREE(np_dir);
return status;
}
@ -167,8 +191,6 @@ NTSTATUS dcesrv_setup_ncacn_np_socket(struct tevent_context *ev_ctx,
int rc;
NTSTATUS status;
const char *endpoint = NULL;
char *endpoint_normalized = NULL;
char *p = NULL;
endpoint = dcerpc_binding_get_string_option(e->ep_description,
"endpoint");
@ -177,19 +199,6 @@ NTSTATUS dcesrv_setup_ncacn_np_socket(struct tevent_context *ev_ctx,
return NT_STATUS_INVALID_PARAMETER;
}
/* The endpoint string from IDL can be mixed uppercase and case is
* normalized by smbd on connection */
endpoint_normalized = strlower_talloc(talloc_tos(), endpoint);
if (endpoint_normalized == NULL) {
return NT_STATUS_NO_MEMORY;
}
/* The endpoint string from IDL can be prefixed by \pipe\ */
p = endpoint_normalized;
if (strncmp(p, "\\pipe\\", 6) == 0) {
p += 6;
}
/* 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 */
@ -206,7 +215,7 @@ NTSTATUS dcesrv_setup_ncacn_np_socket(struct tevent_context *ev_ctx,
state->termination_fn = term_fn;
state->termination_data = term_data;
status = dcesrv_create_ncacn_np_socket(p, &state->fd);
status = dcesrv_create_ncacn_np_socket(e, &state->fd);
if (!NT_STATUS_IS_OK(status)) {
goto out;
}
@ -238,15 +247,12 @@ NTSTATUS dcesrv_setup_ncacn_np_socket(struct tevent_context *ev_ctx,
tevent_fd_set_auto_close(fde);
TALLOC_FREE(endpoint_normalized);
return NT_STATUS_OK;
out:
if (state->fd != -1) {
close(state->fd);
}
TALLOC_FREE(endpoint_normalized);
TALLOC_FREE(state);
return status;
}

View File

@ -77,7 +77,7 @@ int make_server_pipes_struct(TALLOC_CTX *mem_ctx,
void set_incoming_fault(struct pipes_struct *p);
void process_complete_pdu(struct pipes_struct *p, struct ncacn_packet *pkt);
NTSTATUS dcesrv_create_ncacn_np_socket(const char *pipe_name, int *out_fd);
NTSTATUS dcesrv_create_ncacn_np_socket(struct dcesrv_endpoint *e, int *out_fd);
NTSTATUS dcesrv_setup_ncacn_np_socket(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx,
struct dcesrv_context *dce_ctx,

View File

@ -155,8 +155,12 @@ NTSTATUS dcesrv_create_endpoint_sockets(struct tevent_context *ev_ctx,
break;
case NCACN_NP:
/* TODO */
status = NT_STATUS_OK;
status = dcesrv_create_ncacn_np_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;
default: