s4-dsdb: fixed steal of parentGUID for empty msg
authorAndrew Tridgell <tridge@samba.org>
Wed, 9 Dec 2009 03:34:13 +0000 (14:34 +1100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 9 Dec 2009 07:18:25 +0000 (18:18 +1100)
msg->elements could be NULL before we add parentGUID

source4/dsdb/samdb/ldb_modules/operational.c

index badc0c5fa152ae03ae2c9cc7fc7274527d2cff76..aef9598625296540267235c67bbabe49ed19f195 100644 (file)
@@ -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;
 }
 
 /*