diff options
author | Andrew Bartlett <abartlet@samba.org> | 2017-08-15 14:18:19 +1200 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2017-09-22 21:20:21 +0200 |
commit | 754329a9d9812032dc16dcbfb427739b26a101d2 (patch) | |
tree | faf05a4cbd29880271ef4933f80f1fac4b777ba6 /lib/ldb | |
parent | b154acb0c7917aaef0f7bc750a4a0ce2690b1c44 (diff) | |
download | samba-754329a9d9812032dc16dcbfb427739b26a101d2.tar.gz |
ldb_tdb: Optionally store a GUID as the index record
This allows, when enabled, the index record to contain (say) the objectGUID, not the DN
of the record.
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Diffstat (limited to 'lib/ldb')
-rw-r--r-- | lib/ldb/ldb_tdb/ldb_index.c | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c index 29b2d5e7261..52cf3385a5a 100644 --- a/lib/ldb/ldb_tdb/ldb_index.c +++ b/lib/ldb/ldb_tdb/ldb_index.c @@ -1268,7 +1268,6 @@ static int ltdb_index_add1(struct ldb_module *module, const struct ldb_schema_attribute *a; struct dn_list *list; unsigned alloc_len; - const char *dn_str; ldb = ldb_module_get_ctx(module); @@ -1321,14 +1320,34 @@ static int ltdb_index_add1(struct ldb_module *module, return LDB_ERR_OPERATIONS_ERROR; } - dn_str = ldb_dn_get_linearized(msg->dn); - list->dn[list->count].data - = (uint8_t *)talloc_strdup(list->dn, dn_str); - if (list->dn[list->count].data == NULL) { - talloc_free(list); - return LDB_ERR_OPERATIONS_ERROR; + if (ltdb->cache->GUID_index_attribute == NULL) { + const char *dn_str = ldb_dn_get_linearized(msg->dn); + list->dn[list->count].data + = (uint8_t *)talloc_strdup(list->dn, dn_str); + if (list->dn[list->count].data == NULL) { + talloc_free(list); + return LDB_ERR_OPERATIONS_ERROR; + } + list->dn[list->count].length = strlen(dn_str); + } else { + const struct ldb_val *key_val; + key_val = ldb_msg_find_ldb_val(msg, + ltdb->cache->GUID_index_attribute); + if (key_val == NULL) { + talloc_free(list); + return ldb_module_operr(module); + } + + if (key_val->length != LTDB_GUID_SIZE) { + talloc_free(list); + return ldb_module_operr(module); + } + list->dn[list->count] = ldb_val_dup(list->dn, key_val); + if (list->dn[list->count].data == NULL) { + talloc_free(list); + return ldb_module_operr(module); + } } - list->dn[list->count].length = strlen(dn_str); list->count++; ret = ltdb_dn_list_store(module, dn_key, list); |