Blame SOURCES/0042-sysdb-add-sysdb_list_subdomains.patch

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