|
|
b2d430 |
From 960eca66245f23cf8ae0f32c3e44581a0e1117f9 Mon Sep 17 00:00:00 2001
|
|
|
b2d430 |
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
|
|
|
b2d430 |
Date: Tue, 16 Aug 2016 11:20:49 +0200
|
|
|
b2d430 |
Subject: [PATCH 119/121] SYSDB: Rework sysdb_cache_connect()
|
|
|
b2d430 |
MIME-Version: 1.0
|
|
|
b2d430 |
Content-Type: text/plain; charset=UTF-8
|
|
|
b2d430 |
Content-Transfer-Encoding: 8bit
|
|
|
b2d430 |
|
|
|
b2d430 |
As sysdb_cache_connect() has two very specific use cases (connect to the
|
|
|
b2d430 |
cache and connect to the timestamp cache) and each of those calls have a
|
|
|
b2d430 |
predetermined/fixed sets of values for a few parameters, let's try to
|
|
|
b2d430 |
make the code a bit simpler to follow by having explicit functions for
|
|
|
b2d430 |
connecting to the cache and connecting to the timestamp cache.
|
|
|
b2d430 |
|
|
|
b2d430 |
Macros could be used as well, but I have a slightly preference for
|
|
|
b2d430 |
having two new functions instead of macros accessing internal parameters
|
|
|
b2d430 |
of the macro's parameter.
|
|
|
b2d430 |
|
|
|
b2d430 |
Related:
|
|
|
b2d430 |
https://fedorahosted.org/sssd/ticket/3128
|
|
|
b2d430 |
|
|
|
b2d430 |
Signed-off-by: Fabiano FidĂȘncio <fidencio@redhat.com>
|
|
|
b2d430 |
|
|
|
b2d430 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
b2d430 |
---
|
|
|
b2d430 |
src/db/sysdb_init.c | 53 ++++++++++++++++++++++++++++++++++-------------------
|
|
|
b2d430 |
1 file changed, 34 insertions(+), 19 deletions(-)
|
|
|
b2d430 |
|
|
|
b2d430 |
diff --git a/src/db/sysdb_init.c b/src/db/sysdb_init.c
|
|
|
b2d430 |
index 9e3646bfeb9a494ebff2d348ab1c53336f8a5c03..59934701c4d2b9d770385a202af058404a6d3eb9 100644
|
|
|
b2d430 |
--- a/src/db/sysdb_init.c
|
|
|
b2d430 |
+++ b/src/db/sysdb_init.c
|
|
|
b2d430 |
@@ -511,14 +511,14 @@ done:
|
|
|
b2d430 |
return ret;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
-static errno_t sysdb_cache_connect(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
- struct sss_domain_info *domain,
|
|
|
b2d430 |
- const char *ldb_file,
|
|
|
b2d430 |
- int flags,
|
|
|
b2d430 |
- const char *exp_version,
|
|
|
b2d430 |
- const char *base_ldif,
|
|
|
b2d430 |
- struct ldb_context **_ldb,
|
|
|
b2d430 |
- const char **_version)
|
|
|
b2d430 |
+static errno_t sysdb_cache_connect_helper(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
+ struct sss_domain_info *domain,
|
|
|
b2d430 |
+ const char *ldb_file,
|
|
|
b2d430 |
+ int flags,
|
|
|
b2d430 |
+ const char *exp_version,
|
|
|
b2d430 |
+ const char *base_ldif,
|
|
|
b2d430 |
+ struct ldb_context **_ldb,
|
|
|
b2d430 |
+ const char **_version)
|
|
|
b2d430 |
{
|
|
|
b2d430 |
TALLOC_CTX *tmp_ctx = NULL;
|
|
|
b2d430 |
struct ldb_message_element *el;
|
|
|
b2d430 |
@@ -619,6 +619,29 @@ done:
|
|
|
b2d430 |
return ret;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
+static errno_t sysdb_cache_connect(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
+ struct sysdb_ctx *sysdb,
|
|
|
b2d430 |
+ struct sss_domain_info *domain,
|
|
|
b2d430 |
+ struct ldb_context **ldb,
|
|
|
b2d430 |
+ const char **version)
|
|
|
b2d430 |
+{
|
|
|
b2d430 |
+ return sysdb_cache_connect_helper(mem_ctx, domain, sysdb->ldb_file,
|
|
|
b2d430 |
+ 0, SYSDB_VERSION, SYSDB_BASE_LDIF,
|
|
|
b2d430 |
+ ldb, version);
|
|
|
b2d430 |
+}
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+static errno_t sysdb_ts_cache_connect(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
+ struct sysdb_ctx *sysdb,
|
|
|
b2d430 |
+ struct sss_domain_info *domain,
|
|
|
b2d430 |
+ struct ldb_context **ldb,
|
|
|
b2d430 |
+ const char **version)
|
|
|
b2d430 |
+{
|
|
|
b2d430 |
+ return sysdb_cache_connect_helper(mem_ctx, domain, sysdb->ldb_ts_file,
|
|
|
b2d430 |
+ LDB_FLG_NOSYNC, SYSDB_TS_VERSION,
|
|
|
b2d430 |
+ SYSDB_TS_BASE_LDIF,
|
|
|
b2d430 |
+ ldb, version);
|
|
|
b2d430 |
+}
|
|
|
b2d430 |
+
|
|
|
b2d430 |
static errno_t remove_ts_cache(struct sysdb_ctx *sysdb)
|
|
|
b2d430 |
{
|
|
|
b2d430 |
errno_t ret;
|
|
|
b2d430 |
@@ -649,9 +672,7 @@ static int sysdb_domain_cache_connect(struct sysdb_ctx *sysdb,
|
|
|
b2d430 |
return ENOMEM;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
- ret = sysdb_cache_connect(tmp_ctx, domain, sysdb->ldb_file, 0,
|
|
|
b2d430 |
- SYSDB_VERSION, SYSDB_BASE_LDIF,
|
|
|
b2d430 |
- &ldb, &version);
|
|
|
b2d430 |
+ ret = sysdb_cache_connect(tmp_ctx, sysdb, domain, &ldb, &version);
|
|
|
b2d430 |
switch (ret) {
|
|
|
b2d430 |
case ERR_SYSDB_VERSION_TOO_OLD:
|
|
|
b2d430 |
if (upgrade_ctx == NULL) {
|
|
|
b2d430 |
@@ -731,10 +752,7 @@ static int sysdb_timestamp_cache_connect(struct sysdb_ctx *sysdb,
|
|
|
b2d430 |
return ENOMEM;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
- ret = sysdb_cache_connect(tmp_ctx, domain,
|
|
|
b2d430 |
- sysdb->ldb_ts_file, LDB_FLG_NOSYNC,
|
|
|
b2d430 |
- SYSDB_TS_VERSION, SYSDB_TS_BASE_LDIF,
|
|
|
b2d430 |
- &ldb, &version);
|
|
|
b2d430 |
+ ret = sysdb_ts_cache_connect(tmp_ctx, sysdb, domain, &ldb, &version);
|
|
|
b2d430 |
switch (ret) {
|
|
|
b2d430 |
case ERR_SYSDB_VERSION_TOO_OLD:
|
|
|
b2d430 |
if (upgrade_ctx == NULL) {
|
|
|
b2d430 |
@@ -801,10 +819,7 @@ static int sysdb_timestamp_cache_connect(struct sysdb_ctx *sysdb,
|
|
|
b2d430 |
/* Now the connect must succeed because the previous cache doesn't
|
|
|
b2d430 |
* exist anymore.
|
|
|
b2d430 |
*/
|
|
|
b2d430 |
- ret = sysdb_cache_connect(tmp_ctx, domain,
|
|
|
b2d430 |
- sysdb->ldb_ts_file, LDB_FLG_NOSYNC,
|
|
|
b2d430 |
- SYSDB_TS_VERSION, SYSDB_TS_BASE_LDIF,
|
|
|
b2d430 |
- &ldb, &version);
|
|
|
b2d430 |
+ ret = sysdb_ts_cache_connect(tmp_ctx, sysdb, domain, &ldb, &version);
|
|
|
b2d430 |
if (ret != EOK) {
|
|
|
b2d430 |
DEBUG(SSSDBG_MINOR_FAILURE,
|
|
|
b2d430 |
"Could not delete the timestamp ldb file (%d) (%s)\n",
|
|
|
b2d430 |
--
|
|
|
b2d430 |
2.4.11
|
|
|
b2d430 |
|