|
|
b2d430 |
From 9e5fc47e6636f6a149dba9a0a708892be85a6f22 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:46:41 +0200
|
|
|
b2d430 |
Subject: [PATCH 120/121] SYSDB: Remove the timestamp cache for a newly created
|
|
|
b2d430 |
cache
|
|
|
b2d430 |
MIME-Version: 1.0
|
|
|
b2d430 |
Content-Type: text/plain; charset=UTF-8
|
|
|
b2d430 |
Content-Transfer-Encoding: 8bit
|
|
|
b2d430 |
|
|
|
b2d430 |
As many users are used to remove the persistent cache without removing
|
|
|
b2d430 |
the timestamp cache, let's throw away the timestamp cache in this case.
|
|
|
b2d430 |
|
|
|
b2d430 |
Resolves:
|
|
|
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 | 69 ++++++++++++++++++++++++++++++++++++-----------------
|
|
|
b2d430 |
1 file changed, 47 insertions(+), 22 deletions(-)
|
|
|
b2d430 |
|
|
|
b2d430 |
diff --git a/src/db/sysdb_init.c b/src/db/sysdb_init.c
|
|
|
b2d430 |
index 59934701c4d2b9d770385a202af058404a6d3eb9..c387c1b12c116f38d5a13f1adeac5ef64d593af8 100644
|
|
|
b2d430 |
--- a/src/db/sysdb_init.c
|
|
|
b2d430 |
+++ b/src/db/sysdb_init.c
|
|
|
b2d430 |
@@ -511,12 +511,30 @@ done:
|
|
|
b2d430 |
return ret;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
+static errno_t remove_ts_cache(struct sysdb_ctx *sysdb)
|
|
|
b2d430 |
+{
|
|
|
b2d430 |
+ errno_t ret;
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ if (sysdb->ldb_ts_file == NULL) {
|
|
|
b2d430 |
+ return EOK;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ ret = unlink(sysdb->ldb_ts_file);
|
|
|
b2d430 |
+ if (ret != EOK && errno != ENOENT) {
|
|
|
b2d430 |
+ return errno;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ return EOK;
|
|
|
b2d430 |
+}
|
|
|
b2d430 |
+
|
|
|
b2d430 |
static errno_t sysdb_cache_connect_helper(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
+ struct sysdb_ctx *sysdb,
|
|
|
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 |
+ bool *_newly_created,
|
|
|
b2d430 |
struct ldb_context **_ldb,
|
|
|
b2d430 |
const char **_version)
|
|
|
b2d430 |
{
|
|
|
b2d430 |
@@ -527,6 +545,7 @@ static errno_t sysdb_cache_connect_helper(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
const char *version = NULL;
|
|
|
b2d430 |
int ret;
|
|
|
b2d430 |
struct ldb_context *ldb;
|
|
|
b2d430 |
+ bool newly_created;
|
|
|
b2d430 |
|
|
|
b2d430 |
tmp_ctx = talloc_new(NULL);
|
|
|
b2d430 |
if (!tmp_ctx) {
|
|
|
b2d430 |
@@ -592,8 +611,9 @@ static errno_t sysdb_cache_connect_helper(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
goto done;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
- /* The cache has been newly created.
|
|
|
b2d430 |
- * We need to reopen the LDB to ensure that
|
|
|
b2d430 |
+ newly_created = true;
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ /* We need to reopen the LDB to ensure that
|
|
|
b2d430 |
* all of the special values take effect
|
|
|
b2d430 |
* (such as enabling the memberOf plugin and
|
|
|
b2d430 |
* the various indexes).
|
|
|
b2d430 |
@@ -613,6 +633,9 @@ static errno_t sysdb_cache_connect_helper(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
}
|
|
|
b2d430 |
done:
|
|
|
b2d430 |
if (ret == EOK) {
|
|
|
b2d430 |
+ if (_newly_created != NULL) {
|
|
|
b2d430 |
+ *_newly_created = newly_created;
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
*_ldb = talloc_steal(mem_ctx, ldb);
|
|
|
b2d430 |
}
|
|
|
b2d430 |
talloc_free(tmp_ctx);
|
|
|
b2d430 |
@@ -625,9 +648,27 @@ static errno_t sysdb_cache_connect(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
struct ldb_context **ldb,
|
|
|
b2d430 |
const char **version)
|
|
|
b2d430 |
{
|
|
|
b2d430 |
- return sysdb_cache_connect_helper(mem_ctx, domain, sysdb->ldb_file,
|
|
|
b2d430 |
+ bool newly_created;
|
|
|
b2d430 |
+ bool ldb_file_exists;
|
|
|
b2d430 |
+ errno_t ret;
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ ldb_file_exists = !(access(sysdb->ldb_file, F_OK) == -1 && errno == ENOENT);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ ret = sysdb_cache_connect_helper(mem_ctx, sysdb, domain, sysdb->ldb_file,
|
|
|
b2d430 |
0, SYSDB_VERSION, SYSDB_BASE_LDIF,
|
|
|
b2d430 |
- ldb, version);
|
|
|
b2d430 |
+ &newly_created, ldb, version);
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ /* The cache has been newly created. */
|
|
|
b2d430 |
+ if (ret == EOK && newly_created && !ldb_file_exists) {
|
|
|
b2d430 |
+ ret = remove_ts_cache(sysdb);
|
|
|
b2d430 |
+ if (ret != EOK) {
|
|
|
b2d430 |
+ DEBUG(SSSDBG_MINOR_FAILURE,
|
|
|
b2d430 |
+ "Could not delete the timestamp ldb file (%d) (%s)\n",
|
|
|
b2d430 |
+ ret, sss_strerror(ret));
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+ }
|
|
|
b2d430 |
+
|
|
|
b2d430 |
+ return ret;
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
static errno_t sysdb_ts_cache_connect(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
@@ -636,28 +677,12 @@ static errno_t sysdb_ts_cache_connect(TALLOC_CTX *mem_ctx,
|
|
|
b2d430 |
struct ldb_context **ldb,
|
|
|
b2d430 |
const char **version)
|
|
|
b2d430 |
{
|
|
|
b2d430 |
- return sysdb_cache_connect_helper(mem_ctx, domain, sysdb->ldb_ts_file,
|
|
|
b2d430 |
+ return sysdb_cache_connect_helper(mem_ctx, sysdb, domain, sysdb->ldb_ts_file,
|
|
|
b2d430 |
LDB_FLG_NOSYNC, SYSDB_TS_VERSION,
|
|
|
b2d430 |
- SYSDB_TS_BASE_LDIF,
|
|
|
b2d430 |
+ SYSDB_TS_BASE_LDIF, NULL,
|
|
|
b2d430 |
ldb, version);
|
|
|
b2d430 |
}
|
|
|
b2d430 |
|
|
|
b2d430 |
-static errno_t remove_ts_cache(struct sysdb_ctx *sysdb)
|
|
|
b2d430 |
-{
|
|
|
b2d430 |
- errno_t ret;
|
|
|
b2d430 |
-
|
|
|
b2d430 |
- if (sysdb->ldb_ts_file == NULL) {
|
|
|
b2d430 |
- return EOK;
|
|
|
b2d430 |
- }
|
|
|
b2d430 |
-
|
|
|
b2d430 |
- ret = unlink(sysdb->ldb_ts_file);
|
|
|
b2d430 |
- if (ret != EOK && errno != ENOENT) {
|
|
|
b2d430 |
- return errno;
|
|
|
b2d430 |
- }
|
|
|
b2d430 |
-
|
|
|
b2d430 |
- return EOK;
|
|
|
b2d430 |
-}
|
|
|
b2d430 |
-
|
|
|
b2d430 |
static int sysdb_domain_cache_connect(struct sysdb_ctx *sysdb,
|
|
|
b2d430 |
struct sss_domain_info *domain,
|
|
|
b2d430 |
struct sysdb_dom_upgrade_ctx *upgrade_ctx)
|
|
|
b2d430 |
--
|
|
|
b2d430 |
2.4.11
|
|
|
b2d430 |
|