Blame SOURCES/0010-ad-allow-booleans-for-ad_inherit_opts_if_needed.patch

0d441c
From 9beb736aac6aa21433a4541fb56e4fa7d7dbc462 Mon Sep 17 00:00:00 2001
0d441c
From: Sumit Bose <sbose@redhat.com>
0d441c
Date: Thu, 26 Sep 2019 20:24:34 +0200
0d441c
Subject: [PATCH 10/13] ad: allow booleans for ad_inherit_opts_if_needed()
0d441c
MIME-Version: 1.0
0d441c
Content-Type: text/plain; charset=UTF-8
0d441c
Content-Transfer-Encoding: 8bit
0d441c
0d441c
Currently ad_inherit_opts_if_needed() can only handle strings. With this
0d441c
patch it can handle boolean options as well.
0d441c
0d441c
Related to https://pagure.io/SSSD/sssd/issue/4131
0d441c
0d441c
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
0d441c
---
0d441c
 src/providers/ad/ad_common.c | 23 ++++++++++++++++++++---
0d441c
 1 file changed, 20 insertions(+), 3 deletions(-)
0d441c
0d441c
diff --git a/src/providers/ad/ad_common.c b/src/providers/ad/ad_common.c
0d441c
index 5540066d4..600e3ceb2 100644
0d441c
--- a/src/providers/ad/ad_common.c
0d441c
+++ b/src/providers/ad/ad_common.c
0d441c
@@ -1479,9 +1479,26 @@ errno_t ad_inherit_opts_if_needed(struct dp_option *parent_opts,
0d441c
     const char *parent_val = NULL;
0d441c
     char *dummy = NULL;
0d441c
     char *option_list[2] = { NULL, NULL };
0d441c
-
0d441c
-    parent_val = dp_opt_get_cstring(parent_opts, opt_id);
0d441c
-    if (parent_val != NULL) {
0d441c
+    bool is_default = true;
0d441c
+
0d441c
+    switch (parent_opts[opt_id].type) {
0d441c
+    case DP_OPT_STRING:
0d441c
+        parent_val = dp_opt_get_cstring(parent_opts, opt_id);
0d441c
+        break;
0d441c
+    case DP_OPT_BOOL:
0d441c
+        /* For booleans it is hard to say if the option is set or not since
0d441c
+         * both possible values are valid ones. So we check if the value is
0d441c
+         * different from the default and skip if it is the default. In this
0d441c
+         * case the sub-domain option would either be the default as well or
0d441c
+         * manully set and in both cases we do not have to change it. */
0d441c
+        is_default = (parent_opts[opt_id].val.boolean
0d441c
+                                == parent_opts[opt_id].def_val.boolean);
0d441c
+        break;
0d441c
+    default:
0d441c
+        DEBUG(SSSDBG_TRACE_FUNC, "Unsupported type, skipping.\n");
0d441c
+    }
0d441c
+
0d441c
+    if (parent_val != NULL || !is_default) {
0d441c
         ret = confdb_get_string(cdb, NULL, subdom_conf_path,
0d441c
                                 parent_opts[opt_id].opt_name, NULL, &dummy);
0d441c
         if (ret != EOK) {
0d441c
-- 
0d441c
2.20.1
0d441c