summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/confdb/confdb.h2
-rw-r--r--src/db/sysdb.c80
-rw-r--r--src/db/sysdb.h9
-rw-r--r--src/providers/data_provider_be.c10
-rw-r--r--src/python/pysss.c11
-rw-r--r--src/tests/auth-tests.c12
-rw-r--r--src/tests/sysdb-tests.c12
-rw-r--r--src/tools/sss_cache.c10
-rw-r--r--src/tools/tools_util.c10
9 files changed, 105 insertions, 51 deletions
diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h
index 18484f02..aebf5d88 100644
--- a/src/confdb/confdb.h
+++ b/src/confdb/confdb.h
@@ -188,6 +188,8 @@ struct sss_domain_info {
uint32_t service_timeout;
uint32_t autofsmap_timeout;
+ struct sysdb_ctx *sysdb;
+
struct sss_domain_info *next;
};
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 */
diff --git a/src/providers/data_provider_be.c b/src/providers/data_provider_be.c
index 2b76eb3c..695dee0e 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -1750,14 +1750,8 @@ int be_process_init(TALLOC_CTX *mem_ctx,
return ret;
}
- ret = confdb_get_domain(cdb, be_domain, &ctx->domain);
- if (ret != EOK) {
- DEBUG(SSSDBG_FATAL_FAILURE,
- ("fatal error retrieving domain configuration\n"));
- return ret;
- }
-
- ret = sysdb_domain_init(ctx, ctx->domain, DB_PATH, &ctx->sysdb);
+ ret = sysdb_init_domain_and_sysdb(ctx, cdb, be_domain, DB_PATH,
+ &ctx->domain, &ctx->sysdb);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, ("fatal error opening cache database\n"));
return ret;
diff --git a/src/python/pysss.c b/src/python/pysss.c
index 948fd160..45725c0c 100644
--- a/src/python/pysss.c
+++ b/src/python/pysss.c
@@ -772,15 +772,8 @@ static PyObject *PySssLocalObject_new(PyTypeObject *type,
return NULL;
}
- ret = confdb_get_domain(self->confdb, "local", &self->local);
- if (ret != EOK) {
- talloc_free(mem_ctx);
- PyErr_SetSssErrorWithMessage(ret, "Cannot get local domain");
- return NULL;
- }
-
- /* open 'local' sysdb at default path */
- ret = sysdb_domain_init(self->mem_ctx, self->local, DB_PATH, &self->sysdb);
+ ret = sysdb_init_domain_and_sysdb(self->mem_ctx, self->confdb, "local",
+ DB_PATH, &self->local, &self->sysdb);
if (ret != EOK) {
talloc_free(mem_ctx);
PyErr_SetSssErrorWithMessage(ret,
diff --git a/src/tests/auth-tests.c b/src/tests/auth-tests.c
index 96bae98e..4d25e2ef 100644
--- a/src/tests/auth-tests.c
+++ b/src/tests/auth-tests.c
@@ -134,15 +134,9 @@ static int setup_sysdb_tests(struct sysdb_test_ctx **ctx)
return ret;
}
- ret = confdb_get_domain(test_ctx->confdb, "local", &test_ctx->domain);
- if (ret != EOK) {
- fail("Could not retrieve LOCAL domain");
- talloc_free(test_ctx);
- return ret;
- }
-
- ret = sysdb_domain_init(test_ctx,
- test_ctx->domain, TESTS_PATH, &test_ctx->sysdb);
+ ret = sysdb_init_domain_and_sysdb(test_ctx, test_ctx->confdb, "local",
+ TESTS_PATH,
+ &test_ctx->domain, &test_ctx->sysdb);
if (ret != EOK) {
fail("Could not initialize connection to the sysdb (%d)", ret);
talloc_free(test_ctx);
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index b3aaa266..765b59d8 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -141,15 +141,9 @@ static int setup_sysdb_tests(struct sysdb_test_ctx **ctx)
return ret;
}
- ret = confdb_get_domain(test_ctx->confdb, "local", &test_ctx->domain);
- if (ret != EOK) {
- fail("Could not retrieve LOCAL domain");
- talloc_free(test_ctx);
- return ret;
- }
-
- ret = sysdb_domain_init(test_ctx,
- test_ctx->domain, TESTS_PATH, &test_ctx->sysdb);
+ ret = sysdb_init_domain_and_sysdb(test_ctx, test_ctx->confdb, "local",
+ TESTS_PATH,
+ &test_ctx->domain, &test_ctx->sysdb);
if (ret != EOK) {
fail("Could not initialize connection to the sysdb (%d)", ret);
talloc_free(test_ctx);
diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c
index e8b1926b..a9885b07 100644
--- a/src/tools/sss_cache.c
+++ b/src/tools/sss_cache.c
@@ -204,14 +204,8 @@ errno_t init_domains(struct cache_tool_ctx *ctx, const char *domain) {
}
if (domain) {
- ret = confdb_get_domain(ctx->confdb, domain, &ctx->domains);
- if (ret != EOK) {
- DEBUG(1, ("Could not get '%s' domain: [%d] [%s]\n",
- domain, ret, strerror(ret)));
- goto fail;
- }
-
- ret = sysdb_domain_init(ctx, ctx->domains, DB_PATH, &db_ctx);
+ ret = sysdb_init_domain_and_sysdb(ctx, ctx->confdb, domain, DB_PATH,
+ &ctx->domains, &db_ctx);
if (ret != EOK) {
DEBUG(1, ("Could not initialize connection to the sysdb\n"));
goto fail;
diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c
index 00448953..871ba2b1 100644
--- a/src/tools/tools_util.c
+++ b/src/tools/tools_util.c
@@ -53,14 +53,8 @@ static int setup_db(struct tools_ctx *ctx)
return ret;
}
- ret = confdb_get_domain(ctx->confdb, "local", &ctx->local);
- if (ret != EOK) {
- DEBUG(1, ("Could not get 'local' domain: [%d] [%s]\n", ret, strerror(ret)));
- return ret;
- }
-
- /* open 'local' sysdb at default path */
- ret = sysdb_domain_init(ctx, ctx->local, DB_PATH, &ctx->sysdb);
+ ret = sysdb_init_domain_and_sysdb(ctx, ctx->confdb, "local", DB_PATH,
+ &ctx->local, &ctx->sysdb);
if (ret != EOK) {
DEBUG(1, ("Could not initialize connection to the sysdb\n"));
return ret;