samba4: Add python bindings for samba.policy.get_gplink_options.
authorJelmer Vernooij <jelmer@samba.org>
Thu, 6 May 2010 09:16:27 +0000 (11:16 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sun, 20 Jun 2010 15:19:11 +0000 (17:19 +0200)
Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
source4/lib/policy/pypolicy.c
source4/lib/policy/tests/python/bindings.py

index 5389a092004874fa4a76f260941b58029b255c8c..9ace387a80af3cd8018707ddd1b668e4cb61ff6f 100644 (file)
@@ -64,9 +64,53 @@ static PyObject *py_get_gpo_flags(PyObject *self, PyObject *args)
        return py_ret;
 }
 
+static PyObject *py_get_gplink_options(PyObject *self, PyObject *args)
+{
+       int flags;
+       PyObject *py_ret;
+       const char **ret;
+       TALLOC_CTX *mem_ctx;
+       int i;
+       NTSTATUS status;
+
+       if (!PyArg_ParseTuple(args, "i", &flags))
+               return NULL;
+
+       mem_ctx = talloc_new(NULL);
+       if (mem_ctx == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+
+       status = gp_get_gplink_options(mem_ctx, flags, &ret);
+       if (!NT_STATUS_IS_OK(status)) {
+               PyErr_SetNTSTATUS(status);
+               talloc_free(mem_ctx);
+               return NULL;
+       }
+
+       py_ret = PyList_New(0);
+       for (i = 0; ret[i]; i++) {
+               PyObject *item = PyString_FromString(ret[i]);
+               if (item == NULL) {
+                       talloc_free(mem_ctx);
+                       Py_DECREF(py_ret);
+                       PyErr_NoMemory();
+                       return NULL;
+               }
+               PyList_Append(py_ret, item);
+       }
+
+       talloc_free(mem_ctx);
+
+       return py_ret;
+}
+
 static PyMethodDef py_policy_methods[] = {
        { "get_gpo_flags", (PyCFunction)py_get_gpo_flags, METH_VARARGS,
                "get_gpo_flags(flags) -> list" },
+    { "get_gplink_options", (PyCFunction)py_get_gplink_options, METH_VARARGS,
+        "get_gplink_options(options) -> list" },
        { NULL }
 };
 
@@ -82,4 +126,8 @@ void initpolicy(void)
                                           PyInt_FromLong(GPO_FLAG_USER_DISABLE));
        PyModule_AddObject(m, "GPO_MACHINE_USER_DISABLE",
                                           PyInt_FromLong(GPO_FLAG_MACHINE_DISABLE));
+       PyModule_AddObject(m, "GPLINK_OPT_DISABLE",
+                                          PyInt_FromLong(GPLINK_OPT_DISABLE ));
+       PyModule_AddObject(m, "GPLINK_OPT_ENFORCE ",
+                                          PyInt_FromLong(GPLINK_OPT_ENFORCE ));
 }
index 1a698f16e076d291850896a0312d81ee2af4da73..0d6a63bf751472b9cc17ff8445b143825755ce56 100644 (file)
@@ -29,3 +29,7 @@ class PolicyTests(unittest.TestCase):
     def test_get_gpo_flags(self):
         self.assertEquals(["GPO_FLAG_USER_DISABLE"],
             policy.get_gpo_flags(policy.GPO_FLAG_USER_DISABLE))
+
+    def test_get_gplink_options(self):
+        self.assertEquals(["GPLINK_OPT_DISABLE"],
+            policy.get_gplink_options(policy.GPLINK_OPT_DISABLE))