From 6e40811d533b3fe42b2bc16deb529170ebbd9f3f Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 19 Nov 2015 13:45:31 +0100 Subject: [PATCH] Don't fall over if a [domain] section in sssd.conf exists The authoritative place for domains in sssd is the [sssd] domains= line. So check that when adding a domain. Don't complain if there's already a section with the appropriate name. https://bugs.freedesktop.org/show_bug.cgi?id=93011 --- service/realm-sssd-config.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/service/realm-sssd-config.c b/service/realm-sssd-config.c index 4b16a8e..2096afd 100644 --- a/service/realm-sssd-config.c +++ b/service/realm-sssd-config.c @@ -127,9 +127,11 @@ realm_sssd_config_add_domain (RealmIniConfig *config, ...) { const gchar *domains[2]; + gchar **already; gboolean ret; gchar *section; va_list va; + gint i; g_return_val_if_fail (REALM_IS_INI_CONFIG (config), FALSE); g_return_val_if_fail (domain != NULL, FALSE); @@ -138,15 +140,19 @@ realm_sssd_config_add_domain (RealmIniConfig *config, if (!realm_ini_config_begin_change (config, error)) return FALSE; - section = realm_sssd_config_domain_to_section (domain); - if (realm_ini_config_have_section (config, section)) { - realm_ini_config_abort_change (config); - g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_EXIST, - _("Already have domain %s in sssd.conf config file"), domain); - g_free (section); - return FALSE; + already = realm_sssd_config_get_domains (config); + for (i = 0; already && already[i] != NULL; i++) { + if (g_str_equal (domain, already[i])) { + realm_ini_config_abort_change (config); + g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_EXIST, + _("Already have domain %s in sssd.conf config file"), domain); + g_strfreev (already); + return FALSE; + } } + g_strfreev (already); + /* Setup a default sssd section */ if (!realm_ini_config_have (config, "section", "services")) realm_ini_config_set (config, "sssd", "services", "nss, pam", NULL); @@ -157,6 +163,8 @@ realm_sssd_config_add_domain (RealmIniConfig *config, domains[1] = NULL; realm_ini_config_set_list_diff (config, "sssd", "domains", ", ", domains, NULL); + section = realm_sssd_config_domain_to_section (domain); + va_start (va, error); ret = update_domain (config, section, va, error); va_end (va); -- 2.5.0