ldb_tdb: Read GUID index values as one packed LDB attribute
authorAndrew Bartlett <abartlet@samba.org>
Thu, 17 Aug 2017 05:26:35 +0000 (17:26 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Sep 2017 19:20:21 +0000 (21:20 +0200)
This packing should be more efficient to read than the ldb_pack format.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_index.c

index 1fe526f5e3ef837b0150f8bd89dcfab1557547a9..c3458e89db46fed1601076da3e01644837d69f54 100644 (file)
@@ -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);