diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2014-01-28 14:51:58 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-01-29 17:27:55 +0100 |
commit | 407a7e05f9077ccaefe5412f794347e4c9da94bb (patch) | |
tree | eadce60bcc5a1843edfb93aab1c5326a5b9e1900 /src/db/sysdb.c | |
parent | ff4ca560f597303c62b83cc484f33e114e52ba0a (diff) | |
download | sssd-407a7e05f9077ccaefe5412f794347e4c9da94bb.tar.gz sssd-407a7e05f9077ccaefe5412f794347e4c9da94bb.tar.xz sssd-407a7e05f9077ccaefe5412f794347e4c9da94bb.zip |
DB: Add sss_ldb_el_to_string_list
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; } |