summaryrefslogtreecommitdiff
path: root/source3/rpc_server
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2021-01-12 17:53:57 +0100
committerVolker Lendecke <vl@samba.org>2021-01-14 14:35:58 +0000
commit9bb5b3262102c99bf5bb881135739feffacd7108 (patch)
tree792c6abe6f0911dba9707067f2e5c00185c5eacd /source3/rpc_server
parent8004fb4a5bfa00d3199c11e8aadeb9691c0484e8 (diff)
downloadsamba-9bb5b3262102c99bf5bb881135739feffacd7108.tar.gz
rpc_server: Remove protocol-specific dcerpc_setup_ routines
These are all just stream sockets, being taken care of by dcesrv_setup_ncacn_listener() Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Samuel Cabrero <scabrero@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Thu Jan 14 14:35:58 UTC 2021 on sn-devel-184
Diffstat (limited to 'source3/rpc_server')
-rw-r--r--source3/rpc_server/rpc_server.c425
-rw-r--r--source3/rpc_server/rpc_server.h20
-rw-r--r--source3/rpc_server/rpc_sock_helper.c43
-rw-r--r--source3/rpc_server/rpc_sock_helper.h7
4 files changed, 1 insertions, 494 deletions
diff --git a/source3/rpc_server/rpc_server.c b/source3/rpc_server/rpc_server.c
index d676a1d6544..20b727b64df 100644
--- a/source3/rpc_server/rpc_server.c
+++ b/source3/rpc_server/rpc_server.c
@@ -52,11 +52,6 @@ struct dcerpc_ncacn_listen_state {
void *termination_data;
};
-static void dcesrv_ncacn_np_listener(struct tevent_context *ev,
- struct tevent_fd *fde,
- uint16_t flags,
- void *private_data);
-
NTSTATUS dcesrv_create_ncacn_np_socket(struct dcesrv_endpoint *e, int *out_fd)
{
char *np_dir = NULL;
@@ -132,142 +127,10 @@ out:
return status;
}
-NTSTATUS dcesrv_setup_ncacn_np_socket(struct tevent_context *ev_ctx,
- struct messaging_context *msg_ctx,
- struct dcesrv_context *dce_ctx,
- struct dcesrv_endpoint *e,
- dcerpc_ncacn_termination_fn term_fn,
- void *term_data)
-{
- struct dcerpc_ncacn_listen_state *state;
- struct tevent_fd *fde;
- int rc;
- NTSTATUS status;
- const char *endpoint = 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;
- }
-
- /* 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->endpoint = e;
- state->dce_ctx = dce_ctx;
- state->termination_fn = term_fn;
- state->termination_data = term_data;
-
- status = dcesrv_create_ncacn_np_socket(e, &state->fd);
- if (!NT_STATUS_IS_OK(status)) {
- goto out;
- }
-
- rc = listen(state->fd, 5);
- if (rc < 0) {
- status = map_nt_error_from_unix_common(errno);
- DBG_ERR("Failed to listen on ncacn_np socket %s: %s\n",
- endpoint, strerror(errno));
- goto out;
- }
-
- DBG_DEBUG("Opened pipe socket fd %d for %s\n",
- state->fd, endpoint);
-
- errno = 0;
- fde = tevent_add_fd(ev_ctx,
- state, state->fd, TEVENT_FD_READ,
- dcesrv_ncacn_np_listener, state);
- if (fde == NULL) {
- if (errno == 0) {
- errno = ENOMEM;
- }
- status = map_nt_error_from_unix_common(errno);
- DBG_ERR("Failed to add event handler for ncacn_np: %s\n",
- strerror(errno));
- goto out;
- }
-
- tevent_fd_set_auto_close(fde);
-
- return NT_STATUS_OK;
-
-out:
- if (state->fd != -1) {
- close(state->fd);
- }
- TALLOC_FREE(state);
- return status;
-}
-
-static void dcesrv_ncacn_np_listener(struct tevent_context *ev,
- struct tevent_fd *fde,
- uint16_t flags,
- void *private_data)
-{
- struct dcerpc_ncacn_listen_state *state =
- talloc_get_type_abort(private_data,
- struct dcerpc_ncacn_listen_state);
- struct samba_sockaddr addr = {
- .sa_socklen = sizeof(struct sockaddr_un),
- };
- int sd = -1;
- const char *endpoint = NULL;
-
- /* TODO: should we have a limit to the number of clients ? */
-
- sd = accept(state->fd, &addr.u.sa, &addr.sa_socklen);
-
- if (sd == -1) {
- if (errno != EINTR) {
- DEBUG(6, ("Failed to get a valid socket [%s]\n",
- strerror(errno)));
- }
- return;
- }
- smb_set_close_on_exec(sd);
-
- 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 ncacn_np socket %s (fd: %d)\n",
- addr.u.un.sun_path, sd);
-
- dcerpc_ncacn_accept(state->ev_ctx,
- state->msg_ctx,
- state->dce_ctx,
- state->endpoint,
- NULL, /* remote client address */
- NULL, /* local server address */
- sd,
- state->termination_fn,
- state->termination_data);
-}
-
/********************************************************************
* Start listening on the tcp/ip socket
********************************************************************/
-static void dcesrv_ncacn_ip_tcp_listener(struct tevent_context *ev,
- struct tevent_fd *fde,
- uint16_t flags,
- void *private_data);
-
NTSTATUS dcesrv_create_ncacn_ip_tcp_socket(const struct sockaddr_storage *ifss,
uint16_t *port,
int *out_fd)
@@ -311,146 +174,10 @@ NTSTATUS dcesrv_create_ncacn_ip_tcp_socket(const struct sockaddr_storage *ifss,
return NT_STATUS_OK;
}
-NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx,
- struct messaging_context *msg_ctx,
- struct dcesrv_context *dce_ctx,
- struct dcesrv_endpoint *e,
- int fd,
- dcerpc_ncacn_termination_fn term_fn,
- void *term_data)
-{
- struct dcerpc_ncacn_listen_state *state = NULL;
- struct tevent_fd *fde = NULL;
- int rc;
- NTSTATUS status;
-
- /* 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 = fd;
- state->ev_ctx = ev_ctx;
- state->msg_ctx = msg_ctx;
- state->endpoint = e;
- state->dce_ctx = dce_ctx;
- state->termination_fn = term_fn;
- state->termination_data = term_data;
-
- /* Set server socket to non-blocking for the accept. */
- rc = set_blocking(state->fd, false);
- if (rc < 0) {
- status = map_nt_error_from_unix_common(errno);
- goto out;
- }
-
- rc = listen(state->fd, SMBD_LISTEN_BACKLOG);
- if (rc == -1) {
- status = map_nt_error_from_unix_common(errno);
- DBG_ERR("Failed to listen on ncacn_ip_tcp socket: %s\n",
- strerror(errno));
- goto out;
- }
-
- errno = 0;
- fde = tevent_add_fd(state->ev_ctx,
- state,
- state->fd,
- TEVENT_FD_READ,
- dcesrv_ncacn_ip_tcp_listener,
- state);
- if (fde == NULL) {
- if (errno == 0) {
- errno = ENOMEM;
- }
- status = map_nt_error_from_unix_common(errno);
- DBG_ERR("Failed to add event handler for ncacn_ip_tcp: %s\n",
- strerror(errno));
- goto out;
- }
-
- tevent_fd_set_auto_close(fde);
-
- return NT_STATUS_OK;
-
-out:
- if (state->fd != -1) {
- close(state->fd);
- }
- TALLOC_FREE(state);
-
- return status;
-}
-
-static void dcesrv_ncacn_ip_tcp_listener(struct tevent_context *ev,
- struct tevent_fd *fde,
- uint16_t flags,
- void *private_data)
-{
- struct dcerpc_ncacn_listen_state *state =
- talloc_get_type_abort(private_data,
- struct dcerpc_ncacn_listen_state);
- struct tsocket_address *cli_addr = NULL;
- struct tsocket_address *srv_addr = NULL;
- struct samba_sockaddr addr = {
- .sa_socklen = sizeof(struct sockaddr_storage),
- };
- int s = -1;
- int rc;
-
- s = accept(state->fd, &addr.u.sa, &addr.sa_socklen);
- if (s == -1) {
- if (errno != EINTR) {
- DBG_ERR("Failed to accept: %s\n", strerror(errno));
- }
- return;
- }
- smb_set_close_on_exec(s);
-
- rc = tsocket_address_bsd_from_samba_sockaddr(state, &addr, &cli_addr);
- if (rc < 0) {
- close(s);
- return;
- }
-
- rc = getsockname(s, &addr.u.sa, &addr.sa_socklen);
- if (rc < 0) {
- close(s);
- return;
- }
-
- rc = tsocket_address_bsd_from_samba_sockaddr(state, &addr, &srv_addr);
- if (rc < 0) {
- close(s);
- return;
- }
-
- DBG_DEBUG("Accepted ncacn_ip_tcp socket %d\n", s);
-
- dcerpc_ncacn_accept(state->ev_ctx,
- state->msg_ctx,
- state->dce_ctx,
- state->endpoint,
- &cli_addr,
- &srv_addr,
- s,
- state->termination_fn,
- state->termination_data);
-}
-
/********************************************************************
* Start listening on the ncalrpc socket
********************************************************************/
-static void dcesrv_ncalrpc_listener(struct tevent_context *ev,
- struct tevent_fd *fde,
- uint16_t flags,
- void *private_data);
-
NTSTATUS dcesrv_create_ncalrpc_socket(struct dcesrv_endpoint *e, int *out_fd)
{
int fd = -1;
@@ -515,158 +242,6 @@ out:
return status;
}
-NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
- struct messaging_context *msg_ctx,
- struct dcesrv_context *dce_ctx,
- struct dcesrv_endpoint *e,
- dcerpc_ncacn_termination_fn term_fn,
- void *termination_data)
-{
- struct dcerpc_ncacn_listen_state *state;
- struct tevent_fd *fde;
- int rc;
- NTSTATUS status;
-
- /* 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 = dce_ctx;
- state->endpoint = e;
- state->termination_fn = term_fn;
- state->termination_data = termination_data;
-
- status = dcesrv_create_ncalrpc_socket(e, &state->fd);
- if (!NT_STATUS_IS_OK(status)) {
- DBG_ERR("Failed to create ncalrpc socket: %s\n",
- nt_errstr(status));
- goto out;
- }
-
- rc = listen(state->fd, 5);
- if (rc < 0) {
- const char *endpoint = dcerpc_binding_get_string_option(
- e->ep_description, "endpoint");
- status = map_nt_error_from_unix_common(errno);
- DBG_ERR("Failed to listen on ncalrpc socket %s: %s\n",
- endpoint, strerror(errno));
- goto out;
- }
-
- /* Set server socket to non-blocking for the accept. */
- rc = set_blocking(state->fd, false);
- if (rc < 0) {
- status = map_nt_error_from_unix_common(errno);
- goto out;
- }
-
- errno = 0;
- fde = tevent_add_fd(state->ev_ctx,
- state,
- state->fd,
- TEVENT_FD_READ,
- dcesrv_ncalrpc_listener,
- state);
- if (fde == NULL) {
- if (errno == 0) {
- errno = ENOMEM;
- }
- status = map_nt_error_from_unix_common(errno);
- DBG_ERR("Failed to add event handler for ncalrpc: %s\n",
- strerror(errno));
- goto out;
- }
-
- tevent_fd_set_auto_close(fde);
-
- return NT_STATUS_OK;
-out:
- if (state->fd != -1) {
- close(state->fd);
- }
- TALLOC_FREE(state);
-
- return status;
-}
-
-static void dcesrv_ncalrpc_listener(struct tevent_context *ev,
- struct tevent_fd *fde,
- uint16_t flags,
- void *private_data)
-{
- struct dcerpc_ncacn_listen_state *state =
- talloc_get_type_abort(private_data,
- struct dcerpc_ncacn_listen_state);
- struct tsocket_address *cli_addr = NULL, *srv_addr = NULL;
- struct samba_sockaddr addr = {
- .sa_socklen = sizeof(struct sockaddr_un),
- };
- struct samba_sockaddr addr_server = {
- .sa_socklen = sizeof(struct sockaddr_un),
- };
- int sd = -1;
- int rc;
- const char *endpoint = NULL;
-
- sd = accept(state->fd, &addr.u.sa, &addr.sa_socklen);
- if (sd == -1) {
- if (errno != EINTR) {
- DBG_ERR("Failed to accept: %s\n", strerror(errno));
- }
- return;
- }
- smb_set_close_on_exec(sd);
-
- rc = tsocket_address_bsd_from_samba_sockaddr(state, &addr, &cli_addr);
- if (rc < 0) {
- close(sd);
- return;
- }
-
- rc = getsockname(sd, &addr_server.u.sa, &addr_server.sa_socklen);
- if (rc < 0) {
- close(sd);
- return;
- }
-
- rc = tsocket_address_bsd_from_samba_sockaddr(state,
- &addr_server,
- &srv_addr);
- if (rc < 0) {
- close(sd);
- 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,
- state->dce_ctx,
- state->endpoint,
- &cli_addr,
- &srv_addr,
- sd,
- state->termination_fn,
- state->termination_data);
-}
-
static void dcesrv_ncacn_listener(
struct tevent_context *ev,
struct tevent_fd *fde,
diff --git a/source3/rpc_server/rpc_server.h b/source3/rpc_server/rpc_server.h
index 3c47c8fc234..e4a18eb830a 100644
--- a/source3/rpc_server/rpc_server.h
+++ b/source3/rpc_server/rpc_server.h
@@ -68,31 +68,13 @@ NTSTATUS dcerpc_ncacn_conn_init(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(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,
- struct dcesrv_endpoint *e,
- dcerpc_ncacn_termination_fn term_fn,
- void *term_data);
NTSTATUS dcesrv_create_ncacn_ip_tcp_socket(const struct sockaddr_storage *ifss,
uint16_t *port,
int *out_fd);
-NTSTATUS dcesrv_setup_ncacn_ip_tcp_socket(struct tevent_context *ev_ctx,
- struct messaging_context *msg_ctx,
- struct dcesrv_context *dce_ctx,
- struct dcesrv_endpoint *e,
- int fd,
- dcerpc_ncacn_termination_fn term_fn,
- void *term_data);
NTSTATUS dcesrv_create_ncalrpc_socket(struct dcesrv_endpoint *e, int *fd);
-NTSTATUS dcesrv_setup_ncalrpc_socket(struct tevent_context *ev_ctx,
- struct messaging_context *msg_ctx,
- struct dcesrv_context *dce_ctx,
- struct dcesrv_endpoint *e,
- dcerpc_ncacn_termination_fn term_fn,
- void *termination_data);
+
struct dcerpc_ncacn_listen_state;
int dcesrv_setup_ncacn_listener(
TALLOC_CTX *mem_ctx,
diff --git a/source3/rpc_server/rpc_sock_helper.c b/source3/rpc_server/rpc_sock_helper.c
index c07f27016f2..27d5cda9c4e 100644
--- a/source3/rpc_server/rpc_sock_helper.c
+++ b/source3/rpc_server/rpc_sock_helper.c
@@ -154,47 +154,4 @@ fail:
return status;
}
-NTSTATUS dcesrv_setup_ncacn_ip_tcp_sockets(struct tevent_context *ev_ctx,
- struct messaging_context *msg_ctx,
- struct dcesrv_context *dce_ctx,
- struct dcesrv_endpoint *e,
- dcerpc_ncacn_termination_fn t_fn,
- void *t_data)
-{
- TALLOC_CTX *tmp_ctx;
- NTSTATUS status;
- int *fds = NULL;
- size_t i, num_fds = 0;
-
- tmp_ctx = talloc_stackframe();
- if (tmp_ctx == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- status = dcesrv_create_ncacn_ip_tcp_sockets(
- e, tmp_ctx, &num_fds, &fds);
- if (!NT_STATUS_IS_OK(status)) {
- goto done;
- }
-
- for (i=0; i<num_fds; i++) {
- status = dcesrv_setup_ncacn_ip_tcp_socket(
- ev_ctx,
- msg_ctx,
- dce_ctx,
- e,
- fds[i],
- t_fn,
- t_data);
- if (!NT_STATUS_IS_OK(status)) {
- goto done;
- }
- }
-
- status = NT_STATUS_OK;
-done:
- talloc_free(tmp_ctx);
- return status;
-}
-
/* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */
diff --git a/source3/rpc_server/rpc_sock_helper.h b/source3/rpc_server/rpc_sock_helper.h
index bcde82c6a14..6adb34baa20 100644
--- a/source3/rpc_server/rpc_sock_helper.h
+++ b/source3/rpc_server/rpc_sock_helper.h
@@ -33,13 +33,6 @@ NTSTATUS dcesrv_create_ncacn_ip_tcp_sockets(
size_t *pnum_fds,
int **pfds);
-NTSTATUS dcesrv_setup_ncacn_ip_tcp_sockets(struct tevent_context *ev_ctx,
- struct messaging_context *msg_ctx,
- struct dcesrv_context *dce_ctx,
- struct dcesrv_endpoint *e,
- dcerpc_ncacn_termination_fn t_fn,
- void *t_data);
-
#endif /* _RPC_SOCK_HELPER_H_ */
/* vim: set ts=8 sw=8 noet cindent syntax=c.doxygen: */