Blame SOURCES/0022-domain-store-hostname-and-keytab-path.patch

b833e0
From 6715b31f2e12c7f76cfb477551cee46e697c7d51 Mon Sep 17 00:00:00 2001
b833e0
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
b833e0
Date: Thu, 8 Oct 2020 13:25:58 +0200
b833e0
Subject: [PATCH 22/27] domain: store hostname and keytab path
b833e0
b833e0
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
b833e0
Reviewed-by: Sumit Bose <sbose@redhat.com>
b833e0
---
b833e0
 src/confdb/confdb.c       | 45 +++++++++++++++++++++++++++++++++++++++
b833e0
 src/confdb/confdb.h       |  6 ++++++
b833e0
 src/db/sysdb_subdomains.c | 12 +++++++++++
b833e0
 3 files changed, 63 insertions(+)
b833e0
b833e0
diff --git a/src/confdb/confdb.c b/src/confdb/confdb.c
b833e0
index d2fc018fd..f981ddf1e 100644
b833e0
--- a/src/confdb/confdb.c
b833e0
+++ b/src/confdb/confdb.c
b833e0
@@ -871,6 +871,35 @@ done:
b833e0
     return ret;
b833e0
 }
b833e0
 
b833e0
+static char *confdb_get_domain_hostname(TALLOC_CTX *mem_ctx,
b833e0
+                                        struct ldb_result *res,
b833e0
+                                        const char *provider)
b833e0
+{
b833e0
+    char sys[HOST_NAME_MAX + 1] = {'\0'};
b833e0
+    const char *opt = NULL;
b833e0
+    int ret;
b833e0
+
b833e0
+    if (strcasecmp(provider, "ad") == 0) {
b833e0
+        opt = ldb_msg_find_attr_as_string(res->msgs[0], "ad_hostname", NULL);
b833e0
+    } else if (strcasecmp(provider, "ipa") == 0) {
b833e0
+        opt = ldb_msg_find_attr_as_string(res->msgs[0], "ipa_hostname", NULL);
b833e0
+    }
b833e0
+
b833e0
+    if (opt != NULL) {
b833e0
+        return talloc_strdup(mem_ctx, opt);
b833e0
+    }
b833e0
+
b833e0
+    ret = gethostname(sys, sizeof(sys));
b833e0
+    if (ret != 0) {
b833e0
+        ret = errno;
b833e0
+        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get hostname [%d]: %s\n", ret,
b833e0
+              sss_strerror(ret));
b833e0
+        return NULL;
b833e0
+    }
b833e0
+
b833e0
+    return talloc_strdup(mem_ctx, sys);
b833e0
+}
b833e0
+
b833e0
 static int confdb_get_domain_internal(struct confdb_ctx *cdb,
b833e0
                                       TALLOC_CTX *mem_ctx,
b833e0
                                       const char *name,
b833e0
@@ -1536,6 +1565,22 @@ static int confdb_get_domain_internal(struct confdb_ctx *cdb,
b833e0
         goto done;
b833e0
     }
b833e0
 
b833e0
+    domain->hostname = confdb_get_domain_hostname(domain, res, domain->provider);
b833e0
+    if (domain->hostname == NULL) {
b833e0
+        DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get domain hostname\n");
b833e0
+        goto done;
b833e0
+    }
b833e0
+
b833e0
+    domain->krb5_keytab = NULL;
b833e0
+    tmp = ldb_msg_find_attr_as_string(res->msgs[0], "krb5_keytab", NULL);
b833e0
+    if (tmp != NULL) {
b833e0
+        domain->krb5_keytab = talloc_strdup(domain, tmp);
b833e0
+        if (domain->krb5_keytab == NULL) {
b833e0
+            DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get domain keytab!\n");
b833e0
+            goto done;
b833e0
+        }
b833e0
+    }
b833e0
+
b833e0
     domain->has_views = false;
b833e0
     domain->view_name = NULL;
b833e0
 
b833e0
diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h
b833e0
index fd6d76cde..54e3f7380 100644
b833e0
--- a/src/confdb/confdb.h
b833e0
+++ b/src/confdb/confdb.h
b833e0
@@ -425,6 +425,12 @@ struct sss_domain_info {
b833e0
     /* Do not use the _output_fqnames property directly in new code, but rather
b833e0
      * use sss_domain_info_{get,set}_output_fqnames(). */
b833e0
     bool output_fqnames;
b833e0
+
b833e0
+    /* Hostname associated with this domain. */
b833e0
+    const char *hostname;
b833e0
+
b833e0
+    /* Keytab used by this domain. */
b833e0
+    const char *krb5_keytab;
b833e0
 };
b833e0
 
b833e0
 /**
b833e0
diff --git a/src/db/sysdb_subdomains.c b/src/db/sysdb_subdomains.c
b833e0
index d256817a6..5b42f9bdc 100644
b833e0
--- a/src/db/sysdb_subdomains.c
b833e0
+++ b/src/db/sysdb_subdomains.c
b833e0
@@ -125,6 +125,18 @@ struct sss_domain_info *new_subdomain(TALLOC_CTX *mem_ctx,
b833e0
         }
b833e0
     }
b833e0
 
b833e0
+    dom->hostname = talloc_strdup(dom, parent->hostname);
b833e0
+    if (dom->hostname == NULL && parent->hostname != NULL) {
b833e0
+        DEBUG(SSSDBG_OP_FAILURE, "Failed to copy hostname.\n");
b833e0
+        goto fail;
b833e0
+    }
b833e0
+
b833e0
+    dom->krb5_keytab = talloc_strdup(dom, parent->krb5_keytab);
b833e0
+    if (dom->krb5_keytab == NULL && parent->krb5_keytab != NULL) {
b833e0
+        DEBUG(SSSDBG_OP_FAILURE, "Failed to copy krb5_keytab.\n");
b833e0
+        goto fail;
b833e0
+    }
b833e0
+
b833e0
     dom->enumerate = enumerate;
b833e0
     dom->fqnames = true;
b833e0
     dom->mpg_mode = mpg_mode;
b833e0
-- 
b833e0
2.21.3
b833e0