summaryrefslogtreecommitdiff
path: root/source4/lib/ldb
diff options
context:
space:
mode:
Diffstat (limited to 'source4/lib/ldb')
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_index.c66
-rw-r--r--source4/lib/ldb/ldb_tdb/ldb_tdb.c12
2 files changed, 78 insertions, 0 deletions
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c b/source4/lib/ldb/ldb_tdb/ldb_index.c
index 8cda8abff8..95162ae575 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -33,6 +33,7 @@
*/
#include "includes.h"
+#include "ldb/ldb_tdb/ldb_tdb.h"
struct dn_list {
unsigned int count;
@@ -723,3 +724,68 @@ int ltdb_index_del(struct ldb_context *ldb, const struct ldb_message *msg)
return 0;
}
+
+
+/*
+ traversal function that deletes all @INDEX records
+*/
+static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
+{
+ if (strncmp(key.dptr, "@INDEX:", 7) == 0) {
+ return tdb_delete(tdb, key);
+ }
+ return 0;
+}
+
+/*
+ traversal function that adds @INDEX records during a re index
+*/
+static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
+{
+ struct ldb_context *ldb = state;
+ struct ldb_message msg;
+ int ret;
+
+ if (strncmp(key.dptr, "DN=@", 4) == 0 ||
+ strncmp(key.dptr, "DN=", 3) != 0) {
+ return 0;
+ }
+
+ ret = ltdb_unpack_data(ldb, &data, &msg);
+ if (ret != 0) {
+ return -1;
+ }
+
+ msg.dn = key.dptr+3;
+
+ ret = ltdb_index_add(ldb, &msg);
+
+ ltdb_unpack_data_free(&msg);
+
+ return ret;
+}
+
+/*
+ force a complete reindex of the database
+*/
+int ltdb_reindex(struct ldb_context *ldb)
+{
+ struct ltdb_private *ltdb = ldb->private;
+ int ret;
+
+ /* first traverse the database deleting any @INDEX records */
+ ret = tdb_traverse(ltdb->tdb, delete_index, NULL);
+ if (ret == -1) {
+ errno = EIO;
+ return -1;
+ }
+
+ /* now traverse adding any indexes for normal LDB records */
+ ret = tdb_traverse(ltdb->tdb, re_index, ldb);
+ if (ret == -1) {
+ errno = EIO;
+ return -1;
+ }
+
+ return 0;
+}
diff --git a/source4/lib/ldb/ldb_tdb/ldb_tdb.c b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
index b28d73cbea..34cff41794 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_tdb.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_tdb.c
@@ -148,6 +148,10 @@ static int ltdb_add(struct ldb_context *ldb, const struct ldb_message *msg)
ret = ltdb_store(ldb, msg, TDB_INSERT);
+ if (strcmp(msg->dn, "@INDEXLIST") == 0) {
+ ltdb_reindex(ldb);
+ }
+
ltdb_unlock(ldb);
return ret;
@@ -206,6 +210,10 @@ static int ltdb_delete(struct ldb_context *ldb, const char *dn)
ltdb_search_dn1_free(ldb, &msg);
+ if (strcmp(dn, "@INDEXLIST") == 0) {
+ ltdb_reindex(ldb);
+ }
+
ltdb_unlock(ldb);
return ret;
@@ -430,6 +438,10 @@ static int ltdb_modify(struct ldb_context *ldb, const struct ldb_message *msg)
/* we've made all the mods - save the modified record back into the database */
ret = ltdb_store(ldb, &msg2, TDB_MODIFY);
+ if (strcmp(msg2.dn, "@INDEXLIST") == 0) {
+ ltdb_reindex(ldb);
+ }
+
free(tdb_key.dptr);
free(tdb_data.dptr);
ltdb_unpack_data_free(&msg2);