s4-dsdb: Explain better what records are written during schema set
authorAndrew Bartlett <abartlet@samba.org>
Thu, 9 Aug 2012 22:44:04 +0000 (08:44 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 10 Aug 2012 00:18:28 +0000 (10:18 +1000)
This is controlled by setting write_indices_and_attributes.

Andrew Bartlett

source4/dsdb/pydsdb.c
source4/dsdb/schema/schema_set.c
source4/scripting/python/samba/provision/__init__.py
source4/scripting/python/samba/samdb.py

index 9023d69054b401b4672c7d341fc7c0326e3e64ac..39229f487f574c10aa1a0a35d76fa13777edca24 100644 (file)
@@ -873,9 +873,9 @@ static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
        struct ldb_context *from_ldb;
        struct dsdb_schema *schema;
        int ret;
-       char write_attributes = true;
+       char write_indices_and_attributes = true;
        if (!PyArg_ParseTuple(args, "OO|b",
-                             &py_ldb, &py_from_ldb, &write_attributes))
+                             &py_ldb, &py_from_ldb, &write_indices_and_attributes))
                return NULL;
 
        PyErr_LDB_OR_RAISE(py_ldb, ldb);
@@ -888,7 +888,7 @@ static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
                return NULL;
        }
 
-       ret = dsdb_reference_schema(ldb, schema, write_attributes);
+       ret = dsdb_reference_schema(ldb, schema, write_indices_and_attributes);
        PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
 
        Py_RETURN_NONE;
index 286a8a3f23f5f4c8b966dfdb551b3f8832c4d3b7..e226118b4c565cdc87dcde7922a29e12c4577532 100644 (file)
@@ -50,8 +50,13 @@ const struct ldb_schema_attribute *dsdb_attribute_handler_override(struct ldb_co
        }
        return a->ldb_schema_attribute;
 }
-
-static int dsdb_schema_set_attributes(struct ldb_context *ldb, struct dsdb_schema *schema, bool write_attributes)
+/*
+ * Set the attribute handlers onto the LDB, and potentially write the
+ * @INDEXLIST, @IDXONE and @ATTRIBUTES records.  The @ATTRIBUTES records
+ * are required so we can operate on a schema-less database (say the
+ * backend during emergency fixes) and during the schema load.
+ */
+static int dsdb_schema_set_indices_and_attributes(struct ldb_context *ldb, struct dsdb_schema *schema, bool write_indices_and_attributes)
 {
        int ret = LDB_SUCCESS;
        struct ldb_result *res;
@@ -65,7 +70,7 @@ static int dsdb_schema_set_attributes(struct ldb_context *ldb, struct dsdb_schem
        /* setup our own attribute name to schema handler */
        ldb_schema_attribute_set_override_handler(ldb, dsdb_attribute_handler_override, schema);
 
-       if (!write_attributes) {
+       if (!write_indices_and_attributes) {
                return ret;
        }
 
@@ -454,7 +459,7 @@ int dsdb_set_schema(struct ldb_context *ldb, struct dsdb_schema *schema)
        }
 
        /* Set the new attributes based on the new schema */
-       ret = dsdb_schema_set_attributes(ldb, schema, true);
+       ret = dsdb_schema_set_indices_and_attributes(ldb, schema, true);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
@@ -469,9 +474,13 @@ static struct dsdb_schema *global_schema;
 
 /**
  * Make this ldb use a specified schema, already fully calculated and belonging to another ldb
+ *
+ * The write_indices_and_attributes controls writing of the @ records
+ * because we cannot write to a database that does not yet exist on
+ * disk.
  */
 int dsdb_reference_schema(struct ldb_context *ldb, struct dsdb_schema *schema,
-                         bool write_attributes)
+                         bool write_indices_and_attributes)
 {
        int ret;
        struct dsdb_schema *old_schema;
@@ -495,7 +504,7 @@ int dsdb_reference_schema(struct ldb_context *ldb, struct dsdb_schema *schema,
                return ret;
        }
 
-       ret = dsdb_schema_set_attributes(ldb, schema, write_attributes);
+       ret = dsdb_schema_set_indices_and_attributes(ldb, schema, write_indices_and_attributes);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
@@ -519,7 +528,7 @@ int dsdb_set_global_schema(struct ldb_context *ldb)
        }
 
        /* Set the new attributes based on the new schema */
-       ret = dsdb_schema_set_attributes(ldb, global_schema, false /* Don't write attributes, it's expensive */);
+       ret = dsdb_schema_set_indices_and_attributes(ldb, global_schema, false /* Don't write indices and attributes, it's expensive */);
        if (ret == LDB_SUCCESS) {
                /* Keep a reference to this schema, just in case the original copy is replaced */
                if (talloc_reference(ldb, global_schema) == NULL) {
index 94e857e9f4298467ef86d144805555f60e4ff6f8..6834d40eb48000eb1e5df9f29899152cb28298e1 100644 (file)
@@ -1121,7 +1121,7 @@ def setup_samdb(path, session_info, provision_backend, lp, names,
     logger.info("Pre-loading the Samba 4 and AD schema")
 
     # Load the schema from the one we computed earlier
-    samdb.set_schema(schema, write_attributes=False)
+    samdb.set_schema(schema, write_indices_and_attributes=False)
 
     # Set the NTDS settings DN manually - in order to have it already around
     # before the provisioned tree exists and we connect
@@ -1133,8 +1133,8 @@ def setup_samdb(path, session_info, provision_backend, lp, names,
 
     # But we have to give it one more kick to have it use the schema
     # during provision - it needs, now that it is connected, to write
-    # the schema @INDEX records to the database.
-    samdb.set_schema(schema, write_attributes=True)
+    # the schema @ATTRIBUTES and @INDEXLIST records to the database.
+    samdb.set_schema(schema, write_indices_and_attributes=True)
 
     return samdb
 
index 3355e9a58986cf9c1fa3ac8804513611fff42fb4..7db1b00754207fae61253ef677f390c835516a40 100644 (file)
@@ -608,11 +608,11 @@ accountExpires: %u
     def load_partition_usn(self, base_dn):
         return dsdb._dsdb_load_partition_usn(self, base_dn)
 
-    def set_schema(self, schema, write_attributes=True):
-        self.set_schema_from_ldb(schema.ldb, write_attributes=write_attributes)
+    def set_schema(self, schema, write_indices_and_attributes=True):
+        self.set_schema_from_ldb(schema.ldb, write_indices_and_attributes=write_indices_and_attributes)
 
-    def set_schema_from_ldb(self, ldb_conn, write_attributes=True):
-        dsdb._dsdb_set_schema_from_ldb(self, ldb_conn, write_attributes)
+    def set_schema_from_ldb(self, ldb_conn, write_indices_and_attributes=True):
+        dsdb._dsdb_set_schema_from_ldb(self, ldb_conn, write_indices_and_attributes)
 
     def dsdb_DsReplicaAttribute(self, ldb, ldap_display_name, ldif_elements):
         '''convert a list of attribute values to a DRSUAPI DsReplicaAttribute'''