diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-04-23 13:05:27 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:51:33 -0500 |
commit | 07882b5460121c4ed100f9655935501f7cf23856 (patch) | |
tree | f9ecc0c89adc7fbab7d295ee456cfade117f6448 /source4/lib/ldb/ldb_tdb | |
parent | b394a4c2ff4502a0bf2bf05a6c7036f708fdb090 (diff) | |
download | samba-07882b5460121c4ed100f9655935501f7cf23856.tar.gz samba-07882b5460121c4ed100f9655935501f7cf23856.tar.bz2 samba-07882b5460121c4ed100f9655935501f7cf23856.zip |
r343: added automatic reindexing of the database when the index list changes
(This used to be commit a811640ce408373a5c2c0ee2c125bd735d96d5e1)
Diffstat (limited to 'source4/lib/ldb/ldb_tdb')
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_index.c | 66 | ||||
-rw-r--r-- | source4/lib/ldb/ldb_tdb/ldb_tdb.c | 12 |
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); |