1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-27 14:04:05 +03:00

r343: added automatic reindexing of the database when the index list changes

(This used to be commit a811640ce408373a5c2c0ee2c125bd735d96d5e1)
This commit is contained in:
Andrew Tridgell 2004-04-23 13:05:27 +00:00 committed by Gerald (Jerry) Carter
parent b394a4c2ff
commit 07882b5460
2 changed files with 78 additions and 0 deletions

View File

@ -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;
}

View File

@ -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);