ldb_tdb: Add support for an option to restrict the key length
authorGary Lockyer <gary@catalyst.net.nz>
Wed, 21 Feb 2018 02:20:17 +0000 (15:20 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Sat, 3 Mar 2018 04:20:35 +0000 (05:20 +0100)
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 <gary@catalyst.net.nz>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/ldb/ldb_tdb/ldb_tdb.c
lib/ldb/ldb_tdb/ldb_tdb.h

index 16e4b8ea26e8eef67e3faba993444ce947e8b1c3..dcb877312a9a7ceaad2f1240d93068422bb82f58 100644 (file)
@@ -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;
 }
 
index 7e182495928c7f91ee59443ce2963b0da2fe1111..421ae4d95d6106c3d6f5c5c59e0e3db7d48b9ed7 100644 (file)
@@ -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 {