ldb: let ldb_modules_list_from_string() return 'char **'
authorStefan Metzmacher <metze@samba.org>
Tue, 10 Sep 2013 10:55:37 +0000 (12:55 +0200)
committerStefan Metzmacher <metze@samba.org>
Wed, 25 Sep 2013 08:28:37 +0000 (10:28 +0200)
The caller provides a memory context and owns the returned
list.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/ABI/ldb-1.1.16.sigs
lib/ldb/common/ldb_modules.c
lib/ldb/include/ldb_module.h
lib/ldb/include/ldb_private.h

index 1e8a9ce7b38847fb6e125f08f18975be8307169d..617721ce9f7a9519346be12ed9343271fc31c380 100644 (file)
@@ -139,7 +139,7 @@ ldb_module_send_referral: int (struct ldb_request *, char *)
 ldb_module_set_next: void (struct ldb_module *, struct ldb_module *)
 ldb_module_set_private: void (struct ldb_module *, void *)
 ldb_modules_hook: int (struct ldb_context *, enum ldb_module_hook_type)
-ldb_modules_list_from_string: const char **(struct ldb_context *, TALLOC_CTX *, const char *)
+ldb_modules_list_from_string: char **(struct ldb_context *, TALLOC_CTX *, const char *)
 ldb_modules_load: int (const char *, const char *)
 ldb_msg_add: int (struct ldb_message *, const struct ldb_message_element *, int)
 ldb_msg_add_empty: int (struct ldb_message *, const char *, int, struct ldb_message_element **)
index 721f1bc02eaf4f1ac7548db6d2ce779888164b78..f6dacebb8f97c17274f076c1b7f04fb9f9472bed 100644 (file)
@@ -63,10 +63,9 @@ static char *ldb_modules_strdup_no_spaces(TALLOC_CTX *mem_ctx, const char *strin
 /* modules are called in inverse order on the stack.
    Lets place them as an admin would think the right order is.
    Modules order is important */
-const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string)
+char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string)
 {
        char **modules = NULL;
-       const char **m;
        char *modstr, *p;
        unsigned int i;
 
@@ -87,8 +86,7 @@ const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *m
 
        if (modstr[0] == '\0') {
                modules[0] = NULL;
-               m = (const char **)modules;
-               return m;
+               return modules;
        }
 
        i = 0;
@@ -96,7 +94,12 @@ const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *m
        while ((p = strrchr(modstr, ',')) != NULL) {
                *p = '\0';
                p++;
-               modules[i] = p;
+               modules[i] = talloc_strdup(modules, p);
+               if (modules[i] == NULL) {
+                       ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_list_from_string()");
+                       talloc_free(modules);
+                       return NULL;
+               }
 
                i++;
                modules = talloc_realloc(mem_ctx, modules, char *, i + 2);
@@ -106,13 +109,16 @@ const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *m
                }
 
        }
-       modules[i] = modstr;
-
+       modules[i] = talloc_strdup(modules, modstr);
+       if (modules[i] == NULL) {
+               ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_list_from_string()");
+               talloc_free(modules);
+               return NULL;
+       }
        modules[i + 1] = NULL;
 
-       m = (const char **)modules;
-
-       return m;
+       talloc_free(modstr);
+       return modules;
 }
 
 static struct backends_list_entry {
@@ -360,7 +366,7 @@ int ldb_module_init_chain(struct ldb_context *ldb, struct ldb_module *module)
 int ldb_load_modules(struct ldb_context *ldb, const char *options[])
 {
        const char *modules_string;
-       const char **modules = NULL;
+       char **modules = NULL;
        int ret;
        TALLOC_CTX *mem_ctx = talloc_new(ldb);
        if (!mem_ctx) {
index 7e5d67284b42d6e712f9ab6a9745e8fa555d0953..7b9a4bc7f6d89148561a0b8b9dffd9609b613f09 100644 (file)
@@ -327,7 +327,7 @@ struct poptOption **ldb_module_popt_options(struct ldb_context *ldb);
 /* modules are called in inverse order on the stack.
    Lets place them as an admin would think the right order is.
    Modules order is important */
-const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string);
+char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string);
 
 /*
   return the current ldb flags LDB_FLG_*
index 526bf5e49104115afa4f56c6e435018d5440c187..64ade164c0b10f982c6559dccd9a2ea30dc24663 100644 (file)
@@ -170,7 +170,6 @@ void ldb_dump_results(struct ldb_context *ldb, struct ldb_result *result, FILE *
 
 /* The following definitions come from lib/ldb/common/ldb_modules.c  */
 
-const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string);
 int ldb_load_modules(struct ldb_context *ldb, const char *options[]);
 
 struct ldb_val ldb_binary_decode(TALLOC_CTX *mem_ctx, const char *str);