summaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2012-01-23 12:57:33 +0100
committerStephen Gallagher <sgallagh@redhat.com>2012-02-29 12:53:47 -0500
commitd2d2d6ae0c436461bcc8f881df059eb036314c44 (patch)
tree679d929d1b5aa4106413179d99e86c60c200279c /src/db
parentb97595ae059c69b1960a6e7e56d74660388a683b (diff)
downloadsssd-d2d2d6ae0c436461bcc8f881df059eb036314c44.tar.gz
sssd-d2d2d6ae0c436461bcc8f881df059eb036314c44.tar.bz2
sssd-d2d2d6ae0c436461bcc8f881df059eb036314c44.zip
Keep sysdb context in domain info struct
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb.c80
-rw-r--r--src/db/sysdb.h9
2 files changed, 89 insertions, 0 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index a7f65a33..d3a20cf1 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -822,6 +822,37 @@ int sysdb_get_db_file(TALLOC_CTX *mem_ctx,
return EOK;
}
+static int remove_sysdb_from_domain(void *mem)
+{
+ struct sysdb_ctx *ctx = talloc_get_type(mem, struct sysdb_ctx);
+
+ if (ctx->domain != NULL && ctx->domain->sysdb == ctx) {
+ ctx->domain->sysdb = NULL;
+ }
+
+ return 0;
+}
+
+errno_t sysdb_add_to_domain(struct sss_domain_info *domain,
+ struct sysdb_ctx *ctx)
+{
+ if (domain == NULL || ctx == NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Missing domain or sysdb context.\n"));
+ return EINVAL;
+ }
+
+ if (domain->sysdb != NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Sysdb context already set.\n"));
+ return EINVAL;
+ }
+
+ domain->sysdb = ctx;
+
+ talloc_set_destructor((TALLOC_CTX *) ctx, remove_sysdb_from_domain);
+
+ return EOK;
+}
+
int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *db_path,
@@ -1174,6 +1205,12 @@ int sysdb_init(TALLOC_CTX *mem_ctx,
return ret;
}
+ ret = sysdb_add_to_domain(dom, sysdb);
+ if (ret != EOK) {
+ talloc_zfree(ctx_list);
+ return ret;
+ }
+
ctx_list->dbs[ctx_list->num_dbs] = sysdb;
ctx_list->num_dbs++;
}
@@ -1197,6 +1234,41 @@ int sysdb_domain_init(TALLOC_CTX *mem_ctx,
db_path, false, _ctx);
}
+errno_t sysdb_init_domain_and_sysdb(TALLOC_CTX *mem_ctx,
+ struct confdb_ctx *cdb,
+ const char *domain_name,
+ const char *db_path,
+ struct sss_domain_info **_domain,
+ struct sysdb_ctx **_ctx)
+{
+ int ret;
+ struct sss_domain_info *dom;
+ struct sysdb_ctx *ctx;
+
+ ret = confdb_get_domain(cdb, domain_name, &dom);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Error retrieving domain configuration.\n"));
+ return ret;
+ }
+
+ ret = sysdb_domain_init(mem_ctx, dom, db_path, &ctx);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Error opening cache database.\n"));
+ return ret;
+ }
+
+ ret = sysdb_add_to_domain(dom, ctx);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Error storing cache database context.\n"));
+ return ret;
+ }
+
+ *_domain = dom;
+ *_ctx = ctx;
+
+ return EOK;
+}
+
int sysdb_list_init(TALLOC_CTX *mem_ctx,
const char *path,
struct sysdb_ctx *sysdb,
@@ -1244,6 +1316,14 @@ int sysdb_get_ctx_from_list(struct sysdb_ctx_list *ctx_list,
{
int i;
+ if (domain->sysdb != NULL) {
+ *sysdb = domain->sysdb;
+ return EOK;
+ }
+
+ DEBUG(SSSDBG_TRACE_FUNC, ("sysdb context not stored in domain, "
+ "trying to find by name.\n"));
+
for (i = 0; i < ctx_list->num_dbs; i++) {
if (ctx_list->dbs[i]->domain == domain) {
*sysdb = ctx_list->dbs[i];
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 5f264c25..1da61f2c 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -328,6 +328,13 @@ int sysdb_domain_init(TALLOC_CTX *mem_ctx,
const char *db_path,
struct sysdb_ctx **_ctx);
+errno_t sysdb_init_domain_and_sysdb(TALLOC_CTX *mem_ctx,
+ struct confdb_ctx *cdb,
+ const char *domain_name,
+ const char *db_path,
+ struct sss_domain_info **_domain,
+ struct sysdb_ctx **_ctx);
+
int sysdb_list_init(TALLOC_CTX *mem_ctx,
const char *path,
struct sysdb_ctx *sysdb,
@@ -337,6 +344,8 @@ int sysdb_get_ctx_from_list(struct sysdb_ctx_list *ctx_list,
struct sss_domain_info *domain,
struct sysdb_ctx **_ctx);
+errno_t sysdb_add_to_domain(struct sss_domain_info *domain,
+ struct sysdb_ctx *ctx);
/* functions to retrieve information from sysdb
* These functions automatically starts an operation
* therefore they cannot be called within a transaction */