lib/smbconf: add drop method to SMBConf
authorJohn Mulligan <jmulligan@redhat.com>
Sun, 24 Apr 2022 12:17:53 +0000 (08:17 -0400)
committerJeremy Allison <jra@samba.org>
Fri, 6 May 2022 17:16:30 +0000 (17:16 +0000)
Add a drop method wrapping smbconf_drop.

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 b49673c1eb42d5eba4dc85ed2256d29cb44d97ce..bf1540bbb5039ed86f4fb717490917a1e9668772 100644 (file)
@@ -296,6 +296,19 @@ static PyObject *obj_create_share(py_SMBConf_Object * self, PyObject * args)
        Py_RETURN_NONE;
 }
 
+static PyObject *obj_drop(py_SMBConf_Object * self,
+                         PyObject * Py_UNUSED(ignored))
+{
+       sbcErr err;
+
+       err = smbconf_drop(self->conf_ctx);
+       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"
@@ -331,6 +344,10 @@ PyDoc_STRVAR(obj_create_share_doc,
 "Create a new empty share in the configuration. The share\n"
 "name must not exist or an error will be raised.\n");
 
+PyDoc_STRVAR(obj_drop_doc,
+"drop() -> None\n"
+"Drop the entire configuration, resetting it to an empty state.\n");
+
 static PyMethodDef py_smbconf_obj_methods[] = {
        { "requires_messaging", (PyCFunction) obj_requires_messaging,
         METH_NOARGS, obj_requires_messaging_doc },
@@ -344,6 +361,8 @@ static PyMethodDef py_smbconf_obj_methods[] = {
         obj_get_config_doc },
        { "create_share", (PyCFunction) obj_create_share, METH_VARARGS,
         obj_create_share_doc },
+       { "drop", (PyCFunction) obj_drop, METH_NOARGS,
+        obj_drop_doc },
        { 0 },
 };
 
index 749a3eb6d8e027295c52ba108091bb1854c1a8bc..80e0d55984de9146005adbb10da07693f73545f8 100644 (file)
@@ -131,6 +131,7 @@ class SMBConfTests(samba.tests.TestCase):
 
     def test_create_share(self):
         sconf = self.s3smbconf.init_reg(None)
+        sconf.drop()
         sconf.create_share("alice")
         sconf.create_share("bob")
         names = sconf.share_names()
@@ -139,6 +140,14 @@ class SMBConfTests(samba.tests.TestCase):
             self.smbconf.SMBConfError, sconf.create_share, "alice"
         )
 
+    def test_create_share(self):
+        sconf = self.s3smbconf.init_reg(None)
+        sconf.drop()
+        sconf.create_share("alice")
+        sconf.drop()
+        names = sconf.share_names()
+        self.assertEqual(names, [])
+
 
 if __name__ == "__main__":
     import unittest