1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-11 16:58:40 +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

@ -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 && if (epm_mode != RPC_SERVICE_MODE_DISABLED &&
(lp_parm_bool(-1, "rpc_server", "register_embedded_np", false))) { (lp_parm_bool(-1, "rpc_server", "register_embedded_np", false))) {
status = dcerpc_binding_vector_add_np_default(&ndr_table_spoolss, v); status = dcerpc_binding_vector_add_np_default(&ndr_table_spoolss, v);

@ -632,38 +632,6 @@ static NTSTATUS lsasd_create_sockets(struct tevent_context *ev_ctx,
} }
/* LSARPC */ /* 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); v = dcerpc_binding_vector_dup(tmp_ctx, v_orig);
if (v == NULL) { if (v == NULL) {
goto done; goto done;
@ -690,22 +658,6 @@ static NTSTATUS lsasd_create_sockets(struct tevent_context *ev_ctx,
} }
/* SAMR */ /* 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); v = dcerpc_binding_vector_dup(tmp_ctx, v_orig);
if (v == NULL) { if (v == NULL) {
goto done; goto done;
@ -732,22 +684,6 @@ static NTSTATUS lsasd_create_sockets(struct tevent_context *ev_ctx,
} }
/* NETLOGON */ /* 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); v = dcerpc_binding_vector_dup(tmp_ctx, v_orig);
if (v == NULL) { if (v == NULL) {
goto done; goto done;

@ -579,20 +579,6 @@ static NTSTATUS mdssd_create_sockets(struct tevent_context *ev_ctx,
} }
/* mdssvc */ /* 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); v = dcerpc_binding_vector_dup(tmp_ctx, v_orig);
if (v == NULL) { if (v == NULL) {
goto done; goto done;

@ -104,11 +104,34 @@ static void dcesrv_ncacn_np_listener(struct tevent_context *ev,
uint16_t flags, uint16_t flags,
void *private_data); 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; char *np_dir = NULL;
int fd = -1; int fd = -1;
NTSTATUS status; 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 * 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; goto out;
} }
fd = create_pipe_sock(np_dir, pipe_name, 0700); fd = create_pipe_sock(np_dir, p, 0700);
if (fd == -1) { if (fd == -1) {
status = map_nt_error_from_unix_common(errno); status = map_nt_error_from_unix_common(errno);
DBG_ERR("Failed to create ncacn_np socket! '%s/%s': %s\n", 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; 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; *out_fd = fd;
status = NT_STATUS_OK; status = NT_STATUS_OK;
out: out:
talloc_free(np_dir); TALLOC_FREE(endpoint_normalized);
TALLOC_FREE(np_dir);
return status; return status;
} }
@ -167,8 +191,6 @@ NTSTATUS dcesrv_setup_ncacn_np_socket(struct tevent_context *ev_ctx,
int rc; int rc;
NTSTATUS status; NTSTATUS status;
const char *endpoint = NULL; const char *endpoint = NULL;
char *endpoint_normalized = NULL;
char *p = NULL;
endpoint = dcerpc_binding_get_string_option(e->ep_description, endpoint = dcerpc_binding_get_string_option(e->ep_description,
"endpoint"); "endpoint");
@ -177,19 +199,6 @@ NTSTATUS dcesrv_setup_ncacn_np_socket(struct tevent_context *ev_ctx,
return NT_STATUS_INVALID_PARAMETER; 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 /* Alloc in endpoint context. If the endpoint is freed (for example
* when forked daemons reinit the dcesrv_context, the tevent_fd * when forked daemons reinit the dcesrv_context, the tevent_fd
* listener will be stopped and the socket closed */ * 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_fn = term_fn;
state->termination_data = term_data; 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)) { if (!NT_STATUS_IS_OK(status)) {
goto out; goto out;
} }
@ -238,15 +247,12 @@ NTSTATUS dcesrv_setup_ncacn_np_socket(struct tevent_context *ev_ctx,
tevent_fd_set_auto_close(fde); tevent_fd_set_auto_close(fde);
TALLOC_FREE(endpoint_normalized);
return NT_STATUS_OK; return NT_STATUS_OK;
out: out:
if (state->fd != -1) { if (state->fd != -1) {
close(state->fd); close(state->fd);
} }
TALLOC_FREE(endpoint_normalized);
TALLOC_FREE(state); TALLOC_FREE(state);
return status; return status;
} }

@ -77,7 +77,7 @@ int make_server_pipes_struct(TALLOC_CTX *mem_ctx,
void set_incoming_fault(struct pipes_struct *p); void set_incoming_fault(struct pipes_struct *p);
void process_complete_pdu(struct pipes_struct *p, struct ncacn_packet *pkt); 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, NTSTATUS dcesrv_setup_ncacn_np_socket(struct tevent_context *ev_ctx,
struct messaging_context *msg_ctx, struct messaging_context *msg_ctx,
struct dcesrv_context *dce_ctx, struct dcesrv_context *dce_ctx,

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