From d3f0d3011f8b0bed90155cccf49bc21c4e1027ae Mon Sep 17 00:00:00 2001
From: Justin Stephenson <jstephen@redhat.com>
Date: Tue, 3 Aug 2021 11:40:29 -0400
Subject: [PATCH] MONITOR: Return success from genconf with no config

Resolves: https://github.com/SSSD/sssd/issues/5729
---
 src/monitor/monitor.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index 41601ec559..b48b56168d 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -1642,6 +1642,13 @@ errno_t load_configuration(TALLOC_CTX *mem_ctx,
         goto done;
     }
 
+    /* return EOK for genconf-section to exit 0 when no
+     * sssd configuration exists (KCM use case) */
+    if (only_section != NULL) {
+        *monitor = NULL;
+        goto done;
+    }
+
     /* Validate the configuration in the database */
     /* Read in the monitor's configuration */
     ret = get_monitor_config(ctx);
@@ -1666,7 +1673,7 @@ errno_t load_configuration(TALLOC_CTX *mem_ctx,
 
 done:
     talloc_free(cdb_file);
-    if (ret != EOK) {
+    if (ret != EOK || only_section != NULL) {
         talloc_free(ctx);
     }
     return ret;
