From 3c6c9d4d939bb2f1f629421e347285bea9a59341 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Tue, 11 Jun 2019 12:17:55 +0200
Subject: [PATCH 42/44] sysdb: add sysdb_list_subdomains()
To list all cached subdomains names.
Resolves:
https://pagure.io/SSSD/sssd/issue/4009
Reviewed-by: Sumit Bose <sbose@redhat.com>
(cherry picked from commit c7e6530d642f746982c5306cf3455608d1980d1f)
---
src/db/sysdb.h | 5 ++++
src/db/sysdb_subdomains.c | 60 +++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 574f4b120..56468a169 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -529,6 +529,11 @@ sysdb_domain_set_enabled(struct sysdb_ctx *sysdb,
const char *name,
bool enabled);
+errno_t
+sysdb_list_subdomains(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ const char ***_names);
+
errno_t sysdb_subdomain_store(struct sysdb_ctx *sysdb,
const char *name, const char *realm,
const char *flat_name, const char *domain_id,
diff --git a/src/db/sysdb_subdomains.c b/src/db/sysdb_subdomains.c
index cf09b424e..af838b44c 100644
--- a/src/db/sysdb_subdomains.c
+++ b/src/db/sysdb_subdomains.c
@@ -1472,3 +1472,63 @@ sysdb_domain_set_enabled(struct sysdb_ctx *sysdb,
return ret;
}
+
+errno_t
+sysdb_list_subdomains(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ const char ***_names)
+{
+ TALLOC_CTX *tmp_ctx;
+ struct ldb_dn *base_dn;
+ const char *attrs[] = {"cn", NULL};
+ struct ldb_message **msgs;
+ const char *name;
+ size_t count;
+ const char **names;
+ errno_t ret;
+ size_t i;
+
+ tmp_ctx = talloc_new(NULL);
+ if (tmp_ctx == NULL) {
+ return ENOMEM;
+ }
+
+ base_dn = sysdb_base_dn(sysdb, tmp_ctx);
+ if (base_dn == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+
+ ret = sysdb_search_entry(tmp_ctx, sysdb, base_dn, LDB_SCOPE_ONELEVEL,
+ "("SYSDB_OBJECTCLASS"="SYSDB_SUBDOMAIN_CLASS")",
+ attrs, &count, &msgs);
+ if (ret != EOK && ret != ENOENT) {
+ goto done;
+ }
+
+ names = talloc_zero_array(tmp_ctx, const char *, count + 1);
+ if (names == NULL) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ for (i = 0; i < count; i++) {
+ name = ldb_msg_find_attr_as_string(msgs[i], "cn", NULL);
+ if (name == NULL) {
+ ret = EINVAL;
+ goto done;
+ }
+
+ names[i] = talloc_steal(names, name);
+ }
+
+ *_names = talloc_steal(mem_ctx, names);
+
+ ret = EOK;
+
+done:
+ talloc_free(tmp_ctx);
+
+ return ret;
+}
--
2.20.1