summaryrefslogtreecommitdiff
path: root/source4/dsdb
diff options
context:
space:
mode:
authorKamen Mazdrashki <kamenim@samba.org>2010-04-08 10:23:13 +0300
committerKamen Mazdrashki <kamenim@samba.org>2010-04-09 12:21:33 +0300
commit4ba2ac073d7a7859ab73f8b7f40d630ddbff8687 (patch)
tree84e97425c83f3a052ac5957ec9818fe81ddfa9ea /source4/dsdb
parentfbef33fb7369f57e6851d3766f87c953ca2d26bd (diff)
downloadsamba-4ba2ac073d7a7859ab73f8b7f40d630ddbff8687.tar.gz
samba-4ba2ac073d7a7859ab73f8b7f40d630ddbff8687.tar.bz2
samba-4ba2ac073d7a7859ab73f8b7f40d630ddbff8687.zip
s4/dsdb: split writing of schemaInfo blob in two parts
ldb_msg preparation is moved into separate function so that it can be used for implementing schemaInfo updates both on module stack (dsdb_module_... functions) and directly on ldb_context
Diffstat (limited to 'source4/dsdb')
-rw-r--r--source4/dsdb/schema/schema_info_attr.c67
1 files changed, 46 insertions, 21 deletions
diff --git a/source4/dsdb/schema/schema_info_attr.c b/source4/dsdb/schema/schema_info_attr.c
index 21ffb1d79f..ea4d066ff1 100644
--- a/source4/dsdb/schema/schema_info_attr.c
+++ b/source4/dsdb/schema/schema_info_attr.c
@@ -172,6 +172,46 @@ WERROR dsdb_module_schema_info_blob_read(struct ldb_module *ldb_module,
}
/**
+ * Pepares 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 = samdb_schema_dn(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
*
@@ -182,37 +222,22 @@ WERROR dsdb_module_schema_info_blob_write(struct ldb_module *ldb_module,
DATA_BLOB *schema_info_blob)
{
int ldb_err;
+ WERROR werr;
struct ldb_message *msg;
- struct ldb_dn *schema_dn;
- struct ldb_message_element *return_el;
TALLOC_CTX *temp_ctx;
- schema_dn = samdb_schema_dn(ldb_module_get_ctx(ldb_module));
- if (!schema_dn) {
- DEBUG(0,("dsdb_module_schema_info_blob_write: no schema dn present\n"));
- return WERR_INTERNAL_DB_CORRUPTION;
- }
-
temp_ctx = talloc_new(ldb_module);
W_ERROR_HAVE_NO_MEMORY(temp_ctx);
/* write serialized schemaInfo into LDB */
- msg = ldb_msg_new(temp_ctx);
- if (!msg) {
- talloc_free(temp_ctx);
- return WERR_NOMEM;
- }
-
- msg->dn = schema_dn;
- ldb_err = ldb_msg_add_value(msg, "schemaInfo", schema_info_blob, &return_el);
- if (ldb_err != 0) {
+ 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);
- DEBUG(0,("dsdb_module_schema_info_blob_write: ldb_msg_add_value failed\n"));
- return WERR_NOMEM;
+ return werr;
}
- /* mark schemaInfo element for replacement */
- return_el->flags = LDB_FLAG_MOD_REPLACE;
ldb_err = dsdb_module_modify(ldb_module, msg, dsdb_flags | DSDB_MODIFY_PERMISSIVE);