diff --git a/source3/printing/spoolssd.c b/source3/printing/spoolssd.c index 3e640c29269..cad2ad2317e 100644 --- a/source3/printing/spoolssd.c +++ b/source3/printing/spoolssd.c @@ -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); diff --git a/source3/rpc_server/lsasd.c b/source3/rpc_server/lsasd.c index 9628df7df4e..031679f31f0 100644 --- a/source3/rpc_server/lsasd.c +++ b/source3/rpc_server/lsasd.c @@ -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; diff --git a/source3/rpc_server/mdssd.c b/source3/rpc_server/mdssd.c index 85b2cd5f694..f183c14bd53 100644 --- a/source3/rpc_server/mdssd.c +++ b/source3/rpc_server/mdssd.c @@ -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; diff --git a/source3/rpc_server/rpc_server.c b/source3/rpc_server/rpc_server.c index d1d4e4f6f82..6d4284ba54a 100644 --- a/source3/rpc_server/rpc_server.c +++ b/source3/rpc_server/rpc_server.c @@ -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; } diff --git a/source3/rpc_server/rpc_server.h b/source3/rpc_server/rpc_server.h index 6e81651f0e6..3a44b33e169 100644 --- a/source3/rpc_server/rpc_server.h +++ b/source3/rpc_server/rpc_server.h @@ -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, diff --git a/source3/rpc_server/rpc_service_setup.c b/source3/rpc_server/rpc_service_setup.c index 0e77237fd6f..cb8d5b905d9 100644 --- a/source3/rpc_server/rpc_service_setup.c +++ b/source3/rpc_server/rpc_service_setup.c @@ -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: