diff options
author | Gary Lockyer <gary@catalyst.net.nz> | 2019-06-25 16:17:12 +1200 |
---|---|---|
committer | Gary Lockyer <gary@samba.org> | 2019-07-02 02:23:09 +0000 |
commit | 3b52ca59a2d01da35539a2940fda5f4df15aeb21 (patch) | |
tree | 9b46c38f39a053beeac654dca32b56e953d07226 /lib | |
parent | b281fc624e53ead0ef614ea2fcff46bc9b599f92 (diff) | |
download | samba-3b52ca59a2d01da35539a2940fda5f4df15aeb21.tar.gz |
lib ldb: save a copy of the options on the context
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ldb/common/ldb.c | 9 | ||||
-rw-r--r-- | lib/ldb/common/ldb_options.c | 30 | ||||
-rw-r--r-- | lib/ldb/include/ldb_private.h | 7 |
3 files changed, 46 insertions, 0 deletions
diff --git a/lib/ldb/common/ldb.c b/lib/ldb/common/ldb.c index b9f5164c4e9..95e9138a56b 100644 --- a/lib/ldb/common/ldb.c +++ b/lib/ldb/common/ldb.c @@ -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; diff --git a/lib/ldb/common/ldb_options.c b/lib/ldb/common/ldb_options.c index f07f3935624..0aa80f75159 100644 --- a/lib/ldb/common/ldb_options.c +++ b/lib/ldb/common/ldb_options.c @@ -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; +} diff --git a/lib/ldb/include/ldb_private.h b/lib/ldb/include/ldb_private.h index f999f7530bf..4deb24691ca 100644 --- a/lib/ldb/include/ldb_private.h +++ b/lib/ldb/include/ldb_private.h @@ -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 */ |