s4:schema Allow a schema load on an unconnected database
authorAndrew Bartlett <abartlet@samba.org>
Thu, 13 Aug 2009 04:33:57 +0000 (14:33 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Sun, 16 Aug 2009 23:50:56 +0000 (09:50 +1000)
This helps ensure we don't load the schema too often in the provision
(allowing a reference in of the schema before the modules load).

Andrew Bartlett

source4/dsdb/schema/schema_set.c
source4/scripting/python/pyglue.c

index 630c0ba184e2f99a79b9d5683d0cfb09cf285ae5..6745bde127fd774a10f811b37caeb8912e9e5019 100644 (file)
@@ -139,7 +139,7 @@ static int dsdb_schema_set_attributes(struct ldb_context *ldb, struct dsdb_schem
                }
        }
 
-       if (ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS) {
+       if (ret == LDB_ERR_OPERATIONS_ERROR || ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS) {
                /* We might be on a read-only DB */
                ret = LDB_SUCCESS;
        }
@@ -166,7 +166,7 @@ static int dsdb_schema_set_attributes(struct ldb_context *ldb, struct dsdb_schem
                        ret = samdb_replace(ldb, mem_ctx, mod_msg);
                }
        }
-       if (ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS) {
+       if (ret == LDB_ERR_OPERATIONS_ERROR || ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS) {
                /* We might be on a read-only DB */
                ret = LDB_SUCCESS;
        }
@@ -372,7 +372,8 @@ static struct dsdb_schema *global_schema;
 /**
  * Make this ldb use a specified schema, already fully calculated and belonging to another ldb
  */
-int dsdb_reference_schema(struct ldb_context *ldb, struct dsdb_schema *schema)
+int dsdb_reference_schema(struct ldb_context *ldb, struct dsdb_schema *schema,
+                         bool write_attributes)
 {
        int ret;
        ret = ldb_set_opaque(ldb, "dsdb_schema", schema);
@@ -381,7 +382,7 @@ int dsdb_reference_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, false);
+       ret = dsdb_schema_set_attributes(ldb, schema, write_attributes);
        if (ret != LDB_SUCCESS) {
                return ret;
        }
@@ -403,7 +404,7 @@ int dsdb_set_global_schema(struct ldb_context *ldb)
                return LDB_SUCCESS;
        }
 
-       return dsdb_reference_schema(ldb, global_schema);
+       return dsdb_reference_schema(ldb, global_schema, false /* Don't write attributes, it's expensive */);
 }
 
 /**
index 36aae9ccef62b77d1728eb78cec85bcd3a3759fe..d4db55431fe043b3ad7ff5c4bcf5199f31484902 100644 (file)
@@ -348,7 +348,7 @@ static PyObject *py_dsdb_set_schema_from_ldb(PyObject *self, PyObject *args)
                return NULL;
        }
 
-       ret = dsdb_reference_schema(ldb, schema);
+       ret = dsdb_reference_schema(ldb, schema, true);
        PyErr_LDB_ERROR_IS_ERR_RAISE(py_ldb_get_exception(), ret, ldb);
 
        Py_RETURN_NONE;