1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

lib:cmdline: Add callback for loading the config file

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Andreas Schneider 2020-08-10 15:09:54 +02:00 committed by Andrew Bartlett
parent 6c81250565
commit e54f5f9527
4 changed files with 97 additions and 0 deletions

View File

@ -22,6 +22,7 @@
static TALLOC_CTX *cmdline_mem_ctx;
static struct loadparm_context *cmdline_lp_ctx;
static struct cli_credentials *cmdline_creds;
static samba_cmdline_load_config cmdline_load_config_fn;
/* PRIVATE */
bool samba_cmdline_set_talloc_ctx(TALLOC_CTX *mem_ctx)
@ -67,6 +68,12 @@ bool samba_cmdline_init_common(TALLOC_CTX *mem_ctx)
return true;
}
bool samba_cmdline_set_load_config_fn(samba_cmdline_load_config fn)
{
cmdline_load_config_fn = fn;
return true;
}
/* PUBLIC */
bool samba_cmdline_set_lp_ctx(struct loadparm_context *lp_ctx)
{

View File

@ -20,6 +20,8 @@
#include "lib/cmdline/cmdline.h"
typedef bool (*samba_cmdline_load_config)(void);
/**
* @internal
*
@ -40,6 +42,18 @@
*/
bool samba_cmdline_init_common(TALLOC_CTX *mem_ctx);
/**
* @brief Set the callback for loading the smb.conf file.
*
* This is needed as sourc3 and source4 have different code for loading the
* smb.conf file.
*
* @param[in] fn The callback to load the smb.conf file.
*
* @return true on success, false if an error occured.
*/
bool samba_cmdline_set_load_config_fn(samba_cmdline_load_config fn);
/**
* @internal
*

View File

@ -21,11 +21,50 @@
#include "lib/util/debug.h"
#include "lib/util/fault.h"
#include "source3/param/loadparm.h"
#include "source3/lib/interface.h"
#include "auth/credentials/credentials.h"
#include "dynconfig/dynconfig.h"
#include "cmdline_private.h"
static bool _require_smbconf;
static bool _samba_cmdline_load_config_s3(void)
{
struct loadparm_context *lp_ctx = samba_cmdline_get_lp_ctx();
const char *config_file = NULL;
bool ok;
/* Load smb conf */
config_file = lpcfg_configfile(lp_ctx);
if (config_file == NULL) {
if (is_default_dyn_CONFIGFILE()) {
const char *env = getenv("SMB_CONF_PATH");
if (env != NULL && strlen(env) > 0) {
set_dyn_CONFIGFILE(env);
}
}
}
/*
* Load load smb.conf from getenv("SMB_CONF_PATH") default
* location.
*/
ok = lp_load_client(lp_default_path());
if (!ok) {
fprintf(stderr,
"Can't load %s - run testparm to debug it\n",
lp_default_path());
if (_require_smbconf) {
return false;
}
}
load_interfaces();
return true;
}
bool samba_cmdline_init(TALLOC_CTX *mem_ctx, bool require_smbconf)
{
struct loadparm_context *lp_ctx = NULL;
@ -57,5 +96,7 @@ bool samba_cmdline_init(TALLOC_CTX *mem_ctx, bool require_smbconf)
return false;
}
samba_cmdline_set_load_config_fn(_samba_cmdline_load_config_s3);
return true;
}

View File

@ -21,10 +21,43 @@
#include "lib/util/debug.h"
#include "lib/util/fault.h"
#include "auth/credentials/credentials.h"
#include "dynconfig/dynconfig.h"
#include "cmdline_private.h"
static bool _require_smbconf;
static bool _samba_cmdline_load_config_s4(void)
{
struct loadparm_context *lp_ctx = samba_cmdline_get_lp_ctx();
const char *config_file = NULL;
bool ok;
/* Load smb conf */
config_file = lpcfg_configfile(lp_ctx);
if (config_file == NULL) {
if (is_default_dyn_CONFIGFILE()) {
const char *env = getenv("SMB_CONF_PATH");
if (env != NULL && strlen(env) > 0) {
set_dyn_CONFIGFILE(env);
}
}
}
config_file = get_dyn_CONFIGFILE();
ok = lpcfg_load(lp_ctx, config_file);
if (!ok) {
fprintf(stderr,
"Can't load %s - run testparm to debug it\n",
config_file);
if (_require_smbconf) {
return false;
}
}
return true;
}
bool samba_cmdline_init(TALLOC_CTX *mem_ctx, bool require_smbconf)
{
struct loadparm_context *lp_ctx = NULL;
@ -56,5 +89,7 @@ bool samba_cmdline_init(TALLOC_CTX *mem_ctx, bool require_smbconf)
return false;
}
samba_cmdline_set_load_config_fn(_samba_cmdline_load_config_s4);
return true;
}