summaryrefslogtreecommitdiff
path: root/source4/dsdb/schema
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-10-21 12:47:57 +1100
committerAndrew Tridgell <tridge@samba.org>2010-10-21 19:03:25 +1100
commit47591ea5ec03916393d22484e3b551da033260ea (patch)
tree9beda732635d7fe5e630393a1e9c6d7e3c43e804 /source4/dsdb/schema
parentcffbccb5cb0046bc9713de5d5a89d7f8236888f4 (diff)
downloadsamba-47591ea5ec03916393d22484e3b551da033260ea.tar.gz
samba-47591ea5ec03916393d22484e3b551da033260ea.tar.bz2
samba-47591ea5ec03916393d22484e3b551da033260ea.zip
s4-dsdb: moved a bunch of fuctions from schema/schema_info_attr.c to samdb/ldb_modules/schema_util.c
these functions operate on ldb_modules, so they should be in the ldb_modules directory. They also should return ldb errors codes, not WERROR codes, as otherwise the error can be hidden from the ldap caller This re-arrangement fixes a dependency loop in the schema/samdb code. Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org> Pair-Programmed-With: Kamen Mazdrashki <kamenim@samba.org>
Diffstat (limited to 'source4/dsdb/schema')
-rw-r--r--source4/dsdb/schema/schema_info_attr.c268
1 files changed, 0 insertions, 268 deletions
diff --git a/source4/dsdb/schema/schema_info_attr.c b/source4/dsdb/schema/schema_info_attr.c
index 0b5d50b529..31658e210b 100644
--- a/source4/dsdb/schema/schema_info_attr.c
+++ b/source4/dsdb/schema/schema_info_attr.c
@@ -206,271 +206,3 @@ WERROR dsdb_schema_info_cmp(const struct dsdb_schema *schema,
}
-/**
- * Reads schema_info structure from schemaInfo
- * attribute on SCHEMA partition
- *
- * @param dsdb_flags DSDB_FLAG_... flag of 0
- */
-WERROR dsdb_module_schema_info_blob_read(struct ldb_module *ldb_module,
- uint32_t dsdb_flags,
- TALLOC_CTX *mem_ctx, DATA_BLOB *schema_info_blob)
-{
- int ldb_err;
- const struct ldb_val *blob_val;
- struct ldb_dn *schema_dn;
- struct ldb_result *schema_res = NULL;
- static const char *schema_attrs[] = {
- "schemaInfo",
- NULL
- };
-
- schema_dn = ldb_get_schema_basedn(ldb_module_get_ctx(ldb_module));
- if (!schema_dn) {
- DEBUG(0,("dsdb_module_schema_info_blob_read: no schema dn present!\n"));
- return WERR_INTERNAL_DB_CORRUPTION;
- }
-
- ldb_err = dsdb_module_search(ldb_module, mem_ctx, &schema_res, schema_dn,
- LDB_SCOPE_BASE, schema_attrs, dsdb_flags, NULL);
- if (ldb_err == LDB_ERR_NO_SUCH_OBJECT) {
- DEBUG(0,("dsdb_module_schema_info_blob_read: Schema DN not found!\n"));
- talloc_free(schema_res);
- return WERR_INTERNAL_DB_CORRUPTION;
- } else if (ldb_err != LDB_SUCCESS) {
- DEBUG(0,("dsdb_module_schema_info_blob_read: failed to find schemaInfo attribute\n"));
- talloc_free(schema_res);
- return WERR_INTERNAL_DB_CORRUPTION;
- }
-
- blob_val = ldb_msg_find_ldb_val(schema_res->msgs[0], "schemaInfo");
- if (!blob_val) {
- DEBUG(0,("dsdb_module_schema_info_blob_read: no schemaInfo attribute found\n"));
- talloc_free(schema_res);
- return WERR_DS_NO_ATTRIBUTE_OR_VALUE;
- }
-
- /* transfer .data ownership to mem_ctx */
- schema_info_blob->length = blob_val->length;
- schema_info_blob->data = talloc_steal(mem_ctx, blob_val->data);
-
- talloc_free(schema_res);
-
- return WERR_OK;
-}
-
-/**
- * Prepares ldb_msg to be used for updating schemaInfo value in DB
- */
-static WERROR _dsdb_schema_info_write_prepare(struct ldb_context *ldb,
- DATA_BLOB *schema_info_blob,
- TALLOC_CTX *mem_ctx,
- struct ldb_message **_msg)
-{
- int ldb_err;
- struct ldb_message *msg;
- struct ldb_dn *schema_dn;
- struct ldb_message_element *return_el;
-
- schema_dn = ldb_get_schema_basedn(ldb);
- if (!schema_dn) {
- DEBUG(0,("_dsdb_schema_info_write_prepare: no schema dn present\n"));
- return WERR_INTERNAL_DB_CORRUPTION;
- }
-
- /* prepare ldb_msg to update schemaInfo */
- msg = ldb_msg_new(mem_ctx);
- W_ERROR_HAVE_NO_MEMORY(msg);
-
- msg->dn = schema_dn;
- ldb_err = ldb_msg_add_value(msg, "schemaInfo", schema_info_blob, &return_el);
- if (ldb_err != 0) {
- DEBUG(0,("_dsdb_schema_info_write_prepare: ldb_msg_add_value failed - %s\n",
- ldb_strerror(ldb_err)));
- talloc_free(msg);
- return WERR_INTERNAL_ERROR;
- }
-
- /* mark schemaInfo element for replacement */
- return_el->flags = LDB_FLAG_MOD_REPLACE;
-
- *_msg = msg;
-
- return WERR_OK;
-}
-
-/**
- * Writes schema_info structure into schemaInfo
- * attribute on SCHEMA partition
- *
- * @param dsdb_flags DSDB_FLAG_... flag of 0
- */
-WERROR dsdb_module_schema_info_blob_write(struct ldb_module *ldb_module,
- uint32_t dsdb_flags,
- DATA_BLOB *schema_info_blob)
-{
- int ldb_err;
- WERROR werr;
- struct ldb_message *msg;
- TALLOC_CTX *temp_ctx;
-
- temp_ctx = talloc_new(ldb_module);
- W_ERROR_HAVE_NO_MEMORY(temp_ctx);
-
- /* write serialized schemaInfo into LDB */
- werr = _dsdb_schema_info_write_prepare(ldb_module_get_ctx(ldb_module),
- schema_info_blob,
- temp_ctx, &msg);
- if (!W_ERROR_IS_OK(werr)) {
- talloc_free(temp_ctx);
- return werr;
- }
-
-
- ldb_err = dsdb_module_modify(ldb_module, msg, dsdb_flags);
-
- talloc_free(temp_ctx);
-
- if (ldb_err != 0) {
- DEBUG(0,("dsdb_module_schema_info_blob_write: dsdb_replace failed: %s (%s)\n",
- ldb_strerror(ldb_err),
- ldb_errstring(ldb_module_get_ctx(ldb_module))));
- return WERR_INTERNAL_DB_ERROR;
- }
-
- return WERR_OK;
-}
-
-
-/**
- * Reads schema_info structure from schemaInfo
- * attribute on SCHEMA partition
- */
-static WERROR dsdb_module_schema_info_read(struct ldb_module *ldb_module,
- uint32_t dsdb_flags,
- TALLOC_CTX *mem_ctx,
- struct dsdb_schema_info **_schema_info)
-{
- WERROR werr;
- DATA_BLOB ndr_blob;
- TALLOC_CTX *temp_ctx;
-
- temp_ctx = talloc_new(mem_ctx);
- W_ERROR_HAVE_NO_MEMORY(temp_ctx);
-
- /* read serialized schemaInfo from LDB */
- werr = dsdb_module_schema_info_blob_read(ldb_module, dsdb_flags, temp_ctx, &ndr_blob);
- if (!W_ERROR_IS_OK(werr)) {
- talloc_free(temp_ctx);
- return werr;
- }
-
- /* convert NDR blob to dsdb_schema_info object */
- werr = dsdb_schema_info_from_blob(&ndr_blob,
- mem_ctx,
- _schema_info);
- talloc_free(temp_ctx);
-
- return werr;
-}
-
-/**
- * Writes schema_info structure into schemaInfo
- * attribute on SCHEMA partition
- *
- * @param dsdb_flags DSDB_FLAG_... flag of 0
- */
-static WERROR dsdb_module_schema_info_write(struct ldb_module *ldb_module,
- uint32_t dsdb_flags,
- const struct dsdb_schema_info *schema_info)
-{
- WERROR werr;
- DATA_BLOB ndr_blob;
- TALLOC_CTX *temp_ctx;
-
- temp_ctx = talloc_new(ldb_module);
- W_ERROR_HAVE_NO_MEMORY(temp_ctx);
-
- /* convert schema_info to a blob */
- werr = dsdb_blob_from_schema_info(schema_info, temp_ctx, &ndr_blob);
- if (!W_ERROR_IS_OK(werr)) {
- talloc_free(temp_ctx);
- return werr;
- }
-
- /* write serialized schemaInfo into LDB */
- werr = dsdb_module_schema_info_blob_write(ldb_module, dsdb_flags, &ndr_blob);
-
- talloc_free(temp_ctx);
-
- return werr;
-}
-
-
-/**
- * Increments schemaInfo revision and save it to DB
- * setting our invocationID in the process
- * NOTE: this function should be called in a transaction
- * much in the same way prefixMap update function is called
- *
- * @param ldb_module current module
- * @param schema schema cache
- * @param dsdb_flags DSDB_FLAG_... flag of 0
- */
-WERROR dsdb_module_schema_info_update(struct ldb_module *ldb_module,
- struct dsdb_schema *schema,
- int dsdb_flags)
-{
- WERROR werr;
- const struct GUID *invocation_id;
- DATA_BLOB ndr_blob;
- struct dsdb_schema_info *schema_info;
- const char *schema_info_str;
-
- TALLOC_CTX *temp_ctx = talloc_new(schema);
- W_ERROR_HAVE_NO_MEMORY(temp_ctx);
-
- invocation_id = samdb_ntds_invocation_id(ldb_module_get_ctx(ldb_module));
- if (!invocation_id) {
- return WERR_INTERNAL_DB_CORRUPTION;
- }
-
- /* read serialized schemaInfo from LDB */
- werr = dsdb_module_schema_info_read(ldb_module, dsdb_flags, temp_ctx, &schema_info);
- if (W_ERROR_EQUAL(werr, WERR_DS_NO_ATTRIBUTE_OR_VALUE)) {
- /* make default value in case
- * we have no schemaInfo value yet */
- werr = dsdb_schema_info_new(temp_ctx, &schema_info);
- }
- if (!W_ERROR_IS_OK(werr)) {
- DEBUG(0,("dsdb_module_schema_info_update: failed to reload schemaInfo - %s\n",
- win_errstr(werr)));
- talloc_free(temp_ctx);
- return werr;
- }
-
- /* update schemaInfo */
- schema_info->revision++;
- schema_info->invocation_id = *invocation_id;
-
- werr = dsdb_module_schema_info_write(ldb_module, dsdb_flags, schema_info);
- if (!W_ERROR_IS_OK(werr)) {
- DEBUG(0,("dsdb_module_schema_info_update: failed to save schemaInfo - %s\n",
- win_errstr(werr)));
- talloc_free(temp_ctx);
- return werr;
- }
-
- /* finally, update schema_info in the cache */
- werr = dsdb_blob_from_schema_info(schema_info, temp_ctx, &ndr_blob);
- W_ERROR_NOT_OK_RETURN(werr);
-
- schema_info_str = hex_encode_talloc(schema, ndr_blob.data, ndr_blob.length);
- W_ERROR_HAVE_NO_MEMORY(schema_info_str);
-
- talloc_unlink(schema, discard_const(schema->schema_info));
- schema->schema_info = schema_info_str;
-
- talloc_free(temp_ctx);
- return WERR_OK;
-}