librpc:core: Add a function to reinitialize the dcesrv_context
authorSamuel Cabrero <scabrero@samba.org>
Tue, 1 Oct 2019 14:59:07 +0000 (16:59 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 12 Dec 2019 00:35:30 +0000 (00:35 +0000)
Clears all registered endpoints and interfaces, association groups and
broken connections.

To be used by S3 forked daemons.

Signed-off-by: Samuel Cabrero <scabrero@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
librpc/rpc/dcesrv_core.c
librpc/rpc/dcesrv_core.h

index 5ecb815b0ad1ef0c7e2d2625e8893931efaa151c..c1de3e62adfb03aadb0be2e3255501b2d17de6ef 100644 (file)
@@ -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)
 {
index 81f9a8a1633da31bffa0e987589692b4031ed6e4..4273176ea6fcaf8529d8eb15254e5fbce050618e 100644 (file)
@@ -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,