r10917: copy the element name in a ldb_msg_rename_attr() and ldb_msg_copy_attr()...
authorAndrew Tridgell <tridge@samba.org>
Wed, 12 Oct 2005 08:11:45 +0000 (08:11 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:39:42 +0000 (13:39 -0500)
that callers (like the ldap server) can talloc_steal the name
(This used to be commit 9c914542cc346758c82f89990c80eb096a9c0959)

source4/lib/ldb/common/ldb_msg.c
source4/lib/ldb/include/ldb.h
source4/lib/ldb/modules/operational.c

index 1c7ae3920a964de1a5f2e6328e4e5e52fa79826b..a72a4616fbe3113214bd1a6ca19157ef12cd8f77 100644 (file)
@@ -587,12 +587,17 @@ int ldb_attr_in_list(const char * const *attrs, const char *attr)
 /*
   rename the specified attribute in a search result
 */
-void ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace)
+int ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace)
 {
        struct ldb_message_element *el = ldb_msg_find_element(msg, attr);
-       if (el != NULL) {
-               el->name = replace;
+       if (el == NULL) {
+               return 0;
+       }
+       el->name = talloc_strdup(msg->elements, replace);
+       if (el->name == NULL) {
+               return -1;
        }
+       return 0;
 }
 
 
@@ -608,8 +613,7 @@ int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *rep
        if (ldb_msg_add(msg, el, 0) != 0) {
                return -1;
        }
-       ldb_msg_rename_attr(msg, attr, replace);
-       return 0;
+       return ldb_msg_rename_attr(msg, attr, replace);
 }
 
 
index d346d0edacbbc85f95cfa71cff9fead078217bba..3629d9ec473aeef689f8714047de2572d37ffadc 100644 (file)
@@ -497,7 +497,7 @@ void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree,
                                 const char *attr, 
                                 const char *replace);
 
-void ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace);
+int ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace);
 int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace);
 
 char *ldb_timestring(TALLOC_CTX *mem_ctx, time_t t);
index d1e83c02e0690bce62361626ac880ad535fb499c..09f9a9e62ce9f9b8149aee518c64691e252bca94 100644 (file)
@@ -113,6 +113,8 @@ static int operational_search_bytree(struct ldb_module *module,
        int ret;
        const char **search_attrs = NULL;
 
+       (*res) = NULL;
+
        /* replace any attributes in the parse tree that are
           searchable, but are stored using a different name in the
           backend */
@@ -165,9 +167,11 @@ static int operational_search_bytree(struct ldb_module *module,
                                                goto oom;
                                        }
                                } else {
-                                       ldb_msg_rename_attr((*res)[r], 
-                                                           search_sub[i].replace,
-                                                           search_sub[i].attr);
+                                       if (ldb_msg_rename_attr((*res)[r], 
+                                                             search_sub[i].replace,
+                                                             search_sub[i].attr) != 0) {
+                                               goto oom;
+                                       }
                                }
                        }
                }
@@ -179,6 +183,7 @@ static int operational_search_bytree(struct ldb_module *module,
 
 oom:
        talloc_free(search_attrs);
+       talloc_free(*res);
        ldb_oom(module->ldb);
        return -1;
 }