From 37171a92dc9c5e4fe1a0663901fc965b49a78151 Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Tue, 28 Jan 2014 14:51:58 +0100 Subject: DB: Add sss_ldb_el_to_string_list --- src/db/sysdb.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'src/db/sysdb.c') diff --git a/src/db/sysdb.c b/src/db/sysdb.c index b026a298e..65277af01 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -464,12 +464,34 @@ errno_t sysdb_attrs_get_bool(struct sysdb_attrs *attrs, const char *name, return EOK; } +const char **sss_ldb_el_to_string_list(TALLOC_CTX *mem_ctx, + struct ldb_message_element *el) +{ + unsigned int u; + const char **a; + + a = talloc_zero_array(mem_ctx, const char *, el->num_values + 1); + if (a == NULL) { + return NULL; + } + + for (u = 0; u < el->num_values; u++) { + a[u] = talloc_strndup(a, (const char *)el->values[u].data, + el->values[u].length); + if (a[u] == NULL) { + talloc_free(a); + return NULL; + } + } + + return a; +} + int sysdb_attrs_get_string_array(struct sysdb_attrs *attrs, const char *name, TALLOC_CTX *mem_ctx, const char ***string) { struct ldb_message_element *el; int ret; - unsigned int u; const char **a; ret = sysdb_attrs_get_el_ext(attrs, name, false, &el); @@ -477,22 +499,11 @@ int sysdb_attrs_get_string_array(struct sysdb_attrs *attrs, const char *name, return ret; } - a = talloc_array(mem_ctx, const char *, el->num_values + 1); + a = sss_ldb_el_to_string_list(mem_ctx, el); if (a == NULL) { return ENOMEM; } - memset(a, 0, sizeof(const char *) * (el->num_values + 1)); - - for(u = 0; u < el->num_values; u++) { - a[u] = talloc_strndup(a, (const char *)el->values[u].data, - el->values[u].length); - if (a[u] == NULL) { - talloc_free(a); - return ENOMEM; - } - } - *string = a; return EOK; } -- cgit