diff options
author | Andrew Bartlett <abartlet@samba.org> | 2017-09-01 14:35:08 +1200 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2017-09-07 06:56:26 +0200 |
commit | fec666b334ad90408843d8fbfd4c2f62434831e2 (patch) | |
tree | 8ad6131576628c240e60f3abf4b056d9f144fd27 /lib/ldb | |
parent | 2d0007ee5a658d199029f7e81200e206ba0d89e0 (diff) | |
download | samba-fec666b334ad90408843d8fbfd4c2f62434831e2.tar.gz |
ldb_tdb: Create a common ltdb_key_is_record() allowing multiple key forms
If backported, this allows old ldb versions to full-search and re-index newer databases
and in current code allows the transition to and from a GUID or incrementing ID based index
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13016
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Diffstat (limited to 'lib/ldb')
-rw-r--r-- | lib/ldb/ldb_tdb/ldb_index.c | 24 | ||||
-rw-r--r-- | lib/ldb/ldb_tdb/ldb_search.c | 3 | ||||
-rw-r--r-- | lib/ldb/ldb_tdb/ldb_tdb.c | 29 | ||||
-rw-r--r-- | lib/ldb/ldb_tdb/ldb_tdb.h | 5 |
4 files changed, 53 insertions, 8 deletions
diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c index 29f59f3003f..dbed867f94d 100644 --- a/lib/ldb/ldb_tdb/ldb_index.c +++ b/lib/ldb/ldb_tdb/ldb_index.c @@ -1573,14 +1573,20 @@ static int re_key(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *st }; int ret; TDB_DATA key2; - + bool is_record; + ldb = ldb_module_get_ctx(module); - if (strncmp((char *)key.dptr, "DN=@", 4) == 0 || - strncmp((char *)key.dptr, "DN=", 3) != 0) { + if (key.dsize > 4 && + strncmp((char *)key.dptr, "DN=@", 4) == 0) { return 0; } + is_record = ltdb_key_is_record(key); + if (is_record == false) { + return 0; + } + msg = ldb_msg_new(module); if (msg == NULL) { return -1; @@ -1636,14 +1642,20 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void * .length = data.dsize, }; int ret; - + bool is_record; + ldb = ldb_module_get_ctx(module); - if (strncmp((char *)key.dptr, "DN=@", 4) == 0 || - strncmp((char *)key.dptr, "DN=", 3) != 0) { + if (key.dsize > 4 && + strncmp((char *)key.dptr, "DN=@", 4) == 0) { return 0; } + is_record = ltdb_key_is_record(key); + if (is_record == false) { + return 0; + } + msg = ldb_msg_new(module); if (msg == NULL) { return -1; diff --git a/lib/ldb/ldb_tdb/ldb_search.c b/lib/ldb/ldb_tdb/ldb_search.c index 53355e04f6b..a6c408a53ce 100644 --- a/lib/ldb/ldb_tdb/ldb_search.c +++ b/lib/ldb/ldb_tdb/ldb_search.c @@ -410,8 +410,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi ac = talloc_get_type(state, struct ltdb_context); ldb = ldb_module_get_ctx(ac->module); - if (key.dsize < 4 || - strncmp((char *)key.dptr, "DN=", 3) != 0) { + if (ltdb_key_is_record(key) == false) { return 0; } diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index bc8780ad7ee..316a487bfe4 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -127,6 +127,35 @@ int ltdb_unlock_read(struct ldb_module *module) } +/* + * Determine if this key could hold a record. We allow the new GUID + * index, the old DN index and a possible future ID= + */ +bool ltdb_key_is_record(TDB_DATA key) +{ + if (key.dsize < 4) { + return false; + } + + if (strncmp((char *)key.dptr, "DN=", 3) == 0) { + return true; + } + + if (strncmp((char *)key.dptr, "ID=", 3) == 0) { + return true; + } + + if (key.dsize < 6) { + return false; + } + + if (strncmp((char *)key.dptr, "GUID=", 5) == 0) { + return true; + } + + return false; +} + /* form a TDB_DATA for a record key caller frees diff --git a/lib/ldb/ldb_tdb/ldb_tdb.h b/lib/ldb/ldb_tdb/ldb_tdb.h index 26ae68e89c8..a391606dd16 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/lib/ldb/ldb_tdb/ldb_tdb.h @@ -110,6 +110,11 @@ int ltdb_search(struct ltdb_context *ctx); /* The following definitions come from lib/ldb/ldb_tdb/ldb_tdb.c */ int ltdb_lock_read(struct ldb_module *module); int ltdb_unlock_read(struct ldb_module *module); +/* + * Determine if this key could hold a record. We allow the new GUID + * index, the old DN index and a possible future ID= + */ +bool ltdb_key_is_record(TDB_DATA key); TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn); int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flgs); int ltdb_modify_internal(struct ldb_module *module, const struct ldb_message *msg, struct ldb_request *req); |