]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
rpc_server: Lift ph_listen_fd logic one level
authorVolker Lendecke <vl@samba.org>
Thu, 31 Dec 2020 09:47:03 +0000 (10:47 +0100)
committerVolker Lendecke <vl@samba.org>
Mon, 11 Jan 2021 13:19:32 +0000 (13:19 +0000)
Push filling in struct pf_listen_fd into the daemons using
dcesrv_create_endpoint_sockets().

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

index e56ebabd28f702cdceeb339c72aae6d47c65821e..dc2b85912a9a075511f9359422568bae2b6514e9 100644 (file)
@@ -593,12 +593,16 @@ static NTSTATUS spoolssd_create_sockets(struct tevent_context *ev_ctx,
        DBG_INFO("Initializing DCE/RPC connection endpoints\n");
 
        for (e = dce_ctx->endpoint_list; e; e = e->next) {
+               int *fds = NULL;
+               size_t j, num_fds;
+
                status = dcesrv_create_endpoint_sockets(ev_ctx,
                                                        msg_ctx,
                                                        dce_ctx,
                                                        e,
-                                                       listen_fd,
-                                                       listen_fd_size);
+                                                       dce_ctx,
+                                                       &num_fds,
+                                                       &fds);
                if (!NT_STATUS_IS_OK(status)) {
                        char *ep_string = dcerpc_binding_string(
                                        dce_ctx, e->ep_description);
@@ -607,6 +611,12 @@ static NTSTATUS spoolssd_create_sockets(struct tevent_context *ev_ctx,
                        TALLOC_FREE(ep_string);
                        goto done;
                }
+               for (j=0; j<num_fds; j++) {
+                       listen_fd[*listen_fd_size].fd = fds[j];
+                       listen_fd[*listen_fd_size].fd_data = e;
+                       (*listen_fd_size)++;
+               }
+               TALLOC_FREE(fds);
        }
 
        for (i = 0; i < *listen_fd_size; i++) {
index fe94f5a68a67fca3b4b971a39a975b3a85b7ef08..85c4f880c5fbe29166ccc13cc3a3fcdc037ab981 100644 (file)
@@ -558,12 +558,16 @@ static NTSTATUS lsasd_create_sockets(struct tevent_context *ev_ctx,
        DBG_INFO("Initializing DCE/RPC connection endpoints\n");
 
        for (e = dce_ctx->endpoint_list; e; e = e->next) {
+               int *fds = NULL;
+               size_t j, num_fds;
+
                status = dcesrv_create_endpoint_sockets(ev_ctx,
                                                        msg_ctx,
                                                        dce_ctx,
                                                        e,
-                                                       listen_fd,
-                                                       listen_fd_size);
+                                                       dce_ctx,
+                                                       &num_fds,
+                                                       &fds);
                if (!NT_STATUS_IS_OK(status)) {
                        char *ep_string = dcerpc_binding_string(
                                        dce_ctx, e->ep_description);
@@ -572,6 +576,12 @@ static NTSTATUS lsasd_create_sockets(struct tevent_context *ev_ctx,
                        TALLOC_FREE(ep_string);
                        goto done;
                }
+               for (j=0; j<num_fds; j++) {
+                       listen_fd[*listen_fd_size].fd = fds[j];
+                       listen_fd[*listen_fd_size].fd_data = e;
+                       (*listen_fd_size)++;
+               }
+               TALLOC_FREE(fds);
        }
 
        for (i = 0; i < *listen_fd_size; i++) {
index d74f9a2be8b57ec7fb5638eae38a26ed7223b12e..7027a983c6a85e99b13257adaa233420e4c42f2f 100644 (file)
@@ -508,12 +508,16 @@ static NTSTATUS mdssd_create_sockets(struct tevent_context *ev_ctx,
        DBG_INFO("Initializing DCE/RPC connection endpoints\n");
 
        for (e = dce_ctx->endpoint_list; e; e = e->next) {
+               int *fds = NULL;
+               size_t j, num_fds;
+
                status = dcesrv_create_endpoint_sockets(ev_ctx,
                                                        msg_ctx,
                                                        dce_ctx,
                                                        e,
-                                                       listen_fd,
-                                                       listen_fd_size);
+                                                       dce_ctx,
+                                                       &num_fds,
+                                                       &fds);
                if (!NT_STATUS_IS_OK(status)) {
                        char *ep_string = dcerpc_binding_string(
                                        dce_ctx, e->ep_description);
@@ -522,6 +526,12 @@ static NTSTATUS mdssd_create_sockets(struct tevent_context *ev_ctx,
                        TALLOC_FREE(ep_string);
                        goto done;
                }
+               for (j=0; j<num_fds; j++) {
+                       listen_fd[*listen_fd_size].fd = fds[j];
+                       listen_fd[*listen_fd_size].fd_data = e;
+                       (*listen_fd_size)++;
+               }
+               TALLOC_FREE(fds);
        }
 
        for (i = 0; i < *listen_fd_size; i++) {
index a8080f25f489f592685c0cf6e4894ffafee2fbb2..0a81bc7bbf51edd6926dd8c363863a375e032be1 100644 (file)
@@ -89,57 +89,45 @@ NTSTATUS dcesrv_create_endpoint_sockets(struct tevent_context *ev_ctx,
                                        struct messaging_context *msg_ctx,
                                        struct dcesrv_context *dce_ctx,
                                        struct dcesrv_endpoint *e,
-                                       struct pf_listen_fd *listen_fds,
-                                       int *listen_fds_size)
+                                       TALLOC_CTX *mem_ctx,
+                                       size_t *pnum_fds,
+                                       int **pfds)
 {
        enum dcerpc_transport_t transport =
                dcerpc_binding_get_transport(e->ep_description);
        char *binding = NULL;
+       int *fds = NULL;
+       size_t num_fds;
        NTSTATUS status;
-       int out_fd;
 
-       binding = dcerpc_binding_string(dce_ctx, e->ep_description);
+       binding = dcerpc_binding_string(mem_ctx, e->ep_description);
        if (binding == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
-
        DBG_DEBUG("Creating endpoint '%s'\n", binding);
+       TALLOC_FREE(binding);
+
+       fds = talloc(mem_ctx, int);
+       if (fds == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       num_fds = 1;
 
        switch (transport) {
        case NCALRPC:
-               status = dcesrv_create_ncalrpc_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)++;
-               }
+               status = dcesrv_create_ncalrpc_socket(e, fds);
                break;
 
        case NCACN_IP_TCP: {
-               int *fds = NULL;
-               size_t num_fds;
+               TALLOC_FREE(fds);
 
                status = dcesrv_create_ncacn_ip_tcp_sockets(
                        e, talloc_tos(), &num_fds, &fds);
-               if (NT_STATUS_IS_OK(status)) {
-                       size_t i;
-                       for (i=0; i<num_fds; i++) {
-                               listen_fds[*listen_fds_size].fd = fds[i];
-                               listen_fds[*listen_fds_size].fd_data = e;
-                               (*listen_fds_size)++;
-                       }
-               }
-               TALLOC_FREE(fds);
                break;
        }
 
        case NCACN_NP:
-               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)++;
-               }
+               status = dcesrv_create_ncacn_np_socket(e, fds);
                break;
 
        default:
@@ -149,8 +137,7 @@ NTSTATUS dcesrv_create_endpoint_sockets(struct tevent_context *ev_ctx,
 
        /* Build binding string again as the endpoint may have changed by
         * dcesrv_create_<transport>_socket functions */
-       TALLOC_FREE(binding);
-       binding = dcerpc_binding_string(dce_ctx, e->ep_description);
+       binding = dcerpc_binding_string(mem_ctx, e->ep_description);
        if (binding == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -174,6 +161,9 @@ NTSTATUS dcesrv_create_endpoint_sockets(struct tevent_context *ev_ctx,
 
        TALLOC_FREE(binding);
 
+       *pnum_fds = num_fds;
+       *pfds = fds;
+
        return status;
 }
 
index b444c0fa583b3b98ea273d05bb576d904c78d29a..856fce0dab2aca0d21d1ead4f2f42ebf4dc998f3 100644 (file)
@@ -42,8 +42,9 @@ NTSTATUS dcesrv_create_endpoint_sockets(struct tevent_context *ev_ctx,
                                        struct messaging_context *msg_ctx,
                                        struct dcesrv_context *dce_ctx,
                                        struct dcesrv_endpoint *e,
-                                       struct pf_listen_fd *listen_fds,
-                                       int *listen_fds_size);
+                                       TALLOC_CTX *mem_ctx,
+                                       size_t *pnum_fds,
+                                       int **pfds);
 
 NTSTATUS rpc_setup_embedded(struct tevent_context *ev_ctx,
                            struct messaging_context *msg_ctx,