return schema;
}
- ret = dsdb_set_schema(ldb, new_schema);
+ ret = dsdb_set_schema(ldb, new_schema, false);
if (ret != LDB_SUCCESS) {
ldb_debug_set(ldb, LDB_DEBUG_FATAL,
"dsdb_set_schema() failed: %d:%s: %s",
}
/* "dsdb_set_schema()" steals schema into the ldb_context */
- ret = dsdb_set_schema(ldb, new_schema);
+ ret = dsdb_set_schema(ldb, new_schema, false);
if (ret != LDB_SUCCESS) {
ldb_debug_set(ldb, LDB_DEBUG_FATAL,
"schema_load_init: dsdb_set_schema() failed: %d:%s: %s",
return LDB_ERR_OPERATIONS_ERROR;
}
+ /* Now check the @INDEXLIST is correct, or fix it up */
+ ret = dsdb_schema_set_indices_and_attributes(ldb, schema,
+ true);
+ if (ret != LDB_SUCCESS) {
+ ldb_asprintf_errstring(ldb, "Failed to update "
+ "@INDEXLIST and @ATTRIBUTES "
+ "records to match database schema: %s",
+ ldb_errstring(ldb));
+ return ret;
+ }
+
return ret;
}
static int schema_load_extended(struct ldb_module *module, struct ldb_request *req)
{
struct ldb_context *ldb = ldb_module_get_ctx(module);
-
+ struct dsdb_schema *schema;
+ int ret;
+
if (strcmp(req->op.extended.oid, DSDB_EXTENDED_SCHEMA_UPDATE_NOW_OID) != 0) {
return ldb_next_request(module, req);
}
/* Force a refresh */
- dsdb_get_schema(ldb, NULL);
+ schema = dsdb_get_schema(ldb, NULL);
+ ret = dsdb_schema_set_indices_and_attributes(ldb,
+ schema,
+ true);
+
+ if (ret != LDB_SUCCESS) {
+ ldb_asprintf_errstring(ldb, "Failed to write new "
+ "@INDEXLIST and @ATTRIBUTES "
+ "records for updated schema: %s",
+ ldb_errstring(ldb));
+ return ret;
+ }
+
/* Pass to next module, the partition one should finish the chain */
return ldb_next_request(module, req);
}
* 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 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;
* Attach the schema to an opaque pointer on the ldb,
* so ldb modules can find it
*/
-int dsdb_set_schema(struct ldb_context *ldb, struct dsdb_schema *schema)
+int dsdb_set_schema(struct ldb_context *ldb,
+ struct dsdb_schema *schema,
+ bool write_indices_and_attributes)
{
struct dsdb_schema *old_schema;
int ret;
talloc_steal(ldb, schema);
/* Set the new attributes based on the new schema */
- ret = dsdb_schema_set_indices_and_attributes(ldb, schema, true);
+ ret = dsdb_schema_set_indices_and_attributes(ldb, schema,
+ write_indices_and_attributes);
if (ret != LDB_SUCCESS) {
return ret;
}
}
}
- ret = dsdb_set_schema(ldb, schema);
+ ret = dsdb_set_schema(ldb, schema, true);
if (ret != LDB_SUCCESS) {
status = WERR_FOOBAR;
goto failed;
ldb_ldif_read_free(ldb, ldif);
torture_assert_werr_ok(tctx, werr, "dsdb_set_attribute_from_ldb() failed!");
- ldb_res = dsdb_set_schema(ldb, schema);
+ ldb_res = dsdb_set_schema(ldb, schema, true);
torture_assert_int_equal(tctx, ldb_res, LDB_SUCCESS, "dsdb_set_schema() failed");
return true;
* attach the schema we just brought over DRS to the ldb,
* so we can use it in dsdb_convert_object_ex below
*/
- ret = dsdb_set_schema(s->ldb, s->self_made_schema);
+ ret = dsdb_set_schema(s->ldb, s->self_made_schema, true);
if (ret != LDB_SUCCESS) {
DEBUG(0,("Failed to attach working schema from DRS.\n"));
return WERR_INTERNAL_ERROR;
talloc_free(res);
- ret = dsdb_set_schema(ldb, ldap_schema);
+ ret = dsdb_set_schema(ldb, ldap_schema, true);
if (ret != LDB_SUCCESS) {
torture_fail(tctx,
talloc_asprintf(tctx, "dsdb_set_schema() failed: %s", ldb_strerror(ret)));