diff options
author | Pavel Březina <pbrezina@redhat.com> | 2014-05-05 13:28:34 +0200 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2014-05-28 16:41:02 +0200 |
commit | d81f46fb294a6f6f64d3237ab0e0ab01f2c5ea20 (patch) | |
tree | 07389c18eeaf91add01a7dffdf7d30cada2f1ac8 /src/confdb/confdb.c | |
parent | d387c4608dbd3ca056e18e85313ef51aac146fd2 (diff) | |
download | sssd-d81f46fb294a6f6f64d3237ab0e0ab01f2c5ea20.tar.gz sssd-d81f46fb294a6f6f64d3237ab0e0ab01f2c5ea20.tar.xz sssd-d81f46fb294a6f6f64d3237ab0e0ab01f2c5ea20.zip |
confdb: add confdb_list_all_domain_names()
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/confdb/confdb.c')
-rw-r--r-- | src/confdb/confdb.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/confdb/confdb.c b/src/confdb/confdb.c index 9a13f723d..6f36535fd 100644 --- a/src/confdb/confdb.c +++ b/src/confdb/confdb.c @@ -1271,3 +1271,67 @@ int confdb_get_domain(struct confdb_ctx *cdb, return ENOENT; } + +int confdb_list_all_domain_names(TALLOC_CTX *mem_ctx, + struct confdb_ctx *cdb, + char ***_names) +{ + TALLOC_CTX *tmp_ctx = NULL; + struct ldb_dn *dn = NULL; + struct ldb_result *res = NULL; + static const char *attrs[] = {CONFDB_DOMAIN_ATTR, NULL}; + const char *name = NULL; + char **names = NULL; + int i; + int ret; + + tmp_ctx = talloc_new(NULL); + if (tmp_ctx == NULL) { + return ENOMEM; + } + + dn = ldb_dn_new(tmp_ctx, cdb->ldb, CONFDB_DOMAIN_BASEDN); + if (dn == NULL) { + ret = ENOMEM; + goto done; + } + + ret = ldb_search(cdb->ldb, tmp_ctx, &res, dn, LDB_SCOPE_ONELEVEL, + attrs, NULL); + if (ret != LDB_SUCCESS) { + ret = EIO; + goto done; + } + + names = talloc_zero_array(tmp_ctx, char*, res->count + 1); + if (names == NULL) { + ret = ENOMEM; + goto done; + } + + for (i = 0; i < res->count; i++) { + name = ldb_msg_find_attr_as_string(res->msgs[i], CONFDB_DOMAIN_ATTR, + NULL); + if (name == NULL) { + DEBUG(SSSDBG_MINOR_FAILURE, + "The object [%s] doesn't have a name\n", + ldb_dn_get_linearized(res->msgs[i]->dn)); + ret = EINVAL; + goto done; + } + + names[i] = talloc_strdup(names, name); + if (names[i] == NULL) { + ret = ENOMEM; + goto done; + } + } + + *_names = talloc_steal(mem_ctx, names); + + ret = EOK; + +done: + talloc_free(tmp_ctx); + return ret; +} |