From 79af978c815e6ad94797742c8755f4fe8142160e Mon Sep 17 00:00:00 2001 From: Samuel Cabrero Date: Tue, 1 Oct 2019 16:59:07 +0200 Subject: [PATCH] librpc:core: Add a function to reinitialize the dcesrv_context Clears all registered endpoints and interfaces, association groups and broken connections. To be used by S3 forked daemons. Signed-off-by: Samuel Cabrero Reviewed-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett --- librpc/rpc/dcesrv_core.c | 29 +++++++++++++++++++++++++++++ librpc/rpc/dcesrv_core.h | 1 + 2 files changed, 30 insertions(+) diff --git a/librpc/rpc/dcesrv_core.c b/librpc/rpc/dcesrv_core.c index 5ecb815b0ad..c1de3e62adf 100644 --- a/librpc/rpc/dcesrv_core.c +++ b/librpc/rpc/dcesrv_core.c @@ -2349,6 +2349,35 @@ _PUBLIC_ NTSTATUS dcesrv_init_context(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } +_PUBLIC_ NTSTATUS dcesrv_reinit_context(struct dcesrv_context *dce_ctx) +{ + NTSTATUS status; + + status = dcesrv_shutdown_registered_ep_servers(dce_ctx); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + /* Clear endpoints */ + while (dce_ctx->endpoint_list != NULL) { + struct dcesrv_endpoint *e = dce_ctx->endpoint_list; + DLIST_REMOVE(dce_ctx->endpoint_list, e); + TALLOC_FREE(e); + } + + /* Remove broken connections */ + dcesrv_cleanup_broken_connections(dce_ctx); + + /* Reinit assoc group idr */ + TALLOC_FREE(dce_ctx->assoc_groups_idr); + dce_ctx->assoc_groups_idr = idr_init(dce_ctx); + if (dce_ctx->assoc_groups_idr == NULL) { + return NT_STATUS_NO_MEMORY; + } + + return NT_STATUS_OK; +} + _PUBLIC_ NTSTATUS dcesrv_init_ep_servers(struct dcesrv_context *dce_ctx, const char **endpoint_servers) { diff --git a/librpc/rpc/dcesrv_core.h b/librpc/rpc/dcesrv_core.h index 81f9a8a1633..4273176ea6f 100644 --- a/librpc/rpc/dcesrv_core.h +++ b/librpc/rpc/dcesrv_core.h @@ -458,6 +458,7 @@ NTSTATUS dcesrv_init_context(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, struct dcesrv_context_callbacks *cb, struct dcesrv_context **_dce_ctx); +NTSTATUS dcesrv_reinit_context(struct dcesrv_context *dce_ctx); NTSTATUS dcesrv_reply(struct dcesrv_call_state *call); struct dcesrv_handle *dcesrv_handle_create(struct dcesrv_call_state *call, -- 2.11.4.GIT