From 05d56fe9c7bb1d67b1efb79dae715131d927b090 Mon Sep 17 00:00:00 2001 From: Samuel Cabrero Date: Tue, 12 Dec 2023 15:44:21 +0100 Subject: [PATCH] s3:winbind: talloc the static idmap child Next commits will use talloc_get_type_abort() to get the reference. Signed-off-by: Samuel Cabrero Reviewed-by: Alexander Bokovoy --- source3/winbindd/winbindd.c | 6 +++++- source3/winbindd/winbindd_idmap.c | 29 ++++++++++++++++++++--------- source3/winbindd/winbindd_proto.h | 2 +- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/source3/winbindd/winbindd.c b/source3/winbindd/winbindd.c index cdd6d4319cb..b87686f04c5 100644 --- a/source3/winbindd/winbindd.c +++ b/source3/winbindd/winbindd.c @@ -1179,7 +1179,11 @@ static void winbindd_register_handlers(struct messaging_context *msg_ctx, exit(1); } - init_idmap_child(); + status = init_idmap_child(global_event_context()); + if (NT_STATUS_IS_ERR(status)) { + DBG_ERR("Unable to start idmap child: %s\n", nt_errstr(status)); + exit(1); + } init_locator_child(); smb_nscd_flush_user_cache(); diff --git a/source3/winbindd/winbindd_idmap.c b/source3/winbindd/winbindd_idmap.c index 75f7d37d86d..362211223eb 100644 --- a/source3/winbindd/winbindd_idmap.c +++ b/source3/winbindd/winbindd_idmap.c @@ -30,7 +30,7 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_WINBIND -static struct winbindd_child static_idmap_child; +static struct winbindd_child *static_idmap_child = NULL; /* * Map idmap ranges to domain names, taken from smb.conf. This is @@ -41,12 +41,12 @@ static struct wb_parent_idmap_config static_parent_idmap_config; struct winbindd_child *idmap_child(void) { - return &static_idmap_child; + return static_idmap_child; } bool is_idmap_child(const struct winbindd_child *child) { - if (child == &static_idmap_child) { + if (child == static_idmap_child) { return true; } @@ -55,7 +55,7 @@ bool is_idmap_child(const struct winbindd_child *child) pid_t idmap_child_pid(void) { - return static_idmap_child.pid; + return static_idmap_child->pid; } struct dcerpc_binding_handle *idmap_child_handle(void) @@ -65,16 +65,26 @@ struct dcerpc_binding_handle *idmap_child_handle(void) * before talking to the idmap child! */ SMB_ASSERT(static_parent_idmap_config.num_doms > 0); - return static_idmap_child.binding_handle; + return static_idmap_child->binding_handle; } static void init_idmap_child_done(struct tevent_req *subreq); -void init_idmap_child(void) +NTSTATUS init_idmap_child(TALLOC_CTX *mem_ctx) { struct tevent_req *subreq = NULL; - subreq = wb_parent_idmap_setup_send(global_event_context(), + if (static_idmap_child != NULL) { + DBG_ERR("idmap child already allocated\n"); + return NT_STATUS_INTERNAL_ERROR; + } + + static_idmap_child = talloc_zero(mem_ctx, struct winbindd_child); + if (static_idmap_child == NULL) { + return NT_STATUS_NO_MEMORY; + } + + subreq = wb_parent_idmap_setup_send(static_idmap_child, global_event_context()); if (subreq == NULL) { /* @@ -82,10 +92,11 @@ void init_idmap_child(void) * to ignore errors */ DBG_ERR("wb_parent_idmap_setup_send() failed\n"); - return; + return NT_STATUS_NO_MEMORY; } tevent_req_set_callback(subreq, init_idmap_child_done, NULL); DBG_DEBUG("wb_parent_idmap_setup_send() started\n"); + return NT_STATUS_OK; } static void init_idmap_child_done(struct tevent_req *subreq) @@ -335,7 +346,7 @@ static void wb_parent_idmap_setup_lookupname_next(struct tevent_req *req) /* * We're done, so start the idmap child */ - setup_child(NULL, &static_idmap_child, "log.winbindd", "idmap"); + setup_child(NULL, static_idmap_child, "log.winbindd", "idmap"); static_parent_idmap_config.initialized = true; tevent_req_done(req); return; diff --git a/source3/winbindd/winbindd_proto.h b/source3/winbindd/winbindd_proto.h index 16e4e0ff14d..975263bc656 100644 --- a/source3/winbindd/winbindd_proto.h +++ b/source3/winbindd/winbindd_proto.h @@ -383,7 +383,7 @@ struct tevent_req *wb_parent_idmap_setup_send(TALLOC_CTX *mem_ctx, NTSTATUS wb_parent_idmap_setup_recv(struct tevent_req *req, const struct wb_parent_idmap_config **_cfg); -void init_idmap_child(void); +NTSTATUS init_idmap_child(TALLOC_CTX *mem_ctx); struct winbindd_child *idmap_child(void); bool is_idmap_child(const struct winbindd_child *child); pid_t idmap_child_pid(void); -- 2.34.1