/** * 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, bool write_attributes) { int ret; struct dsdb_schema *old_schema; old_schema = ldb_get_opaque(ldb, "dsdb_schema"); ret = ldb_set_opaque(ldb, "dsdb_schema", schema); if (ret != LDB_SUCCESS) { return ret; } /* Remove the reference to the schema we just overwrote - if there was * none, NULL is harmless here */ talloc_unlink(ldb, old_schema); if (talloc_reference(ldb, schema) == NULL) { return ldb_oom(ldb); } /* Make this ldb use local schema preferably */ ret = ldb_set_opaque(ldb, "dsdb_use_global_schema", NULL); if (ret != LDB_SUCCESS) { return ret; } ret = dsdb_schema_set_attributes(ldb, schema, write_attributes); if (ret != LDB_SUCCESS) { return ret; } return LDB_SUCCESS; }
int dsdb_set_schema(struct ldb_context *ldb, struct dsdb_schema *schema) { int ret; ret = dsdb_setup_sorted_accessors(ldb, schema); if (ret != LDB_SUCCESS) { return ret; } ret = schema_fill_constructed(schema); if (ret != LDB_SUCCESS) { return ret; } ret = ldb_set_opaque(ldb, "dsdb_schema", schema); 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) { return ret; } talloc_steal(ldb, schema); return LDB_SUCCESS; }
/** * 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, bool write_attributes) { int ret; ret = ldb_set_opaque(ldb, "dsdb_schema", schema); if (ret != LDB_SUCCESS) { 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; }
/** * Make this ldb use the 'global' schema, setup to avoid having multiple copies in this process */ int dsdb_set_global_schema(struct ldb_context *ldb) { int ret; void *use_global_schema = (void *)1; if (!global_schema) { return LDB_SUCCESS; } 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 in case the original copy is replaced */ if (talloc_reference(ldb, global_schema) == NULL) { return ldb_oom(ldb); } } return ret; }
/** * 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) { struct dsdb_schema *old_schema; int ret; ret = dsdb_setup_sorted_accessors(ldb, schema); if (ret != LDB_SUCCESS) { return ret; } old_schema = ldb_get_opaque(ldb, "dsdb_schema"); ret = ldb_set_opaque(ldb, "dsdb_schema", schema); if (ret != LDB_SUCCESS) { return ret; } /* Remove the reference to the schema we just overwrote - if there was * none, NULL is harmless here */ if (old_schema != schema) { talloc_unlink(ldb, old_schema); talloc_steal(ldb, schema); } 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) { return ret; } return LDB_SUCCESS; }