1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

lib/smbconf: add set_global_parameter method to SMBConf

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>
This commit is contained in:
John Mulligan 2022-04-24 10:19:37 -04:00 committed by Jeremy Allison
parent 565d8ae8cd
commit 35df07d5ca
2 changed files with 37 additions and 0 deletions

View 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 },
};

View 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