summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/db/sysdb.c139
-rw-r--r--src/db/sysdb.h19
-rw-r--r--src/monitor/monitor.c3
-rw-r--r--src/responder/common/responder.h1
-rw-r--r--src/responder/common/responder_common.c2
-rw-r--r--src/tools/sss_cache.c31
6 files changed, 25 insertions, 170 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index b0bea9a73..8b200b01b 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -917,37 +917,6 @@ done:
return ret;
}
-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;
-}
-
/* Compare versions of sysdb, returns ERRNO accordingly */
static errno_t
sysdb_version_check(const char *expected,
@@ -1226,82 +1195,41 @@ done:
}
int sysdb_init(TALLOC_CTX *mem_ctx,
- struct confdb_ctx *cdb,
+ struct sss_domain_info *domains,
const char *alt_db_path,
- bool allow_upgrade,
- struct sysdb_ctx_list **_ctx_list)
+ bool allow_upgrade)
{
- struct sysdb_ctx_list *ctx_list;
- struct sss_domain_info *domains, *dom;
+ struct sss_domain_info *dom;
struct sysdb_ctx *sysdb;
+ const char *db_path;
int ret;
- ctx_list = talloc_zero(mem_ctx, struct sysdb_ctx_list);
- if (!ctx_list) {
- return ENOMEM;
- }
-
if (alt_db_path) {
- ctx_list->db_path = talloc_strdup(ctx_list, alt_db_path);
+ db_path = alt_db_path;
} else {
- ctx_list->db_path = talloc_strdup(ctx_list, DB_PATH);
- }
- if (!ctx_list->db_path) {
- talloc_zfree(ctx_list);
- return ENOMEM;
- }
-
- /* open a db for each backend */
- ret = confdb_get_domains(cdb, &domains);
- if (ret != EOK) {
- talloc_zfree(ctx_list);
- return ret;
+ db_path = DB_PATH;
}
if (allow_upgrade) {
/* check if we have an old sssd.ldb to upgrade */
- ret = sysdb_check_upgrade_02(domains, ctx_list->db_path);
+ ret = sysdb_check_upgrade_02(domains, db_path);
if (ret != EOK) {
- talloc_zfree(ctx_list);
return ret;
}
}
+ /* open a db for each domain */
for (dom = domains; dom; dom = dom->next) {
- ctx_list->dbs = talloc_realloc(ctx_list, ctx_list->dbs,
- struct sysdb_ctx *,
- ctx_list->num_dbs + 1);
- if (!ctx_list->dbs) {
- talloc_zfree(ctx_list);
- return ENOMEM;
- }
-
- ret = sysdb_domain_init_internal(ctx_list, dom,
- ctx_list->db_path,
+ ret = sysdb_domain_init_internal(mem_ctx, dom, db_path,
allow_upgrade, &sysdb);
if (ret != EOK) {
- talloc_zfree(ctx_list);
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++;
- }
- if (ctx_list->num_dbs == 0) {
- /* what? .. */
- talloc_zfree(ctx_list);
- return ENOENT;
+ dom->sysdb = talloc_move(dom, &sysdb);
}
- *_ctx_list = ctx_list;
-
return EOK;
}
@@ -1337,11 +1265,7 @@ errno_t sysdb_init_domain_and_sysdb(TALLOC_CTX *mem_ctx,
return ret;
}
- ret = sysdb_add_to_domain(dom, ctx);
- if (ret != EOK) {
- DEBUG(SSSDBG_OP_FAILURE, ("Error storing cache database context.\n"));
- return ret;
- }
+ dom->sysdb = talloc_steal(dom, ctx);
*_domain = dom;
*_ctx = ctx;
@@ -1349,47 +1273,6 @@ errno_t sysdb_init_domain_and_sysdb(TALLOC_CTX *mem_ctx,
return EOK;
}
-int sysdb_list_init(TALLOC_CTX *mem_ctx,
- const char *path,
- struct sysdb_ctx *sysdb,
- struct sysdb_ctx_list **_list)
-{
- struct sysdb_ctx_list *list;
- int ret;
-
- list = talloc_zero(mem_ctx, struct sysdb_ctx_list);
- if (!list) {
- DEBUG(1, ("talloc_zero failed\n"));
- return ENOMEM;
- }
-
- list->db_path = talloc_strdup(list, path);
- if (!list->db_path) {
- DEBUG(1, ("talloc_strdup failed\n"));
- ret = ENOMEM;
- goto fail;
- }
-
- if (sysdb) {
- list->num_dbs = 1;
- list->dbs = talloc_array(list, struct sysdb_ctx *, list->num_dbs);
- if (!list->dbs) {
- DEBUG(1, ("talloc_array failed\n"));
- ret = ENOMEM;
- goto fail;
- }
-
- list->dbs[0] = talloc_steal(list, sysdb);
- }
-
- *_list = list;
- return EOK;
-
-fail:
- talloc_free(list);
- return ret;
-}
-
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 378ce4889..d191dd3d2 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -227,13 +227,6 @@
struct confdb_ctx;
struct sysdb_ctx;
-struct sysdb_ctx_list {
- struct sysdb_ctx **dbs;
- size_t num_dbs;
-
- char *db_path;
-};
-
struct sysdb_attrs {
int num;
struct ldb_message_element *a;
@@ -452,10 +445,9 @@ errno_t sysdb_update_ranges(struct sysdb_ctx *sysdb,
* call this function *only* once to initialize the database and get
* the sysdb ctx */
int sysdb_init(TALLOC_CTX *mem_ctx,
- struct confdb_ctx *cdb,
+ struct sss_domain_info *domains,
const char *alt_db_path,
- bool allow_upgrade,
- struct sysdb_ctx_list **_ctx_list);
+ bool allow_upgrade);
/* used to initialize only one domain database.
* Do NOT use if sysdb_init has already been called */
int sysdb_domain_init(TALLOC_CTX *mem_ctx,
@@ -470,13 +462,6 @@ errno_t sysdb_init_domain_and_sysdb(TALLOC_CTX *mem_ctx,
struct sss_domain_info **_domain,
struct sysdb_ctx **_ctx);
-int sysdb_list_init(TALLOC_CTX *mem_ctx,
- const char *path,
- struct sysdb_ctx *sysdb,
- struct sysdb_ctx_list **_list);
-
-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/monitor/monitor.c b/src/monitor/monitor.c
index 1fa1592a5..2b699ca7e 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -2110,7 +2110,6 @@ int monitor_process_init(struct mt_ctx *ctx,
const char *config_file)
{
TALLOC_CTX *tmp_ctx;
- struct sysdb_ctx_list *db_list;
struct tevent_signal *tes;
struct sss_domain_info *dom;
char *rcachedir;
@@ -2212,7 +2211,7 @@ int monitor_process_init(struct mt_ctx *ctx,
if (!tmp_ctx) {
return ENOMEM;
}
- ret = sysdb_init(tmp_ctx, ctx->cdb, NULL, true, &db_list);
+ ret = sysdb_init(tmp_ctx, ctx->domains, NULL, true);
if (ret != EOK) {
SYSDB_VERSION_ERROR_DAEMON(ret);
return ret;
diff --git a/src/responder/common/responder.h b/src/responder/common/responder.h
index 2903aac00..a265d61d9 100644
--- a/src/responder/common/responder.h
+++ b/src/responder/common/responder.h
@@ -88,7 +88,6 @@ struct resp_ctx {
struct sss_domain_info *domains;
int domains_timeout;
int client_idle_timeout;
- struct sysdb_ctx_list *db_list;
struct sss_cmd_table *sss_cmds;
const char *sss_pipe_name;
diff --git a/src/responder/common/responder_common.c b/src/responder/common/responder_common.c
index 35381be8a..9defdba46 100644
--- a/src/responder/common/responder_common.c
+++ b/src/responder/common/responder_common.c
@@ -838,7 +838,7 @@ int sss_process_init(TALLOC_CTX *mem_ctx,
}
}
- ret = sysdb_init(rctx, cdb, NULL, false, &rctx->db_list);
+ ret = sysdb_init(rctx, rctx->domains, NULL, false);
if (ret != EOK) {
SYSDB_VERSION_ERROR_DAEMON(ret);
DEBUG(0, ("fatal error initializing resp_ctx\n"));
diff --git a/src/tools/sss_cache.c b/src/tools/sss_cache.c
index 684b8b25b..5f8450f7d 100644
--- a/src/tools/sss_cache.c
+++ b/src/tools/sss_cache.c
@@ -53,7 +53,6 @@ static errno_t search_autofsmaps(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
struct cache_tool_ctx {
struct confdb_ctx *confdb;
struct sss_domain_info *domains;
- struct sysdb_ctx_list *sysdb_list;
struct sss_names_ctx *nctx;
char *user_filter;
@@ -90,7 +89,6 @@ int main(int argc, const char *argv[])
errno_t ret;
struct cache_tool_ctx *tctx = NULL;
struct sysdb_ctx *sysdb;
- int i;
bool skipped = true;
struct sss_domain_info *dinfo;
@@ -101,9 +99,8 @@ int main(int argc, const char *argv[])
goto done;
}
- for (i = 0; i < tctx->sysdb_list->num_dbs; i++) {
- sysdb = tctx->sysdb_list->dbs[i];
- dinfo = sysdb_ctx_get_domain(sysdb);
+ for (dinfo = tctx->domains; dinfo; dinfo = dinfo->next) {
+ sysdb = dinfo->sysdb;
/* Update filters for each domain */
ret = update_all_filters(tctx, dinfo->name);
@@ -422,33 +419,25 @@ errno_t init_domains(struct cache_tool_ctx *ctx, const char *domain)
if (ret != EOK) {
SYSDB_VERSION_ERROR(ret);
DEBUG(1, ("Could not initialize connection to the sysdb\n"));
- goto fail;
+ return ret;
}
- ret = sysdb_list_init(ctx, DB_PATH, db_ctx, &ctx->sysdb_list);
+ } else {
+ ret = confdb_get_domains(ctx->confdb, &ctx->domains);
if (ret != EOK) {
- DEBUG(1, ("Could not initialize the list of connections\n"));
- goto fail;
+ DEBUG(1, ("Could not initialize domains\n"));
+ return ret;
}
- } else {
- ret = sysdb_init(ctx, ctx->confdb, NULL, false, &ctx->sysdb_list);
+
+ ret = sysdb_init(ctx, ctx->domains, NULL, false);
SYSDB_VERSION_ERROR(ret);
if (ret != EOK) {
DEBUG(1, ("Could not initialize connection to the sysdb\n"));
- goto fail;
+ return ret;
}
}
return EOK;
-fail:
- if (ctx->confdb) talloc_zfree(ctx->confdb);
- if (ctx->domains) talloc_zfree(ctx->domains);
- if (ctx->sysdb_list) {
- talloc_zfree(ctx->sysdb_list);
- } else {
- if (db_ctx) talloc_free(db_ctx);
- }
- return ret;
}
errno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx)