dpward / rpms / sssd

Forked from rpms/sssd 3 years ago
Clone

Blame SOURCES/0020-MONITOR-Add-a-new-option-to-control-resolv.conf-moni.patch

464b57
From f952a5de24ba7c40310bbf63fa83d772a9cbaec9 Mon Sep 17 00:00:00 2001
464b57
From: Samuel Cabrero <scabrero@suse.de>
464b57
Date: Mon, 2 Sep 2019 15:31:09 +0200
464b57
Subject: [PATCH 20/21] MONITOR: Add a new option to control resolv.conf
464b57
 monitoring
464b57
MIME-Version: 1.0
464b57
Content-Type: text/plain; charset=UTF-8
464b57
Content-Transfer-Encoding: 8bit
464b57
464b57
For those use-cases where resolv.conf will never exist the new
464b57
'monitor_resolv_conf' option can be set to false to skip the retry loop
464b57
which tries to set the inotify watcher.
464b57
464b57
Signed-off-by: Samuel Cabrero <scabrero@suse.de>
464b57
464b57
Reviewed-by: Sumit Bose <sbose@redhat.com>
464b57
(cherry picked from commit 9b6323d8e99c3edb16b64ef60a769efbc3a292aa)
464b57
464b57
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
464b57
---
464b57
 src/confdb/confdb.h          |  1 +
464b57
 src/config/SSSDConfigTest.py |  1 +
464b57
 src/config/cfg_rules.ini     |  1 +
464b57
 src/config/etc/sssd.api.conf |  1 +
464b57
 src/man/sssd.conf.5.xml      | 23 ++++++++++++-----
464b57
 src/monitor/monitor.c        | 49 ++++++++++++++++++++++++++++--------
464b57
 6 files changed, 59 insertions(+), 17 deletions(-)
464b57
464b57
diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h
464b57
index 0251ab606..d3e71be86 100644
464b57
--- a/src/confdb/confdb.h
464b57
+++ b/src/confdb/confdb.h
464b57
@@ -66,6 +66,7 @@
464b57
 #define CONFDB_MONITOR_SBUS_TIMEOUT "sbus_timeout"
464b57
 #define CONFDB_MONITOR_ACTIVE_SERVICES "services"
464b57
 #define CONFDB_MONITOR_ACTIVE_DOMAINS "domains"
464b57
+#define CONFDB_MONITOR_RESOLV_CONF "monitor_resolv_conf"
464b57
 #define CONFDB_MONITOR_TRY_INOTIFY "try_inotify"
464b57
 #define CONFDB_MONITOR_KRB5_RCACHEDIR "krb5_rcache_dir"
464b57
 #define CONFDB_MONITOR_DEFAULT_DOMAIN "default_domain_suffix"
464b57
diff --git a/src/config/SSSDConfigTest.py b/src/config/SSSDConfigTest.py
464b57
index 863304424..979b1806f 100755
464b57
--- a/src/config/SSSDConfigTest.py
464b57
+++ b/src/config/SSSDConfigTest.py
464b57
@@ -391,6 +391,7 @@ class SSSDConfigTestSSSDService(unittest.TestCase):
464b57
             'enable_files_domain',
464b57
             'domain_resolution_order',
464b57
             'try_inotify',
464b57
+            'monitor_resolv_conf',
464b57
         ]
464b57
 
464b57
         self.assertTrue(type(options) == dict,
464b57
diff --git a/src/config/cfg_rules.ini b/src/config/cfg_rules.ini
464b57
index 228c8841e..997ba5aec 100644
464b57
--- a/src/config/cfg_rules.ini
464b57
+++ b/src/config/cfg_rules.ini
464b57
@@ -51,6 +51,7 @@ option = disable_netlink
464b57
 option = enable_files_domain
464b57
 option = domain_resolution_order
464b57
 option = try_inotify
464b57
+option = monitor_resolv_conf
464b57
 
464b57
 [rule/allowed_nss_options]
464b57
 validator = ini_allowed_options
464b57
diff --git a/src/config/etc/sssd.api.conf b/src/config/etc/sssd.api.conf
464b57
index a10e74889..355c1fc9b 100644
464b57
--- a/src/config/etc/sssd.api.conf
464b57
+++ b/src/config/etc/sssd.api.conf
464b57
@@ -34,6 +34,7 @@ disable_netlink = bool, None, false
464b57
 enable_files_domain = str, None, false
464b57
 domain_resolution_order = list, str, false
464b57
 try_inotify = bool, None, false
464b57
+monitor_resolv_conf = bool, None, false
464b57
 
464b57
 [nss]
464b57
 # Name service
464b57
diff --git a/src/man/sssd.conf.5.xml b/src/man/sssd.conf.5.xml
464b57
index 277a3c0cb..0e1a97a31 100644
464b57
--- a/src/man/sssd.conf.5.xml
464b57
+++ b/src/man/sssd.conf.5.xml
464b57
@@ -318,16 +318,27 @@
464b57
                             </para>
464b57
                         </listitem>
464b57
                     </varlistentry>
464b57
+                    <varlistentry>
464b57
+                        <term>monitor_resolv_conf (boolean)</term>
464b57
+                        <listitem>
464b57
+                            <para>
464b57
+                                Controls if SSSD should monitor the state of
464b57
+                                resolv.conf to identify when it needs to
464b57
+                                update its internal DNS resolver.
464b57
+                            </para>
464b57
+                            <para>
464b57
+                                Default: true
464b57
+                            </para>
464b57
+                        </listitem>
464b57
+                    </varlistentry>
464b57
                     <varlistentry>
464b57
                         <term>try_inotify (boolean)</term>
464b57
                         <listitem>
464b57
                             <para>
464b57
-                                SSSD monitors the state of resolv.conf to
464b57
-                                identify when it needs to update its internal
464b57
-                                DNS resolver. By default, we will attempt to
464b57
-                                use inotify for this, and will fall back to
464b57
-                                polling resolv.conf every five seconds if
464b57
-                                inotify cannot be used.
464b57
+                                By default, SSSD will attempt to use inotify
464b57
+                                to monitor configuration files changes and
464b57
+                                will fall back to polling every five seconds
464b57
+                                if inotify cannot be used.
464b57
                             </para>
464b57
                             <para>
464b57
                                 There are some limited situations where it is
464b57
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
464b57
index 04e0017a2..5dfc4423c 100644
464b57
--- a/src/monitor/monitor.c
464b57
+++ b/src/monitor/monitor.c
464b57
@@ -1971,13 +1971,46 @@ static void missing_resolv_conf(struct tevent_context *ev,
464b57
     }
464b57
 }
464b57
 
464b57
+static int monitor_config_files(struct mt_ctx *ctx)
464b57
+{
464b57
+    int ret;
464b57
+    bool monitor_resolv_conf;
464b57
+    struct timeval tv;
464b57
+    struct tevent_timer *te;
464b57
+
464b57
+    /* Watch for changes to the DNS resolv.conf */
464b57
+    ret = confdb_get_bool(ctx->cdb,
464b57
+                          CONFDB_MONITOR_CONF_ENTRY,
464b57
+                          CONFDB_MONITOR_RESOLV_CONF,
464b57
+                          true, &monitor_resolv_conf);
464b57
+    if (ret != EOK) {
464b57
+        return ret;
464b57
+    }
464b57
+
464b57
+    if (monitor_resolv_conf) {
464b57
+        ret = monitor_config_file(ctx, ctx, monitor_update_resolv,
464b57
+                                  RESOLV_CONF_PATH);
464b57
+        if (ret == ENOENT) {
464b57
+            tv = tevent_timeval_current_ofs(MISSING_RESOLV_CONF_POLL_TIME, 0);
464b57
+            te = tevent_add_timer(ctx->ev, ctx, tv, missing_resolv_conf, ctx);
464b57
+            if (te == NULL) {
464b57
+                DEBUG(SSSDBG_FATAL_FAILURE, "resolv.conf will be ignored\n");
464b57
+            }
464b57
+        } else if (ret != EOK) {
464b57
+            return ret;
464b57
+        }
464b57
+    } else {
464b57
+        DEBUG(SSS_LOG_NOTICE, "%s monitoring is disabled\n", RESOLV_CONF_PATH);
464b57
+    }
464b57
+
464b57
+    return EOK;
464b57
+}
464b57
+
464b57
 static int monitor_process_init(struct mt_ctx *ctx,
464b57
                                 const char *config_file)
464b57
 {
464b57
     TALLOC_CTX *tmp_ctx;
464b57
     struct tevent_signal *tes;
464b57
-    struct timeval tv;
464b57
-    struct tevent_timer *te;
464b57
     struct sss_domain_info *dom;
464b57
     char *rcachedir;
464b57
     int num_providers;
464b57
@@ -2052,15 +2085,9 @@ static int monitor_process_init(struct mt_ctx *ctx,
464b57
     ret = sss_sigchld_init(ctx, ctx->ev, &ctx->sigchld_ctx);
464b57
     if (ret != EOK) return ret;
464b57
 
464b57
-    /* Watch for changes to the DNS resolv.conf */
464b57
-    ret = monitor_config_file(ctx, ctx, monitor_update_resolv, RESOLV_CONF_PATH);
464b57
-    if (ret == ENOENT) {
464b57
-        tv = tevent_timeval_current_ofs(MISSING_RESOLV_CONF_POLL_TIME, 0);
464b57
-        te = tevent_add_timer(ctx->ev, ctx, tv, missing_resolv_conf, ctx);
464b57
-        if (te == NULL) {
464b57
-            DEBUG(SSSDBG_FATAL_FAILURE, "resolv.conf will be ignored\n");
464b57
-        }
464b57
-    } else if (ret != EOK) {
464b57
+    /* Set up watchers for system config files */
464b57
+    ret = monitor_config_files(ctx);
464b57
+    if (ret != EOK) {
464b57
         return ret;
464b57
     }
464b57
 
464b57
-- 
464b57
2.21.1
464b57