diff options
author | Aaron Haslett <aaronhaslett@catalyst.net.nz> | 2018-05-01 11:10:36 +1200 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2018-06-28 03:34:27 +0200 |
commit | 5728867ddcc4487bde53a11cf865563b59624eb1 (patch) | |
tree | 2507d4395f7be1fe0b083506d232dad49e6db2ff /source4/param | |
parent | f0aad4a18736cbcbb3c87dd03cf24ae190fe8b4f (diff) | |
download | samba-5728867ddcc4487bde53a11cf865563b59624eb1.tar.gz |
param: Add non-global smb.cfg option (support 2 different smb.confs)
The default behaviour is that there is only a single global underlying
LoadParm object. E.g. if you create 2 different LoadParm objects in
python, they both modify the same underlying object.
This patch adds a mechanism to override this and create a separate
non-global LoadParm object. The use-case is the backup tool, where we
want to manipulate 2 different smb.conf files (the one used to create
the backup, and the smb.conf in the backup itself).
Signed-off-by: Aaron Haslett <aaronhaslett@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'source4/param')
-rw-r--r-- | source4/param/pyparam.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c index e7e908fcac3..11257c356aa 100644 --- a/source4/param/pyparam.c +++ b/source4/param/pyparam.c @@ -445,7 +445,52 @@ static PyGetSetDef py_lp_ctx_getset[] = { static PyObject *py_lp_ctx_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { - return pytalloc_reference(type, loadparm_init_global(false)); + const char *kwnames[] = {"filename_for_non_global_lp", NULL}; + PyObject *lp_ctx; + const char *non_global_conf = NULL; + struct loadparm_context *ctx; + + if (!PyArg_ParseTupleAndKeywords(args, + kwargs, + "|s", + discard_const_p(char *, + kwnames), + &non_global_conf)) { + return NULL; + } + + /* + * by default, any LoadParm python objects map to a single global + * underlying object. The filename_for_non_global_lp arg overrides this + * default behaviour and creates a separate underlying LoadParm object. + */ + if (non_global_conf != NULL) { + bool ok; + ctx = loadparm_init(NULL); + if (ctx == NULL) { + PyErr_NoMemory(); + return NULL; + } + + lp_ctx = pytalloc_reference(type, ctx); + if (lp_ctx == NULL) { + PyErr_NoMemory(); + return NULL; + } + + ok = lpcfg_load_no_global( + PyLoadparmContext_AsLoadparmContext(lp_ctx), + non_global_conf); + if (!ok) { + PyErr_Format(PyExc_ValueError, + "Could not load non-global conf %s", + non_global_conf); + return NULL; + } + return lp_ctx; + } else{ + return pytalloc_reference(type, loadparm_init_global(false)); + } } static Py_ssize_t py_lp_ctx_len(PyObject *self) |