From ad26b4e2923ad2468eef8e48d065b2ca2ca11d36 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 17 Aug 2017 17:26:35 +1200 Subject: [PATCH] ldb_tdb: Read GUID index values as one packed LDB attribute This packing should be more efficient to read than the ldb_pack format. Signed-off-by: Andrew Bartlett Reviewed-by: Garming Sam --- lib/ldb/ldb_tdb/ldb_index.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c index 1fe526f5e3e..c3458e89db4 100644 --- a/lib/ldb/ldb_tdb/ldb_index.c +++ b/lib/ldb/ldb_tdb/ldb_index.c @@ -215,9 +215,30 @@ normal_index: * asked for the memory to be allocated on msg, not on each * value with LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC above */ - talloc_steal(el->values, msg); - list->dn = talloc_steal(list, el->values); - list->count = el->num_values; + if (ltdb->cache->GUID_index_attribute == NULL) { + talloc_steal(el->values, msg); + list->dn = talloc_steal(list, el->values); + list->count = el->num_values; + } else { + unsigned int i; + static const size_t GUID_val_size = 16; + if (el->num_values != 1) { + return LDB_ERR_OPERATIONS_ERROR; + } + + list->count = el->values[0].length / GUID_val_size; + list->dn = talloc_array(list, struct ldb_val, list->count); + + /* + * The actual data is on msg, due to + * LDB_UNPACK_DATA_FLAG_NO_DATA_ALLOC + */ + talloc_steal(list->dn, msg); + for (i = 0; i < list->count; i++) { + list->dn[i].data = &el->values[0].data[i * GUID_val_size]; + list->dn[i].length = GUID_val_size; + } + } /* We don't need msg->elements any more */ talloc_free(msg->elements); -- 2.34.1