From: Garming Sam Date: Thu, 4 Apr 2019 01:36:08 +0000 (+1300) Subject: ldb_kv_index: Make the edge keys slightly cleaner and generic X-Git-Tag: tdb-1.4.1~500 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a894515229f1edc3f07ea08faafdbfba16cf32ff;p=thirdparty%2Fsamba.git 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 Reviewed-by: Andrew Bartlett --- diff --git a/lib/ldb/ldb_key_value/ldb_kv_index.c b/lib/ldb/ldb_key_value/ldb_kv_index.c index cad8fdc90bf..8580db1c778 100644 --- a/lib/ldb/ldb_key_value/ldb_kv_index.c +++ b/lib/ldb/ldb_key_value/ldb_kv_index.c @@ -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::\0. + * + * We can simply make our start key DN=@INDEX:: and our end + * key DN=@INDEX:; 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 {