From 707cd30cda11acdcad59cfdb6743eb822f69f5ba Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Dec 2009 14:34:13 +1100 Subject: s4-dsdb: fixed steal of parentGUID for empty msg msg->elements could be NULL before we add parentGUID --- source4/dsdb/samdb/ldb_modules/operational.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'source4/dsdb/samdb/ldb_modules/operational.c') diff --git a/source4/dsdb/samdb/ldb_modules/operational.c b/source4/dsdb/samdb/ldb_modules/operational.c index badc0c5fa1..aef9598625 100644 --- a/source4/dsdb/samdb/ldb_modules/operational.c +++ b/source4/dsdb/samdb/ldb_modules/operational.c @@ -125,11 +125,12 @@ static int construct_parent_guid(struct ldb_module *module, const struct ldb_val *parent_guid; const char *attrs[] = { "objectGUID", NULL }; int ret; + struct ldb_val v; /* TODO: In the future, this needs to honour the partition boundaries */ struct ldb_dn *parent_dn = ldb_dn_get_parent(msg, msg->dn); - if (parent_dn == NULL){ + if (parent_dn == NULL) { DEBUG(4,(__location__ ": Failed to find parent for dn %s\n", ldb_dn_get_linearized(msg->dn))); return LDB_SUCCESS; @@ -138,7 +139,7 @@ static int construct_parent_guid(struct ldb_module *module, ret = dsdb_module_search_dn(module, msg, &res, parent_dn, attrs, DSDB_SEARCH_SHOW_DELETED); talloc_free(parent_dn); /* if there is no parentGUID for this object, then return */ - if (ret == LDB_ERR_NO_SUCH_OBJECT){ + if (ret == LDB_ERR_NO_SUCH_OBJECT) { DEBUG(4,(__location__ ": Parent dn for %s does not exist \n", ldb_dn_get_linearized(msg->dn))); return LDB_SUCCESS; @@ -152,9 +153,14 @@ static int construct_parent_guid(struct ldb_module *module, return LDB_SUCCESS; } - talloc_steal(msg->elements, parent_guid->data); + v = data_blob_dup_talloc(res, parent_guid); + if (!v.data) { + talloc_free(res); + return LDB_ERR_OPERATIONS_ERROR; + } + ret = ldb_msg_add_steal_value(msg, "parentGUID", &v); talloc_free(res); - return ldb_msg_add_value(msg, "parentGUID", parent_guid, 0); + return ret; } /* -- cgit