From 28d9dcbeabdf919506fe59e9d1cbed84fbd6e649 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 3 Sep 2009 19:29:41 -0400 Subject: Split database in multiple files The special persistent local database retains the original name. All other backends now have their own cache-NAME.ldb file. --- server/confdb/confdb.c | 52 +++++++++++++++++++++++++++++++----------- server/confdb/confdb.h | 2 -- server/confdb/confdb_private.h | 2 ++ 3 files changed, 41 insertions(+), 15 deletions(-) (limited to 'server/confdb') diff --git a/server/confdb/confdb.c b/server/confdb/confdb.c index 72e5eeb42..7d89f75f2 100644 --- a/server/confdb/confdb.c +++ b/server/confdb/confdb.c @@ -673,10 +673,10 @@ int confdb_init(TALLOC_CTX *mem_ctx, return EOK; } -int confdb_get_domain(struct confdb_ctx *cdb, - TALLOC_CTX *mem_ctx, - const char *name, - struct sss_domain_info **_domain) +static int confdb_get_domain_internal(struct confdb_ctx *cdb, + TALLOC_CTX *mem_ctx, + const char *name, + struct sss_domain_info **_domain) { struct sss_domain_info *domain; struct ldb_result *res; @@ -803,16 +803,19 @@ done: } int confdb_get_domains(struct confdb_ctx *cdb, - TALLOC_CTX *mem_ctx, struct sss_domain_info **domains) { TALLOC_CTX *tmp_ctx; struct sss_domain_info *domain, *prevdom = NULL; - struct sss_domain_info *first = NULL; char **domlist; int ret, i; - tmp_ctx = talloc_new(mem_ctx); + if (cdb->doms) { + *domains = cdb->doms; + return EOK; + } + + tmp_ctx = talloc_new(NULL); if (!tmp_ctx) return ENOMEM; ret = confdb_get_string_as_list(cdb, tmp_ctx, @@ -827,7 +830,7 @@ int confdb_get_domains(struct confdb_ctx *cdb, } for (i = 0; domlist[i]; i++) { - ret = confdb_get_domain(cdb, mem_ctx, domlist[i], &domain); + ret = confdb_get_domain_internal(cdb, cdb, domlist[i], &domain); if (ret) { DEBUG(0, ("Error (%d [%s]) retrieving domain [%s], skipping!\n", ret, strerror(ret), domlist[i])); @@ -835,23 +838,46 @@ int confdb_get_domains(struct confdb_ctx *cdb, continue; } - if (first == NULL) { - first = domain; - prevdom = first; + if (cdb->doms == NULL) { + cdb->doms = domain; + prevdom = cdb->doms; } else { prevdom->next = domain; prevdom = domain; } } - if (first == NULL) { + if (cdb->doms == NULL) { DEBUG(0, ("No domains configured, fatal error!\n")); ret = ENOENT; } - *domains = first; + *domains = cdb->doms; + ret = EOK; done: talloc_free(tmp_ctx); return ret; } + +int confdb_get_domain(struct confdb_ctx *cdb, + const char *name, + struct sss_domain_info **_domain) +{ + struct sss_domain_info *dom, *doms; + int ret; + + ret = confdb_get_domains(cdb, &doms); + if (ret != EOK) { + return ret; + } + + for (dom = doms; dom; dom = dom->next) { + if (strcasecmp(dom->name, name) == 0) { + *_domain = dom; + return EOK; + } + } + + return ENOENT; +} diff --git a/server/confdb/confdb.h b/server/confdb/confdb.h index f56508877..d325ac8fb 100644 --- a/server/confdb/confdb.h +++ b/server/confdb/confdb.h @@ -91,12 +91,10 @@ int confdb_init(TALLOC_CTX *mem_ctx, char *confdb_location); int confdb_get_domain(struct confdb_ctx *cdb, - TALLOC_CTX *mem_ctx, const char *name, struct sss_domain_info **domain); int confdb_get_domains(struct confdb_ctx *cdb, - TALLOC_CTX *mem_ctx, struct sss_domain_info **domains); #endif diff --git a/server/confdb/confdb_private.h b/server/confdb/confdb_private.h index 41fcd2692..1bab99cae 100644 --- a/server/confdb/confdb_private.h +++ b/server/confdb/confdb_private.h @@ -25,6 +25,8 @@ struct confdb_ctx { struct tevent_context *pev; struct ldb_context *ldb; + + struct sss_domain_info *doms; }; int parse_section(TALLOC_CTX *mem_ctx, const char *section, -- cgit