From: Gary Lockyer Date: Wed, 21 Feb 2018 02:20:17 +0000 (+1300) Subject: ldb_tdb: Add support for an option to restrict the key length X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=0bfbcdb69155315415867cee34d5293b1ee125fa;p=metze%2Fsamba%2Fwip.git ldb_tdb: Add support for an option to restrict the key length Allow the setting of the maximum key length, this allows the testing of index key truncation code. Index key truncation is required to allow the samba indexing scheme to be used with backends that enforce a maximum key length. This will allow emulation of a length-limited key DB for testing. This is a testing-only feature, as the index format changes based on this value. Signed-off-by: Gary Lockyer Reviewed-by: Douglas Bagnall Reviewed-by: Andrew Bartlett --- diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index 16e4b8ea26e8..dcb877312a9a 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -1952,6 +1952,19 @@ static int ltdb_connect(struct ldb_context *ldb, const char *url, } *_module = module; + + /* + * Set the maximum key length + */ + { + const char *len_str = + ldb_options_find(ldb, options, + "max_key_len_for_self_test"); + if (len_str != NULL) { + unsigned len = strtoul(len_str, NULL, 0); + ltdb->max_key_length = len; + } + } return LDB_SUCCESS; } diff --git a/lib/ldb/ldb_tdb/ldb_tdb.h b/lib/ldb/ldb_tdb/ldb_tdb.h index 7e182495928c..421ae4d95d61 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.h +++ b/lib/ldb/ldb_tdb/ldb_tdb.h @@ -38,6 +38,13 @@ struct ltdb_private { bool read_only; const struct ldb_schema_syntax *GUID_index_syntax; + + /* + * Maximum index key length. If non zero keys longer than this length + * will be truncated for non unique indexes. Keys for unique indexes + * greater than this length will be rejected. + */ + unsigned max_key_length; }; struct ltdb_context {