s4-python: Move set_opaque_integer -> dsdb.
authorJelmer Vernooij <jelmer@samba.org>
Sat, 3 Apr 2010 22:40:01 +0000 (00:40 +0200)
committerJelmer Vernooij <jelmer@samba.org>
Sat, 3 Apr 2010 22:40:01 +0000 (00:40 +0200)
source4/dsdb/pydsdb.c
source4/scripting/python/pyglue.c
source4/scripting/python/samba/__init__.py

index 248bc1a07ac6728bbd31fab3dc24e14338d2f02b..b4f0b0f339506661a9f0f57a69b9866f56b0ea9f 100644 (file)
@@ -36,15 +36,15 @@ static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
        PyObject *py_ldb, *result;
        struct ldb_context *ldb;
        const char *site;
-       TALLOC_CTX *mem_ctx = talloc_new(NULL);
+       TALLOC_CTX *mem_ctx;
 
-       if (!PyArg_ParseTuple(args, "O", &py_ldb)) {
-               talloc_free(mem_ctx);
+       if (!PyArg_ParseTuple(args, "O", &py_ldb))
                return NULL;
-       }
 
        PyErr_LDB_OR_RAISE(py_ldb, ldb);
 
+       mem_ctx = talloc_new(NULL);
+
        site = samdb_server_site_name(ldb, mem_ctx);
        if (site == NULL) {
                PyErr_SetString(PyExc_RuntimeError, "Failed to find server site");
@@ -57,9 +57,75 @@ static PyObject *py_samdb_server_site_name(PyObject *self, PyObject *args)
        return result;
 }
 
+/* XXX: This function really should be in pyldb.c */
+static PyObject *py_dsdb_set_opaque_integer(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb;
+       int value;
+       int *old_val, *new_val;
+       char *py_opaque_name, *opaque_name_talloc;
+       struct ldb_context *ldb;
+       TALLOC_CTX *tmp_ctx;
+
+       if (!PyArg_ParseTuple(args, "Osi", &py_ldb, &py_opaque_name, &value))
+               return NULL;
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       /* see if we have a cached copy */
+       old_val = (int *)ldb_get_opaque(ldb, py_opaque_name);
+       /* XXX: We shouldn't just blindly assume that the value that is 
+        * already present has the size of an int and is not shared 
+        * with other code that may rely on it not changing. 
+        * JRV 20100403 */
+
+       if (old_val) {
+               *old_val = value;
+               Py_RETURN_NONE;
+       } 
+
+       tmp_ctx = talloc_new(ldb);
+       if (tmp_ctx == NULL) {
+               PyErr_NoMemory();
+               return NULL;
+       }
+       
+       new_val = talloc(tmp_ctx, int);
+       if (new_val == NULL) {
+               talloc_free(tmp_ctx);
+               PyErr_NoMemory();
+               return NULL;
+       }
+       
+       opaque_name_talloc = talloc_strdup(tmp_ctx, py_opaque_name);
+       if (opaque_name_talloc == NULL) {
+               talloc_free(tmp_ctx);
+               PyErr_NoMemory();
+               return NULL;
+       }
+       
+       *new_val = value;
+
+       /* cache the domain_sid in the ldb */
+       if (ldb_set_opaque(ldb, opaque_name_talloc, new_val) != LDB_SUCCESS) {
+               talloc_free(tmp_ctx);
+               PyErr_SetString(PyExc_RuntimeError,
+                                       "Failed to set opaque integer into the ldb");
+               return NULL;
+       }
+
+       talloc_steal(ldb, new_val);
+       talloc_steal(ldb, opaque_name_talloc);
+       talloc_free(tmp_ctx);
+
+       Py_RETURN_NONE;
+}
+
 static PyMethodDef py_dsdb_methods[] = {
-       { "server_site_name", (PyCFunction)py_samdb_server_site_name, METH_VARARGS,
-               "get the server site name as a string"},
+       { "samdb_server_site_name", (PyCFunction)py_samdb_server_site_name,
+               METH_VARARGS, "Get the server site name as a string"},
+       { "dsdb_set_opaque_integer", (PyCFunction)py_dsdb_set_opaque_integer,
+               METH_VARARGS, NULL },
        { NULL }
 };
 
index 852231f68179f6998af89591b7fc72cd4b3830ee..d852b3db6a85c9fa2ca9570528f18e01d9a7b8aa 100644 (file)
@@ -277,63 +277,6 @@ static PyObject *py_dsdb_set_ntds_invocation_id(PyObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
-static PyObject *py_dsdb_set_opaque_integer(PyObject *self, PyObject *args)
-{
-       PyObject *py_ldb;
-       int value;
-       int *old_val, *new_val;
-       char *py_opaque_name, *opaque_name_talloc;
-       struct ldb_context *ldb;
-       TALLOC_CTX *tmp_ctx;
-
-       if (!PyArg_ParseTuple(args, "Osi", &py_ldb, &py_opaque_name, &value))
-               return NULL;
-
-       PyErr_LDB_OR_RAISE(py_ldb, ldb);
-
-       /* see if we have a cached copy */
-       old_val = (int *)ldb_get_opaque(ldb, 
-                                       py_opaque_name);
-
-       if (old_val) {
-               *old_val = value;
-               Py_RETURN_NONE;
-       } 
-
-       tmp_ctx = talloc_new(ldb);
-       if (tmp_ctx == NULL) {
-               goto failed;
-       }
-       
-       new_val = talloc(tmp_ctx, int);
-       if (!new_val) {
-               goto failed;
-       }
-       
-       opaque_name_talloc = talloc_strdup(tmp_ctx, py_opaque_name);
-       if (!opaque_name_talloc) {
-               goto failed;
-       }
-       
-       *new_val = value;
-
-       /* cache the domain_sid in the ldb */
-       if (ldb_set_opaque(ldb, opaque_name_talloc, new_val) != LDB_SUCCESS) {
-               goto failed;
-       }
-
-       talloc_steal(ldb, new_val);
-       talloc_steal(ldb, opaque_name_talloc);
-       talloc_free(tmp_ctx);
-
-       Py_RETURN_NONE;
-
-failed:
-       talloc_free(tmp_ctx);
-       PyErr_SetString(PyExc_RuntimeError, "Failed to set opaque integer into the ldb!\n");
-       return NULL;
-}
-
 static PyObject *py_dsdb_set_global_schema(PyObject *self, PyObject *args)
 {
        PyObject *py_ldb;
@@ -486,11 +429,8 @@ static PyObject *py_dsdb_load_partition_usn(PyObject *self, PyObject *args)
 
 
        return result;
-
 }
 
-
-
 static PyObject *py_samdb_ntds_invocation_id(PyObject *self, PyObject *args)
 {
        PyObject *py_ldb, *result;
@@ -642,8 +582,6 @@ static PyMethodDef py_misc_methods[] = {
                "Set the right Samba casefolding function for UTF8 charset." },
        { "dsdb_set_ntds_invocation_id", (PyCFunction)py_dsdb_set_ntds_invocation_id, METH_VARARGS,
                NULL },
-       { "dsdb_set_opaque_integer", (PyCFunction)py_dsdb_set_opaque_integer, METH_VARARGS,
-               NULL },
        { "dsdb_set_global_schema", (PyCFunction)py_dsdb_set_global_schema, METH_VARARGS,
                NULL },
        { "dsdb_set_schema_from_ldif", (PyCFunction)py_dsdb_set_schema_from_ldif, METH_VARARGS,
index dd876f910d27ed6a5ed8c5949870fe1eaa7f4968..d122523f6166d0c972ae2734050eb95bdce7eebd 100644 (file)
@@ -321,7 +321,7 @@ class Ldb(ldb.Ldb):
         :param name: The name for the opaque value
         :param value: The integer value
         """
-        glue.dsdb_set_opaque_integer(self, name, value)
+        dsdb.dsdb_set_opaque_integer(self, name, value)
 
 
 def substitute_var(text, values):