From ccfefe289093457587009e1862e1ed8591495aac Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 27 Aug 2021 13:06:00 +0200 Subject: [PATCH] s4:samba: split out a samba_service_init() helper function The loading function should be in the same SAMBA_LIBRARY() as the modules. Signed-off-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett Reviewed-by: Andreas Schneider Autobuild-User(master): Stefan Metzmacher Autobuild-Date(master): Tue Nov 30 16:44:57 UTC 2021 on sn-devel-184 --- source4/samba/server.c | 12 +----------- source4/samba/service.c | 24 ++++++++++++++++++++++++ source4/samba/service.h | 2 ++ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/source4/samba/server.c b/source4/samba/server.c index d8948337847..2915cd327c2 100644 --- a/source4/samba/server.c +++ b/source4/samba/server.c @@ -40,7 +40,6 @@ #include "librpc/gen_ndr/ndr_irpc.h" #include "cluster/cluster.h" #include "dynconfig/dynconfig.h" -#include "lib/util/samba_modules.h" #include "nsswitch/winbind_client.h" #include "libds/common/roles.h" #include "lib/util/tfork.h" @@ -510,10 +509,6 @@ static int binary_smbd_main(TALLOC_CTX *mem_ctx, int opt; int ret; poptContext pc; -#define _MODULE_PROTO(init) extern NTSTATUS init(TALLOC_CTX *); - STATIC_service_MODULES_PROTO; - init_module_fn static_init[] = { STATIC_service_MODULES }; - init_module_fn *shared_init; uint16_t stdin_event_flags; NTSTATUS status; const char *model = "prefork"; @@ -705,12 +700,7 @@ static int binary_smbd_main(TALLOC_CTX *mem_ctx, process_model_init(lp_ctx); - shared_init = load_samba_modules(mem_ctx, "service"); - - run_init_functions(mem_ctx, static_init); - run_init_functions(mem_ctx, shared_init); - - TALLOC_FREE(shared_init); + samba_service_init(); /* the event context is the top level structure in smbd. Everything else should hang off that */ diff --git a/source4/samba/service.c b/source4/samba/service.c index f801e4c8eab..2ad6c8f3715 100644 --- a/source4/samba/service.c +++ b/source4/samba/service.c @@ -23,6 +23,7 @@ #include "includes.h" #include "../lib/util/dlinklist.h" #include "samba/process_model.h" +#include "lib/util/samba_modules.h" #undef strcasecmp @@ -114,3 +115,26 @@ NTSTATUS server_service_startup(struct tevent_context *event_ctx, return NT_STATUS_OK; } + +_PUBLIC_ NTSTATUS samba_service_init(void) +{ +#define _MODULE_PROTO(init) extern NTSTATUS init(TALLOC_CTX *); + STATIC_service_MODULES_PROTO; + init_module_fn static_init[] = { STATIC_service_MODULES }; + init_module_fn *shared_init = NULL; + static bool initialised; + + if (initialised) { + return NT_STATUS_OK; + } + initialised = true; + + shared_init = load_samba_modules(NULL, "service"); + + run_init_functions(NULL, static_init); + run_init_functions(NULL, shared_init); + + TALLOC_FREE(shared_init); + + return NT_STATUS_OK; +} diff --git a/source4/samba/service.h b/source4/samba/service.h index 88d2478dfe5..7649101b97b 100644 --- a/source4/samba/service.h +++ b/source4/samba/service.h @@ -75,6 +75,8 @@ struct service_details { void (*post_fork) (struct task_server *, struct process_details *); }; +NTSTATUS samba_service_init(void); + #include "samba/service_proto.h" #endif /* __SERVICE_H__ */