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

s4-loadparm: added loadparm_init_global()

This ensures we use the same loadparm_context in all our command line
tools.

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Andrew Tridgell 2010-11-29 13:24:51 +11:00
parent 6982a00ded
commit b20ce4392e
2 changed files with 28 additions and 0 deletions

View File

@ -531,6 +531,8 @@ struct loadparm_context {
time_t modtime;
} *file_lists;
unsigned int flags[NUMPARAMETERS];
bool loaded;
bool refuse_free;
};
@ -2263,6 +2265,13 @@ static int lp_destructor(struct loadparm_context *lp_ctx)
{
struct parmlist_entry *data;
if (lp_ctx->refuse_free) {
/* someone is trying to free the
global_loadparm_context.
We can't allow that. */
return -1;
}
if (lp_ctx->globals->param_opt != NULL) {
struct parmlist_entry *next;
for (data = lp_ctx->globals->param_opt; data; data=next) {
@ -2278,6 +2287,8 @@ static int lp_destructor(struct loadparm_context *lp_ctx)
/**
* Initialise the global parameter structure.
*
* Note that most callers should use loadparm_init_global() instead
*/
struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
{
@ -2481,6 +2492,21 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
return lp_ctx;
}
/**
* Initialise the global parameter structure.
*/
struct loadparm_context *loadparm_init_global(bool load_default)
{
if (global_loadparm_context == NULL) {
global_loadparm_context = loadparm_init(NULL);
}
if (load_default && !global_loadparm_context->loaded) {
lpcfg_load_default(global_loadparm_context);
}
global_loadparm_context->refuse_free = true;
return global_loadparm_context;
}
const char *lpcfg_configfile(struct loadparm_context *lp_ctx)
{
return lp_ctx->szConfigFile;
@ -2588,6 +2614,7 @@ bool lpcfg_load(struct loadparm_context *lp_ctx, const char *filename)
/* set the context used by the lp_*() function
varients */
global_loadparm_context = lp_ctx;
lp_ctx->loaded = true;
}
return bRetval;

View File

@ -175,6 +175,7 @@ void lpcfg_killunused(struct loadparm_context *lp_ctx,
* Initialise the global parameter structure.
*/
struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx);
struct loadparm_context *loadparm_init_global(bool load_default);
const char *lpcfg_configfile(struct loadparm_context *lp_ctx);
bool lpcfg_load_default(struct loadparm_context *lp_ctx);
const char *lp_default_path(void);