1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-28 01:58:17 +03:00

ldb_kv_index: Make the edge keys slightly cleaner and generic

It makes no difference in our standard case because \0 will always go
before any value for our index_format_fn, but this is better for
correctness (in case we do mess up our NUL terminations elsewhere).

Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
This commit is contained in:
Garming Sam 2019-04-04 14:36:08 +13:00 committed by Andrew Bartlett
parent 9b3021b8d6
commit a894515229

View File

@ -1862,8 +1862,25 @@ static int ldb_kv_index_dn_ordered(struct ldb_module *module,
return LDB_ERR_OPERATIONS_ERROR;
}
/*
* In order to avoid defining a start and end key for the search, we
* notice that each index key is of the form:
*
* DN=@INDEX:<ATTRIBUTE>:<VALUE>\0.
*
* We can simply make our start key DN=@INDEX:<ATTRIBUTE>: and our end
* key DN=@INDEX:<ATTRIBUTE>; to return all index entries for a
* particular attribute.
*
* Our LMDB backend uses the default memcmp for key comparison.
*/
/* Eliminate NUL byte at the end of the empty key */
ldb_key2.length--;
if (ascending) {
ldb_key2.data[ldb_key2.length-2]++;
/* : becomes ; for pseudo end-key */
ldb_key2.data[ldb_key2.length-1]++;
start_key = ldb_key;
end_key = ldb_key2;
} else {