From 565d8ae8cdfae9e15e18a0c9350e2ebb4f502f92 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Sun, 24 Apr 2022 10:18:42 -0400 Subject: [PATCH] lib/smbconf: add set_parameter method to SMBConf Add a set_parameter method wrapping smbconf_set_parameter. Signed-off-by: John Mulligan Reviewed-by: Jeremy Allison Reviewed-by: Douglas Bagnall --- lib/smbconf/pysmbconf.c | 26 ++++++++++++++++++++++++++ python/samba/tests/smbconf.py | 12 ++++++++++++ 2 files changed, 38 insertions(+) diff --git a/lib/smbconf/pysmbconf.c b/lib/smbconf/pysmbconf.c index bf1540bbb50..ae06c52f0c2 100644 --- a/lib/smbconf/pysmbconf.c +++ b/lib/smbconf/pysmbconf.c @@ -309,6 +309,25 @@ static PyObject *obj_drop(py_SMBConf_Object * self, Py_RETURN_NONE; } +static PyObject *obj_set_parameter(py_SMBConf_Object * self, PyObject * args) +{ + sbcErr err; + char *servicename = NULL; + char *param = NULL; + char *val = NULL; + + if (!PyArg_ParseTuple(args, "sss", &servicename, ¶m, &val)) { + return NULL; + } + + err = smbconf_set_parameter(self->conf_ctx, servicename, 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" @@ -348,6 +367,11 @@ PyDoc_STRVAR(obj_drop_doc, "drop() -> None\n" "Drop the entire configuration, resetting it to an empty state.\n"); +PyDoc_STRVAR(obj_set_parameter_doc, +"set_parameter(str, str, str) -> None\n" +"Set a configuration parmeter. Specify service name, 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 }, @@ -363,6 +387,8 @@ static PyMethodDef py_smbconf_obj_methods[] = { obj_create_share_doc }, { "drop", (PyCFunction) obj_drop, METH_NOARGS, obj_drop_doc }, + { "set_parameter", (PyCFunction) obj_set_parameter, METH_VARARGS, + obj_set_parameter_doc }, { 0 }, }; diff --git a/python/samba/tests/smbconf.py b/python/samba/tests/smbconf.py index 80e0d55984d..749a6fd3985 100644 --- a/python/samba/tests/smbconf.py +++ b/python/samba/tests/smbconf.py @@ -148,6 +148,18 @@ class SMBConfTests(samba.tests.TestCase): names = sconf.share_names() self.assertEqual(names, []) + def test_set_parameter(self): + sconf = self.s3smbconf.init_reg(None) + sconf.drop() + sconf.create_share("foobar") + sconf.set_parameter("foobar", "path", "/mnt/foobar") + sconf.set_parameter("foobar", "browseable", "no") + + s1 = sconf.get_share("foobar") + self.assertEqual( + s1, ("foobar", [("path", "/mnt/foobar"), ("browseable", "no")]) + ) + if __name__ == "__main__": import unittest -- 2.11.4.GIT