s3:rpc_server: Add a function to setup the endpoints
authorSamuel Cabrero <scabrero@suse.de>
Wed, 27 Feb 2019 13:01:11 +0000 (14:01 +0100)
committerSamuel Cabrero <scabrero@sn-devel-184>
Fri, 20 Mar 2020 15:36:33 +0000 (15:36 +0000)
The pidl-generated initialization function for each endpoint server will
register the RPC interface in all endpoints defined in the idl file.

The interface registration code will create the endpoint if it does not
exists (as an endpoint can serve multiple interfaces) and will add it to
the endpoint list exiting in the dcesrv_context.

This commit adds a generic dcesrv_setup_endpoint_sockets function which
will be used by embedded services and non-preforking external daemons to
setup the sockets regardless the transport.

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/rpc_server/rpc_server.h
source3/rpc_server/rpc_service_setup.c
source3/rpc_server/rpc_service_setup.h

index 3891d5d6c40864fd446027f062b5f6c74c9cb853..8d96198067eb5c6f4532eaa9e87ff230b139065b 100644 (file)
 
 #include "librpc/rpc/rpc_common.h" /* For enum dcerpc_transport_t */
 
+#include "librpc/rpc/dcesrv_core.h"
+
 struct pipes_struct;
 struct auth_session_info;
-struct dcesrv_call_state;
 struct cli_credentials;
 
 typedef void (*dcerpc_ncacn_termination_fn)(struct pipes_struct *, void *);
index 77b0af8bdcf98295be569449d0cd38e55c02443f..23c284697633039d327c2f1f28c66c175e254b10 100644 (file)
@@ -115,6 +115,77 @@ NTSTATUS rpc_setup_embedded(struct tevent_context *ev_ctx,
        return NT_STATUS_OK;
 }
 
+NTSTATUS dcesrv_setup_endpoint_sockets(struct tevent_context *ev_ctx,
+                                      struct messaging_context *msg_ctx,
+                                      struct dcesrv_context *dce_ctx,
+                                      struct dcesrv_endpoint *e,
+                                      struct dcerpc_binding_vector *bvec,
+                                      dcerpc_ncacn_termination_fn term_fn,
+                                      void *term_data)
+{
+       enum dcerpc_transport_t transport =
+               dcerpc_binding_get_transport(e->ep_description);
+       char *binding = NULL;
+       NTSTATUS status;
+
+       binding = dcerpc_binding_string(dce_ctx, e->ep_description);
+       if (binding == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       DBG_DEBUG("Setting up endpoint '%s'\n", binding);
+
+       switch (transport) {
+       case NCALRPC:
+               /* TODO */
+               status = NT_STATUS_OK;
+               break;
+
+       case NCACN_IP_TCP:
+               /* TODO */
+               status = NT_STATUS_OK;
+               break;
+
+       case NCACN_NP:
+               /* TODO */
+               status = NT_STATUS_OK;
+               break;
+
+       default:
+               status = NT_STATUS_NOT_SUPPORTED;
+               break;
+       }
+
+       /* 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);
+       if (binding == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       if (!NT_STATUS_IS_OK(status)) {
+               struct dcesrv_if_list *iface = NULL;
+               DBG_ERR("Failed to setup '%s' sockets for ", binding);
+               for (iface = e->interface_list; iface; iface = iface->next) {
+                       DEBUGADD(DBGLVL_ERR, ("'%s' ", iface->iface->name));
+               }
+               DEBUGADD(DBGLVL_ERR, (": %s\n", nt_errstr(status)));
+               return status;
+       } else {
+               struct dcesrv_if_list *iface = NULL;
+               DBG_INFO("Successfully listening on '%s' for ", binding);
+               for (iface = e->interface_list; iface; iface = iface->next) {
+                       DEBUGADD(DBGLVL_INFO, ("'%s' ", iface->iface->name));
+               }
+               DEBUGADD(DBGLVL_INFO, ("\n"));
+       }
+
+       TALLOC_FREE(binding);
+
+       return status;
+}
+
 static NTSTATUS rpc_setup_winreg(struct tevent_context *ev_ctx,
                                 struct messaging_context *msg_ctx)
 {
index 197eca918934086ed4bc84d23584bbdc151b3a4c..08bca1d49559b16ddb0279248e6961985e54eeac 100644 (file)
 #ifndef _RPC_EP_SETUP_H
 #define _RPC_EP_SETUP_H
 
-struct ndr_interface_table;
-struct rpc_srv_callbacks;
-struct dcesrv_context;
+#include "rpc_server/rpc_server.h"
+
+struct dcerpc_binding_vector;
 
 NTSTATUS dcesrv_init(TALLOC_CTX *mem_ctx,
                     struct tevent_context *ev_ctx,
                     struct messaging_context *msg_ctx,
                     struct dcesrv_context *dce_ctx);
 
+NTSTATUS dcesrv_setup_endpoint_sockets(struct tevent_context *ev_ctx,
+                                      struct messaging_context *msg_ctx,
+                                      struct dcesrv_context *dce_ctx,
+                                      struct dcesrv_endpoint *e,
+                                      struct dcerpc_binding_vector *bvec,
+                                      dcerpc_ncacn_termination_fn term_fn,
+                                      void *term_data);
+
 NTSTATUS rpc_setup_embedded(struct tevent_context *ev_ctx,
                            struct messaging_context *msg_ctx,
                            const struct ndr_interface_table *t,