From: Andrew Bartlett Date: Thu, 30 Mar 2017 00:23:44 +0000 (+1300) Subject: ldb: Allow a caller (in particular Samba) to handle the list of attributes with an... X-Git-Tag: ldb-1.1.30~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e584fe85a51ec8a81274dc65e689cc0e0ddb4a50;p=thirdparty%2Fsamba.git ldb: Allow a caller (in particular Samba) to handle the list of attributes with an index By doing that, Samba will use a binary search to locate the attributes rather than an O(n) search, during every search or modify of the database. Signed-off-by: Andrew Bartlett Reviewed-by: Stefan Metzmacher Reviewed-by: Garming Sam --- diff --git a/lib/ldb/ABI/ldb-1.1.29.sigs b/lib/ldb/ABI/ldb-1.1.29.sigs index 0ea968d0d69..9b865ed8907 100644 --- a/lib/ldb/ABI/ldb-1.1.29.sigs +++ b/lib/ldb/ABI/ldb-1.1.29.sigs @@ -225,6 +225,7 @@ ldb_schema_attribute_fill_with_syntax: int (struct ldb_context *, TALLOC_CTX *, ldb_schema_attribute_remove: void (struct ldb_context *, const char *) ldb_schema_attribute_remove_flagged: void (struct ldb_context *, unsigned int) ldb_schema_attribute_set_override_handler: void (struct ldb_context *, ldb_attribute_handler_override_fn_t, void *) +ldb_schema_set_override_indexlist: void (struct ldb_context *, bool) ldb_search: int (struct ldb_context *, TALLOC_CTX *, struct ldb_result **, struct ldb_dn *, enum ldb_scope, const char * const *, const char *, ...) ldb_search_default_callback: int (struct ldb_request *, struct ldb_reply *) ldb_sequence_number: int (struct ldb_context *, enum ldb_sequence_type, uint64_t *) diff --git a/lib/ldb/common/ldb_attributes.c b/lib/ldb/common/ldb_attributes.c index 2021a0bf64a..98ec5a409ba 100644 --- a/lib/ldb/common/ldb_attributes.c +++ b/lib/ldb/common/ldb_attributes.c @@ -383,3 +383,15 @@ void ldb_schema_attribute_set_override_handler(struct ldb_context *ldb, ldb->schema.attribute_handler_override_private = private_data; ldb->schema.attribute_handler_override = override; } + +/* + set that the attribute handler override function - used to delegate + schema handling to external code, is handling setting + LDB_ATTR_FLAG_INDEXED + */ +void ldb_schema_set_override_indexlist(struct ldb_context *ldb, + bool one_level_indexes) +{ + ldb->schema.index_handler_override = true; + ldb->schema.one_level_indexes = one_level_indexes; +} diff --git a/lib/ldb/include/ldb.h b/lib/ldb/include/ldb.h index 1160a48cc06..3fab929ff5e 100644 --- a/lib/ldb/include/ldb.h +++ b/lib/ldb/include/ldb.h @@ -441,6 +441,11 @@ const struct ldb_dn_extended_syntax *ldb_dn_extended_syntax_by_name(struct ldb_c */ #define LDB_ATTR_FLAG_FROM_DB (1<<6) +/* + * The attribute was loaded from a DB, rather than via the C API + */ +#define LDB_ATTR_FLAG_INDEXED (1<<7) + /** LDAP attribute syntax for a DN diff --git a/lib/ldb/include/ldb_module.h b/lib/ldb/include/ldb_module.h index 833d5a8f3d0..75f3fcb2bf8 100644 --- a/lib/ldb/include/ldb_module.h +++ b/lib/ldb/include/ldb_module.h @@ -125,6 +125,8 @@ typedef const struct ldb_schema_attribute *(*ldb_attribute_handler_override_fn_t void ldb_schema_attribute_set_override_handler(struct ldb_context *ldb, ldb_attribute_handler_override_fn_t override, void *private_data); +void ldb_schema_set_override_indexlist(struct ldb_context *ldb, + bool one_level_indexes); /* A useful function to build comparison functions with */ int ldb_any_comparison(struct ldb_context *ldb, void *mem_ctx, diff --git a/lib/ldb/include/ldb_private.h b/lib/ldb/include/ldb_private.h index 644d49cd23f..bd975b81fec 100644 --- a/lib/ldb/include/ldb_private.h +++ b/lib/ldb/include/ldb_private.h @@ -88,6 +88,13 @@ struct ldb_schema { unsigned num_dn_extended_syntax; struct ldb_dn_extended_syntax *dn_extended_syntax; + + /* + * If set, the attribute_handler_override has the details of + * what attributes have an index + */ + bool index_handler_override; + bool one_level_indexes; }; /* diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c index 46ba725c07f..721ec1c9a6a 100644 --- a/lib/ldb/ldb_tdb/ldb_index.c +++ b/lib/ldb/ldb_tdb/ldb_index.c @@ -449,9 +449,25 @@ static bool ltdb_is_indexed(struct ldb_module *module, struct ltdb_private *ltdb, const char *attr) { + struct ldb_context *ldb = ldb_module_get_ctx(module); unsigned int i; struct ldb_message_element *el; + if (ldb->schema.index_handler_override) { + const struct ldb_schema_attribute *a + = ldb_schema_attribute_by_name(ldb, attr); + + if (a == NULL) { + return false; + } + + if (a->flags & LDB_ATTR_FLAG_INDEXED) { + return true; + } else { + return false; + } + } + if (!ltdb->cache->attribute_indexes) { return false; }