librpc:core: Allocate struct dcesrv_interface with talloc
authorSamuel Cabrero <scabrero@samba.org>
Tue, 1 Oct 2019 14:48:01 +0000 (16:48 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Fri, 18 Oct 2019 16:07:37 +0000 (16:07 +0000)
The S3 implementation needs to reinit the dcesrv_context and free the
endpoints list with their registered interfaces.

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
librpc/rpc/dcesrv_core.c
librpc/rpc/dcesrv_core.h
librpc/rpc/dcesrv_mgmt.c
source4/rpc_server/dcerpc_server.c
source4/rpc_server/epmapper/rpc_epmapper.c

index f7f0e627e337625df7894b6c0451a03ec5c1aa9e..132649665df7dfbec043985dedc3f9817e7f76ff 100644 (file)
@@ -122,8 +122,8 @@ static const struct dcesrv_interface *find_interface_by_binding(struct dcesrv_co
                if (endpoints_match(ep->ep_description, binding)) {
                        struct dcesrv_if_list *ifl;
                        for (ifl=ep->interface_list; ifl; ifl=ifl->next) {
-                               if (interface_match(&(ifl->iface), iface)) {
-                                       return &(ifl->iface);
+                               if (interface_match(ifl->iface, iface)) {
+                                       return ifl->iface;
                                }
                        }
                }
@@ -149,8 +149,8 @@ const struct dcesrv_interface *find_interface_by_uuid(const struct dcesrv_endpoi
 {
        struct dcesrv_if_list *ifl;
        for (ifl=endpoint->interface_list; ifl; ifl=ifl->next) {
-               if (interface_match_by_uuid(&(ifl->iface), uuid, if_version)) {
-                       return &(ifl->iface);
+               if (interface_match_by_uuid(ifl->iface, uuid, if_version)) {
+                       return ifl->iface;
                }
        }
        return NULL;
@@ -322,7 +322,13 @@ _PUBLIC_ NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
                        return NT_STATUS_NO_MEMORY;
                }
 
-               ifl->iface = dcesrv_get_mgmt_interface();
+               ifl->iface = talloc_memdup(ifl,
+                                          dcesrv_get_mgmt_interface(),
+                                          sizeof(struct dcesrv_interface));
+               if (ifl->iface == NULL) {
+                       talloc_free(ep);
+                       return NT_STATUS_NO_MEMORY;
+               }
 
                DLIST_ADD(ep->interface_list, ifl);
        }
@@ -346,7 +352,13 @@ _PUBLIC_ NTSTATUS dcesrv_interface_register(struct dcesrv_context *dce_ctx,
        }
 
        /* copy the given interface struct to the one on the endpoints interface list */
-       memcpy(&(ifl->iface),iface, sizeof(struct dcesrv_interface));
+       ifl->iface = talloc_memdup(ifl,
+                                  iface,
+                                  sizeof(struct dcesrv_interface));
+       if (ifl->iface == NULL) {
+               talloc_free(ep);
+               return NT_STATUS_NO_MEMORY;
+       }
 
        /* if we have a security descriptor given,
         * we should see if we can set it up on the endpoint
index 8e2f1a750a3de20d95dfe1720d3009f8c2ffd465..663a09b418afb527e4df17e3188835532162013f 100644 (file)
@@ -404,7 +404,7 @@ struct dcesrv_context {
                /* the list of interfaces available on this endpoint */
                struct dcesrv_if_list {
                        struct dcesrv_if_list *next, *prev;
-                       struct dcesrv_interface iface;
+                       struct dcesrv_interface *iface;
                } *interface_list;
 
                /*
index 80e78d56b0e8e9d700da191c34941563e6bf35b5..d75f08b56e6108f8d9513ee32091fd17f0e6a756 100644 (file)
@@ -58,7 +58,7 @@ static WERROR dcesrv_mgmt_inq_if_ids(struct dcesrv_call_state *dce_call, TALLOC_
        for (l = ep->interface_list; l; l = l->next) {
                vector->count++;
                vector->if_id = talloc_realloc(mem_ctx, vector->if_id, struct ndr_syntax_id_p, vector->count);
-               vector->if_id[vector->count-1].id = &l->iface.syntax_id;
+               vector->if_id[vector->count-1].id = &l->iface->syntax_id;
        }
        return WERR_OK;
 }
@@ -119,7 +119,7 @@ static WERROR dcesrv_mgmt_inq_princ_name(struct dcesrv_call_state *dce_call, TAL
 /* include the generated boilerplate */
 #include "librpc/gen_ndr/ndr_mgmt_s.c"
 
-const struct dcesrv_interface dcesrv_get_mgmt_interface(void)
+const struct dcesrv_interface *dcesrv_get_mgmt_interface(void)
 {
-       return dcesrv_mgmt_interface;
+       return &dcesrv_mgmt_interface;
 }
index ffdf34f02f86805550be95be4bde97b3a93abd96..084857a44bf165ab51a0271d61ce12edcf72f982 100644 (file)
@@ -508,7 +508,7 @@ static NTSTATUS add_socket_rpc_tcp_iface(struct dcesrv_context *dce_ctx,
                DEBUG(0,("service_setup_stream_socket(address=%s,port=%u) for ",
                         address, port));
                for (iface = e->interface_list; iface; iface = iface->next) {
-                       DEBUGADD(0, ("%s ", iface->iface.name));
+                       DEBUGADD(0, ("%s ", iface->iface->name));
                }
                DEBUGADD(0, ("failed - %s\n",
                             nt_errstr(status)));
@@ -528,7 +528,7 @@ static NTSTATUS add_socket_rpc_tcp_iface(struct dcesrv_context *dce_ctx,
                DEBUG(4,("Successfully listening on ncacn_ip_tcp endpoint [%s]:[%s] for ",
                         address, port_str));
                for (iface = e->interface_list; iface; iface = iface->next) {
-                       DEBUGADD(4, ("%s ", iface->iface.name));
+                       DEBUGADD(4, ("%s ", iface->iface->name));
                }
                DEBUGADD(4, ("\n"));
        }
index 793070d470e7df13696678aa5b10589f0ff25c9a..462553dfe6f5076889a6bec8e92f46f6d1dff213 100644 (file)
@@ -69,7 +69,7 @@ static uint32_t build_ep_list(TALLOC_CTX *mem_ctx,
                        if (!*eps) {
                                return 0;
                        }
-                       (*eps)[total].name = iface->iface.name;
+                       (*eps)[total].name = iface->iface->name;
 
                        description = dcerpc_binding_dup(*eps, d->ep_description);
                        if (description == NULL) {
@@ -77,7 +77,7 @@ static uint32_t build_ep_list(TALLOC_CTX *mem_ctx,
                        }
 
                        status = dcerpc_binding_set_abstract_syntax(description,
-                                                       &iface->iface.syntax_id);
+                                               &iface->iface->syntax_id);
                        if (!NT_STATUS_IS_OK(status)) {
                                return 0;
                        }
@@ -85,8 +85,9 @@ static uint32_t build_ep_list(TALLOC_CTX *mem_ctx,
                        status = dcerpc_binding_build_tower(*eps, description, &(*eps)[total].ep);
                        TALLOC_FREE(description);
                        if (!NT_STATUS_IS_OK(status)) {
-                               DEBUG(1, ("Unable to build tower for %s - %s\n",
-                                         iface->iface.name, nt_errstr(status)));
+                               DBG_ERR("Unable to build tower for %s - %s\n",
+                                       iface->iface->name,
+                                       nt_errstr(status));
                                continue;
                        }
                        total++;