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

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