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

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