From 50f36e4fb5e251042d2c35e804f0bc477e2b790e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 15 Aug 2017 15:57:57 +1200 Subject: [PATCH] ldb_tdb: Read from @INDEXLIST or an override if we are using a GUID index This allows all the previous patches to be enabled. Signed-off-by: Andrew Bartlett Reviewed-by: Garming Sam --- lib/ldb/common/ldb_attributes.c | 14 ++++++++++++++ lib/ldb/include/ldb_module.h | 16 ++++++++++++++++ lib/ldb/include/ldb_private.h | 3 +++ lib/ldb/ldb_tdb/ldb_cache.c | 10 ++++++++++ 4 files changed, 43 insertions(+) diff --git a/lib/ldb/common/ldb_attributes.c b/lib/ldb/common/ldb_attributes.c index 98ec5a409ba..32f25fd0fe8 100644 --- a/lib/ldb/common/ldb_attributes.c +++ b/lib/ldb/common/ldb_attributes.c @@ -395,3 +395,17 @@ void ldb_schema_set_override_indexlist(struct ldb_context *ldb, ldb->schema.index_handler_override = true; ldb->schema.one_level_indexes = one_level_indexes; } + +/* + * set that the GUID index mode is in operation + * + * The caller must ensure the supplied strings do not go out of + * scope (they are typically constant memory). + */ +void ldb_schema_set_override_GUID_index(struct ldb_context *ldb, + const char *GUID_index_attribute, + const char *GUID_index_dn_component) +{ + ldb->schema.GUID_index_attribute = GUID_index_attribute; + ldb->schema.GUID_index_dn_component = GUID_index_dn_component; +} diff --git a/lib/ldb/include/ldb_module.h b/lib/ldb/include/ldb_module.h index 71b407496f0..ffa6c2eedb8 100644 --- a/lib/ldb/include/ldb_module.h +++ b/lib/ldb/include/ldb_module.h @@ -183,6 +183,22 @@ void ldb_schema_attribute_set_override_handler(struct ldb_context *ldb, void ldb_schema_set_override_indexlist(struct ldb_context *ldb, bool one_level_indexes); +/** + + \param ldb The ldb context + \param GUID_index_attribute The globally attribute (eg objectGUID) + on each entry + \param GUID_index_attribute The DN component matching the + globally attribute on each entry (eg GUID) + + The caller must ensure the supplied strings do not go out of + scope (they are typically constant memory). + +*/ +void ldb_schema_set_override_GUID_index(struct ldb_context *ldb, + const char *GUID_index_attribute, + const char *GUID_index_dn_component); + /* A useful function to build comparison functions with */ int ldb_any_comparison(struct ldb_context *ldb, void *mem_ctx, ldb_attr_handler_t canonicalise_fn, diff --git a/lib/ldb/include/ldb_private.h b/lib/ldb/include/ldb_private.h index ab215411a9a..f999f7530bf 100644 --- a/lib/ldb/include/ldb_private.h +++ b/lib/ldb/include/ldb_private.h @@ -98,6 +98,9 @@ struct ldb_schema { */ bool index_handler_override; bool one_level_indexes; + + const char *GUID_index_attribute; + const char *GUID_index_dn_component; }; /* diff --git a/lib/ldb/ldb_tdb/ldb_cache.c b/lib/ldb/ldb_tdb/ldb_cache.c index 137ddf97fe8..7bf5f156b45 100644 --- a/lib/ldb/ldb_tdb/ldb_cache.c +++ b/lib/ldb/ldb_tdb/ldb_cache.c @@ -243,6 +243,10 @@ static int ltdb_index_load(struct ldb_module *module, */ ltdb->cache->attribute_indexes = true; ltdb->cache->one_level_indexes = ldb->schema.one_level_indexes; + ltdb->cache->GUID_index_attribute + = ldb->schema.GUID_index_attribute; + ltdb->cache->GUID_index_dn_component + = ldb->schema.GUID_index_dn_component; return 0; } @@ -276,6 +280,12 @@ static int ltdb_index_load(struct ldb_module *module, if (ldb_msg_find_element(ltdb->cache->indexlist, LTDB_IDXATTR) != NULL) { ltdb->cache->attribute_indexes = true; } + ltdb->cache->GUID_index_attribute + = ldb_msg_find_attr_as_string(ltdb->cache->indexlist, + LTDB_IDXGUID, NULL); + ltdb->cache->GUID_index_dn_component + = ldb_msg_find_attr_as_string(ltdb->cache->indexlist, + LTDB_IDX_DN_GUID, NULL); return 0; }