s4-testparm: modify dumping of parameters to use the lib/param code to have more...
authorGarming Sam <garming@catalyst.net.nz>
Fri, 27 Dec 2013 04:09:35 +0000 (17:09 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 28 Jan 2014 04:26:36 +0000 (17:26 +1300)
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 <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Jelmer Vernooij <jelmer@samba.org>
python/samba/netcmd/testparm.py
source4/param/pyparam.c

index 92514694218a4b46b8dca9cc40303638cfbbfcea..7825d259fb50ad2f8fdf560f3fb90b7eeed4ca33 100644 (file)
@@ -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")
index 9874006bfaaf8ce95a689f4c2ed3cc737a848887..303a2096c62887f9217d10de9194432533ad7a9b 100644 (file)
@@ -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, &param_name, &section_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." },