From b41ff634e302aa034cd1cb28759efed51db87469 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
Date: Thu, 4 Apr 2013 12:28:15 +0200
Subject: [PATCH 6/9] DNS sites support - use SRV DNS lookup plugin in all
 providers

https://fedorahosted.org/sssd/ticket/1032

We set a plugin during an initialization of ID provider, which
is an authoritative provider for a plugin choice. The plugin is
set only once. When other provider is initalized (e.g. id = IPA,
sudo = LDAP), we do not overwrite the plugin.

Since sssm_*_id_init() is called from all module constructors,
this patch relies on the fact, that ID provider is initialized
before all other providers.
---
 src/providers/ad/ad_init.c     |  5 +++++
 src/providers/ipa/ipa_init.c   |  5 +++++
 src/providers/ldap/ldap_init.c | 14 ++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/src/providers/ad/ad_init.c b/src/providers/ad/ad_init.c
index 2add74a2051d677fb36eb70edb46ddd6bf7e61d9..6ae9c05c0762e3eba9207b0e90ba29dcfcbe8ecf 100644
--- a/src/providers/ad/ad_init.c
+++ b/src/providers/ad/ad_init.c
@@ -107,6 +107,7 @@ sssm_ad_id_init(struct be_ctx *bectx,
     errno_t ret;
     struct ad_id_ctx *ad_ctx;
     struct sdap_id_ctx *sdap_ctx;
+    const char *hostname;
 
     if (!ad_options) {
         ret = common_ad_init(bectx);
@@ -175,6 +176,10 @@ sssm_ad_id_init(struct be_ctx *bectx,
         goto done;
     }
 
+    /* setup SRV lookup plugin */
+    hostname = dp_opt_get_string(ad_options->basic, AD_HOSTNAME);
+    be_fo_set_standard_srv_lookup_plugin(bectx, hostname);
+
     *ops = &ad_id_ops;
     *pvt_data = ad_ctx;
 
diff --git a/src/providers/ipa/ipa_init.c b/src/providers/ipa/ipa_init.c
index a6c32be2a5e9b28647a50fbb1595e2ac74fbd650..6774c326196f35ee96272f8a6373fdad006292f9 100644
--- a/src/providers/ipa/ipa_init.c
+++ b/src/providers/ipa/ipa_init.c
@@ -110,6 +110,7 @@ int sssm_ipa_id_init(struct be_ctx *bectx,
     struct ipa_id_ctx *ipa_ctx;
     struct sdap_id_ctx *sdap_ctx;
     struct stat stat_buf;
+    const char *hostname;
     errno_t err;
     int ret;
 
@@ -207,6 +208,10 @@ int sssm_ipa_id_init(struct be_ctx *bectx,
         goto done;
     }
 
+    /* setup SRV lookup plugin */
+    hostname = dp_opt_get_string(ipa_options->basic, IPA_HOSTNAME);
+    be_fo_set_standard_srv_lookup_plugin(bectx, hostname);
+
     *ops = &ipa_id_ops;
     *pvt_data = ipa_ctx;
     ret = EOK;
diff --git a/src/providers/ldap/ldap_init.c b/src/providers/ldap/ldap_init.c
index fa888ba7dce2c98a74b144ae4ec536b3ef8b2f54..fb0bb110b306223fb73442a96fe015fb4d933ee0 100644
--- a/src/providers/ldap/ldap_init.c
+++ b/src/providers/ldap/ldap_init.c
@@ -29,6 +29,7 @@
 #include "providers/ldap/sdap_sudo.h"
 #include "providers/ldap/sdap_autofs.h"
 #include "providers/ldap/sdap_idmap.h"
+#include "providers/fail_over_srv.h"
 
 static void sdap_shutdown(struct be_req *req);
 
@@ -87,6 +88,7 @@ int sssm_ldap_id_init(struct be_ctx *bectx,
                       void **pvt_data)
 {
     struct sdap_id_ctx *ctx;
+    char hostname[HOST_NAME_MAX];
     const char *urls;
     const char *backup_urls;
     const char *dns_service_name;
@@ -172,6 +174,18 @@ int sssm_ldap_id_init(struct be_ctx *bectx,
         goto done;
     }
 
+    /* setup SRV lookup plugin */
+    ret = gethostname(hostname, HOST_NAME_MAX);
+    if (ret) {
+        ret = errno;
+        DEBUG(SSSDBG_CRIT_FAILURE,
+              ("gethostname() failed: [%d]: %s\n",ret, strerror(ret)));
+        goto done;
+    }
+    hostname[HOST_NAME_MAX-1] = '\0';
+
+    be_fo_set_standard_srv_lookup_plugin(bectx, hostname);
+
     *ops = &sdap_id_ops;
     *pvt_data = ctx;
     ret = EOK;
-- 
1.7.11.7

