]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
rpc_server: Add dcesrv_create_endpoint_list_fd_listen_fds()
authorVolker Lendecke <vl@samba.org>
Thu, 31 Dec 2020 13:49:26 +0000 (14:49 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 11 Jan 2021 13:19:32 +0000 (13:19 +0000)
This encapsulates the loop in the three standalone rpc daemons walking
the endpoints in a dcesrv_context.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Samuel Cabrero <scabrero@samba.org>
source3/rpc_server/rpc_service_setup.c
source3/rpc_server/rpc_service_setup.h

index 0a81bc7bbf51edd6926dd8c363863a375e032be1..a05c6db1fb8f2ab7b8f1f6289771fcf2d4cd5e52 100644 (file)
@@ -167,6 +167,83 @@ NTSTATUS dcesrv_create_endpoint_sockets(struct tevent_context *ev_ctx,
        return status;
 }
 
+NTSTATUS dcesrv_create_endpoint_list_pf_listen_fds(
+       struct tevent_context *ev_ctx,
+       struct messaging_context *msg_ctx,
+       struct dcesrv_context *dce_ctx,
+       struct dcesrv_endpoint *e,
+       TALLOC_CTX *mem_ctx,
+       size_t *pnum_fds,
+       struct pf_listen_fd **pfds)
+{
+       struct pf_listen_fd *fds = NULL;
+       size_t num_fds = 0;
+       NTSTATUS status;
+
+       for (; e != NULL; e = e->next) {
+               int *ep_fds = NULL;
+               struct pf_listen_fd *tmp = NULL;
+               size_t i, num_ep_fds;
+
+               status = dcesrv_create_endpoint_sockets(
+                       ev_ctx,
+                       msg_ctx,
+                       dce_ctx,
+                       e,
+                       mem_ctx,
+                       &num_ep_fds,
+                       &ep_fds);
+               if (!NT_STATUS_IS_OK(status)) {
+                       char *ep_string = dcerpc_binding_string(
+                                       dce_ctx, e->ep_description);
+                       DBG_ERR("Failed to create endpoint '%s': %s\n",
+                               ep_string, nt_errstr(status));
+                       TALLOC_FREE(ep_string);
+                       goto fail;
+               }
+
+               if (num_fds + num_ep_fds < num_fds) {
+                       /* overflow */
+                       status = NT_STATUS_INTEGER_OVERFLOW;
+                       goto fail;
+               }
+
+               tmp = talloc_realloc(
+                       mem_ctx,
+                       fds,
+                       struct pf_listen_fd,
+                       num_fds + num_ep_fds);
+               if (tmp == NULL) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto fail;
+               }
+               fds = tmp;
+
+               for (i=0; i<num_ep_fds; i++) {
+                       fds[num_fds].fd = ep_fds[i];
+                       fds[num_fds].fd_data = e;
+                       num_fds += 1;
+               }
+
+               TALLOC_FREE(ep_fds);
+       }
+
+       *pnum_fds = num_fds;
+       *pfds = fds;
+       return NT_STATUS_OK;
+
+fail:
+       {
+               size_t i;
+               for (i=0; i<num_fds; i++) {
+                       close(fds[i].fd);
+               }
+       }
+
+       TALLOC_FREE(fds);
+       return status;
+}
+
 NTSTATUS dcesrv_setup_endpoint_sockets(struct tevent_context *ev_ctx,
                                       struct messaging_context *msg_ctx,
                                       struct dcesrv_context *dce_ctx,
index 856fce0dab2aca0d21d1ead4f2f42ebf4dc998f3..0288dab539ae584090f6b80a4afdb5cd23bc573c 100644 (file)
@@ -45,6 +45,14 @@ NTSTATUS dcesrv_create_endpoint_sockets(struct tevent_context *ev_ctx,
                                        TALLOC_CTX *mem_ctx,
                                        size_t *pnum_fds,
                                        int **pfds);
+NTSTATUS dcesrv_create_endpoint_list_pf_listen_fds(
+       struct tevent_context *ev_ctx,
+       struct messaging_context *msg_ctx,
+       struct dcesrv_context *dce_ctx,
+       struct dcesrv_endpoint *e,
+       TALLOC_CTX *mem_ctx,
+       size_t *pnum_fds,
+       struct pf_listen_fd **pfds);
 
 NTSTATUS rpc_setup_embedded(struct tevent_context *ev_ctx,
                            struct messaging_context *msg_ctx,