lib/smbconf: add set_global_parameter method to SMBConf
authorJohn Mulligan <jmulligan@redhat.com>
Sun, 24 Apr 2022 14:19:37 +0000 (10:19 -0400)
committerJeremy Allison <jra@samba.org>
Fri, 6 May 2022 17:16:30 +0000 (17:16 +0000)
Add a set_global_parameter method wrapping smbconf_set_global_parameter.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
Reviewed-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
lib/smbconf/pysmbconf.c
python/samba/tests/smbconf.py

index ae06c52f0c2d8867ab6d5be18d2b5b6836fff9e9..d800e0134c43d4cc7fe184d962117e8cfe18c337 100644 (file)
@@ -328,6 +328,25 @@ static PyObject *obj_set_parameter(py_SMBConf_Object * self, PyObject * args)
        Py_RETURN_NONE;
 }
 
+static PyObject *obj_set_global_parameter(py_SMBConf_Object * self,
+                                         PyObject * args)
+{
+       sbcErr err;
+       char *param = NULL;
+       char *val = NULL;
+
+       if (!PyArg_ParseTuple(args, "ss", &param, &val)) {
+               return NULL;
+       }
+
+       err = smbconf_set_global_parameter(self->conf_ctx, param, val);
+       if (err != SBC_ERR_OK) {
+               py_raise_SMBConfError(err);
+               return NULL;
+       }
+       Py_RETURN_NONE;
+}
+
 PyDoc_STRVAR(obj_requires_messaging_doc,
 "requires_messaging() -> bool\n"
 "\n"
@@ -372,6 +391,11 @@ PyDoc_STRVAR(obj_set_parameter_doc,
 "Set a configuration parmeter. Specify service name, parameter name,\n"
 "and parameter value.\n");
 
+PyDoc_STRVAR(obj_set_global_parameter_doc,
+"set_global_parameter(str, str) -> None\n"
+"Set a global configuration parmeter. Specify the parameter name\n"
+"and parameter value.\n");
+
 static PyMethodDef py_smbconf_obj_methods[] = {
        { "requires_messaging", (PyCFunction) obj_requires_messaging,
         METH_NOARGS, obj_requires_messaging_doc },
@@ -389,6 +413,8 @@ static PyMethodDef py_smbconf_obj_methods[] = {
         obj_drop_doc },
        { "set_parameter", (PyCFunction) obj_set_parameter, METH_VARARGS,
         obj_set_parameter_doc },
+       { "set_global_parameter", (PyCFunction) obj_set_global_parameter,
+        METH_VARARGS, obj_set_global_parameter_doc },
        { 0 },
 };
 
index 749a6fd398578c04c86ae887226455bb3cf6cd14..c81db2916515dc7baeadc10f71b5d63ef1b99dad 100644 (file)
@@ -160,6 +160,17 @@ class SMBConfTests(samba.tests.TestCase):
             s1, ("foobar", [("path", "/mnt/foobar"), ("browseable", "no")])
         )
 
+    def test_set_global_parameter(self):
+        sconf = self.s3smbconf.init_reg(None)
+        sconf.drop()
+        sconf.set_global_parameter("workgroup", "EXAMPLE")
+        sconf.set_global_parameter("x:custom", "fake")
+
+        s1 = sconf.get_share("global")
+        self.assertEqual(
+            s1, ("global", [("workgroup", "EXAMPLE"), ("x:custom", "fake")])
+        )
+
 
 if __name__ == "__main__":
     import unittest