From 960eca66245f23cf8ae0f32c3e44581a0e1117f9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Tue, 16 Aug 2016 11:20:49 +0200
Subject: [PATCH 119/121] SYSDB: Rework sysdb_cache_connect()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
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>
---
src/db/sysdb_init.c | 53 ++++++++++++++++++++++++++++++++++-------------------
1 file changed, 34 insertions(+), 19 deletions(-)
diff --git a/src/db/sysdb_init.c b/src/db/sysdb_init.c
index 9e3646bfeb9a494ebff2d348ab1c53336f8a5c03..59934701c4d2b9d770385a202af058404a6d3eb9 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",
--
2.4.11