From 5e39ef9cb9b7bf63efb4268cf01463fb3a55447a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 12 Dec 2023 11:46:55 +0100 Subject: [PATCH] s3:param: alloc lp_load_ex() to take an existing 'FILE *' pointer instead of a path This will be useful in order to use open_memstream()/fmemopen() in order to create a deep copy of an s4 lpctx into an s3 context without having an existing smb.conf file on disk. Signed-off-by: Stefan Metzmacher --- source3/param/loadparm.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 797baa66309f..10fca68965b9 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -3966,6 +3966,7 @@ static void lp_enforce_ad_dc_settings(void) ***************************************************************************/ static bool lp_load_ex(const char *pszFname, + FILE *existing_file_handle, bool global_only, bool save_defaults, bool add_ipc, @@ -4007,7 +4008,20 @@ static bool lp_load_ex(const char *pszFname, /* We get sections first, so have to start 'behind' to make up */ iServiceIndex = -1; - if (lp_config_backend_is_file()) { + if (existing_file_handle != NULL) { + bRetval = tini_parse(existing_file_handle, + false, /* allow_empty_values */ + lp_do_section, + do_parameter, + lp_ctx); + /* finish up the last section */ + DEBUG(4, ("tini_parse() returned %s\n", BOOLSTR(bRetval))); + if (bRetval) { + if (iServiceIndex >= 0) { + bRetval = lpcfg_service_ok(ServicePtrs[iServiceIndex]); + } + } + } else if (lp_config_backend_is_file()) { n2 = talloc_sub_basic(talloc_tos(), get_current_username(), get_current_user_info_domain(), pszFname); @@ -4142,6 +4156,7 @@ static bool lp_load(const char *pszFname, bool reinit_globals) { return lp_load_ex(pszFname, + NULL, /* existing_file_handle */ global_only, save_defaults, add_ipc, @@ -4153,6 +4168,7 @@ static bool lp_load(const char *pszFname, bool lp_load_initial_only(const char *pszFname) { return lp_load_ex(pszFname, + NULL, /* existing_file_handle */ true, /* global only */ true, /* save_defaults */ false, /* add_ipc */ -- 2.34.1