File pacemaker#3658-0001-Fix-libcib-treat-empty-variant-variables-same-as-uns.patch of Package pacemaker.38493

From a63a7b4947aa05924a2ea211e398f46465b58da7 Mon Sep 17 00:00:00 2001
From: Ken Gaillot <kgaillot@redhat.com>
Date: Tue, 17 Sep 2024 09:45:30 -0500
Subject: [PATCH] Fix: libcib: treat empty variant variables same as unset

Previously, an empty environment variable such as CIB_file= or
CIB_port= would trigger the relevant CIB variant even though it
couldn't work. Now, ignore an empty variable the same as if it were
unset.

Also improve logs.
---
 lib/cib/cib_client.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/lib/cib/cib_client.c b/lib/cib/cib_client.c
index 40ede8e713..cd91f21a85 100644
--- a/lib/cib/cib_client.c
+++ b/lib/cib/cib_client.c
@@ -600,17 +600,17 @@ cib_new(void)
     const char *value = getenv("CIB_shadow");
     int port;
 
-    if (value && value[0] != 0) {
+    if (!pcmk__str_empty(value)) {
         return cib_shadow_new(value);
     }
 
     value = getenv("CIB_file");
-    if (value) {
+    if (!pcmk__str_empty(value)) {
         return cib_file_new(value);
     }
 
     value = getenv("CIB_port");
-    if (value) {
+    if (!pcmk__str_empty(value)) {
         gboolean encrypted = TRUE;
         const char *server = getenv("CIB_server");
         const char *user = getenv("CIB_user");
@@ -623,22 +623,20 @@ cib_new(void)
          */
         pcmk__scan_port(value, &port);
 
-        value = getenv("CIB_encrypted");
-        if (value && crm_is_true(value) == FALSE) {
-            crm_info("Disabling TLS");
+        if (!crm_is_true(getenv("CIB_encrypted"))) {
             encrypted = FALSE;
         }
 
-        if (user == NULL) {
+        if (pcmk__str_empty(user)) {
             user = CRM_DAEMON_USER;
-            crm_info("Defaulting to user: %s", user);
         }
 
-        if (server == NULL) {
+        if (pcmk__str_empty(server)) {
             server = "localhost";
-            crm_info("Defaulting to localhost");
         }
 
+        crm_debug("Initializing %s remote CIB access to %s:%d as user %s",
+                  (encrypted? "encrypted" : "plain-text"), server, port, user);
         return cib_remote_new(server, user, pass, port, encrypted);
     }
 
-- 
2.43.0

openSUSE Build Service is sponsored by