]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib ldb: save a copy of the options on the context
authorGary Lockyer <gary@catalyst.net.nz>
Tue, 25 Jun 2019 04:17:12 +0000 (16:17 +1200)
committerGary Lockyer <gary@samba.org>
Tue, 2 Jul 2019 02:23:09 +0000 (02:23 +0000)
Copy the options supplied to to ldb_connect, and place them on the
ldb_context. This allows backend options i.e. lmbd map size to be passed
cleanly from the callers.

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/common/ldb.c
lib/ldb/common/ldb_options.c
lib/ldb/include/ldb_private.h

index b9f5164c4e99bc0eb2292bb1e2d638bf11f4a957..95e9138a56b82f993a628890f45fac8b9013cc0b 100644 (file)
@@ -257,6 +257,15 @@ int ldb_connect(struct ldb_context *ldb, const char *url,
                return ret;
        }
 
+       /*
+        * Take a copy of the options.
+        */
+       ldb->options = ldb_options_copy(ldb, options);
+       if (ldb->options == NULL && options != NULL) {
+               ldb_oom(ldb);
+               return LDB_ERR_OPERATIONS_ERROR;
+       }
+
        ret = ldb_module_connect_backend(ldb, url, options, &ldb->modules);
        if (ret != LDB_SUCCESS) {
                return ret;
index f07f3935624e4970c9bafabb8340041d6a480ded..0aa80f7515970e73332b2812be99c5a3bc294424 100644 (file)
@@ -70,3 +70,33 @@ const char *ldb_options_find(struct ldb_context *ldb, const char *options[],
 
        return NULL;
 }
+
+const char **ldb_options_copy(TALLOC_CTX *ctx, const char *options[])
+{
+
+       size_t num_options = 0;
+       const char **copy = NULL;
+       size_t i = 0;
+
+       if (options == NULL) {
+               return copy;
+       }
+
+       for (i=0; options[i]; i++) {
+               num_options++;
+       }
+
+       copy = talloc_zero_array(ctx, const char *, num_options + 1);
+       if (copy == NULL) {
+               return copy;
+       }
+
+       for (i=0; options[i]; i++) {
+               copy[i] = talloc_strdup(copy, options[i]);
+               if (copy[i] == NULL) {
+                       TALLOC_FREE(copy);
+                       return copy;
+               }
+       }
+       return copy;
+}
index f999f7530bf1c44a3a5afdad63a269af55841124..4deb24691ca08f037a1d6b865e1cdfcf0c393319 100644 (file)
@@ -155,6 +155,12 @@ struct ldb_context {
        char *partial_debug;
 
        struct poptOption *popt_options;
+
+       /*
+        * The ldb options passed to ldb_connect
+        * A NULL terminated array of zero terminated strings
+        */
+       const char **options;
 };
 
 /* The following definitions come from lib/ldb/common/ldb.c  */
@@ -218,6 +224,7 @@ struct ldb_val ldb_binary_decode(TALLOC_CTX *mem_ctx, const char *str);
 
 const char *ldb_options_find(struct ldb_context *ldb, const char *options[],
                             const char *option_name);
+const char **ldb_options_copy(TALLOC_CTX *ctx, const char *options[]);
 
 /* The following definitions come from lib/ldb/common/ldb_ldif.c  */