Blame SOURCES/0009-SYSDB-Index-the-ccacheFile-attribute.patch

5fca41
From 7d8b28ad691335ebb679c6230b5e4818a7434bc5 Mon Sep 17 00:00:00 2001
5fca41
From: Jakub Hrozek <jhrozek@redhat.com>
5fca41
Date: Sat, 23 Mar 2019 22:18:18 +0100
5fca41
Subject: [PATCH] SYSDB: Index the ccacheFile attribute
5fca41
5fca41
Related:
5fca41
https://pagure.io/SSSD/sssd/issue/3968
5fca41
5fca41
The Kerberos ticket renewal code searches for user entries which have
5fca41
the ccacheFile attribute set. Since the search can potentially traverse
5fca41
all the users, it might be a good idea to index the attribute.
5fca41
5fca41
Reviewed-by: Alexey Tikhonov <atikhono@redhat.com>
5fca41
(cherry picked from commit 96013bbb7d937d1a9e4e5c678df3034520d98f32)
5fca41
---
5fca41
 src/db/sysdb_init.c    |  7 ++++++
5fca41
 src/db/sysdb_private.h |  5 +++-
5fca41
 src/db/sysdb_upgrade.c | 52 ++++++++++++++++++++++++++++++++++++++++++
5fca41
 3 files changed, 63 insertions(+), 1 deletion(-)
5fca41
5fca41
diff --git a/src/db/sysdb_init.c b/src/db/sysdb_init.c
5fca41
index 89f8c6a5b..48e21baab 100644
5fca41
--- a/src/db/sysdb_init.c
5fca41
+++ b/src/db/sysdb_init.c
5fca41
@@ -558,6 +558,13 @@ static errno_t sysdb_domain_cache_upgrade(TALLOC_CTX *mem_ctx,
5fca41
         }
5fca41
     }
5fca41
 
5fca41
+    if (strcmp(version, SYSDB_VERSION_0_20) == 0) {
5fca41
+        ret = sysdb_upgrade_20(sysdb, &version);
5fca41
+        if (ret != EOK) {
5fca41
+            goto done;
5fca41
+        }
5fca41
+    }
5fca41
+
5fca41
 
5fca41
     ret = EOK;
5fca41
 done:
5fca41
diff --git a/src/db/sysdb_private.h b/src/db/sysdb_private.h
5fca41
index c297715cd..58544d826 100644
5fca41
--- a/src/db/sysdb_private.h
5fca41
+++ b/src/db/sysdb_private.h
5fca41
@@ -23,6 +23,7 @@
5fca41
 #ifndef __INT_SYS_DB_H__
5fca41
 #define __INT_SYS_DB_H__
5fca41
 
5fca41
+#define SYSDB_VERSION_0_21 "0.21"
5fca41
 #define SYSDB_VERSION_0_20 "0.20"
5fca41
 #define SYSDB_VERSION_0_19 "0.19"
5fca41
 #define SYSDB_VERSION_0_18 "0.18"
5fca41
@@ -44,7 +45,7 @@
5fca41
 #define SYSDB_VERSION_0_2 "0.2"
5fca41
 #define SYSDB_VERSION_0_1 "0.1"
5fca41
 
5fca41
-#define SYSDB_VERSION SYSDB_VERSION_0_20
5fca41
+#define SYSDB_VERSION SYSDB_VERSION_0_21
5fca41
 
5fca41
 #define SYSDB_BASE_LDIF \
5fca41
      "dn: @ATTRIBUTES\n" \
5fca41
@@ -79,6 +80,7 @@
5fca41
      "@IDXATTR: uniqueID\n" \
5fca41
      "@IDXATTR: mail\n" \
5fca41
      "@IDXATTR: userMappedCertificate\n" \
5fca41
+     "@IDXATTR: ccacheFile\n" \
5fca41
      "\n" \
5fca41
      "dn: @MODULES\n" \
5fca41
      "@LIST: asq,memberof\n" \
5fca41
@@ -171,6 +173,7 @@ int sysdb_upgrade_17(struct sysdb_ctx *sysdb,
5fca41
                      const char **ver);
5fca41
 int sysdb_upgrade_18(struct sysdb_ctx *sysdb, const char **ver);
5fca41
 int sysdb_upgrade_19(struct sysdb_ctx *sysdb, const char **ver);
5fca41
+int sysdb_upgrade_20(struct sysdb_ctx *sysdb, const char **ver);
5fca41
 
5fca41
 int sysdb_ts_upgrade_01(struct sysdb_ctx *sysdb, const char **ver);
5fca41
 
5fca41
diff --git a/src/db/sysdb_upgrade.c b/src/db/sysdb_upgrade.c
5fca41
index 46df971e9..f6a481147 100644
5fca41
--- a/src/db/sysdb_upgrade.c
5fca41
+++ b/src/db/sysdb_upgrade.c
5fca41
@@ -2501,6 +2501,58 @@ done:
5fca41
     return ret;
5fca41
 }
5fca41
 
5fca41
+int sysdb_upgrade_20(struct sysdb_ctx *sysdb, const char **ver)
5fca41
+{
5fca41
+    struct upgrade_ctx *ctx;
5fca41
+    errno_t ret;
5fca41
+    struct ldb_message *msg = NULL;
5fca41
+
5fca41
+    ret = commence_upgrade(sysdb, sysdb->ldb, SYSDB_VERSION_0_21, &ctx;;
5fca41
+    if (ret) {
5fca41
+        return ret;
5fca41
+    }
5fca41
+
5fca41
+    /* Add missing indices */
5fca41
+    msg = ldb_msg_new(ctx);
5fca41
+    if (msg == NULL) {
5fca41
+        ret = ENOMEM;
5fca41
+        goto done;
5fca41
+    }
5fca41
+
5fca41
+    msg->dn = ldb_dn_new(msg, sysdb->ldb, "@INDEXLIST");
5fca41
+    if (msg->dn == NULL) {
5fca41
+        ret = ENOMEM;
5fca41
+        goto done;
5fca41
+    }
5fca41
+
5fca41
+    ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
5fca41
+    if (ret != LDB_SUCCESS) {
5fca41
+        ret = ENOMEM;
5fca41
+        goto done;
5fca41
+    }
5fca41
+
5fca41
+    ret = ldb_msg_add_string(msg, "@IDXATTR", SYSDB_CCACHE_FILE);
5fca41
+    if (ret != LDB_SUCCESS) {
5fca41
+        ret = ENOMEM;
5fca41
+        goto done;
5fca41
+    }
5fca41
+
5fca41
+    ret = ldb_modify(sysdb->ldb, msg);
5fca41
+    if (ret != LDB_SUCCESS) {
5fca41
+        ret = sysdb_error_to_errno(ret);
5fca41
+        goto done;
5fca41
+    }
5fca41
+
5fca41
+    talloc_free(msg);
5fca41
+
5fca41
+    /* conversion done, update version number */
5fca41
+    ret = update_version(ctx);
5fca41
+
5fca41
+done:
5fca41
+    ret = finish_upgrade(ret, &ctx, ver);
5fca41
+    return ret;
5fca41
+}
5fca41
+
5fca41
 int sysdb_ts_upgrade_01(struct sysdb_ctx *sysdb, const char **ver)
5fca41
 {
5fca41
     struct upgrade_ctx *ctx;
5fca41
-- 
5fca41
2.19.1
5fca41