[SSSD] [PATCH] SYSDB: index sudoUser
Jakub Hrozek
jhrozek at redhat.com
Tue Jan 31 22:05:16 UTC 2012
On Tue, Jan 31, 2012 at 10:17:04AM -0500, Stephen Gallagher wrote:
> On Tue, 2012-01-31 at 16:09 +0100, Jakub Hrozek wrote:
> > Most of the the searches in the Sudo responder include the sudoUser
> > attribute. Indexing it will make the responder faster.
>
>
> Nack.
>
> You're adding indexes for "sudoNotAfter" and "sudoNotBefore" in the
> upgrade routine, but not in the initial creation (in sysdb_private.h)
Thank you, that was not supposed to be there.
-------------- next part --------------
From 6676e1feeadbabe042d53b8479bde3cc9091d625 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek at redhat.com>
Date: Tue, 24 Jan 2012 22:17:46 +0100
Subject: [PATCH] SYSDB: index sudoUser
Most of the the searches in the Sudo responder include the sudoUser
attribute. Indexing it will make the responder faster.
---
src/db/sysdb.c | 7 ++++
src/db/sysdb_private.h | 5 ++-
src/db/sysdb_upgrade.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 99 insertions(+), 1 deletions(-)
diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index 6bd787f7e6eb898e88823c64dd61f2168ea866f0..a7f65a332894966b100a4ff7a9a186065f5a9af9 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -962,6 +962,13 @@ int sysdb_domain_init_internal(TALLOC_CTX *mem_ctx,
}
}
+ if (strcmp(version, SYSDB_VERSION_0_9) == 0) {
+ ret = sysdb_upgrade_09(sysdb, &version);
+ if (ret != EOK) {
+ goto done;
+ }
+ }
+
/* The version should now match SYSDB_VERSION.
* If not, it means we didn't match any of the
* known older versions. The DB might be
diff --git a/src/db/sysdb_private.h b/src/db/sysdb_private.h
index 37090f8a8578d0ba06854eb9efac3c588824633a..a162cbba82bba8fef1e57ab2774d156307ead2cd 100644
--- a/src/db/sysdb_private.h
+++ b/src/db/sysdb_private.h
@@ -23,6 +23,7 @@
#ifndef __INT_SYS_DB_H__
#define __INT_SYS_DB_H__
+#define SYSDB_VERSION_0_10 "0.10"
#define SYSDB_VERSION_0_9 "0.9"
#define SYSDB_VERSION_0_8 "0.8"
#define SYSDB_VERSION_0_7 "0.7"
@@ -33,7 +34,7 @@
#define SYSDB_VERSION_0_2 "0.2"
#define SYSDB_VERSION_0_1 "0.1"
-#define SYSDB_VERSION SYSDB_VERSION_0_9
+#define SYSDB_VERSION SYSDB_VERSION_0_10
#define SYSDB_BASE_LDIF \
"dn: @ATTRIBUTES\n" \
@@ -58,6 +59,7 @@
"@IDXATTR: nameAlias\n" \
"@IDXATTR: servicePort\n" \
"@IDXATTR: serviceProtocol\n" \
+ "@IDXATTR: sudoUser\n" \
"@IDXONE: 1\n" \
"\n" \
"dn: @MODULES\n" \
@@ -101,6 +103,7 @@ int sysdb_upgrade_05(struct sysdb_ctx *sysdb, const char **ver);
int sysdb_upgrade_06(struct sysdb_ctx *sysdb, const char **ver);
int sysdb_upgrade_07(struct sysdb_ctx *sysdb, const char **ver);
int sysdb_upgrade_08(struct sysdb_ctx *sysdb, const char **ver);
+int sysdb_upgrade_09(struct sysdb_ctx *sysdb, const char **ver);
int add_string(struct ldb_message *msg, int flags,
const char *attr, const char *value);
diff --git a/src/db/sysdb_upgrade.c b/src/db/sysdb_upgrade.c
index ab8394f57a393b7306895549509bd889cbc03690..434cc832a66ade786eb1b2f6524d4a1604da11e1 100644
--- a/src/db/sysdb_upgrade.c
+++ b/src/db/sysdb_upgrade.c
@@ -1072,3 +1072,91 @@ done:
talloc_free(tmp_ctx);
return ret;
}
+
+int sysdb_upgrade_09(struct sysdb_ctx *sysdb, const char **ver)
+{
+ TALLOC_CTX *tmp_ctx;
+ int ret;
+ struct ldb_message *msg;
+
+ tmp_ctx = talloc_new(NULL);
+ if (!tmp_ctx) {
+ return ENOMEM;
+ }
+
+ DEBUG(0, ("UPGRADING DB TO VERSION %s\n", SYSDB_VERSION_0_10));
+
+ ret = ldb_transaction_start(sysdb->ldb);
+ if (ret != LDB_SUCCESS) {
+ ret = EIO;
+ goto done;
+ }
+
+ /* Add new indexes */
+ msg = ldb_msg_new(tmp_ctx);
+ if (!msg) {
+ ret = ENOMEM;
+ goto done;
+ }
+ msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, "@INDEXLIST");
+ if (!msg->dn) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ /* Add Index for servicePort and serviceProtocol */
+ ret = ldb_msg_add_empty(msg, "@IDXATTR", LDB_FLAG_MOD_ADD, NULL);
+ if (ret != LDB_SUCCESS) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = ldb_msg_add_string(msg, "@IDXATTR", "sudoUser");
+ if (ret != LDB_SUCCESS) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = ldb_modify(sysdb->ldb, msg);
+ if (ret != LDB_SUCCESS) {
+ ret = sysdb_error_to_errno(ret);
+ goto done;
+ }
+
+ /* conversion done, upgrade version number */
+ msg = ldb_msg_new(tmp_ctx);
+ if (!msg) {
+ ret = ENOMEM;
+ goto done;
+ }
+ msg->dn = ldb_dn_new(tmp_ctx, sysdb->ldb, SYSDB_BASE);
+ if (!msg->dn) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = ldb_msg_add_empty(msg, "version", LDB_FLAG_MOD_REPLACE, NULL);
+ if (ret != LDB_SUCCESS) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = ldb_msg_add_string(msg, "version", SYSDB_VERSION_0_10);
+ if (ret != LDB_SUCCESS) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = ldb_modify(sysdb->ldb, msg);
+ if (ret != LDB_SUCCESS) {
+ ret = sysdb_error_to_errno(ret);
+ goto done;
+ }
+
+ ret = EOK;
+
+done:
+ ret = finish_upgrade(ret, sysdb->ldb, SYSDB_VERSION_0_10, ver);
+ talloc_free(tmp_ctx);
+ return ret;
+}
--
1.7.7.6
More information about the sssd-devel
mailing list