diff options
author | Andrew Bartlett <abartlet@samba.org> | 2010-03-22 16:03:33 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2010-03-22 20:24:41 +1100 |
commit | fe3e1af901c970f738bee92baac5d7d4f5736e17 (patch) | |
tree | 88666ac36e3d7041b24592600f361c412aaa5c3f /source4/dsdb/schema | |
parent | d0b54476fc9f855d1e482597538a7ec60e04f331 (diff) | |
download | samba-fe3e1af901c970f738bee92baac5d7d4f5736e17.tar.gz samba-fe3e1af901c970f738bee92baac5d7d4f5736e17.tar.bz2 samba-fe3e1af901c970f738bee92baac5d7d4f5736e17.zip |
s4:dsdb Rework schema loading and add schema reloading
This commit reworks Samba4's schema loading code to detect when it
needs to reload the schema. This is done by watching the @REPLCHANGED
special DN.
The reload happens by means of a callback, which is only set when the
schema is loaded from the ldb - not when loaded from an LDIF file or
DRS.
We also rework the global schema handling - instead of storing the
pointer to the global schema in each ldb, we store a flag indicating
that the global schema should be returned at run time. This makes it
much easier to switch to a new global schema.
Andrew Bartlett
Diffstat (limited to 'source4/dsdb/schema')
-rw-r--r-- | source4/dsdb/schema/schema_set.c | 80 |
1 files changed, 55 insertions, 25 deletions
diff --git a/source4/dsdb/schema/schema_set.c b/source4/dsdb/schema/schema_set.c index e8fe7c4c65..1c7d39aa53 100644 --- a/source4/dsdb/schema/schema_set.c +++ b/source4/dsdb/schema/schema_set.c @@ -357,6 +357,11 @@ int dsdb_set_schema(struct ldb_context *ldb, struct dsdb_schema *schema) return ret; } + ret = ldb_set_opaque(ldb, "dsdb_use_global_schema", NULL); + if (ret != LDB_SUCCESS) { + return ret; + } + /* Set the new attributes based on the new schema */ ret = dsdb_schema_set_attributes(ldb, schema, true); if (ret != LDB_SUCCESS) { @@ -385,17 +390,6 @@ int dsdb_reference_schema(struct ldb_context *ldb, struct dsdb_schema *schema, return ret; } - /* Set the new attributes based on the new schema */ - ret = dsdb_schema_set_attributes(ldb, schema, write_attributes); - if (ret != LDB_SUCCESS) { - return ret; - } - - /* Keep a reference to this schema, just incase the original copy is replaced */ - if (talloc_reference(ldb, schema) == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - return LDB_SUCCESS; } @@ -404,11 +398,27 @@ int dsdb_reference_schema(struct ldb_context *ldb, struct dsdb_schema *schema, */ int dsdb_set_global_schema(struct ldb_context *ldb) { + int ret; + void *use_global_schema = (void *)1; if (!global_schema) { return LDB_SUCCESS; } - return dsdb_reference_schema(ldb, global_schema, false /* Don't write attributes, it's expensive */); + ret = ldb_set_opaque(ldb, "dsdb_use_global_schema", use_global_schema); + if (ret != LDB_SUCCESS) { + return ret; + } + + /* 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 */); + if (ret == LDB_SUCCESS) { + /* Keep a reference to this schema, just incase the original copy is replaced */ + if (talloc_reference(ldb, global_schema) == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + } + + return ret; } /** @@ -420,23 +430,41 @@ int dsdb_set_global_schema(struct ldb_context *ldb) struct dsdb_schema *dsdb_get_schema(struct ldb_context *ldb, TALLOC_CTX *reference_ctx) { const void *p; - struct dsdb_schema *schema; + struct dsdb_schema *schema_out; + struct dsdb_schema *schema_in; + bool use_global_schema; /* see if we have a cached copy */ - p = ldb_get_opaque(ldb, "dsdb_schema"); - if (!p) { - return NULL; + use_global_schema = (ldb_get_opaque(ldb, "dsdb_use_global_schema") != NULL); + if (use_global_schema) { + schema_in = global_schema; + } else { + p = ldb_get_opaque(ldb, "dsdb_schema"); + + schema_in = talloc_get_type(p, struct dsdb_schema); + if (!schema_in) { + return NULL; + } } - schema = talloc_get_type(p, struct dsdb_schema); - if (!schema) { - return NULL; + if (schema_in->refresh_fn && !schema_in->refresh_in_progress) { + schema_in->refresh_in_progress = true; + /* This may change schema, if it needs to reload it from disk */ + schema_out = schema_in->refresh_fn(schema_in->loaded_from_module, + schema_in, + use_global_schema); + schema_in->refresh_in_progress = false; + if (schema_out != schema_in) { + talloc_unlink(schema_in, ldb); + } + } else { + schema_out = schema_in; } if (!reference_ctx) { - return schema; + return schema_out; } else { - return talloc_reference(reference_ctx, schema); + return talloc_reference(reference_ctx, schema_out); } } @@ -444,9 +472,8 @@ struct dsdb_schema *dsdb_get_schema(struct ldb_context *ldb, TALLOC_CTX *referen * Make the schema found on this ldb the 'global' schema */ -void dsdb_make_schema_global(struct ldb_context *ldb) +void dsdb_make_schema_global(struct ldb_context *ldb, struct dsdb_schema *schema) { - struct dsdb_schema *schema = dsdb_get_schema(ldb, NULL); if (!schema) { return; } @@ -455,11 +482,14 @@ void dsdb_make_schema_global(struct ldb_context *ldb) talloc_unlink(talloc_autofree_context(), global_schema); } - /* we want the schema to be around permanently */ - talloc_reparent(talloc_parent(schema), talloc_autofree_context(), schema); + /* Wipe any reference to the exact schema - we will set 'use the global schema' below */ + ldb_set_opaque(ldb, "dsdb_schema", NULL); + /* we want the schema to be around permanently */ + talloc_reparent(ldb, talloc_autofree_context(), schema); global_schema = schema; + /* This calls the talloc_reference() of the global schema back onto the ldb */ dsdb_set_global_schema(ldb); } |