Skip to content

Commit

Permalink
lib ldb: save a copy of the options on the context
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Andrew Bartlett <[email protected]>
  • Loading branch information
GaryWL committed Jul 2, 2019
1 parent b281fc6 commit 3b52ca5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/ldb/common/ldb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
30 changes: 30 additions & 0 deletions lib/ldb/common/ldb_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
7 changes: 7 additions & 0 deletions lib/ldb/include/ldb_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */

Expand Down

0 comments on commit 3b52ca5

Please sign in to comment.