Add a way to set an opaque integer onto a samdb
authorAndrew Bartlett <abartlet@samba.org>
Mon, 13 Jul 2009 22:00:09 +0000 (08:00 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 15 Jul 2009 23:23:35 +0000 (09:23 +1000)
This will allow us to set some more flags into ldb during the provision.

source4/scripting/python/pyglue.c
source4/scripting/python/samba/samdb.py

index 5816d9637d8e3a973474c4e4ad91da86f01f5859..abd018f6fc67b46c6a68d810a00ac03ad68bcf2d 100644 (file)
@@ -204,6 +204,63 @@ 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;
@@ -284,6 +341,8 @@ static PyMethodDef py_misc_methods[] = {
                "Register Samba-specific LDB modules and schemas." },
        { "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_attach_schema_from_ldif", (PyCFunction)py_dsdb_attach_schema_from_ldif, METH_VARARGS,
index bc76cd3c5fdbbf576c590234cb880fa336112af1..6cb24698462de17c3e4acc5e1e311a506556e287 100644 (file)
@@ -231,6 +231,14 @@ userPassword:: %s
         """
         glue.dsdb_set_ntds_invocation_id(self, invocation_id)
 
+    def set_opaque_integer(self, name, value):
+        """Set an integer as an opaque (a flag or other value) value on the database
+        
+        :param name: The name for the opaque value
+        :param value: The integer value
+        """
+        glue.dsdb_set_opaque_integer(self, name, value)
+
     def setexpiry(self, user, expiry_seconds, noexpiry):
         """Set the account expiry for a user