summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-11-29 13:24:51 +1100
committerAndrew Tridgell <tridge@samba.org>2010-11-29 18:04:42 +1100
commitb20ce4392e2d00c3edff8b4b8f329cf22341ea76 (patch)
tree2278b1705aa4e661f2fd250fee33b3dff71fed29 /source4
parent6982a00ded40a70cddea22451482342e99102e58 (diff)
downloadsamba-b20ce4392e2d00c3edff8b4b8f329cf22341ea76.tar.gz
samba-b20ce4392e2d00c3edff8b4b8f329cf22341ea76.tar.bz2
samba-b20ce4392e2d00c3edff8b4b8f329cf22341ea76.zip
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>
Diffstat (limited to 'source4')
-rw-r--r--source4/param/loadparm.c27
-rw-r--r--source4/param/param.h1
2 files changed, 28 insertions, 0 deletions
diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c
index f6f894d5bc..55cb45eaed 100644
--- a/source4/param/loadparm.c
+++ b/source4/param/loadparm.c
@@ -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;
diff --git a/source4/param/param.h b/source4/param/param.h
index ea121fa6da..21a97fbcd0 100644
--- a/source4/param/param.h
+++ b/source4/param/param.h
@@ -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);