From 5fad9a3d700ba24783e66c6941f68f84459b4d61 Mon Sep 17 00:00:00 2001 From: Sumit Bose Date: Fri, 28 May 2010 14:28:06 +0200 Subject: Add sysdb_attrs_get_string_array() --- src/db/sysdb.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/db/sysdb.c') diff --git a/src/db/sysdb.c b/src/db/sysdb.c index bfad77d8..f784e735 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -130,6 +130,39 @@ int sysdb_attrs_get_string(struct sysdb_attrs *attrs, const char *name, return EOK; } +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_int(attrs, name, false, &el); + if (ret) { + return ret; + } + + a = talloc_array(mem_ctx, const char *, el->num_values + 1); + 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; +} + int sysdb_attrs_add_val(struct sysdb_attrs *attrs, const char *name, const struct ldb_val *val) { -- cgit