diff options
Diffstat (limited to 'src/db/sysdb.c')
-rw-r--r-- | src/db/sysdb.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c index 0e07ed608..592cadc1a 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -466,12 +466,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); @@ -479,22 +501,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; } |