summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Zeleny <jzeleny@redhat.com>2012-03-28 07:53:53 -0400
committerStephen Gallagher <sgallagh@redhat.com>2012-04-24 09:19:42 -0400
commit20d0bc6d587f346238062df4da5edfde815e59b1 (patch)
treef5102659ed392161b8cde13c972237b5220d7573
parente76d78338026fa47dca32eaf7f5c15eabb1b951a (diff)
downloadsssd-20d0bc6d587f346238062df4da5edfde815e59b1.tar.gz
sssd-20d0bc6d587f346238062df4da5edfde815e59b1.tar.xz
sssd-20d0bc6d587f346238062df4da5edfde815e59b1.zip
Add some utility functions for subdomains
-rw-r--r--Makefile.am3
-rw-r--r--src/confdb/confdb.h1
-rw-r--r--src/util/domain_info_utils.c110
-rw-r--r--src/util/util.h9
4 files changed, 122 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index 9cf904ebc..5a14b6fc7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -460,7 +460,8 @@ libsss_util_la_SOURCES = \
src/util/sss_tc_utf8.c \
src/util/murmurhash3.c \
src/util/atomic_io.c \
- src/util/sss_selinux.c
+ src/util/sss_selinux.c \
+ src/util/domain_info_utils.c
libsss_util_la_LIBADD = \
$(SSSD_LIBS) \
$(UNICODE_LIBS) \
diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h
index b1053bda5..370970b81 100644
--- a/src/confdb/confdb.h
+++ b/src/confdb/confdb.h
@@ -192,6 +192,7 @@ struct sss_domain_info {
struct sysdb_ctx *sysdb;
+ struct sss_domain_info *parent;
char *flat_name;
char *domain_id;
diff --git a/src/util/domain_info_utils.c b/src/util/domain_info_utils.c
new file mode 100644
index 000000000..5ee0aecef
--- /dev/null
+++ b/src/util/domain_info_utils.c
@@ -0,0 +1,110 @@
+/*
+ Authors:
+ Sumit Bose <sbose@redhat.com>
+
+ Copyright (C) 2012 Red Hat
+
+ 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/confdb.h"
+#include "db/sysdb.h"
+#include "util/util.h"
+
+struct sss_domain_info *new_subdomain(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *parent,
+ const char *name,
+ const char *flat_name,
+ const char *id)
+{
+ int ret;
+ struct sss_domain_info *dom = NULL;
+
+ dom = talloc_zero(mem_ctx, struct sss_domain_info);
+ if (dom == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, ("talloc_zero failed.\n"));
+ return NULL;
+ }
+
+ dom->parent = parent;
+ dom->name = talloc_strdup(dom, name);
+ if (dom->name == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Failed to copy domain name.\n"));
+ goto fail;
+ }
+
+ dom->provider = talloc_strdup(dom, parent->provider);
+ if (dom->provider == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Failed to copy provider name.\n"));
+ goto fail;
+ }
+
+ dom->name = talloc_strdup(dom, parent->name);
+ if (dom->name == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Failed to copy connection name.\n"));
+ goto fail;
+ }
+
+ if (flat_name != NULL) {
+ dom->flat_name = talloc_strdup(dom, flat_name);
+ if (dom->flat_name == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Failed to copy flat name.\n"));
+ goto fail;
+ }
+ }
+
+ if (id != NULL) {
+ dom->domain_id = talloc_strdup(dom, id);
+ if (dom->domain_id == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Failed to copy id.\n"));
+ goto fail;
+ }
+ }
+
+ dom->enumerate = false;
+ dom->fqnames = true;
+ /* FIXME: get ranges from the server */
+ dom->id_min = 0;
+ dom->id_max = 0xffffffff;
+ dom->cache_credentials = parent->cache_credentials;
+ dom->case_sensitive = parent->case_sensitive;
+ dom->user_timeout = parent->user_timeout;
+ dom->group_timeout = parent->group_timeout;
+ dom->netgroup_timeout = parent->netgroup_timeout;
+ dom->service_timeout = parent->service_timeout;
+ dom->override_homedir = parent->override_homedir;
+
+ if (parent->sysdb == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Missing sysdb context in parent domain.\n"));
+ goto fail;
+ }
+ ret = sysdb_get_subdomain_context(dom, parent->sysdb, dom, &dom->sysdb);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, ("sysdb_get_subdomain_context failed.\n"));
+ goto fail;
+ }
+
+ return dom;
+
+fail:
+ talloc_free(dom);
+ return NULL;
+}
+
+struct sss_domain_info *copy_subdomain(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *subdomain)
+{
+ return new_subdomain(mem_ctx, subdomain, subdomain->name,
+ subdomain->flat_name, subdomain->domain_id);
+}
diff --git a/src/util/util.h b/src/util/util.h
index 181e75166..370729018 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -527,4 +527,13 @@ struct sized_string {
void to_sized_string(struct sized_string *out, const char *in);
+/* form domain_info.c */
+struct sss_domain_info *new_subdomain(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *parent,
+ const char *name,
+ const char *flat_name,
+ const char *id);
+struct sss_domain_info *copy_subdomain(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *subdomain);
+
#endif /* __SSSD_UTIL_H__ */