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