From e465634eec1ce8ec22948b193f98861199ca59e7 Mon Sep 17 00:00:00 2001 From: Garming Sam Date: Fri, 27 Dec 2013 17:09:35 +1300 Subject: [PATCH] s4-testparm: modify dumping of parameters to use the lib/param code to have more consistent output In making this change, it also fixes a bug where attempting to dump a parameter would immediately cause an error (due to a lack of string conversion). Signed-off-by: Garming Sam Reviewed-by: Andrew Bartlett Reviewed-by: Jelmer Vernooij --- python/samba/netcmd/testparm.py | 2 +- source4/param/pyparam.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/python/samba/netcmd/testparm.py b/python/samba/netcmd/testparm.py index 92514694218..7825d259fb5 100644 --- a/python/samba/netcmd/testparm.py +++ b/python/samba/netcmd/testparm.py @@ -105,7 +105,7 @@ class cmd_testparm(Command): lp[section_name].dump(sys.stdout, lp.default_service, verbose) else: - self.outf.write(lp.get(parameter_name, section_name)+"\n") + lp.dump_a_parameter(sys.stdout, parameter_name, section_name) else: if not suppress_prompt: self.outf.write("Press enter to see a dump of your service definitions\n") diff --git a/source4/param/pyparam.c b/source4/param/pyparam.c index 9874006bfaa..303a2096c62 100644 --- a/source4/param/pyparam.c +++ b/source4/param/pyparam.c @@ -288,6 +288,41 @@ static PyObject *py_lp_dump(PyObject *self, PyObject *args) Py_RETURN_NONE; } +static PyObject *py_lp_dump_a_parameter(PyObject *self, PyObject *args) +{ + PyObject *py_stream; + char *param_name; + char *section_name = NULL; + FILE *f; + struct loadparm_context *lp_ctx = PyLoadparmContext_AsLoadparmContext(self); + struct loadparm_service *service; + + if (!PyArg_ParseTuple(args, "Os|z", &py_stream, ¶m_name, §ion_name)) + return NULL; + + f = PyFile_AsFile(py_stream); + if (f == NULL) { + return NULL; + } + + if (section_name != NULL && strwicmp(section_name, GLOBAL_NAME) && + strwicmp(section_name, GLOBAL_NAME2)) { + /* it's a share parameter */ + service = lpcfg_service(lp_ctx, section_name); + if (service == NULL) { + Py_RETURN_NONE; + } + } else { + /* it's global */ + service = NULL; + } + + lpcfg_dump_a_parameter(lp_ctx, service, param_name, f); + + Py_RETURN_NONE; + +} + static PyObject *py_samdb_url(PyObject *self) { struct loadparm_context *lp_ctx = PyLoadparmContext_AsLoadparmContext(self); @@ -323,6 +358,8 @@ static PyMethodDef py_lp_ctx_methods[] = { "Get the server role." }, { "dump", (PyCFunction)py_lp_dump, METH_VARARGS, "S.dump(stream, show_defaults=False)" }, + { "dump_a_parameter", (PyCFunction)py_lp_dump_a_parameter, METH_VARARGS, + "S.dump_a_parameter(stream, name, service_name)" }, { "samdb_url", (PyCFunction)py_samdb_url, METH_NOARGS, "S.samdb_url() -> string\n" "Returns the current URL for sam.ldb." }, -- 2.11.4.GIT