ldb_tdb: Optionally use GUID index in ltdb_search_dn1()
authorAndrew Bartlett <abartlet@samba.org>
Thu, 10 Aug 2017 05:12:30 +0000 (17:12 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Sep 2017 19:20:22 +0000 (21:20 +0200)
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
lib/ldb/ldb_tdb/ldb_search.c

index 350f01b80930cd8799d5e146dea455e66d6f83f3..249ecfeb8109c2c784d3e58fda9de3102e878a59 100644 (file)
@@ -271,11 +271,28 @@ int ltdb_search_dn1(struct ldb_module *module, struct ldb_dn *dn, struct ldb_mes
                return ldb_module_oom(module);
        }
 
-       /* form the key */
-       tdb_key = ltdb_key_dn(module, tdb_key_ctx, dn);
-       if (!tdb_key.dptr) {
-               TALLOC_FREE(tdb_key_ctx);
-               return LDB_ERR_OPERATIONS_ERROR;
+       if (ltdb->cache->GUID_index_attribute == NULL) {
+               /* form the key */
+               tdb_key = ltdb_key_dn(module, tdb_key_ctx, dn);
+               if (!tdb_key.dptr) {
+                       TALLOC_FREE(tdb_key_ctx);
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
+       } else if (ldb_dn_is_special(dn)) {
+               /* form the key */
+               tdb_key = ltdb_key_dn(module, tdb_key_ctx, dn);
+               if (!tdb_key.dptr) {
+                       TALLOC_FREE(tdb_key_ctx);
+                       return LDB_ERR_OPERATIONS_ERROR;
+               }
+       } else {
+               /* Look in the index to find the key for this DN */
+               ret = ltdb_key_dn_from_idx(module, ltdb, tdb_key_ctx,
+                                          dn, &tdb_key);
+               if (ret != LDB_SUCCESS) {
+                       TALLOC_FREE(tdb_key_ctx);
+                       return ret;
+               }
        }
 
        ret = ltdb_search_key(module, ltdb, tdb_key, msg, unpack_flags);