From 6a6546b565793341f3be6a6fcf30a40a186f9ae9 Mon Sep 17 00:00:00 2001 From: Samuel Cabrero Date: Tue, 1 Oct 2019 16:48:01 +0200 Subject: [PATCH] librpc:core: Allocate struct dcesrv_interface with talloc The S3 implementation needs to reinit the dcesrv_context and free the endpoints list with their registered interfaces. Signed-off-by: Samuel Cabrero Reviewed-by: Andrew Bartlett Reviewed-by: Andreas Schneider --- librpc/rpc/dcesrv_core.c | 24 ++++++++++++++++------ librpc/rpc/dcesrv_core.h | 2 +- librpc/rpc/dcesrv_mgmt.c | 6 +++--- source4/rpc_server/dcerpc_server.c | 4 ++-- source4/rpc_server/epmapper/rpc_epmapper.c | 9 ++++---- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/librpc/rpc/dcesrv_core.c b/librpc/rpc/dcesrv_core.c index f7f0e627e33..132649665df 100644 --- a/librpc/rpc/dcesrv_core.c +++ b/librpc/rpc/dcesrv_core.c @@ -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 diff --git a/librpc/rpc/dcesrv_core.h b/librpc/rpc/dcesrv_core.h index 8e2f1a750a3..663a09b418a 100644 --- a/librpc/rpc/dcesrv_core.h +++ b/librpc/rpc/dcesrv_core.h @@ -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; /* diff --git a/librpc/rpc/dcesrv_mgmt.c b/librpc/rpc/dcesrv_mgmt.c index 80e78d56b0e..d75f08b56e6 100644 --- a/librpc/rpc/dcesrv_mgmt.c +++ b/librpc/rpc/dcesrv_mgmt.c @@ -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; } diff --git a/source4/rpc_server/dcerpc_server.c b/source4/rpc_server/dcerpc_server.c index ffdf34f02f8..084857a44bf 100644 --- a/source4/rpc_server/dcerpc_server.c +++ b/source4/rpc_server/dcerpc_server.c @@ -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")); } diff --git a/source4/rpc_server/epmapper/rpc_epmapper.c b/source4/rpc_server/epmapper/rpc_epmapper.c index 793070d470e..462553dfe6f 100644 --- a/source4/rpc_server/epmapper/rpc_epmapper.c +++ b/source4/rpc_server/epmapper/rpc_epmapper.c @@ -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++; -- 2.47.3