param: Add python binding for lpcfg_state_path
authorDavid Mulder <dmulder@suse.com>
Fri, 29 Jun 2018 20:08:34 +0000 (14:08 -0600)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 12 Jul 2018 20:11:23 +0000 (22:11 +0200)
Signed-off-by: David Mulder <dmulder@suse.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source4/param/pyparam.c

index 11257c356aa2150404ea9f43f0b92ee73b06f95a..7f69d7b3c8be5bd96bbaf960b8e8eddc8def9ed6 100644 (file)
@@ -381,6 +381,30 @@ static PyObject *py_cache_path(PyObject *self, PyObject *args)
        return ret;
 }
 
+static PyObject *py_state_path(PyObject *self, PyObject *args)
+{
+       struct loadparm_context *lp_ctx =
+               PyLoadparmContext_AsLoadparmContext(self);
+       char *name = NULL;
+       char *path = NULL;
+       PyObject *ret = NULL;
+
+       if (!PyArg_ParseTuple(args, "s", &name)) {
+               return NULL;
+       }
+
+       path = lpcfg_state_path(NULL, lp_ctx, name);
+       if (!path) {
+               PyErr_Format(PyExc_RuntimeError,
+                            "Unable to access cache %s", name);
+               return NULL;
+       }
+       ret = PyStr_FromString(path);
+       talloc_free(path);
+
+       return ret;
+}
+
 static PyMethodDef py_lp_ctx_methods[] = {
        { "load", py_lp_ctx_load, METH_VARARGS,
                "S.load(filename) -> None\n"
@@ -419,6 +443,9 @@ static PyMethodDef py_lp_ctx_methods[] = {
        { "cache_path", py_cache_path, METH_VARARGS,
                "S.cache_path(name) -> string\n"
                "Returns a path in the Samba cache directory." },
+       { "state_path", py_state_path, METH_VARARGS,
+               "S.state_path(name) -> string\n"
+               "Returns a path in the Samba state directory." },
        { NULL }
 };