diff options
author | Simo Sorce <simo@redhat.com> | 2013-01-06 03:16:08 -0500 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2013-01-15 10:49:20 +0100 |
commit | 72aa8e7b1d234b6b68446d42efa1cff22b70c81b (patch) | |
tree | b712144660ce3eb931a173fc2d98f00031ca6a52 /src/db | |
parent | f2ce4a4a45bfc0c9ba6d1a13348494dd4c49d4fb (diff) | |
download | sssd-72aa8e7b1d234b6b68446d42efa1cff22b70c81b.tar.gz sssd-72aa8e7b1d234b6b68446d42efa1cff22b70c81b.tar.bz2 sssd-72aa8e7b1d234b6b68446d42efa1cff22b70c81b.zip |
Refactor sysdb initialization
Change the way sysdbs are initialized. Make callers responsible for providing
the list of domains.
Remove the returned array of sysdb contexts, it was used only by sss_cache
and not really necessary there either as that tool can easily iterate the
domains.
Make sysdb ctx children of their respective domains.
Neither sysdb context nor domains are ever freed until a program is done so
there shouldn't be any memory hierarchy issue. As plus we simplify the code by
removing a destructor and a setter function.
Diffstat (limited to 'src/db')
-rw-r--r-- | src/db/sysdb.c | 139 | ||||
-rw-r--r-- | src/db/sysdb.h | 19 |
2 files changed, 13 insertions, 145 deletions
diff --git a/src/db/sysdb.c b/src/db/sysdb.c index b0bea9a7..8b200b01 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 378ce488..d191dd3d 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 */ |