summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2009-08-26 13:44:50 +1000
committerAndrew Bartlett <abartlet@samba.org>2009-08-26 13:49:10 +1000
commit74218726e89c297eb957b9df989dd42fd1601742 (patch)
tree138ce066c95837f907686ed30859f4c65a503528 /source4
parenta1da91174b8db082c42ec7e8a6438e11e0e56e91 (diff)
downloadsamba-74218726e89c297eb957b9df989dd42fd1601742.tar.gz
samba-74218726e89c297eb957b9df989dd42fd1601742.tar.bz2
samba-74218726e89c297eb957b9df989dd42fd1601742.zip
s4:schema Rework dsdb_write_prefixes_from_schema_to_ldb() to use talloc
This changes dsdb_write_prefixes_from_schema_to_ldb() to use an internal talloc hirarchy, so we can safely give it a NULL context from the python. It also fixes manual construction of the ldb_message - we now use the right helper functions. Andrew Bartlett
Diffstat (limited to 'source4')
-rw-r--r--source4/dsdb/schema/schema_init.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/source4/dsdb/schema/schema_init.c b/source4/dsdb/schema/schema_init.c
index e741bc0ee5..3b701ad31c 100644
--- a/source4/dsdb/schema/schema_init.c
+++ b/source4/dsdb/schema/schema_init.c
@@ -458,14 +458,17 @@ WERROR dsdb_find_prefix_for_oid(uint32_t num_prefixes, const struct dsdb_schema_
WERROR dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb,
const struct dsdb_schema *schema)
{
- struct ldb_message msg;
+ struct ldb_message *msg = ldb_msg_new(mem_ctx);
struct ldb_dn *schema_dn;
- struct ldb_message_element el;
struct prefixMapBlob pm;
struct ldb_val ndr_blob;
enum ndr_err_code ndr_err;
uint32_t i;
int ret;
+
+ if (!msg) {
+ return WERR_NOMEM;
+ }
schema_dn = samdb_schema_dn(ldb);
if (!schema_dn) {
@@ -475,10 +478,11 @@ WERROR dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_co
pm.version = PREFIX_MAP_VERSION_DSDB;
pm.ctr.dsdb.num_mappings = schema->num_prefixes;
- pm.ctr.dsdb.mappings = talloc_array(mem_ctx,
+ pm.ctr.dsdb.mappings = talloc_array(msg,
struct drsuapi_DsReplicaOIDMapping,
pm.ctr.dsdb.num_mappings);
if (!pm.ctr.dsdb.mappings) {
+ talloc_free(msg);
return WERR_NOMEM;
}
@@ -487,26 +491,28 @@ WERROR dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_co
pm.ctr.dsdb.mappings[i].oid.oid = talloc_strdup(pm.ctr.dsdb.mappings, schema->prefixes[i].oid);
}
- ndr_err = ndr_push_struct_blob(&ndr_blob, ldb,
+ ndr_err = ndr_push_struct_blob(&ndr_blob, msg,
lp_iconv_convenience(ldb_get_opaque(ldb, "loadparm")),
&pm,
(ndr_push_flags_fn_t)ndr_push_prefixMapBlob);
if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
+ talloc_free(msg);
return WERR_FOOBAR;
}
- el.num_values = 1;
- el.values = &ndr_blob;
- el.flags = LDB_FLAG_MOD_REPLACE;
- el.name = talloc_strdup(mem_ctx, "prefixMap");
-
- msg.dn = ldb_dn_copy(mem_ctx, schema_dn);
- msg.num_elements = 1;
- msg.elements = &el;
+ msg->dn = schema_dn;
+ ret = ldb_msg_add_value(msg, "prefixMap", &ndr_blob, NULL);
+ if (ret != 0) {
+ talloc_free(msg);
+ DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: ldb_msg_add_value failed\n"));
+ return WERR_NOMEM;
+ }
- ret = ldb_modify( ldb, &msg );
+ ret = samdb_replace( ldb, msg, msg );
+ talloc_free(msg);
+
if (ret != 0) {
- DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: ldb_modify failed\n"));
+ DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: samdb_replace failed\n"));
return WERR_FOOBAR;
}