diff options
author | Aaron Haslett <aaronhaslett@catalyst.net.nz> | 2019-03-14 18:05:23 +1300 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2019-04-08 02:07:23 +0000 |
commit | c9b2a37268e793f2d8a8e3a6a340d2bc869f3f0e (patch) | |
tree | c668d2c3ed1d7db33a513fa9e65651a7e1b58017 /lib/ldb-samba | |
parent | f775606516015715379dd76fa545da7c02c65e45 (diff) | |
download | samba-c9b2a37268e793f2d8a8e3a6a340d2bc869f3f0e.tar.gz |
ldb: activating <= and >= indexing for integers
Activating <= and >= mdb indexing in samba for int32 and int64 attributes by:
1. Adding index_format_fn to LDB_SYNTAX_SAMBA_INT32 in ldb_samba
2. Cloning the 64bit LDB_SYNTAX_INTEGER type as LDB_SYNTAX_ORDERED_INTEGER
3. Adding index_format_fn to the new type
4. Modifying LargeInteger use the new type in samba schema
5. Bumping the index version to trigger reindexing
Pair-programmed-with: Garming Sam <garming@catalyst.net.nz>
Signed-off-by: Aaron Haslett <aaronhaslett@catalyst.net.nz>
Signed-off-by: Garming Sam <garming@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib/ldb-samba')
-rw-r--r-- | lib/ldb-samba/ldif_handlers.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/ldb-samba/ldif_handlers.c b/lib/ldb-samba/ldif_handlers.c index d38cdd0c9a3..bd8b63c42ed 100644 --- a/lib/ldb-samba/ldif_handlers.c +++ b/lib/ldb-samba/ldif_handlers.c @@ -835,6 +835,50 @@ static int ldif_canonicalise_int32(struct ldb_context *ldb, void *mem_ctx, return 0; } +/* Lexicographically sorted representation for a 32-bit integer */ +static int ldif_index_format_int32(struct ldb_context *ldb, + void *mem_ctx, + const struct ldb_val *in, + struct ldb_val *out) +{ + int32_t i; + int ret; + char prefix; + size_t len; + + ret = val_to_int32(in, &i); + if (ret != LDB_SUCCESS) { + return ret; + } + + if (i < 0) { + prefix = 'n'; + i = INT32_MAX + i + 1; + } else if (i > 0) { + prefix = 'p'; + } else { + prefix = 'o'; + } + + out->data = (uint8_t *) talloc_asprintf(mem_ctx, "%c%010ld", prefix, (long)i); + if (out->data == NULL) { + ldb_oom(ldb); + return LDB_ERR_OPERATIONS_ERROR; + } + + len = talloc_array_length(out->data) - 1; + if (len != 11) { + ldb_debug(ldb, LDB_DEBUG_ERROR, + __location__ ": expected index format str %s to" + " have length 11 but got %zu", + (char*)out->data, len); + return LDB_ERR_OPERATIONS_ERROR; + } + + out->length = 11; + return 0; +} + /* Comparison of two 32-bit integers */ static int ldif_comparison_int32(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) @@ -1427,6 +1471,7 @@ static const struct ldb_schema_syntax samba_syntaxes[] = { .ldif_read_fn = ldb_handler_copy, .ldif_write_fn = ldb_handler_copy, .canonicalise_fn = ldif_canonicalise_int32, + .index_format_fn = ldif_index_format_int32, .comparison_fn = ldif_comparison_int32, .operator_fn = samba_syntax_operator_fn },{ |