|
|
71e593 |
From 861302754636745a9b60aa3946a749b779d4ef06 Mon Sep 17 00:00:00 2001
|
|
|
71e593 |
From: Sumit Bose <sbose@redhat.com>
|
|
|
71e593 |
Date: Mon, 2 Jul 2018 10:38:54 +0200
|
|
|
71e593 |
Subject: [PATCH 06/19] confdb: add confdb_certmap_to_sysdb()
|
|
|
71e593 |
|
|
|
71e593 |
Add a function to write certificate mapping and matching rules from the
|
|
|
71e593 |
config database to the cache of a domain.
|
|
|
71e593 |
|
|
|
71e593 |
Related to https://pagure.io/SSSD/sssd/issue/3500
|
|
|
71e593 |
|
|
|
71e593 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
71e593 |
(cherry picked from commit d9cc38008a51a8a5189904f175e4d10cbde4a974)
|
|
|
71e593 |
---
|
|
|
71e593 |
src/confdb/confdb.c | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
71e593 |
src/confdb/confdb.h | 23 +++++++++++++
|
|
|
71e593 |
2 files changed, 122 insertions(+)
|
|
|
71e593 |
|
|
|
71e593 |
diff --git a/src/confdb/confdb.c b/src/confdb/confdb.c
|
|
|
71e593 |
index 22068cacccc90d83047b148513b58618f176dd9a..7de0fb3cc7031767d748bd4fb739a3376fd364e3 100644
|
|
|
71e593 |
--- a/src/confdb/confdb.c
|
|
|
71e593 |
+++ b/src/confdb/confdb.c
|
|
|
71e593 |
@@ -2196,3 +2196,102 @@ done:
|
|
|
71e593 |
talloc_free(tmp_ctx);
|
|
|
71e593 |
return ret;
|
|
|
71e593 |
}
|
|
|
71e593 |
+
|
|
|
71e593 |
+static errno_t confdb_get_all_certmaps(TALLOC_CTX *mem_ctx,
|
|
|
71e593 |
+ struct confdb_ctx *cdb,
|
|
|
71e593 |
+ struct sss_domain_info *dom,
|
|
|
71e593 |
+ struct certmap_info ***_certmap_list)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ TALLOC_CTX *tmp_ctx = NULL;
|
|
|
71e593 |
+ struct ldb_dn *dn = NULL;
|
|
|
71e593 |
+ struct ldb_result *res = NULL;
|
|
|
71e593 |
+ /* The attributte order is important, because it is used in
|
|
|
71e593 |
+ * sysdb_ldb_msg_attr_to_certmap_info and must match
|
|
|
71e593 |
+ * enum certmap_info_member. */
|
|
|
71e593 |
+ static const char *attrs[] = { CONFDB_CERTMAP_NAME,
|
|
|
71e593 |
+ CONFDB_CERTMAP_MAPRULE,
|
|
|
71e593 |
+ CONFDB_CERTMAP_MATCHRULE,
|
|
|
71e593 |
+ CONFDB_CERTMAP_PRIORITY,
|
|
|
71e593 |
+ CONFDB_CERTMAP_DOMAINS,
|
|
|
71e593 |
+ NULL};
|
|
|
71e593 |
+ struct certmap_info **certmap_list = NULL;
|
|
|
71e593 |
+ size_t c;
|
|
|
71e593 |
+ int ret;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
71e593 |
+ if (tmp_ctx == NULL) {
|
|
|
71e593 |
+ return ENOMEM;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ dn = ldb_dn_new_fmt(tmp_ctx, cdb->ldb, "cn=%s,%s", dom->name,
|
|
|
71e593 |
+ CONFDB_CERTMAP_BASEDN);
|
|
|
71e593 |
+ if (dn == NULL) {
|
|
|
71e593 |
+ ret = ENOMEM;
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = ldb_search(cdb->ldb, tmp_ctx, &res, dn, LDB_SCOPE_ONELEVEL,
|
|
|
71e593 |
+ attrs, NULL);
|
|
|
71e593 |
+ if (ret != LDB_SUCCESS) {
|
|
|
71e593 |
+ ret = EIO;
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ certmap_list = talloc_zero_array(tmp_ctx, struct certmap_info *,
|
|
|
71e593 |
+ res->count + 1);
|
|
|
71e593 |
+ if (certmap_list == NULL) {
|
|
|
71e593 |
+ ret = ENOMEM;
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ for (c = 0; c < res->count; c++) {
|
|
|
71e593 |
+ ret = sysdb_ldb_msg_attr_to_certmap_info(certmap_list, res->msgs[c],
|
|
|
71e593 |
+ attrs, &certmap_list[c]);
|
|
|
71e593 |
+ if (ret != EOK) {
|
|
|
71e593 |
+ DEBUG(SSSDBG_OP_FAILURE,
|
|
|
71e593 |
+ "sysdb_ldb_msg_attr_to_certmap_info failed.\n");
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ *_certmap_list = talloc_steal(mem_ctx, certmap_list);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = EOK;
|
|
|
71e593 |
+
|
|
|
71e593 |
+done:
|
|
|
71e593 |
+ talloc_free(tmp_ctx);
|
|
|
71e593 |
+ return ret;
|
|
|
71e593 |
+}
|
|
|
71e593 |
+
|
|
|
71e593 |
+int confdb_certmap_to_sysdb(struct confdb_ctx *cdb,
|
|
|
71e593 |
+ struct sss_domain_info *dom)
|
|
|
71e593 |
+{
|
|
|
71e593 |
+ int ret;
|
|
|
71e593 |
+ TALLOC_CTX *tmp_ctx;
|
|
|
71e593 |
+ struct certmap_info **certmap_list;
|
|
|
71e593 |
+
|
|
|
71e593 |
+ tmp_ctx = talloc_new(NULL);
|
|
|
71e593 |
+ if (tmp_ctx == NULL) {
|
|
|
71e593 |
+ DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
|
|
|
71e593 |
+ return ENOMEM;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = confdb_get_all_certmaps(tmp_ctx, cdb, dom, &certmap_list);
|
|
|
71e593 |
+ if (ret != EOK) {
|
|
|
71e593 |
+ DEBUG(SSSDBG_OP_FAILURE, "confdb_get_all_certmaps failed.\n");
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = sysdb_update_certmap(dom->sysdb, certmap_list, false /* TODO */);
|
|
|
71e593 |
+ if (ret != EOK) {
|
|
|
71e593 |
+ DEBUG(SSSDBG_OP_FAILURE, "sysdb_update_certmap failed.\n");
|
|
|
71e593 |
+ goto done;
|
|
|
71e593 |
+ }
|
|
|
71e593 |
+
|
|
|
71e593 |
+ ret = EOK;
|
|
|
71e593 |
+
|
|
|
71e593 |
+done:
|
|
|
71e593 |
+ talloc_free(tmp_ctx);
|
|
|
71e593 |
+
|
|
|
71e593 |
+ return ret;
|
|
|
71e593 |
+}
|
|
|
71e593 |
diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h
|
|
|
71e593 |
index 22665013aba1f768b7ecd38df9261b84807f70b8..2aae93a278eb62e9b8a18885f06d66b20f269f60 100644
|
|
|
71e593 |
--- a/src/confdb/confdb.h
|
|
|
71e593 |
+++ b/src/confdb/confdb.h
|
|
|
71e593 |
@@ -265,6 +265,15 @@
|
|
|
71e593 |
#define CONFDB_KCM_SOCKET "socket_path"
|
|
|
71e593 |
#define CONFDB_KCM_DB "ccache_storage" /* Undocumented on purpose */
|
|
|
71e593 |
|
|
|
71e593 |
+/* Certificate mapping rules */
|
|
|
71e593 |
+#define CONFDB_CERTMAP_BASEDN "cn=certmap,cn=config"
|
|
|
71e593 |
+#define CONFDB_CERTMAP_NAME "cn"
|
|
|
71e593 |
+#define CONFDB_CERTMAP_MAPRULE "maprule"
|
|
|
71e593 |
+#define CONFDB_CERTMAP_MATCHRULE "matchrule"
|
|
|
71e593 |
+#define CONFDB_CERTMAP_DOMAINS "domains"
|
|
|
71e593 |
+#define CONFDB_CERTMAP_PRIORITY "priority"
|
|
|
71e593 |
+
|
|
|
71e593 |
+
|
|
|
71e593 |
struct confdb_ctx;
|
|
|
71e593 |
struct config_file_ctx;
|
|
|
71e593 |
|
|
|
71e593 |
@@ -662,6 +671,20 @@ int confdb_get_sub_sections(TALLOC_CTX *mem_ctx,
|
|
|
71e593 |
const char *section,
|
|
|
71e593 |
char ***sections,
|
|
|
71e593 |
int *num_sections);
|
|
|
71e593 |
+
|
|
|
71e593 |
+/**
|
|
|
71e593 |
+ * @brief Convenience function to write the certificate mapping and matching
|
|
|
71e593 |
+ * rules from the configuration database to the cache of a domain
|
|
|
71e593 |
+ *
|
|
|
71e593 |
+ * @param[in] cdb The connection object to the confdb
|
|
|
71e593 |
+ * @param[in] dom Target domain where to rules should be written to
|
|
|
71e593 |
+ *
|
|
|
71e593 |
+ * @return 0 - Successfully retrieved the entry (or used the default)
|
|
|
71e593 |
+ * @return ENOMEM - There was insufficient memory to complete the operation
|
|
|
71e593 |
+ * @return EINVAL - Typically internal processing error
|
|
|
71e593 |
+ */
|
|
|
71e593 |
+int confdb_certmap_to_sysdb(struct confdb_ctx *cdb,
|
|
|
71e593 |
+ struct sss_domain_info *dom);
|
|
|
71e593 |
/**
|
|
|
71e593 |
* @}
|
|
|
71e593 |
*/
|
|
|
71e593 |
--
|
|
|
71e593 |
2.14.4
|
|
|
71e593 |
|