summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPavel Březina <pbrezina@redhat.com>2014-05-05 13:28:34 +0200
committerJakub Hrozek <jhrozek@redhat.com>2014-05-28 16:41:02 +0200
commitd81f46fb294a6f6f64d3237ab0e0ab01f2c5ea20 (patch)
tree07389c18eeaf91add01a7dffdf7d30cada2f1ac8 /src
parentd387c4608dbd3ca056e18e85313ef51aac146fd2 (diff)
downloadsssd-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')
-rw-r--r--src/confdb/confdb.c64
-rw-r--r--src/confdb/confdb.h16
2 files changed, 80 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;
+}
diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h
index 7994a6757..2cebf2426 100644
--- a/src/confdb/confdb.h
+++ b/src/confdb/confdb.h
@@ -297,6 +297,22 @@ int confdb_get_domain(struct confdb_ctx *cdb,
int confdb_get_domains(struct confdb_ctx *cdb,
struct sss_domain_info **domains);
+/**
+ * Get a null-terminated linked-list of all domain names
+ * @param[in] mem_ctx The parent memory context for the value list
+ * @param[in] cdb The connection object to the confdb
+ * @param[out] _names Output list
+ *
+ * @return 0 - Lookup succeeded and all domain names are in the list
+ * @return ENOMEM - There was insufficient memory to complete the operation
+ * @return ENOENT - No active domains are configured
+ * @return EIO - There was an I/O error communicating with the ConfDB file
+ * @return EINVAL - Corrupted confdb object
+ */
+int confdb_list_all_domain_names(TALLOC_CTX *mem_ctx,
+ struct confdb_ctx *cdb,
+ char ***_names);
+
/**
* @brief Add an arbitrary parameter to the confdb.