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

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