sssd/0050-IPA_COMMON-Introduce-ipa_get_host_attrs.patch

148 lines
4.9 KiB
Diff
Raw Normal View History

From 7c1d1393537dec95e09b83b607ce9d0e8f49584c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Tue, 18 Apr 2017 14:33:20 +0200
Subject: [PATCH 50/93] IPA_COMMON: Introduce ipa_get_host_attrs()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
By adding this method it can reused in the future for new backend
modules.
Related:
https://pagure.io/SSSD/sssd/issue/2995
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
---
src/providers/ipa/ipa_access.c | 35 ++++++----------------------------
src/providers/ipa/ipa_common.c | 43 ++++++++++++++++++++++++++++++++++++++++++
src/providers/ipa/ipa_common.h | 6 ++++++
3 files changed, 55 insertions(+), 29 deletions(-)
diff --git a/src/providers/ipa/ipa_access.c b/src/providers/ipa/ipa_access.c
index 36f05ed60eff7d6aadaa8ea0a5f4965cfbe5a4da..32ccf541c9436b633e7724b2c44ee545810a7fb8 100644
--- a/src/providers/ipa/ipa_access.c
+++ b/src/providers/ipa/ipa_access.c
@@ -338,10 +338,7 @@ static void ipa_fetch_hbac_services_done(struct tevent_req *subreq)
{
struct ipa_fetch_hbac_state *state;
struct tevent_req *req;
- const char *ipa_hostname;
- const char *hostname;
errno_t ret;
- size_t i;
req = tevent_req_callback_data(subreq, struct tevent_req);
state = tevent_req_data(req, struct ipa_fetch_hbac_state);
@@ -359,32 +356,12 @@ static void ipa_fetch_hbac_services_done(struct tevent_req *subreq)
}
/* Get the ipa_host attrs */
- state->ipa_host = NULL;
- ipa_hostname = dp_opt_get_cstring(state->ipa_options, IPA_HOSTNAME);
- if (ipa_hostname == NULL) {
- DEBUG(SSSDBG_CRIT_FAILURE,
- "Missing ipa_hostname, this should never happen.\n");
- ret = EINVAL;
- goto done;
- }
-
- for (i = 0; i < state->hosts->entry_count; i++) {
- ret = sysdb_attrs_get_string(state->hosts->entries[i], SYSDB_FQDN,
- &hostname);
- if (ret != EOK) {
- DEBUG(SSSDBG_CRIT_FAILURE, "Could not locate IPA host\n");
- goto done;
- }
-
- if (strcasecmp(hostname, ipa_hostname) == 0) {
- state->ipa_host = state->hosts->entries[i];
- break;
- }
- }
-
- if (state->ipa_host == NULL) {
- DEBUG(SSSDBG_CRIT_FAILURE, "Could not locate IPA host\n");
- ret = EINVAL;
+ ret = ipa_get_host_attrs(state->ipa_options,
+ state->hosts->entry_count,
+ state->hosts->entries,
+ &state->ipa_host);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Could not locate IPA host.\n");
goto done;
}
diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c
index 657994508e0733e86ba474419380a0081c51ee6e..6b29f2fde31f3866bb62b5c03e47e6c24f837550 100644
--- a/src/providers/ipa/ipa_common.c
+++ b/src/providers/ipa/ipa_common.c
@@ -1194,3 +1194,46 @@ errno_t ipa_get_dyndns_options(struct be_ctx *be_ctx,
return EOK;
}
+
+errno_t ipa_get_host_attrs(struct dp_option *ipa_options,
+ size_t host_count,
+ struct sysdb_attrs **hosts,
+ struct sysdb_attrs **_ipa_host)
+{
+ const char *ipa_hostname;
+ const char *hostname;
+ errno_t ret;
+
+ *_ipa_host = NULL;
+ ipa_hostname = dp_opt_get_cstring(ipa_options, IPA_HOSTNAME);
+ if (ipa_hostname == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Missing ipa_hostname, this should never happen.\n");
+ ret = EINVAL;
+ goto done;
+ }
+
+ for (size_t i = 0; i < host_count; i++) {
+ ret = sysdb_attrs_get_string(hosts[i], SYSDB_FQDN, &hostname);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Could not locate IPA host\n");
+ goto done;
+ }
+
+ if (strcasecmp(hostname, ipa_hostname) == 0) {
+ *_ipa_host = hosts[i];
+ break;
+ }
+ }
+
+ if (*_ipa_host == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Could not locate IPA host\n");
+ ret = EINVAL;
+ goto done;
+ }
+
+ ret = EOK;
+
+done:
+ return ret;
+}
diff --git a/src/providers/ipa/ipa_common.h b/src/providers/ipa/ipa_common.h
index add9df87692c732b3567eee5584e7698991c66ca..b1d90d3624b5bc6a126709e6bd6fb1fdbbaafad8 100644
--- a/src/providers/ipa/ipa_common.h
+++ b/src/providers/ipa/ipa_common.h
@@ -292,4 +292,10 @@ errno_t ipa_idmap_init(TALLOC_CTX *mem_ctx,
struct krb5_ctx *ipa_init_get_krb5_auth_ctx(void *data);
+
+errno_t ipa_get_host_attrs(struct dp_option *ipa_options,
+ size_t host_count,
+ struct sysdb_attrs **hosts,
+ struct sysdb_attrs **_ipa_host);
+
#endif /* _IPA_COMMON_H_ */
--
2.14.1