diff options
Diffstat (limited to 'src/db')
-rw-r--r-- | src/db/sysdb.c | 53 | ||||
-rw-r--r-- | src/db/sysdb.h | 6 |
2 files changed, 59 insertions, 0 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c index ef9d0a237..94738c606 100644 --- a/src/db/sysdb.c +++ b/src/db/sysdb.c @@ -2256,3 +2256,56 @@ done: talloc_free(tmpctx); return ret; } + +errno_t sysdb_attrs_primary_name_list(struct sysdb_ctx *sysdb, + TALLOC_CTX *mem_ctx, + struct sysdb_attrs **attr_list, + size_t attr_count, + const char *ldap_attr, + char ***name_list) +{ + errno_t ret; + size_t i, j; + char **list; + const char *name; + + /* Assume that every entry has a primary name */ + list = talloc_array(mem_ctx, char *, attr_count+1); + if (!list) { + return ENOMEM; + } + + j = 0; + for (i = 0; i < attr_count; i++) { + ret = sysdb_attrs_primary_name(sysdb, + attr_list[i], + ldap_attr, + &name); + if (ret != EOK) { + DEBUG(1, ("Could not determine primary name\n")); + /* Skip and continue. Don't advance 'j' */ + continue; + } + + list[j] = talloc_strdup(list, name); + if (!list[j]) { + ret = ENOMEM; + goto done; + } + + j++; + } + + /* NULL-terminate the list */ + list[j] = NULL; + + *name_list = list; + + ret = EOK; + +done: + if (ret != EOK) { + talloc_free(list); + } + return ret; +} diff --git a/src/db/sysdb.h b/src/db/sysdb.h index 971a35f99..b7256911a 100644 --- a/src/db/sysdb.h +++ b/src/db/sysdb.h @@ -219,6 +219,12 @@ errno_t sysdb_attrs_primary_name(struct sysdb_ctx *sysdb, struct sysdb_attrs *attrs, const char *ldap_attr, const char **_primary); +errno_t sysdb_attrs_primary_name_list(struct sysdb_ctx *sysdb, + TALLOC_CTX *mem_ctx, + struct sysdb_attrs **attr_list, + size_t attr_count, + const char *ldap_attr, + char ***name_list); /* convert an ldb error into an errno error */ int sysdb_error_to_errno(int ldberr); |