From 33d178767b425510448435748bdd780402106ded Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 29 Nov 2010 13:25:59 +1100 Subject: s4-loadparm: use loadparm_init_global() instead of loadparm_init() this prevents us having two lp_ctx contexts in these tools which leads to bizarre behaviour Pair-Programmed-With: Andrew Bartlett --- source4/param/pyparam.c | 2 +- source4/param/pyparam_util.c | 35 ++++++++++++++--------------------- 2 files changed, 15 insertions(+), 22 deletions(-) (limited to 'source4/param') diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c index cb7169e68d..be29c724f1 100644 --- a/source4/param/pyparam.c +++ b/source4/param/pyparam.c @@ -330,7 +330,7 @@ static PyObject *py_lp_ctx_new(PyTypeObject *type, PyObject *args, PyObject *kwa PyErr_NoMemory(); return NULL; } - ret->ptr = loadparm_init(ret->talloc_ctx); + ret->ptr = loadparm_init_global(false); return (PyObject *)ret; } diff --git a/source4/param/pyparam_util.c b/source4/param/pyparam_util.c index 474dd31504..57a9b1b772 100644 --- a/source4/param/pyparam_util.c +++ b/source4/param/pyparam_util.c @@ -22,33 +22,30 @@ #include "param/param.h" #include "param/loadparm.h" #include "lib/talloc/pytalloc.h" +#include "lib/cmdline/popt_common.h" #define PyLoadparmContext_AsLoadparmContext(obj) py_talloc_get_type(obj, struct loadparm_context) _PUBLIC_ struct loadparm_context *lpcfg_from_py_object(TALLOC_CTX *mem_ctx, PyObject *py_obj) { - struct loadparm_context *lp_ctx; + struct loadparm_context *lp_ctx; PyObject *param_mod; PyTypeObject *lp_type; bool is_lpobj; - if (PyString_Check(py_obj)) { - lp_ctx = loadparm_init(mem_ctx); - if (!lpcfg_load(lp_ctx, PyString_AsString(py_obj))) { - talloc_free(lp_ctx); + if (PyString_Check(py_obj)) { + lp_ctx = loadparm_init_global(false); + if (!lpcfg_load(lp_ctx, PyString_AsString(py_obj))) { PyErr_Format(PyExc_RuntimeError, "Unable to load %s", - PyString_AsString(py_obj)); - return NULL; - } - return lp_ctx; - } + PyString_AsString(py_obj)); + return NULL; + } + return lp_ctx; + } - if (py_obj == Py_None) { - lp_ctx = loadparm_init(mem_ctx); - /* We're not checking that loading the file succeeded *on purpose */ - lpcfg_load_default(lp_ctx); - return lp_ctx; - } + if (py_obj == Py_None) { + return loadparm_init_global(true); + } param_mod = PyImport_ImportModule("samba.param"); if (param_mod == NULL) { @@ -74,11 +71,7 @@ _PUBLIC_ struct loadparm_context *lpcfg_from_py_object(TALLOC_CTX *mem_ctx, PyOb struct loadparm_context *py_default_loadparm_context(TALLOC_CTX *mem_ctx) { - struct loadparm_context *ret; - ret = loadparm_init(mem_ctx); - if (!lpcfg_load_default(ret)) - return NULL; - return ret; + return loadparm_init_global(true); } -- cgit