summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorFabiano FidĂȘncio <fidencio@redhat.com>2016-08-16 11:20:49 +0200
committerJakub Hrozek <jhrozek@redhat.com>2016-08-26 15:19:31 +0200
commitb6d1cd5eaab4c7c73df8ee041944ec05630a9630 (patch)
treeb368140550519e6c58ce5bb1e87c063e0e71170f /src/db
parentf49724cd6b3e0e3274302c3d475e93f7a7094f40 (diff)
downloadsssd-b6d1cd5eaab4c7c73df8ee041944ec05630a9630.tar.gz
sssd-b6d1cd5eaab4c7c73df8ee041944ec05630a9630.tar.xz
sssd-b6d1cd5eaab4c7c73df8ee041944ec05630a9630.zip
SYSDB: Rework sysdb_cache_connect()
As sysdb_cache_connect() has two very specific use cases (connect to the cache and connect to the timestamp cache) and each of those calls have a predetermined/fixed sets of values for a few parameters, let's try to make the code a bit simpler to follow by having explicit functions for connecting to the cache and connecting to the timestamp cache. Macros could be used as well, but I have a slightly preference for having two new functions instead of macros accessing internal parameters of the macro's parameter. Related: https://fedorahosted.org/sssd/ticket/3128 Signed-off-by: Fabiano FidĂȘncio <fidencio@redhat.com> Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb_init.c53
1 files changed, 34 insertions, 19 deletions
diff --git a/src/db/sysdb_init.c b/src/db/sysdb_init.c
index 9e3646bfe..59934701c 100644
--- a/src/db/sysdb_init.c
+++ b/src/db/sysdb_init.c
@@ -511,14 +511,14 @@ done:
return ret;
}
-static errno_t sysdb_cache_connect(TALLOC_CTX *mem_ctx,
- struct sss_domain_info *domain,
- const char *ldb_file,
- int flags,
- const char *exp_version,
- const char *base_ldif,
- struct ldb_context **_ldb,
- const char **_version)
+static errno_t sysdb_cache_connect_helper(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *domain,
+ const char *ldb_file,
+ int flags,
+ const char *exp_version,
+ const char *base_ldif,
+ struct ldb_context **_ldb,
+ const char **_version)
{
TALLOC_CTX *tmp_ctx = NULL;
struct ldb_message_element *el;
@@ -619,6 +619,29 @@ done:
return ret;
}
+static errno_t sysdb_cache_connect(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ struct sss_domain_info *domain,
+ struct ldb_context **ldb,
+ const char **version)
+{
+ return sysdb_cache_connect_helper(mem_ctx, domain, sysdb->ldb_file,
+ 0, SYSDB_VERSION, SYSDB_BASE_LDIF,
+ ldb, version);
+}
+
+static errno_t sysdb_ts_cache_connect(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
+ struct sss_domain_info *domain,
+ struct ldb_context **ldb,
+ const char **version)
+{
+ return sysdb_cache_connect_helper(mem_ctx, domain, sysdb->ldb_ts_file,
+ LDB_FLG_NOSYNC, SYSDB_TS_VERSION,
+ SYSDB_TS_BASE_LDIF,
+ ldb, version);
+}
+
static errno_t remove_ts_cache(struct sysdb_ctx *sysdb)
{
errno_t ret;
@@ -649,9 +672,7 @@ static int sysdb_domain_cache_connect(struct sysdb_ctx *sysdb,
return ENOMEM;
}
- ret = sysdb_cache_connect(tmp_ctx, domain, sysdb->ldb_file, 0,
- SYSDB_VERSION, SYSDB_BASE_LDIF,
- &ldb, &version);
+ ret = sysdb_cache_connect(tmp_ctx, sysdb, domain, &ldb, &version);
switch (ret) {
case ERR_SYSDB_VERSION_TOO_OLD:
if (upgrade_ctx == NULL) {
@@ -731,10 +752,7 @@ static int sysdb_timestamp_cache_connect(struct sysdb_ctx *sysdb,
return ENOMEM;
}
- ret = sysdb_cache_connect(tmp_ctx, domain,
- sysdb->ldb_ts_file, LDB_FLG_NOSYNC,
- SYSDB_TS_VERSION, SYSDB_TS_BASE_LDIF,
- &ldb, &version);
+ ret = sysdb_ts_cache_connect(tmp_ctx, sysdb, domain, &ldb, &version);
switch (ret) {
case ERR_SYSDB_VERSION_TOO_OLD:
if (upgrade_ctx == NULL) {
@@ -801,10 +819,7 @@ static int sysdb_timestamp_cache_connect(struct sysdb_ctx *sysdb,
/* Now the connect must succeed because the previous cache doesn't
* exist anymore.
*/
- ret = sysdb_cache_connect(tmp_ctx, domain,
- sysdb->ldb_ts_file, LDB_FLG_NOSYNC,
- SYSDB_TS_VERSION, SYSDB_TS_BASE_LDIF,
- &ldb, &version);
+ ret = sysdb_ts_cache_connect(tmp_ctx, sysdb, domain, &ldb, &version);
if (ret != EOK) {
DEBUG(SSSDBG_MINOR_FAILURE,
"Could not delete the timestamp ldb file (%d) (%s)\n",