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

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