ldb_tdb: Use the objectGUID (or similar) as the TDB key in ltdb_key_msg()
authorAndrew Bartlett <abartlet@samba.org>
Thu, 10 Aug 2017 05:11:13 +0000 (17:11 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 22 Sep 2017 19:20:22 +0000 (21:20 +0200)
When we have the full ldb_message we can read the objectGUID as the TDB key

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

index 59e554363d86e2541a7b4d8854eb67be849c96fd..8593830ee6032567f93a8f3903901a465553c9b1 100644 (file)
@@ -258,7 +258,30 @@ TDB_DATA ltdb_guid_to_key(struct ldb_module *module,
 TDB_DATA ltdb_key_msg(struct ldb_module *module, TALLOC_CTX *mem_ctx,
                      const struct ldb_message *msg)
 {
-       return ltdb_key_dn(module, mem_ctx, msg->dn);
+       void *data = ldb_module_get_private(module);
+       struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private);
+       TDB_DATA key;
+       const struct ldb_val *guid_val;
+
+       if (ltdb->cache->GUID_index_attribute == NULL) {
+               return ltdb_key_dn(module, mem_ctx, msg->dn);
+       }
+
+       if (ldb_dn_is_special(msg->dn)) {
+               return ltdb_key_dn(module, mem_ctx, msg->dn);
+       }
+
+       guid_val = ldb_msg_find_ldb_val(msg,
+                                      ltdb->cache->GUID_index_attribute);
+       if (guid_val == NULL) {
+               errno = EINVAL;
+               key.dptr = NULL;
+               key.dsize = 0;
+               return key;
+       }
+
+       return ltdb_guid_to_key(module, ltdb, mem_ctx, guid_val);
+
 }
 
 /*