Blame SOURCES/0088-confdb-Always-read-snippet-files.patch

71e593
From 8a3517c5466c107f4d4e0970a1c33b51d6c762f8 Mon Sep 17 00:00:00 2001
71e593
From: =?UTF-8?q?Michal=20=C5=BDidek?= <mzidek@redhat.com>
71e593
Date: Wed, 9 Jan 2019 14:08:29 +0100
71e593
Subject: [PATCH 88/89] confdb: Always read snippet files
71e593
71e593
This patch removes the ldif with fallback configuration
71e593
and adds the fallback configuration as in-memory
71e593
INI snippet.
71e593
71e593
Fixes:
71e593
https://pagure.io/SSSD/sssd/issue/3439
71e593
71e593
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
71e593
---
71e593
 src/confdb/confdb_setup.c | 122 +++++++++++++++++---------------------
71e593
 src/util/sss_ini.c        |  13 +++-
71e593
 src/util/sss_ini.h        |   5 ++
71e593
 3 files changed, 70 insertions(+), 70 deletions(-)
71e593
71e593
diff --git a/src/confdb/confdb_setup.c b/src/confdb/confdb_setup.c
71e593
index 7acefbe6b..7d039341d 100644
71e593
--- a/src/confdb/confdb_setup.c
71e593
+++ b/src/confdb/confdb_setup.c
71e593
@@ -28,16 +28,6 @@
71e593
 #include "confdb_setup.h"
71e593
 #include "util/sss_ini.h"
71e593
 
71e593
-#ifndef SSSD_FALLBACK_CONFIG_LDIF
71e593
-#define SSSD_FALLBACK_CONFIG_LDIF \
71e593
-"dn: cn=config\n" \
71e593
-"version: 2\n\n" \
71e593
-"dn: cn=sssd,cn=config\n" \
71e593
-"cn: sssd\n" \
71e593
-"enable_files_domain: true\n" \
71e593
-"services: nss\n\n"
71e593
-#endif /* SSSD_FALLBACK_CONFIG_LDIF */
71e593
-
71e593
 static int confdb_test(struct confdb_ctx *cdb)
71e593
 {
71e593
     char **values;
71e593
@@ -146,28 +136,52 @@ static int confdb_ldif_from_ini_file(TALLOC_CTX *mem_ctx,
71e593
     errno_t ret;
71e593
     char timestr[21];
71e593
     int version;
71e593
+    char fallback_cfg[] =
71e593
+        "[sssd]\n"
71e593
+        "enable_files_domain = true\n"
71e593
+        "services = nss\n";
71e593
 
71e593
-    ret = sss_ini_config_access_check(init_data);
71e593
-    if (ret != EOK) {
71e593
-        DEBUG(SSSDBG_CRIT_FAILURE,
71e593
-              "Permission check on config file failed.\n");
71e593
-        return EPERM;
71e593
-    }
71e593
+    /* Open config file */
71e593
+    ret = sss_ini_config_file_open(init_data, config_file);
71e593
+    if (ret == ENOENT) {
71e593
+        DEBUG(SSSDBG_TRACE_FUNC, "No sssd.conf.\n");
71e593
+        ret = sss_ini_config_file_from_mem(fallback_cfg,
71e593
+                                           strlen(fallback_cfg),
71e593
+                                           init_data);
71e593
+        if (ret != EOK) {
71e593
+            DEBUG(SSSDBG_FATAL_FAILURE,
71e593
+                  "sss_ini_config_file_from_mem failed. Error %d: %s\n",
71e593
+                  ret, sss_strerror(ret));
71e593
+            return ret;
71e593
+        }
71e593
+    } else if (ret == EOK) {
71e593
+        ret = sss_ini_config_access_check(init_data);
71e593
+        if (ret != EOK) {
71e593
+            DEBUG(SSSDBG_CRIT_FAILURE,
71e593
+                  "Permission check on config file failed.\n");
71e593
+            return EPERM;
71e593
+        }
71e593
 
71e593
-    ret = sss_ini_get_stat(init_data);
71e593
-    if (ret != EOK) {
71e593
-        ret = errno;
71e593
-        DEBUG(SSSDBG_FATAL_FAILURE,
71e593
+        ret = sss_ini_get_stat(init_data);
71e593
+        if (ret != EOK) {
71e593
+            ret = errno;
71e593
+            DEBUG(SSSDBG_FATAL_FAILURE,
71e593
               "Status check on config file failed.\n");
71e593
-        return ret;
71e593
-    }
71e593
+            return ret;
71e593
+        }
71e593
 
71e593
-    errno = 0;
71e593
-    ret = sss_ini_get_mtime(init_data, sizeof(timestr), timestr);
71e593
-    if (ret <= 0 || ret >= (int)sizeof(timestr)) {
71e593
-        DEBUG(SSSDBG_FATAL_FAILURE,
71e593
-              "Failed to convert time_t to string??\n");
71e593
-        ret = errno ? errno : EFAULT;
71e593
+        errno = 0;
71e593
+        ret = sss_ini_get_mtime(init_data, sizeof(timestr), timestr);
71e593
+        if (ret <= 0 || ret >= (int)sizeof(timestr)) {
71e593
+            DEBUG(SSSDBG_FATAL_FAILURE,
71e593
+                  "Failed to convert time_t to string??\n");
71e593
+            ret = errno ? errno : EFAULT;
71e593
+            return ret;
71e593
+        }
71e593
+    } else {
71e593
+        DEBUG(SSSDBG_CONF_SETTINGS,
71e593
+              "sss_ini_config_file_open failed: %s [%d]\n", sss_strerror(ret),
71e593
+              ret);
71e593
         return ret;
71e593
     }
71e593
 
71e593
@@ -237,19 +251,6 @@ static int confdb_ldif_from_ini_file(TALLOC_CTX *mem_ctx,
71e593
     return EOK;
71e593
 }
71e593
 
71e593
-static int confdb_fallback_ldif(TALLOC_CTX *mem_ctx,
71e593
-                                const char **_timestr,
71e593
-                                const char **_ldif)
71e593
-{
71e593
-    *_timestr = talloc_strdup(mem_ctx, "1");
71e593
-    *_ldif = talloc_strdup(mem_ctx, SSSD_FALLBACK_CONFIG_LDIF);
71e593
-    if (*_timestr == NULL || *_ldif == NULL) {
71e593
-        return ENOMEM;
71e593
-    }
71e593
-
71e593
-    return EOK;
71e593
-}
71e593
-
71e593
 static int confdb_write_ldif(struct confdb_ctx *cdb,
71e593
                              const char *config_ldif,
71e593
                              bool replace_whole_db)
71e593
@@ -318,34 +319,17 @@ static int confdb_init_db(const char *config_file,
71e593
         goto done;
71e593
     }
71e593
 
71e593
-    /* Open config file */
71e593
-    ret = sss_ini_config_file_open(init_data, config_file);
71e593
-    if (ret == EOK) {
71e593
-        ret = confdb_ldif_from_ini_file(tmp_ctx,
71e593
-                                        config_file,
71e593
-                                        config_dir,
71e593
-                                        only_section,
71e593
-                                        init_data,
71e593
-                                        &timestr,
71e593
-                                        &config_ldif);
71e593
-        if (ret != EOK) {
71e593
-            DEBUG(SSSDBG_CRIT_FAILURE,
71e593
-                  "Cannot convert INI to LDIF [%d]: [%s]\n",
71e593
-                  ret, sss_strerror(ret));
71e593
-            goto done;
71e593
-        }
71e593
-    } else if (ret == ENOENT) {
71e593
-        ret = confdb_fallback_ldif(tmp_ctx, &timestr, &config_ldif);
71e593
-        if (ret != EOK) {
71e593
-            DEBUG(SSSDBG_CRIT_FAILURE,
71e593
-                  "Cannot create a fallback configuration [%d]: [%s]\n",
71e593
-                  ret, sss_strerror(ret));
71e593
-            goto done;
71e593
-        }
71e593
-    } else {
71e593
-        DEBUG(SSSDBG_CONF_SETTINGS,
71e593
-              "sss_ini_config_file_open failed: %s [%d]\n", sss_strerror(ret),
71e593
-              ret);
71e593
+    ret = confdb_ldif_from_ini_file(tmp_ctx,
71e593
+                                    config_file,
71e593
+                                    config_dir,
71e593
+                                    only_section,
71e593
+                                    init_data,
71e593
+                                    &timestr,
71e593
+                                    &config_ldif);
71e593
+    if (ret != EOK) {
71e593
+        DEBUG(SSSDBG_CRIT_FAILURE,
71e593
+              "Cannot convert INI to LDIF [%d]: [%s]\n",
71e593
+            ret, sss_strerror(ret));
71e593
         goto done;
71e593
     }
71e593
 
71e593
diff --git a/src/util/sss_ini.c b/src/util/sss_ini.c
71e593
index 3c15b2809..010b77889 100644
71e593
--- a/src/util/sss_ini.c
71e593
+++ b/src/util/sss_ini.c
71e593
@@ -123,7 +123,18 @@ int sss_ini_config_file_open(struct sss_ini_initdata *init_data,
71e593
 #endif
71e593
 }
71e593
 
71e593
-
71e593
+int sss_ini_config_file_from_mem(void *data_buf,
71e593
+                                 uint32_t data_len,
71e593
+                                 struct sss_ini_initdata *init_data)
71e593
+{
71e593
+#ifdef HAVE_LIBINI_CONFIG_V1
71e593
+    return ini_config_file_from_mem(data_buf, strlen(data_buf),
71e593
+                                   &init_data->file);
71e593
+#else
71e593
+    /* FIXME: Remove support for older libini versions */
71e593
+    return EINVAL;
71e593
+#endif
71e593
+}
71e593
 
71e593
 /* Check configuration file permissions */
71e593
 
71e593
diff --git a/src/util/sss_ini.h b/src/util/sss_ini.h
71e593
index 470b88f99..0bf9c0ff5 100644
71e593
--- a/src/util/sss_ini.h
71e593
+++ b/src/util/sss_ini.h
71e593
@@ -45,6 +45,11 @@ void sss_ini_close_file(struct sss_ini_initdata *init_data);
71e593
 int sss_ini_config_file_open(struct sss_ini_initdata *init_data,
71e593
                              const char *config_file);
71e593
 
71e593
+/* Load config from buffer */
71e593
+int sss_ini_config_file_from_mem(void *data_buf,
71e593
+                                 uint32_t data_len,
71e593
+                                 struct sss_ini_initdata *init_data);
71e593
+
71e593
 /* Check file permissions */
71e593
 int sss_ini_config_access_check(struct sss_ini_initdata *init_data);
71e593
 
71e593
-- 
71e593
2.19.1
71e593