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