s4/dsdb: Set schemaInfo attribute value during provisioning
authorKamen Mazdrashki <kamenim@samba.org>
Fri, 9 Apr 2010 07:48:20 +0000 (10:48 +0300)
committerKamen Mazdrashki <kamenim@samba.org>
Fri, 9 Apr 2010 09:21:34 +0000 (12:21 +0300)
After provisioning new Forest, schemaInfo should be set
to a value with revision=1 and current invocation_id

source4/dsdb/schema/schema_info_attr.c
source4/scripting/python/pyglue.c
source4/scripting/python/samba/__init__.py
source4/scripting/python/samba/provision.py

index ea4d066ff10998642e6435cd3298225764bc83df..bb89be117291e8b16e03f8ca422c423c6cb04bea 100644 (file)
@@ -354,6 +354,55 @@ WERROR dsdb_schema_info_create(struct ldb_context *ldb, bool check_invocation_id
 }
 
 
+/**
+ *
+ * @param ldb
+ * @param schema
+ * @return
+ */
+WERROR dsdb_schema_info_reset(struct ldb_context *ldb, struct dsdb_schema *schema)
+{
+       int ldb_err;
+       WERROR werr;
+       DATA_BLOB blob;
+       struct dsdb_schema_info *schema_info;
+       struct ldb_message *msg;
+       TALLOC_CTX *temp_ctx;
+
+       temp_ctx = talloc_new(ldb);
+       W_ERROR_HAVE_NO_MEMORY(temp_ctx);
+
+       /* create default schemaInfo value */
+       werr = dsdb_schema_info_create(ldb, true, temp_ctx, &schema_info);
+       W_ERROR_NOT_OK_GOTO(werr, DONE);
+
+       /* serialize schemaInfo to be stored in LDB and schema cache */
+       werr = dsdb_blob_from_schema_info(schema_info, temp_ctx, &blob);
+       W_ERROR_NOT_OK_GOTO(werr, DONE);
+
+       /* store initial schemaInfo in DB */
+       werr = _dsdb_schema_info_write_prepare(ldb, &blob, temp_ctx, &msg);
+       W_ERROR_NOT_OK_GOTO(werr, DONE);
+
+       ldb_err = dsdb_modify(ldb, msg, DSDB_MODIFY_PERMISSIVE);
+       if (ldb_err != 0) {
+               DEBUG(0,("dsdb_module_schema_info_blob_write: dsdb_replace failed: %s (%s)\n",
+                        ldb_strerror(ldb_err),
+                        ldb_errstring(ldb)));
+               werr = WERR_INTERNAL_DB_ERROR;
+               goto DONE;
+       }
+
+       /* update dsdb_schema cache */
+       talloc_free(discard_const(schema->schema_info));
+       schema->schema_info = data_blob_hex_string_upper(schema, &blob);
+
+DONE:
+       talloc_free(temp_ctx);
+       return werr;
+}
+
+
 /**
  * Increments schemaInfo revision and save it to DB
  * setting our invocationID in the process
index f08571463526950402f6212a40ddd776c7610c5f..a80dedc717750f0d713b8fdd882899f0d7431757 100644 (file)
@@ -159,6 +159,30 @@ static PyObject *py_dsdb_write_prefixes_from_schema_to_ldb(PyObject *self, PyObj
        Py_RETURN_NONE;
 }
 
+static PyObject *py_dsdb_schema_info_reset(PyObject *self, PyObject *args)
+{
+       PyObject *py_ldb;
+       struct ldb_context *ldb;
+       WERROR result;
+       struct dsdb_schema *schema;
+
+       if (!PyArg_ParseTuple(args, "O", &py_ldb))
+               return NULL;
+
+       PyErr_LDB_OR_RAISE(py_ldb, ldb);
+
+       schema = dsdb_get_schema(ldb, NULL);
+       if (!schema) {
+               PyErr_SetString(PyExc_RuntimeError, "Failed to set find a schema on ldb!\n");
+               return NULL;
+       }
+
+       result = dsdb_schema_info_reset(ldb, schema);
+       PyErr_WERROR_IS_ERR_RAISE(result);
+
+       Py_RETURN_NONE;
+}
+
 static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
 {
        PyObject *py_ldb;
@@ -253,6 +277,8 @@ static PyMethodDef py_misc_methods[] = {
                NULL },
        { "dsdb_write_prefixes_from_schema_to_ldb", (PyCFunction)py_dsdb_write_prefixes_from_schema_to_ldb, METH_VARARGS,
                NULL },
+       { "dsdb_schema_info_reset", (PyCFunction)py_dsdb_schema_info_reset, METH_VARARGS,
+               "Reset schemaInfo value to default for a new Forest" },
        { "dsdb_set_schema_from_ldb", (PyCFunction)py_dsdb_set_schema_from_ldb, METH_VARARGS,
                NULL },
        { "set_debug_level", (PyCFunction)py_set_debug_level, METH_VARARGS,
index d7fc05cabd00fd45be6e45cda3b5481c274bbc2d..682f40048bebe861a839ae752dc76090e44ac5e7 100644 (file)
@@ -283,6 +283,9 @@ class Ldb(_Ldb):
     def write_prefixes_from_schema(self):
         _glue.dsdb_write_prefixes_from_schema_to_ldb(self)
 
+    def set_schema_info(self):
+        _glue.dsdb_schema_info_reset(self)
+
     def convert_schema_to_openldap(self, target, mapping):
         return dsdb.dsdb_convert_schema_to_openldap(self, target, mapping)
 
index abbcf5221055b8da7c1203ade0de669ce818d03a..2e4aa34a8ce90826e2969e46c9c8c91cf40c4ce6 100644 (file)
@@ -945,6 +945,8 @@ def setup_samdb(path, setup_path, session_info, provision_backend, lp,
         message("Setting up sam.ldb schema")
         samdb.add_ldif(schema.schema_dn_add, controls=["relax:0"])
         samdb.modify_ldif(schema.schema_dn_modify)
+        # set schemaInfo to defalt value for a new Forest
+        samdb.set_schema_info()
         samdb.write_prefixes_from_schema()
         samdb.add_ldif(schema.schema_data, controls=["relax:0"])
         setup_add_ldif(samdb, setup_path("aggregate_schema.ldif"),