sssd/0011-SYSDB-Remove-the-timestamp-cache-for-a-newly-created.patch
Lukas Slebodnik 2b61bbee11 Backport important patches from upstream 1.14.2 prerelease
- Resolves: upstream #3154 - sssd exits if clock is adjusted backwards after
                             boot
- Resolves: upstream #3163 - resolving IPA nested user group is broken in 1.14
2016-09-01 18:13:49 +02:00

153 lines
5.2 KiB
Diff

From 85fed431388c7f7f70dbf5bcd0b4f8a889c60bc6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= <fidencio@redhat.com>
Date: Tue, 16 Aug 2016 11:46:41 +0200
Subject: [PATCH 11/39] SYSDB: Remove the timestamp cache for a newly created
cache
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
As many users are used to remove the persistent cache without removing
the timestamp cache, let's throw away the timestamp cache in this case.
Resolves:
https://fedorahosted.org/sssd/ticket/3128
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
(cherry picked from commit 9023bf51de6c84337af024388f1860ac1051924c)
---
src/db/sysdb_init.c | 69 ++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 47 insertions(+), 22 deletions(-)
diff --git a/src/db/sysdb_init.c b/src/db/sysdb_init.c
index 59934701c4d2b9d770385a202af058404a6d3eb9..c387c1b12c116f38d5a13f1adeac5ef64d593af8 100644
--- a/src/db/sysdb_init.c
+++ b/src/db/sysdb_init.c
@@ -511,12 +511,30 @@ done:
return ret;
}
+static errno_t remove_ts_cache(struct sysdb_ctx *sysdb)
+{
+ errno_t ret;
+
+ if (sysdb->ldb_ts_file == NULL) {
+ return EOK;
+ }
+
+ ret = unlink(sysdb->ldb_ts_file);
+ if (ret != EOK && errno != ENOENT) {
+ return errno;
+ }
+
+ return EOK;
+}
+
static errno_t sysdb_cache_connect_helper(TALLOC_CTX *mem_ctx,
+ struct sysdb_ctx *sysdb,
struct sss_domain_info *domain,
const char *ldb_file,
int flags,
const char *exp_version,
const char *base_ldif,
+ bool *_newly_created,
struct ldb_context **_ldb,
const char **_version)
{
@@ -527,6 +545,7 @@ static errno_t sysdb_cache_connect_helper(TALLOC_CTX *mem_ctx,
const char *version = NULL;
int ret;
struct ldb_context *ldb;
+ bool newly_created;
tmp_ctx = talloc_new(NULL);
if (!tmp_ctx) {
@@ -592,8 +611,9 @@ static errno_t sysdb_cache_connect_helper(TALLOC_CTX *mem_ctx,
goto done;
}
- /* The cache has been newly created.
- * We need to reopen the LDB to ensure that
+ newly_created = true;
+
+ /* We need to reopen the LDB to ensure that
* all of the special values take effect
* (such as enabling the memberOf plugin and
* the various indexes).
@@ -613,6 +633,9 @@ static errno_t sysdb_cache_connect_helper(TALLOC_CTX *mem_ctx,
}
done:
if (ret == EOK) {
+ if (_newly_created != NULL) {
+ *_newly_created = newly_created;
+ }
*_ldb = talloc_steal(mem_ctx, ldb);
}
talloc_free(tmp_ctx);
@@ -625,9 +648,27 @@ static errno_t sysdb_cache_connect(TALLOC_CTX *mem_ctx,
struct ldb_context **ldb,
const char **version)
{
- return sysdb_cache_connect_helper(mem_ctx, domain, sysdb->ldb_file,
+ bool newly_created;
+ bool ldb_file_exists;
+ errno_t ret;
+
+ ldb_file_exists = !(access(sysdb->ldb_file, F_OK) == -1 && errno == ENOENT);
+
+ ret = sysdb_cache_connect_helper(mem_ctx, sysdb, domain, sysdb->ldb_file,
0, SYSDB_VERSION, SYSDB_BASE_LDIF,
- ldb, version);
+ &newly_created, ldb, version);
+
+ /* The cache has been newly created. */
+ if (ret == EOK && newly_created && !ldb_file_exists) {
+ ret = remove_ts_cache(sysdb);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_MINOR_FAILURE,
+ "Could not delete the timestamp ldb file (%d) (%s)\n",
+ ret, sss_strerror(ret));
+ }
+ }
+
+ return ret;
}
static errno_t sysdb_ts_cache_connect(TALLOC_CTX *mem_ctx,
@@ -636,28 +677,12 @@ static errno_t sysdb_ts_cache_connect(TALLOC_CTX *mem_ctx,
struct ldb_context **ldb,
const char **version)
{
- return sysdb_cache_connect_helper(mem_ctx, domain, sysdb->ldb_ts_file,
+ return sysdb_cache_connect_helper(mem_ctx, sysdb, domain, sysdb->ldb_ts_file,
LDB_FLG_NOSYNC, SYSDB_TS_VERSION,
- SYSDB_TS_BASE_LDIF,
+ SYSDB_TS_BASE_LDIF, NULL,
ldb, version);
}
-static errno_t remove_ts_cache(struct sysdb_ctx *sysdb)
-{
- errno_t ret;
-
- if (sysdb->ldb_ts_file == NULL) {
- return EOK;
- }
-
- ret = unlink(sysdb->ldb_ts_file);
- if (ret != EOK && errno != ENOENT) {
- return errno;
- }
-
- return EOK;
-}
-
static int sysdb_domain_cache_connect(struct sysdb_ctx *sysdb,
struct sss_domain_info *domain,
struct sysdb_dom_upgrade_ctx *upgrade_ctx)
--
2.9.3