[SSSD] [RFC][PATCH] adding domain-type config option

Sumit Bose sbose at redhat.com
Thu Sep 3 12:02:13 UTC 2009


Hi,

this patch is work in progress, please do not push it to the master
repository.

I think it makes sense to introduce meta-options which can set more than
on option at once. As an example I have implemented a 'domain-type'
option which will set a couple of option for an IPA domain at once. To
handle more than one meta-option this patch needs a bit more
abstraction, but I would like to get some feedback on the general idea.

Thanks.

bye,
Sumit
-------------- next part --------------
>From 2d58e76d1300dd5d7457642d3a0dc54ee1f8e81f Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Wed, 2 Sep 2009 11:58:17 +0200
Subject: [PATCH] adding domain-type config option

---
 server/Makefile.am              |    2 +
 server/confdb/confdb.c          |    1 -
 server/confdb/confdb.h          |    1 +
 server/confdb/confdb_setup.c    |    7 ++
 server/confdb/domain_defaults.c |  118 +++++++++++++++++++++++++++++++++++++++
 server/confdb/domain_defaults.h |   32 +++++++++++
 6 files changed, 160 insertions(+), 1 deletions(-)
 create mode 100644 server/confdb/domain_defaults.c
 create mode 100644 server/confdb/domain_defaults.h

diff --git a/server/Makefile.am b/server/Makefile.am
index 12ec4b1..a06761e 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -222,6 +222,7 @@ dist_noinst_HEADERS = \
     providers/data_provider.h \
     providers/dp_interfaces.h \
     providers/dp_backend.h \
+    confdb/domain_defaults.h \
     providers/providers.h \
     providers/krb5/krb5_auth.h \
     providers/ldap/sdap.h \
@@ -239,6 +240,7 @@ dist_noinst_HEADERS = \
 sssd_SOURCES = \
     monitor/monitor.c \
     confdb/confdb_setup.c \
+    confdb/domain_defaults.c \
     $(SSSD_UTIL_OBJ)
 sssd_LDADD = \
     $(SSSD_LIBS)
diff --git a/server/confdb/confdb.c b/server/confdb/confdb.c
index 72e5eeb..865e044 100644
--- a/server/confdb/confdb.c
+++ b/server/confdb/confdb.c
@@ -28,7 +28,6 @@
 #include "util/btreemap.h"
 #include "db/sysdb.h"
 
-#define CONFDB_DOMAINS_PATH "config/domains"
 #define CONFDB_DOMAIN_BASEDN "cn=domains,cn=config"
 #define CONFDB_DOMAIN_ATTR "cn"
 #define CONFDB_MPG "magicPrivateGroups"
diff --git a/server/confdb/confdb.h b/server/confdb/confdb.h
index f565088..565edfc 100644
--- a/server/confdb/confdb.h
+++ b/server/confdb/confdb.h
@@ -34,6 +34,7 @@
 #define CONFDB_DEFAULT_CONFIG_FILE SSSD_CONF_DIR"/sssd.conf"
 #define SSSD_MIN_ID 1000
 
+#define CONFDB_DOMAINS_PATH "config/domains"
 #define SERVICE_CONF_ENTRY "config/services"
 
 struct confdb_ctx;
diff --git a/server/confdb/confdb_setup.c b/server/confdb/confdb_setup.c
index 00bba7f..95ae728 100644
--- a/server/confdb/confdb_setup.c
+++ b/server/confdb/confdb_setup.c
@@ -26,6 +26,7 @@
 #include "confdb.h"
 #include "confdb_private.h"
 #include "confdb_setup.h"
+#include "domain_defaults.h"
 #include "collection.h"
 #include "collection_tools.h"
 #include "ini_config.h"
@@ -348,6 +349,12 @@ int confdb_init_db(const char *config_file, struct confdb_ctx *cdb)
         ldb_ldif_read_free(cdb->ldb, ldif);
     }
 
+    ret = set_domain_defaults(tmp_ctx, cdb);
+    if (ret != EOK) {
+        DEBUG(1, ("set_domain_defaults failed.\n"));
+        goto done;
+    }
+
     /* now store the lastUpdate time so that we do not re-init if nothing
      * changed on restart */
 
diff --git a/server/confdb/domain_defaults.c b/server/confdb/domain_defaults.c
new file mode 100644
index 0000000..299b00e
--- /dev/null
+++ b/server/confdb/domain_defaults.c
@@ -0,0 +1,118 @@
+/*
+   SSSD
+
+   Data Provider Backend -- Domain Defaults
+
+   Copyright (C) Sumit Bose <sbose at redhat.com> 2008
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "confdb/domain_defaults.h"
+
+struct domain_defaults {
+    const char *name;
+    const char *value;
+};
+
+struct domain_defaults ipa_defaults[] = {
+    {"provider", "ldap"},
+    {"enumerate", "true"},
+    {"auth-module", "krb5"},
+    {"chpass-module", "krb5"},
+    {"access-module", "ipa"},
+    {"ldapSchema", "rfc2307bis"},
+    {NULL, NULL}
+};
+
+errno_t set_domain_defaults(TALLOC_CTX *mem_ctx, struct confdb_ctx *cdb)
+{
+    int ret;
+    int i;
+    int d;
+    char *conf_path = NULL;
+    char **get_values = NULL;
+    const char *val[2];
+    val[1] = NULL;
+    char **domlist = NULL;
+    struct domain_defaults *defaults = NULL;
+
+    ret = confdb_get_string_as_list(cdb, mem_ctx, CONFDB_DOMAINS_PATH,
+                                    "domains", &domlist);
+    if (ret != EOK ) {
+        DEBUG(0, ("Fatal error retrieving domains list!\n"));
+        goto done;
+    }
+
+    for (d = 0; domlist[d] != NULL; d++) {
+        conf_path = talloc_asprintf(mem_ctx, "config/domains/%s", domlist[d]);
+        if (conf_path == NULL) {
+            DEBUG(1, ("talloc_asprintf failed.\n"));
+            ret = ENOMEM;
+            goto done;
+        }
+
+        ret = confdb_get_param(cdb, mem_ctx, conf_path, "domain-type",
+                               &get_values);
+        if (ret != EOK) {
+            DEBUG(1, ("Failed to get domain_type.\n"));
+            goto done;
+        }
+        if (get_values[0] == NULL) {
+            DEBUG(9, ("Domain [%s] has no domain type defined.\n", domlist[d]));
+            continue;
+        }
+
+        if (strcasecmp(get_values[0], "ipa") == 0) {
+            DEBUG(5, ("Setting defaults for IPA domain\n"));
+            defaults = ipa_defaults;
+        } else {
+            DEBUG(1, ("Unsupported domain type [%s].\n", get_values[0]));
+            ret = EINVAL;
+            goto done;
+        }
+        talloc_zfree(get_values);
+
+        for (i = 0; defaults[i].name != NULL; i++) {
+            ret = confdb_get_param(cdb, mem_ctx,conf_path, defaults[i].name,
+                                   &get_values);
+            if (ret != EOK) {
+                DEBUG(1, ("Failed to get [%s].\n", defaults[i].name));
+                goto done;
+            }
+            if (get_values[0] != NULL) {
+                DEBUG(9 ,("Leaving attribute [%s] set to [%s].\n",
+                          defaults[i].name, get_values[0]));
+                talloc_zfree(get_values);
+                continue;
+            }
+            talloc_zfree(get_values);
+
+            val[0] = defaults[i].value;
+            DEBUG(9, ("Setting [%s] to [%s].\n", defaults[i].name, val[0]));
+            ret = confdb_add_param(cdb, true, conf_path, defaults[i].name, val);
+            if (ret != EOK) {
+                DEBUG(1, ("Failed to set [%s] to [%s].\n", defaults[i].name,
+                                                           val[0]));
+                goto done;
+            }
+        }
+    }
+
+    ret = EOK;
+done:
+    talloc_zfree(domlist);
+    talloc_zfree(conf_path);
+    return ret;
+}
diff --git a/server/confdb/domain_defaults.h b/server/confdb/domain_defaults.h
new file mode 100644
index 0000000..d1ac65e
--- /dev/null
+++ b/server/confdb/domain_defaults.h
@@ -0,0 +1,32 @@
+/*
+   SSSD
+
+   Data Provider Backend -- Domain Defaults header file
+
+   Copyright (C) Sumit Bose <sbose at redhat.com> 2008
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __DOMAIN_DEFAULTS_H__
+#define __DOMAIN_DEFAULTS_H__
+
+#include "util/util.h"
+#include "confdb/confdb.h"
+#include "confdb/confdb_private.h"
+#include "providers/dp_backend.h"
+
+errno_t set_domain_defaults(TALLOC_CTX *mem_ctx, struct confdb_ctx *cdb);
+
+#endif /* __DOMAIN_DEFAULTS_H__ */
-- 
1.6.2.5



More information about the sssd-devel mailing list