summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2013-01-06 03:58:58 -0500
committerJakub Hrozek <jhrozek@redhat.com>2013-01-15 10:49:20 +0100
commit234958be042980242fff6da936af674da877c5ef (patch)
treea2f96f1cf185f950629f0718e9ce69e314c5fada /src
parent72aa8e7b1d234b6b68446d42efa1cff22b70c81b (diff)
downloadsssd-234958be042980242fff6da936af674da877c5ef.tar.gz
sssd-234958be042980242fff6da936af674da877c5ef.tar.bz2
sssd-234958be042980242fff6da936af674da877c5ef.zip
Refactor single domain initialization
Bring it out of sysdb, which will slowly remove internal dependencies on domains and instead will always require them to be passed by callers.
Diffstat (limited to 'src')
-rw-r--r--src/db/sysdb.c31
-rw-r--r--src/db/sysdb.h7
-rw-r--r--src/providers/data_provider_be.c4
-rw-r--r--src/python/pysss.c5
-rw-r--r--src/tests/auth-tests.c6
-rw-r--r--src/tests/sysdb-tests.c6
-rw-r--r--src/tests/sysdb_ssh-tests.c6
-rw-r--r--src/tools/sss_cache.c5
-rw-r--r--src/tools/sss_seed.c6
-rw-r--r--src/tools/tools_util.c4
-rw-r--r--src/util/domain_info_utils.c34
-rw-r--r--src/util/util.h6
12 files changed, 60 insertions, 60 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index 8b200b01..f68c30ac 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -1242,37 +1242,6 @@ 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;
- }
-
- dom->sysdb = talloc_steal(dom, ctx);
-
- *_domain = dom;
- *_ctx = ctx;
-
- return EOK;
-}
-
int compare_ldb_dn_comp_num(const void *m1, const void *m2)
{
struct ldb_message *msg1 = talloc_get_type(*(void **) discard_const(m1),
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index d191dd3d..10eec5e6 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -455,13 +455,6 @@ 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);
-
/* 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 5208b48c..5b6bbc4a 100644
--- a/src/providers/data_provider_be.c
+++ b/src/providers/data_provider_be.c
@@ -2344,12 +2344,12 @@ int be_process_init(TALLOC_CTX *mem_ctx,
goto fail;
}
- ret = sysdb_init_domain_and_sysdb(ctx, cdb, be_domain, DB_PATH,
- &ctx->domain, &ctx->sysdb);
+ ret = sssd_domain_init(ctx, cdb, be_domain, DB_PATH, &ctx->domain);
if (ret != EOK) {
DEBUG(SSSDBG_FATAL_FAILURE, ("fatal error opening cache database\n"));
goto fail;
}
+ ctx->sysdb = ctx->domain->sysdb;
ret = sss_monitor_init(ctx, ctx->ev, &monitor_be_interface,
ctx->identity, DATA_PROVIDER_VERSION,
diff --git a/src/python/pysss.c b/src/python/pysss.c
index 842c1b5e..95cf781d 100644
--- a/src/python/pysss.c
+++ b/src/python/pysss.c
@@ -800,14 +800,15 @@ static PyObject *PySssLocalObject_new(PyTypeObject *type,
return NULL;
}
- ret = sysdb_init_domain_and_sysdb(self->mem_ctx, self->confdb, "local",
- DB_PATH, &self->local, &self->sysdb);
+ ret = sssd_domain_init(self->mem_ctx, self->confdb, "local",
+ DB_PATH, &self->local);
if (ret != EOK) {
talloc_free(mem_ctx);
PyErr_SetSssErrorWithMessage(ret,
"Could not initialize connection to the sysdb\n");
return NULL;
}
+ self->sysdb = self->local->sysdb;
self->lock = DO_LOCK;
self->unlock = DO_UNLOCK;
diff --git a/src/tests/auth-tests.c b/src/tests/auth-tests.c
index ff8b9e1b..7b53c9b9 100644
--- a/src/tests/auth-tests.c
+++ b/src/tests/auth-tests.c
@@ -134,14 +134,14 @@ static int setup_sysdb_tests(struct sysdb_test_ctx **ctx)
return ret;
}
- ret = sysdb_init_domain_and_sysdb(test_ctx, test_ctx->confdb, "local",
- TESTS_PATH,
- &test_ctx->domain, &test_ctx->sysdb);
+ ret = sssd_domain_init(test_ctx, test_ctx->confdb, "local",
+ TESTS_PATH, &test_ctx->domain);
if (ret != EOK) {
fail("Could not initialize connection to the sysdb (%d)", ret);
talloc_free(test_ctx);
return ret;
}
+ test_ctx->sysdb = test_ctx->domain->sysdb;
*ctx = test_ctx;
return EOK;
diff --git a/src/tests/sysdb-tests.c b/src/tests/sysdb-tests.c
index a5526280..c2e20c0a 100644
--- a/src/tests/sysdb-tests.c
+++ b/src/tests/sysdb-tests.c
@@ -145,14 +145,14 @@ static int setup_sysdb_tests(struct sysdb_test_ctx **ctx)
return ret;
}
- ret = sysdb_init_domain_and_sysdb(test_ctx, test_ctx->confdb, "local",
- TESTS_PATH,
- &test_ctx->domain, &test_ctx->sysdb);
+ ret = sssd_domain_init(test_ctx, test_ctx->confdb, "local",
+ TESTS_PATH, &test_ctx->domain);
if (ret != EOK) {
fail("Could not initialize connection to the sysdb (%d)", ret);
talloc_free(test_ctx);
return ret;
}
+ test_ctx->sysdb = test_ctx->domain->sysdb;
*ctx = test_ctx;
return EOK;
diff --git a/src/tests/sysdb_ssh-tests.c b/src/tests/sysdb_ssh-tests.c
index cb5bd4b3..013a1d43 100644
--- a/src/tests/sysdb_ssh-tests.c
+++ b/src/tests/sysdb_ssh-tests.c
@@ -130,14 +130,14 @@ static int setup_sysdb_tests(struct sysdb_test_ctx **ctx)
return ret;
}
- ret = sysdb_init_domain_and_sysdb(test_ctx, test_ctx->confdb, "local",
- TESTS_PATH,
- &test_ctx->domain, &test_ctx->sysdb);
+ ret = sssd_domain_init(test_ctx, test_ctx->confdb, "local",
+ TESTS_PATH, &test_ctx->domain);
if (ret != EOK) {
fail("Could not initialize connection to the sysdb (%d)", ret);
talloc_free(test_ctx);
return ret;
}
+ test_ctx->sysdb = test_ctx->domain->sysdb;
*ctx = test_ctx;
return EOK;
diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c
index 5f8450f7..2ab5303a 100644
--- a/src/tools/sss_cache.c
+++ b/src/tools/sss_cache.c
@@ -398,7 +398,6 @@ errno_t init_domains(struct cache_tool_ctx *ctx, const char *domain)
{
char *confdb_path;
int ret;
- struct sysdb_ctx *db_ctx = NULL;
confdb_path = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
if (confdb_path == NULL) {
@@ -414,8 +413,8 @@ errno_t init_domains(struct cache_tool_ctx *ctx, const char *domain)
}
if (domain) {
- ret = sysdb_init_domain_and_sysdb(ctx, ctx->confdb, domain, DB_PATH,
- &ctx->domains, &db_ctx);
+ ret = sssd_domain_init(ctx, ctx->confdb,
+ domain, DB_PATH, &ctx->domains);
if (ret != EOK) {
SYSDB_VERSION_ERROR(ret);
DEBUG(1, ("Could not initialize connection to the sysdb\n"));
diff --git a/src/tools/sss_seed.c b/src/tools/sss_seed.c
index aa11ab51..d3c1cb44 100644
--- a/src/tools/sss_seed.c
+++ b/src/tools/sss_seed.c
@@ -603,7 +603,6 @@ static int seed_init_db(TALLOC_CTX *mem_ctx,
TALLOC_CTX *tmp_ctx = NULL;
char *confdb_path = NULL;
struct confdb_ctx *confdb = NULL;
- struct sysdb_ctx *sysdb = NULL;
struct sss_domain_info *domain = NULL;
int ret = EOK;
@@ -628,8 +627,7 @@ static int seed_init_db(TALLOC_CTX *mem_ctx,
goto done;
}
- ret = sysdb_init_domain_and_sysdb(tmp_ctx, confdb, domain_name,
- DB_PATH, &domain, &sysdb);
+ ret = sssd_domain_init(tmp_ctx, confdb, domain_name, DB_PATH, &domain);
if (ret != EOK) {
SYSDB_VERSION_ERROR(ret);
DEBUG(SSSDBG_CRIT_FAILURE,
@@ -641,8 +639,8 @@ static int seed_init_db(TALLOC_CTX *mem_ctx,
goto done;
}
- *_sysdb = talloc_steal(mem_ctx, sysdb);
*_confdb = talloc_steal(mem_ctx, confdb);
+ *_sysdb = domain->sysdb;
done:
talloc_free(tmp_ctx);
diff --git a/src/tools/tools_util.c b/src/tools/tools_util.c
index 406077c8..b2dc4ff5 100644
--- a/src/tools/tools_util.c
+++ b/src/tools/tools_util.c
@@ -54,13 +54,13 @@ static int setup_db(struct tools_ctx *ctx)
return ret;
}
- ret = sysdb_init_domain_and_sysdb(ctx, ctx->confdb, "local", DB_PATH,
- &ctx->local, &ctx->sysdb);
+ ret = sssd_domain_init(ctx, ctx->confdb, "local", DB_PATH, &ctx->local);
if (ret != EOK) {
SYSDB_VERSION_ERROR(ret);
DEBUG(1, ("Could not initialize connection to the sysdb\n"));
return ret;
}
+ ctx->sysdb = ctx->local->sysdb;
talloc_free(confdb_path);
return EOK;
diff --git a/src/util/domain_info_utils.c b/src/util/domain_info_utils.c
index a6aa5c73..cee11eb5 100644
--- a/src/util/domain_info_utils.c
+++ b/src/util/domain_info_utils.c
@@ -112,3 +112,37 @@ struct sss_domain_info *copy_subdomain(TALLOC_CTX *mem_ctx,
return new_subdomain(mem_ctx, subdomain->parent, subdomain->name,
subdomain->flat_name, subdomain->domain_id);
}
+
+errno_t sssd_domain_init(TALLOC_CTX *mem_ctx,
+ struct confdb_ctx *cdb,
+ const char *domain_name,
+ const char *db_path,
+ struct sss_domain_info **_domain)
+{
+ int ret;
+ struct sss_domain_info *dom;
+ struct sysdb_ctx *sysdb;
+
+ ret = confdb_get_domain(cdb, domain_name, &dom);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Error retrieving domain configuration.\n"));
+ return ret;
+ }
+
+ if (dom->sysdb != NULL) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Sysdb context already initialized.\n"));
+ return EEXIST;
+ }
+
+ ret = sysdb_domain_init(mem_ctx, dom, db_path, &sysdb);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Error opening cache database.\n"));
+ return ret;
+ }
+
+ dom->sysdb = talloc_steal(dom, sysdb);
+
+ *_domain = dom;
+
+ return EOK;
+}
diff --git a/src/util/util.h b/src/util/util.h
index cc5a2baf..df1ee3b0 100644
--- a/src/util/util.h
+++ b/src/util/util.h
@@ -574,6 +574,12 @@ struct sss_domain_info *new_subdomain(TALLOC_CTX *mem_ctx,
struct sss_domain_info *copy_subdomain(TALLOC_CTX *mem_ctx,
struct sss_domain_info *subdomain);
+errno_t sssd_domain_init(TALLOC_CTX *mem_ctx,
+ struct confdb_ctx *cdb,
+ const char *domain_name,
+ const char *db_path,
+ struct sss_domain_info **_domain);
+
/* from util_lock.c */
errno_t sss_br_lock_file(int fd, size_t start, size_t len,
int num_tries, useconds_t wait);