From 0dc811bb7674e325791cb63f53b12fc45c46f8d2 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 10 Sep 2013 12:51:52 +0200 Subject: [PATCH 01/12] s3:samba_dsdb: fix 'const char **' vs. 'char **' compiler warnings Signed-off-by: Stefan Metzmacher --- source4/dsdb/samdb/ldb_modules/samba_dsdb.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source4/dsdb/samdb/ldb_modules/samba_dsdb.c b/source4/dsdb/samdb/ldb_modules/samba_dsdb.c index ac993db..eb23c37 100644 --- a/source4/dsdb/samdb/ldb_modules/samba_dsdb.c +++ b/source4/dsdb/samdb/ldb_modules/samba_dsdb.c @@ -81,7 +81,8 @@ static int prepare_modules_line(struct ldb_context *ldb, const char *backend_mod, const char **backend_mod_list) { int ret; - const char **backend_full_list; + char **backend_full_list1; + const char **backend_full_list2; const char *backend_dn; char *mod_list_string; char *full_string; @@ -105,22 +106,24 @@ static int prepare_modules_line(struct ldb_context *ldb, } if (backend_mod) { - backend_full_list = (const char **)str_list_make_single(tmp_ctx, backend_mod); + backend_full_list1 = str_list_make_single(tmp_ctx, backend_mod); } else { - backend_full_list = (const char **)str_list_make_empty(tmp_ctx); + backend_full_list1 = str_list_make_empty(tmp_ctx); } - if (!backend_full_list) { + if (!backend_full_list1) { talloc_free(tmp_ctx); return ldb_oom(ldb); } - backend_full_list = str_list_append_const(backend_full_list, backend_mod_list); - if (!backend_full_list) { + backend_full_list2 = discard_const_p(const char *, backend_full_list1); + backend_full_list2 = str_list_append_const(backend_full_list2, + backend_mod_list); + if (!backend_full_list2) { talloc_free(tmp_ctx); return ldb_oom(ldb); } - mod_list_string = str_list_join(tmp_ctx, backend_full_list, ','); + mod_list_string = str_list_join(tmp_ctx, backend_full_list2, ','); if (!mod_list_string) { talloc_free(tmp_ctx); return ldb_oom(ldb); -- 1.7.9.5 From 7c9b0714f25ae40ac0bbbc978f2c92f378d7c307 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 10 Sep 2013 12:55:10 +0200 Subject: [PATCH 02/12] ldb: add more const to ldb_module_load_list() Signed-off-by: Stefan Metzmacher --- lib/ldb/ABI/ldb-1.1.16.sigs | 2 +- lib/ldb/common/ldb_modules.c | 5 +++-- lib/ldb/include/ldb_module.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ldb/ABI/ldb-1.1.16.sigs b/lib/ldb/ABI/ldb-1.1.16.sigs index eac5194..1e8a9ce 100644 --- a/lib/ldb/ABI/ldb-1.1.16.sigs +++ b/lib/ldb/ABI/ldb-1.1.16.sigs @@ -130,7 +130,7 @@ ldb_module_get_name: const char *(struct ldb_module *) ldb_module_get_ops: const struct ldb_module_ops *(struct ldb_module *) ldb_module_get_private: void *(struct ldb_module *) ldb_module_init_chain: int (struct ldb_context *, struct ldb_module *) -ldb_module_load_list: int (struct ldb_context *, const char **, struct ldb_module *, struct ldb_module **) +ldb_module_load_list: int (struct ldb_context *, const char * const *, struct ldb_module *, struct ldb_module **) ldb_module_new: struct ldb_module *(TALLOC_CTX *, struct ldb_context *, const char *, const struct ldb_module_ops *) ldb_module_next: struct ldb_module *(struct ldb_module *) ldb_module_popt_options: struct poptOption **(struct ldb_context *) diff --git a/lib/ldb/common/ldb_modules.c b/lib/ldb/common/ldb_modules.c index 4403656..978cf87 100644 --- a/lib/ldb/common/ldb_modules.c +++ b/lib/ldb/common/ldb_modules.c @@ -295,7 +295,7 @@ int ldb_register_module(const struct ldb_module_ops *ops) /* load a list of modules */ -int ldb_module_load_list(struct ldb_context *ldb, const char **module_list, +int ldb_module_load_list(struct ldb_context *ldb, const char * const *module_list, struct ldb_module *backend, struct ldb_module **out) { struct ldb_module *module; @@ -419,7 +419,8 @@ int ldb_load_modules(struct ldb_context *ldb, const char *options[]) } if (modules != NULL) { - ret = ldb_module_load_list(ldb, modules, ldb->modules, &ldb->modules); + const char * const *mlist = (const char * const *)modules; + ret = ldb_module_load_list(ldb, mlist, ldb->modules, &ldb->modules); if (ret != LDB_SUCCESS) { talloc_free(mem_ctx); return ret; diff --git a/lib/ldb/include/ldb_module.h b/lib/ldb/include/ldb_module.h index be50c09..7e5d672 100644 --- a/lib/ldb/include/ldb_module.h +++ b/lib/ldb/include/ldb_module.h @@ -315,7 +315,7 @@ void ldb_module_set_next(struct ldb_module *module, struct ldb_module *next); /* load a list of modules */ -int ldb_module_load_list(struct ldb_context *ldb, const char **module_list, +int ldb_module_load_list(struct ldb_context *ldb, const char * const *module_list, struct ldb_module *backend, struct ldb_module **out); /* -- 1.7.9.5 From b96e43d2085881785993948fbdb40280a2b39046 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 10 Sep 2013 12:55:37 +0200 Subject: [PATCH 03/12] ldb: let ldb_modules_list_from_string() return 'char **' The caller provides a memory context and owns the returned list. Signed-off-by: Stefan Metzmacher --- lib/ldb/ABI/ldb-1.1.16.sigs | 2 +- lib/ldb/common/ldb_modules.c | 28 +++++++++++++++++----------- lib/ldb/include/ldb_module.h | 2 +- lib/ldb/include/ldb_private.h | 1 - 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/lib/ldb/ABI/ldb-1.1.16.sigs b/lib/ldb/ABI/ldb-1.1.16.sigs index 1e8a9ce..617721c 100644 --- a/lib/ldb/ABI/ldb-1.1.16.sigs +++ b/lib/ldb/ABI/ldb-1.1.16.sigs @@ -139,7 +139,7 @@ ldb_module_send_referral: int (struct ldb_request *, char *) ldb_module_set_next: void (struct ldb_module *, struct ldb_module *) ldb_module_set_private: void (struct ldb_module *, void *) ldb_modules_hook: int (struct ldb_context *, enum ldb_module_hook_type) -ldb_modules_list_from_string: const char **(struct ldb_context *, TALLOC_CTX *, const char *) +ldb_modules_list_from_string: char **(struct ldb_context *, TALLOC_CTX *, const char *) ldb_modules_load: int (const char *, const char *) ldb_msg_add: int (struct ldb_message *, const struct ldb_message_element *, int) ldb_msg_add_empty: int (struct ldb_message *, const char *, int, struct ldb_message_element **) diff --git a/lib/ldb/common/ldb_modules.c b/lib/ldb/common/ldb_modules.c index 978cf87..4225ac8 100644 --- a/lib/ldb/common/ldb_modules.c +++ b/lib/ldb/common/ldb_modules.c @@ -63,10 +63,9 @@ static char *ldb_modules_strdup_no_spaces(TALLOC_CTX *mem_ctx, const char *strin /* modules are called in inverse order on the stack. Lets place them as an admin would think the right order is. Modules order is important */ -const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string) +char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string) { char **modules = NULL; - const char **m; char *modstr, *p; unsigned int i; @@ -87,8 +86,7 @@ const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *m if (modstr[0] == '\0') { modules[0] = NULL; - m = (const char **)modules; - return m; + return modules; } i = 0; @@ -96,7 +94,12 @@ const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *m while ((p = strrchr(modstr, ',')) != NULL) { *p = '\0'; p++; - modules[i] = p; + modules[i] = talloc_strdup(modules, p); + if (modules[i] == NULL) { + ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_list_from_string()"); + talloc_free(modules); + return NULL; + } i++; modules = talloc_realloc(mem_ctx, modules, char *, i + 2); @@ -106,13 +109,16 @@ const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *m } } - modules[i] = modstr; - + modules[i] = talloc_strdup(modules, modstr); + if (modules[i] == NULL) { + ldb_debug(ldb, LDB_DEBUG_FATAL, "Out of Memory in ldb_modules_list_from_string()"); + talloc_free(modules); + return NULL; + } modules[i + 1] = NULL; - m = (const char **)modules; - - return m; + talloc_free(modstr); + return modules; } static struct backends_list_entry { @@ -360,7 +366,7 @@ int ldb_module_init_chain(struct ldb_context *ldb, struct ldb_module *module) int ldb_load_modules(struct ldb_context *ldb, const char *options[]) { const char *modules_string; - const char **modules = NULL; + char **modules = NULL; int ret; TALLOC_CTX *mem_ctx = talloc_new(ldb); if (!mem_ctx) { diff --git a/lib/ldb/include/ldb_module.h b/lib/ldb/include/ldb_module.h index 7e5d672..7b9a4bc 100644 --- a/lib/ldb/include/ldb_module.h +++ b/lib/ldb/include/ldb_module.h @@ -327,7 +327,7 @@ struct poptOption **ldb_module_popt_options(struct ldb_context *ldb); /* modules are called in inverse order on the stack. Lets place them as an admin would think the right order is. Modules order is important */ -const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string); +char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string); /* return the current ldb flags LDB_FLG_* diff --git a/lib/ldb/include/ldb_private.h b/lib/ldb/include/ldb_private.h index 526bf5e..64ade16 100644 --- a/lib/ldb/include/ldb_private.h +++ b/lib/ldb/include/ldb_private.h @@ -170,7 +170,6 @@ void ldb_dump_results(struct ldb_context *ldb, struct ldb_result *result, FILE * /* The following definitions come from lib/ldb/common/ldb_modules.c */ -const char **ldb_modules_list_from_string(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const char *string); int ldb_load_modules(struct ldb_context *ldb, const char *options[]); struct ldb_val ldb_binary_decode(TALLOC_CTX *mem_ctx, const char *str); -- 1.7.9.5 From 95ffd20524d054e873228d9e0ff6f5995effd312 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 11 Sep 2013 08:30:40 +0200 Subject: [PATCH 04/12] ldb/tdb: avoid casting TDB_DATA to struct ldb_val This generates compiler warnings. Signed-off-by: Stefan Metzmacher --- lib/ldb/ldb_tdb/ldb_index.c | 5 ++++- lib/ldb/ldb_tdb/ldb_search.c | 12 ++++++++++-- lib/ldb/ldb_tdb/ldb_tdb.c | 10 ++++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c index cf21092..32a4160 100644 --- a/lib/ldb/ldb_tdb/ldb_index.c +++ b/lib/ldb/ldb_tdb/ldb_index.c @@ -1514,6 +1514,7 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void * const char *dn = NULL; int ret; TDB_DATA key2; + struct ldb_val unpack_val; ldb = ldb_module_get_ctx(module); @@ -1527,7 +1528,9 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void * return -1; } - ret = ldb_unpack_data(ldb, (struct ldb_val *)&data, msg); + unpack_val.data = data.dptr; + unpack_val.length = data.dsize; + ret = ldb_unpack_data(ldb, &unpack_val, msg); if (ret != 0) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid data for index %s\n", ldb_dn_get_linearized(msg->dn)); diff --git a/lib/ldb/ldb_tdb/ldb_search.c b/lib/ldb/ldb_tdb/ldb_search.c index 1e7e7ea..cd2e2f1 100644 --- a/lib/ldb/ldb_tdb/ldb_search.c +++ b/lib/ldb/ldb_tdb/ldb_search.c @@ -246,7 +246,12 @@ static int ltdb_parse_data_unpack(TDB_DATA key, TDB_DATA data, struct ltdb_parse_data_unpack_ctx *ctx = private_data; struct ldb_context *ldb = ldb_module_get_ctx(ctx->module); - int ret = ldb_unpack_data(ldb, (struct ldb_val *)&data, ctx->msg); + struct ldb_val unpack_val; + int ret; + + unpack_val.data = data.dptr; + unpack_val.length = data.dsize; + ret = ldb_unpack_data(ldb, &unpack_val, ctx->msg); if (ret == -1) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Invalid data for index %*.*s\n", (int)key.dsize, (int)key.dsize, key.dptr); @@ -424,6 +429,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi struct ldb_context *ldb; struct ltdb_context *ac; struct ldb_message *msg; + struct ldb_val unpack_val; int ret; bool matched; @@ -441,7 +447,9 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } /* unpack the record */ - ret = ldb_unpack_data(ldb, (struct ldb_val *)&data, msg); + unpack_val.data = data.dptr; + unpack_val.length = data.dsize; + ret = ldb_unpack_data(ldb, &unpack_val, msg); if (ret == -1) { talloc_free(msg); return -1; diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index 30c58f5..1994f45 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -263,6 +263,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg { void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); + struct ldb_val val; TDB_DATA tdb_key, tdb_data; int ret = LDB_SUCCESS; @@ -272,11 +273,13 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg } ret = ldb_pack_data(ldb_module_get_ctx(module), - msg, (struct ldb_val *)&tdb_data); + msg, &val); if (ret == -1) { talloc_free(tdb_key.dptr); return LDB_ERR_OTHER; } + tdb_data.dptr = val.data; + tdb_data.dsize = val.length; ret = tdb_store(ltdb->tdb, tdb_key, tdb_data, flgs); if (ret != 0) { @@ -673,6 +676,7 @@ int ltdb_modify_internal(struct ldb_module *module, void *data = ldb_module_get_private(module); struct ltdb_private *ltdb = talloc_get_type(data, struct ltdb_private); TDB_DATA tdb_key, tdb_data; + struct ldb_val unpack_val; struct ldb_message *msg2; unsigned int i, j, k; int ret = LDB_SUCCESS, idx; @@ -701,7 +705,9 @@ int ltdb_modify_internal(struct ldb_module *module, goto done; } - ret = ldb_unpack_data(ldb_module_get_ctx(module), (struct ldb_val *)&tdb_data, msg2); + unpack_val.data = tdb_data.dptr; + unpack_val.length = tdb_data.dsize; + ret = ldb_unpack_data(ldb_module_get_ctx(module), &unpack_val, msg2); free(tdb_data.dptr); if (ret == -1) { ret = LDB_ERR_OTHER; -- 1.7.9.5 From 9218873aea59e01a8092a44684fa0f392e175439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Dieter=20Walln=C3=B6fer?= Date: Tue, 4 Sep 2012 22:25:04 +0200 Subject: [PATCH 05/12] LDB:ldb_attributes.c - handle special attributes (@...) always in the default syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a requirement for correct schema syntax comparison. "lib/ldb/tests/test-tdb-features.sh" demostrates this when adding index entries and the default syntax is set to INTEGER. Bug: https://bugzilla.samba.org/show_bug.cgi?id=8929 Signed-off-by: Matthias Dieter Wallnöfer Reviewed-by: Andrew Bartlett Reviewed-by: Stefan Metzmacher --- lib/ldb/common/ldb_attributes.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/ldb/common/ldb_attributes.c b/lib/ldb/common/ldb_attributes.c index 21a3e6e..924655d 100644 --- a/lib/ldb/common/ldb_attributes.c +++ b/lib/ldb/common/ldb_attributes.c @@ -127,6 +127,11 @@ static const struct ldb_schema_attribute *ldb_schema_attribute_by_name_internal( int r; const struct ldb_schema_attribute *def = &ldb_attribute_default; + /* special attributes should always be handled by the default syntax */ + if (name[0] == '@') { + return def; + } + /* as handlers are sorted, '*' must be the first if present */ if (strcmp(ldb->schema.attributes[0].name, "*") == 0) { def = &ldb->schema.attributes[0]; -- 1.7.9.5 From 154b02d531e5250ecc484f11a02498b1cae140ee Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 10 Sep 2013 11:02:43 +0200 Subject: [PATCH 06/12] ldb/tdb: let the caller pass ldb_schema_attribute to msg_delete_element() Signed-off-by: Stefan Metzmacher --- lib/ldb/ldb_tdb/ldb_tdb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index 1994f45..e427cab 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -602,6 +602,7 @@ static int msg_delete_attribute(struct ldb_module *module, */ static int msg_delete_element(struct ldb_module *module, struct ldb_message *msg, + const struct ldb_schema_attribute *a, const char *name, const struct ldb_val *val) { @@ -609,7 +610,6 @@ static int msg_delete_element(struct ldb_module *module, unsigned int i; int found, ret; struct ldb_message_element *el; - const struct ldb_schema_attribute *a; found = find_element(msg, name); if (found == -1) { @@ -619,8 +619,6 @@ static int msg_delete_element(struct ldb_module *module, i = (unsigned int) found; el = &(msg->elements[i]); - a = ldb_schema_attribute_by_name(ldb, el->name); - for (i=0;inum_values;i++) { bool matched; if (a->syntax->operator_fn) { @@ -932,6 +930,7 @@ int ltdb_modify_internal(struct ldb_module *module, for (j=0; j < msg->elements[i].num_values; j++) { ret = msg_delete_element(module, msg2, + a, msg->elements[i].name, &msg->elements[i].values[j]); if (ret == LDB_ERR_NO_SUCH_ATTRIBUTE && -- 1.7.9.5 From fc531e32c7293d566609d5c2bdc32e3476abb9c0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 11 Sep 2013 08:33:14 +0200 Subject: [PATCH 07/12] ldb/tdb: make sure we use the default syntax for all attributes of dn: @ATTRIBUTES The values are already checked in ltdb_check_special_dn() which is called before calling into ltdb_add_internal/ltdb_modify_internal. So ltdb_add_internal/ltdb_modify_internal should not verify it again and get the default syntax by forcing "@" as attribute name for ldb_schema_attribute_by_name(). Signed-off-by: Stefan Metzmacher --- lib/ldb/ldb_tdb/ldb_tdb.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index e427cab..3c24c15 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -330,10 +330,29 @@ static int ltdb_add_internal(struct ldb_module *module, struct ldb_context *ldb = ldb_module_get_ctx(module); int ret = LDB_SUCCESS; unsigned int i, j; + const char *forced_schema_attr_name = NULL; + + if (ldb_dn_is_special(msg->dn) && + ldb_dn_check_special(msg->dn, LTDB_ATTRIBUTES)) { + /* + * @ATTRIBUTES is checked in ltdb_check_special_dn() + * + * Here we force the ldb_attribute_default syntax + * for all attributes of the @ATTRIBUTES object. + */ + forced_schema_attr_name = "@"; + } for (i=0;inum_elements;i++) { struct ldb_message_element *el = &msg->elements[i]; - const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(ldb, el->name); + const char *schema_attr_name = el->name; + const struct ldb_schema_attribute *a; + + if (forced_schema_attr_name != NULL) { + schema_attr_name = forced_schema_attr_name; + } + + a = ldb_schema_attribute_by_name(ldb, schema_attr_name); if (el->num_values == 0) { ldb_asprintf_errstring(ldb, "attribute '%s' on '%s' specified, but with 0 values (illegal)", @@ -679,6 +698,7 @@ int ltdb_modify_internal(struct ldb_module *module, unsigned int i, j, k; int ret = LDB_SUCCESS, idx; struct ldb_control *control_permissive = NULL; + const char *forced_schema_attr_name = NULL; if (req) { control_permissive = ldb_request_get_control(req, @@ -716,11 +736,29 @@ int ltdb_modify_internal(struct ldb_module *module, msg2->dn = msg->dn; } + if (ldb_dn_is_special(msg2->dn) && + ldb_dn_check_special(msg2->dn, LTDB_ATTRIBUTES)) { + /* + * @ATTRIBUTES is checked in ltdb_check_special_dn() + * + * Here we force the ldb_attribute_default syntax + * for all attributes of the @ATTRIBUTES object. + */ + forced_schema_attr_name = "@"; + } + for (i=0; inum_elements; i++) { struct ldb_message_element *el = &msg->elements[i], *el2; struct ldb_val *vals; - const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(ldb, el->name); const char *dn; + const char *schema_attr_name = el->name; + const struct ldb_schema_attribute *a; + + if (forced_schema_attr_name != NULL) { + schema_attr_name = forced_schema_attr_name; + } + + a = ldb_schema_attribute_by_name(ldb, schema_attr_name); switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { case LDB_FLAG_MOD_ADD: -- 1.7.9.5 From eb013b9db0494526c18c15678538c55147c50c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Dieter=20Walln=C3=B6fer?= Date: Tue, 4 Sep 2012 19:02:02 +0200 Subject: [PATCH 08/12] LDB:ldb_tdb.c - also special entries should be checked for duplicate values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The exclusion can be removed since the special attribute (@...) handling has been fixed. Bug: https://bugzilla.samba.org/show_bug.cgi?id=8929 Signed-off-by: Matthias Dieter Wallnöfer Reviewed-by: Stefan Metzmacher Reviewed-by: Andrew Bartlett --- lib/ldb/ldb_tdb/ldb_tdb.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index 3c24c15..a8c6e97 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -367,12 +367,6 @@ static int ltdb_add_internal(struct ldb_module *module, return LDB_ERR_CONSTRAINT_VIOLATION; } - /* Do not check "@ATTRIBUTES" for duplicated values */ - if (ldb_dn_is_special(msg->dn) && - ldb_dn_check_special(msg->dn, LTDB_ATTRIBUTES)) { - continue; - } - /* TODO: This is O(n^2) - replace with more efficient check */ for (j=0; jnum_values; j++) { if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) { -- 1.7.9.5 From 0edad7ddd7d528221b7038ed5fea002d1bf2dd7a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 11 Sep 2013 09:25:30 +0200 Subject: [PATCH 09/12] ldb: add some const to ldb_msg_find_val() Signed-off-by: Stefan Metzmacher --- lib/ldb/ABI/ldb-1.1.16.sigs | 2 +- lib/ldb/common/ldb_msg.c | 2 +- lib/ldb/include/ldb.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ldb/ABI/ldb-1.1.16.sigs b/lib/ldb/ABI/ldb-1.1.16.sigs index 617721c..8958998 100644 --- a/lib/ldb/ABI/ldb-1.1.16.sigs +++ b/lib/ldb/ABI/ldb-1.1.16.sigs @@ -169,7 +169,7 @@ ldb_msg_find_attr_as_uint: unsigned int (const struct ldb_message *, const char ldb_msg_find_attr_as_uint64: uint64_t (const struct ldb_message *, const char *, uint64_t) ldb_msg_find_element: struct ldb_message_element *(const struct ldb_message *, const char *) ldb_msg_find_ldb_val: const struct ldb_val *(const struct ldb_message *, const char *) -ldb_msg_find_val: struct ldb_val *(const struct ldb_message_element *, struct ldb_val *) +ldb_msg_find_val: struct ldb_val *(const struct ldb_message_element *, const struct ldb_val *) ldb_msg_new: struct ldb_message *(TALLOC_CTX *) ldb_msg_normalize: int (struct ldb_context *, TALLOC_CTX *, const struct ldb_message *, struct ldb_message **) ldb_msg_remove_attr: void (struct ldb_message *, const char *) diff --git a/lib/ldb/common/ldb_msg.c b/lib/ldb/common/ldb_msg.c index 809e3af..bbed284 100644 --- a/lib/ldb/common/ldb_msg.c +++ b/lib/ldb/common/ldb_msg.c @@ -78,7 +78,7 @@ int ldb_val_equal_exact(const struct ldb_val *v1, const struct ldb_val *v2) assumes case sensitive comparison */ struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el, - struct ldb_val *val) + const struct ldb_val *val) { unsigned int i; for (i=0;inum_values;i++) { diff --git a/lib/ldb/include/ldb.h b/lib/ldb/include/ldb.h index 748def9..be73070 100644 --- a/lib/ldb/include/ldb.h +++ b/lib/ldb/include/ldb.h @@ -1889,7 +1889,7 @@ int ldb_val_equal_exact(const struct ldb_val *v1, const struct ldb_val *v2); \note This search is case sensitive */ struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el, - struct ldb_val *val); + const struct ldb_val *val); /** add a new empty element to a ldb_message -- 1.7.9.5 From 0f22299869a9c0b6daf5f5df080d102d381d4ede Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 11 May 2012 09:52:18 +0200 Subject: [PATCH 10/12] lib/ldb: add schema based ldb_val comparison and ldb_msg_element search routines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on an earlier patch by Matthias Dieter Wallnöfer This is necessary to perform correct schema enforcement, becuase we must enforce uniquiness based on the schema matching rules. Bug: https://bugzilla.samba.org/show_bug.cgi?id=7485 Bug: https://bugzilla.samba.org/show_bug.cgi?id=8929 Andrew Bartlett Signed-off-by: Andrew Bartlett Signed-off-by: Stefan Metzmacher Reviewed-by: Stefan Metzmacher --- lib/ldb/ABI/ldb-1.2.0.sigs | 264 +++++++++++++++++++++++++++++++++++++ lib/ldb/ABI/pyldb-util-1.2.0.sigs | 2 + lib/ldb/common/ldb_match.c | 16 +-- lib/ldb/common/ldb_msg.c | 65 +++++++++ lib/ldb/include/ldb.h | 34 ++++- lib/ldb/modules/rdn_name.c | 11 +- lib/ldb/wscript | 2 +- 7 files changed, 372 insertions(+), 22 deletions(-) create mode 100644 lib/ldb/ABI/ldb-1.2.0.sigs create mode 100644 lib/ldb/ABI/pyldb-util-1.2.0.sigs diff --git a/lib/ldb/ABI/ldb-1.2.0.sigs b/lib/ldb/ABI/ldb-1.2.0.sigs new file mode 100644 index 0000000..9db2e42 --- /dev/null +++ b/lib/ldb/ABI/ldb-1.2.0.sigs @@ -0,0 +1,264 @@ +ldb_add: int (struct ldb_context *, const struct ldb_message *) +ldb_any_comparison: int (struct ldb_context *, void *, ldb_attr_handler_t, const struct ldb_val *, const struct ldb_val *) +ldb_asprintf_errstring: void (struct ldb_context *, const char *, ...) +ldb_attr_casefold: char *(TALLOC_CTX *, const char *) +ldb_attr_dn: int (const char *) +ldb_attr_in_list: int (const char * const *, const char *) +ldb_attr_list_copy: const char **(TALLOC_CTX *, const char * const *) +ldb_attr_list_copy_add: const char **(TALLOC_CTX *, const char * const *, const char *) +ldb_base64_decode: int (char *) +ldb_base64_encode: char *(TALLOC_CTX *, const char *, int) +ldb_binary_decode: struct ldb_val (TALLOC_CTX *, const char *) +ldb_binary_encode: char *(TALLOC_CTX *, struct ldb_val) +ldb_binary_encode_string: char *(TALLOC_CTX *, const char *) +ldb_build_add_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, const struct ldb_message *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_del_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, struct ldb_dn *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_extended_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, const char *, void *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_mod_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, const struct ldb_message *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_rename_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, struct ldb_dn *, struct ldb_dn *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_search_req: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, struct ldb_dn *, enum ldb_scope, const char *, const char * const *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_build_search_req_ex: int (struct ldb_request **, struct ldb_context *, TALLOC_CTX *, struct ldb_dn *, enum ldb_scope, struct ldb_parse_tree *, const char * const *, struct ldb_control **, void *, ldb_request_callback_t, struct ldb_request *) +ldb_casefold: char *(struct ldb_context *, TALLOC_CTX *, const char *, size_t) +ldb_casefold_default: char *(void *, TALLOC_CTX *, const char *, size_t) +ldb_check_critical_controls: int (struct ldb_control **) +ldb_comparison_binary: int (struct ldb_context *, void *, const struct ldb_val *, const struct ldb_val *) +ldb_comparison_fold: int (struct ldb_context *, void *, const struct ldb_val *, const struct ldb_val *) +ldb_connect: int (struct ldb_context *, const char *, unsigned int, const char **) +ldb_control_to_string: char *(TALLOC_CTX *, const struct ldb_control *) +ldb_controls_except_specified: struct ldb_control **(struct ldb_control **, TALLOC_CTX *, struct ldb_control *) +ldb_debug: void (struct ldb_context *, enum ldb_debug_level, const char *, ...) +ldb_debug_add: void (struct ldb_context *, const char *, ...) +ldb_debug_end: void (struct ldb_context *, enum ldb_debug_level) +ldb_debug_set: void (struct ldb_context *, enum ldb_debug_level, const char *, ...) +ldb_delete: int (struct ldb_context *, struct ldb_dn *) +ldb_dn_add_base: bool (struct ldb_dn *, struct ldb_dn *) +ldb_dn_add_base_fmt: bool (struct ldb_dn *, const char *, ...) +ldb_dn_add_child: bool (struct ldb_dn *, struct ldb_dn *) +ldb_dn_add_child_fmt: bool (struct ldb_dn *, const char *, ...) +ldb_dn_alloc_casefold: char *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_alloc_linearized: char *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_canonical_ex_string: char *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_canonical_string: char *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_check_local: bool (struct ldb_module *, struct ldb_dn *) +ldb_dn_check_special: bool (struct ldb_dn *, const char *) +ldb_dn_compare: int (struct ldb_dn *, struct ldb_dn *) +ldb_dn_compare_base: int (struct ldb_dn *, struct ldb_dn *) +ldb_dn_copy: struct ldb_dn *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_escape_value: char *(TALLOC_CTX *, struct ldb_val) +ldb_dn_extended_add_syntax: int (struct ldb_context *, unsigned int, const struct ldb_dn_extended_syntax *) +ldb_dn_extended_filter: void (struct ldb_dn *, const char * const *) +ldb_dn_extended_syntax_by_name: const struct ldb_dn_extended_syntax *(struct ldb_context *, const char *) +ldb_dn_from_ldb_val: struct ldb_dn *(TALLOC_CTX *, struct ldb_context *, const struct ldb_val *) +ldb_dn_get_casefold: const char *(struct ldb_dn *) +ldb_dn_get_comp_num: int (struct ldb_dn *) +ldb_dn_get_component_name: const char *(struct ldb_dn *, unsigned int) +ldb_dn_get_component_val: const struct ldb_val *(struct ldb_dn *, unsigned int) +ldb_dn_get_extended_comp_num: int (struct ldb_dn *) +ldb_dn_get_extended_component: const struct ldb_val *(struct ldb_dn *, const char *) +ldb_dn_get_extended_linearized: char *(TALLOC_CTX *, struct ldb_dn *, int) +ldb_dn_get_linearized: const char *(struct ldb_dn *) +ldb_dn_get_parent: struct ldb_dn *(TALLOC_CTX *, struct ldb_dn *) +ldb_dn_get_rdn_name: const char *(struct ldb_dn *) +ldb_dn_get_rdn_val: const struct ldb_val *(struct ldb_dn *) +ldb_dn_has_extended: bool (struct ldb_dn *) +ldb_dn_is_null: bool (struct ldb_dn *) +ldb_dn_is_special: bool (struct ldb_dn *) +ldb_dn_is_valid: bool (struct ldb_dn *) +ldb_dn_map_local: struct ldb_dn *(struct ldb_module *, void *, struct ldb_dn *) +ldb_dn_map_rebase_remote: struct ldb_dn *(struct ldb_module *, void *, struct ldb_dn *) +ldb_dn_map_remote: struct ldb_dn *(struct ldb_module *, void *, struct ldb_dn *) +ldb_dn_minimise: bool (struct ldb_dn *) +ldb_dn_new: struct ldb_dn *(TALLOC_CTX *, struct ldb_context *, const char *) +ldb_dn_new_fmt: struct ldb_dn *(TALLOC_CTX *, struct ldb_context *, const char *, ...) +ldb_dn_remove_base_components: bool (struct ldb_dn *, unsigned int) +ldb_dn_remove_child_components: bool (struct ldb_dn *, unsigned int) +ldb_dn_remove_extended_components: void (struct ldb_dn *) +ldb_dn_replace_components: bool (struct ldb_dn *, struct ldb_dn *) +ldb_dn_set_component: int (struct ldb_dn *, int, const char *, const struct ldb_val) +ldb_dn_set_extended_component: int (struct ldb_dn *, const char *, const struct ldb_val *) +ldb_dn_update_components: int (struct ldb_dn *, const struct ldb_dn *) +ldb_dn_validate: bool (struct ldb_dn *) +ldb_dump_results: void (struct ldb_context *, struct ldb_result *, FILE *) +ldb_error_at: int (struct ldb_context *, int, const char *, const char *, int) +ldb_errstring: const char *(struct ldb_context *) +ldb_extended: int (struct ldb_context *, const char *, void *, struct ldb_result **) +ldb_extended_default_callback: int (struct ldb_request *, struct ldb_reply *) +ldb_filter_from_tree: char *(TALLOC_CTX *, const struct ldb_parse_tree *) +ldb_get_config_basedn: struct ldb_dn *(struct ldb_context *) +ldb_get_create_perms: unsigned int (struct ldb_context *) +ldb_get_default_basedn: struct ldb_dn *(struct ldb_context *) +ldb_get_event_context: struct tevent_context *(struct ldb_context *) +ldb_get_flags: unsigned int (struct ldb_context *) +ldb_get_opaque: void *(struct ldb_context *, const char *) +ldb_get_root_basedn: struct ldb_dn *(struct ldb_context *) +ldb_get_schema_basedn: struct ldb_dn *(struct ldb_context *) +ldb_global_init: int (void) +ldb_handle_new: struct ldb_handle *(TALLOC_CTX *, struct ldb_context *) +ldb_handler_copy: int (struct ldb_context *, void *, const struct ldb_val *, struct ldb_val *) +ldb_handler_fold: int (struct ldb_context *, void *, const struct ldb_val *, struct ldb_val *) +ldb_init: struct ldb_context *(TALLOC_CTX *, struct tevent_context *) +ldb_ldif_message_string: char *(struct ldb_context *, TALLOC_CTX *, enum ldb_changetype, const struct ldb_message *) +ldb_ldif_parse_modrdn: int (struct ldb_context *, const struct ldb_ldif *, TALLOC_CTX *, struct ldb_dn **, struct ldb_dn **, bool *, struct ldb_dn **, struct ldb_dn **) +ldb_ldif_read: struct ldb_ldif *(struct ldb_context *, int (*)(void *), void *) +ldb_ldif_read_file: struct ldb_ldif *(struct ldb_context *, FILE *) +ldb_ldif_read_file_state: struct ldb_ldif *(struct ldb_context *, struct ldif_read_file_state *) +ldb_ldif_read_free: void (struct ldb_context *, struct ldb_ldif *) +ldb_ldif_read_string: struct ldb_ldif *(struct ldb_context *, const char **) +ldb_ldif_write: int (struct ldb_context *, int (*)(void *, const char *, ...), void *, const struct ldb_ldif *) +ldb_ldif_write_file: int (struct ldb_context *, FILE *, const struct ldb_ldif *) +ldb_ldif_write_redacted_trace_string: char *(struct ldb_context *, TALLOC_CTX *, const struct ldb_ldif *) +ldb_ldif_write_string: char *(struct ldb_context *, TALLOC_CTX *, const struct ldb_ldif *) +ldb_load_modules: int (struct ldb_context *, const char **) +ldb_map_add: int (struct ldb_module *, struct ldb_request *) +ldb_map_delete: int (struct ldb_module *, struct ldb_request *) +ldb_map_init: int (struct ldb_module *, const struct ldb_map_attribute *, const struct ldb_map_objectclass *, const char * const *, const char *, const char *) +ldb_map_modify: int (struct ldb_module *, struct ldb_request *) +ldb_map_rename: int (struct ldb_module *, struct ldb_request *) +ldb_map_search: int (struct ldb_module *, struct ldb_request *) +ldb_match_msg: int (struct ldb_context *, const struct ldb_message *, const struct ldb_parse_tree *, struct ldb_dn *, enum ldb_scope) +ldb_match_msg_error: int (struct ldb_context *, const struct ldb_message *, const struct ldb_parse_tree *, struct ldb_dn *, enum ldb_scope, bool *) +ldb_match_msg_objectclass: int (const struct ldb_message *, const char *) +ldb_mod_register_control: int (struct ldb_module *, const char *) +ldb_modify: int (struct ldb_context *, const struct ldb_message *) +ldb_modify_default_callback: int (struct ldb_request *, struct ldb_reply *) +ldb_module_call_chain: char *(struct ldb_request *, TALLOC_CTX *) +ldb_module_connect_backend: int (struct ldb_context *, const char *, const char **, struct ldb_module **) +ldb_module_done: int (struct ldb_request *, struct ldb_control **, struct ldb_extended *, int) +ldb_module_flags: uint32_t (struct ldb_context *) +ldb_module_get_ctx: struct ldb_context *(struct ldb_module *) +ldb_module_get_name: const char *(struct ldb_module *) +ldb_module_get_ops: const struct ldb_module_ops *(struct ldb_module *) +ldb_module_get_private: void *(struct ldb_module *) +ldb_module_init_chain: int (struct ldb_context *, struct ldb_module *) +ldb_module_load_list: int (struct ldb_context *, const char * const *, struct ldb_module *, struct ldb_module **) +ldb_module_new: struct ldb_module *(TALLOC_CTX *, struct ldb_context *, const char *, const struct ldb_module_ops *) +ldb_module_next: struct ldb_module *(struct ldb_module *) +ldb_module_popt_options: struct poptOption **(struct ldb_context *) +ldb_module_send_entry: int (struct ldb_request *, struct ldb_message *, struct ldb_control **) +ldb_module_send_referral: int (struct ldb_request *, char *) +ldb_module_set_next: void (struct ldb_module *, struct ldb_module *) +ldb_module_set_private: void (struct ldb_module *, void *) +ldb_modules_hook: int (struct ldb_context *, enum ldb_module_hook_type) +ldb_modules_list_from_string: char **(struct ldb_context *, TALLOC_CTX *, const char *) +ldb_modules_load: int (const char *, const char *) +ldb_msg_add: int (struct ldb_message *, const struct ldb_message_element *, int) +ldb_msg_add_empty: int (struct ldb_message *, const char *, int, struct ldb_message_element **) +ldb_msg_add_fmt: int (struct ldb_message *, const char *, const char *, ...) +ldb_msg_add_linearized_dn: int (struct ldb_message *, const char *, struct ldb_dn *) +ldb_msg_add_steal_string: int (struct ldb_message *, const char *, char *) +ldb_msg_add_steal_value: int (struct ldb_message *, const char *, struct ldb_val *) +ldb_msg_add_string: int (struct ldb_message *, const char *, const char *) +ldb_msg_add_value: int (struct ldb_message *, const char *, const struct ldb_val *, struct ldb_message_element **) +ldb_msg_canonicalize: struct ldb_message *(struct ldb_context *, const struct ldb_message *) +ldb_msg_check_string_attribute: int (const struct ldb_message *, const char *, const char *) +ldb_msg_copy: struct ldb_message *(TALLOC_CTX *, const struct ldb_message *) +ldb_msg_copy_attr: int (struct ldb_message *, const char *, const char *) +ldb_msg_copy_shallow: struct ldb_message *(TALLOC_CTX *, const struct ldb_message *) +ldb_msg_diff: struct ldb_message *(struct ldb_context *, struct ldb_message *, struct ldb_message *) +ldb_msg_difference: int (struct ldb_context *, TALLOC_CTX *, struct ldb_message *, struct ldb_message *, struct ldb_message **) +ldb_msg_element_compare: int (struct ldb_message_element *, struct ldb_message_element *) +ldb_msg_element_compare_name: int (struct ldb_message_element *, struct ldb_message_element *) +ldb_msg_element_equal_ordered: bool (const struct ldb_message_element *, const struct ldb_message_element *) +ldb_msg_find_attr_as_bool: int (const struct ldb_message *, const char *, int) +ldb_msg_find_attr_as_dn: struct ldb_dn *(struct ldb_context *, TALLOC_CTX *, const struct ldb_message *, const char *) +ldb_msg_find_attr_as_double: double (const struct ldb_message *, const char *, double) +ldb_msg_find_attr_as_int: int (const struct ldb_message *, const char *, int) +ldb_msg_find_attr_as_int64: int64_t (const struct ldb_message *, const char *, int64_t) +ldb_msg_find_attr_as_string: const char *(const struct ldb_message *, const char *, const char *) +ldb_msg_find_attr_as_uint: unsigned int (const struct ldb_message *, const char *, unsigned int) +ldb_msg_find_attr_as_uint64: uint64_t (const struct ldb_message *, const char *, uint64_t) +ldb_msg_find_element: struct ldb_message_element *(const struct ldb_message *, const char *) +ldb_msg_find_ldb_val: const struct ldb_val *(const struct ldb_message *, const char *) +ldb_msg_find_val: struct ldb_val *(const struct ldb_message_element *, const struct ldb_val *) +ldb_msg_find_val_schema: int (struct ldb_context *, const struct ldb_schema_attribute *, const struct ldb_message_element *, const struct ldb_val *, struct ldb_val **) +ldb_msg_new: struct ldb_message *(TALLOC_CTX *) +ldb_msg_normalize: int (struct ldb_context *, TALLOC_CTX *, const struct ldb_message *, struct ldb_message **) +ldb_msg_remove_attr: void (struct ldb_message *, const char *) +ldb_msg_remove_element: void (struct ldb_message *, struct ldb_message_element *) +ldb_msg_rename_attr: int (struct ldb_message *, const char *, const char *) +ldb_msg_sanity_check: int (struct ldb_context *, const struct ldb_message *) +ldb_msg_sort_elements: void (struct ldb_message *) +ldb_next_del_trans: int (struct ldb_module *) +ldb_next_end_trans: int (struct ldb_module *) +ldb_next_init: int (struct ldb_module *) +ldb_next_prepare_commit: int (struct ldb_module *) +ldb_next_remote_request: int (struct ldb_module *, struct ldb_request *) +ldb_next_request: int (struct ldb_module *, struct ldb_request *) +ldb_next_start_trans: int (struct ldb_module *) +ldb_op_default_callback: int (struct ldb_request *, struct ldb_reply *) +ldb_options_find: const char *(struct ldb_context *, const char **, const char *) +ldb_pack_data: int (struct ldb_context *, const struct ldb_message *, struct ldb_val *) +ldb_parse_control_from_string: struct ldb_control *(struct ldb_context *, TALLOC_CTX *, const char *) +ldb_parse_control_strings: struct ldb_control **(struct ldb_context *, TALLOC_CTX *, const char **) +ldb_parse_tree: struct ldb_parse_tree *(TALLOC_CTX *, const char *) +ldb_parse_tree_attr_replace: void (struct ldb_parse_tree *, const char *, const char *) +ldb_parse_tree_copy_shallow: struct ldb_parse_tree *(TALLOC_CTX *, const struct ldb_parse_tree *) +ldb_parse_tree_walk: int (struct ldb_parse_tree *, int (*)(struct ldb_parse_tree *, void *), void *) +ldb_qsort: void (void * const, size_t, size_t, void *, ldb_qsort_cmp_fn_t) +ldb_register_backend: int (const char *, ldb_connect_fn, bool) +ldb_register_hook: int (ldb_hook_fn) +ldb_register_module: int (const struct ldb_module_ops *) +ldb_rename: int (struct ldb_context *, struct ldb_dn *, struct ldb_dn *) +ldb_reply_add_control: int (struct ldb_reply *, const char *, bool, void *) +ldb_reply_get_control: struct ldb_control *(struct ldb_reply *, const char *) +ldb_req_get_custom_flags: uint32_t (struct ldb_request *) +ldb_req_is_untrusted: bool (struct ldb_request *) +ldb_req_location: const char *(struct ldb_request *) +ldb_req_mark_trusted: void (struct ldb_request *) +ldb_req_mark_untrusted: void (struct ldb_request *) +ldb_req_set_custom_flags: void (struct ldb_request *, uint32_t) +ldb_req_set_location: void (struct ldb_request *, const char *) +ldb_request: int (struct ldb_context *, struct ldb_request *) +ldb_request_add_control: int (struct ldb_request *, const char *, bool, void *) +ldb_request_done: int (struct ldb_request *, int) +ldb_request_get_control: struct ldb_control *(struct ldb_request *, const char *) +ldb_request_get_status: int (struct ldb_request *) +ldb_request_replace_control: int (struct ldb_request *, const char *, bool, void *) +ldb_request_set_state: void (struct ldb_request *, int) +ldb_reset_err_string: void (struct ldb_context *) +ldb_save_controls: int (struct ldb_control *, struct ldb_request *, struct ldb_control ***) +ldb_schema_attribute_add: int (struct ldb_context *, const char *, unsigned int, const char *) +ldb_schema_attribute_add_with_syntax: int (struct ldb_context *, const char *, unsigned int, const struct ldb_schema_syntax *) +ldb_schema_attribute_by_name: const struct ldb_schema_attribute *(struct ldb_context *, const char *) +ldb_schema_attribute_remove: void (struct ldb_context *, const char *) +ldb_schema_attribute_set_override_handler: void (struct ldb_context *, ldb_attribute_handler_override_fn_t, void *) +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 *) +ldb_set_create_perms: void (struct ldb_context *, unsigned int) +ldb_set_debug: int (struct ldb_context *, void (*)(void *, enum ldb_debug_level, const char *, va_list), void *) +ldb_set_debug_stderr: int (struct ldb_context *) +ldb_set_default_dns: void (struct ldb_context *) +ldb_set_errstring: void (struct ldb_context *, const char *) +ldb_set_event_context: void (struct ldb_context *, struct tevent_context *) +ldb_set_flags: void (struct ldb_context *, unsigned int) +ldb_set_modules_dir: void (struct ldb_context *, const char *) +ldb_set_opaque: int (struct ldb_context *, const char *, void *) +ldb_set_timeout: int (struct ldb_context *, struct ldb_request *, int) +ldb_set_timeout_from_prev_req: int (struct ldb_context *, struct ldb_request *, struct ldb_request *) +ldb_set_utf8_default: void (struct ldb_context *) +ldb_set_utf8_fns: void (struct ldb_context *, void *, char *(*)(void *, void *, const char *, size_t)) +ldb_setup_wellknown_attributes: int (struct ldb_context *) +ldb_should_b64_encode: int (struct ldb_context *, const struct ldb_val *) +ldb_standard_syntax_by_name: const struct ldb_schema_syntax *(struct ldb_context *, const char *) +ldb_strerror: const char *(int) +ldb_string_to_time: time_t (const char *) +ldb_string_utc_to_time: time_t (const char *) +ldb_timestring: char *(TALLOC_CTX *, time_t) +ldb_timestring_utc: char *(TALLOC_CTX *, time_t) +ldb_transaction_cancel: int (struct ldb_context *) +ldb_transaction_cancel_noerr: int (struct ldb_context *) +ldb_transaction_commit: int (struct ldb_context *) +ldb_transaction_prepare_commit: int (struct ldb_context *) +ldb_transaction_start: int (struct ldb_context *) +ldb_unpack_data: int (struct ldb_context *, const struct ldb_val *, struct ldb_message *) +ldb_val_dup: struct ldb_val (TALLOC_CTX *, const struct ldb_val *) +ldb_val_equal_exact: int (const struct ldb_val *, const struct ldb_val *) +ldb_val_equal_schema: int (struct ldb_context *, const struct ldb_schema_attribute *, const struct ldb_val *, const struct ldb_val *, bool *) +ldb_val_map_local: struct ldb_val (struct ldb_module *, void *, const struct ldb_map_attribute *, const struct ldb_val *) +ldb_val_map_remote: struct ldb_val (struct ldb_module *, void *, const struct ldb_map_attribute *, const struct ldb_val *) +ldb_val_string_cmp: int (const struct ldb_val *, const char *) +ldb_val_to_time: int (const struct ldb_val *, time_t *) +ldb_valid_attr_name: int (const char *) +ldb_vdebug: void (struct ldb_context *, enum ldb_debug_level, const char *, va_list) +ldb_wait: int (struct ldb_handle *, enum ldb_wait_type) diff --git a/lib/ldb/ABI/pyldb-util-1.2.0.sigs b/lib/ldb/ABI/pyldb-util-1.2.0.sigs new file mode 100644 index 0000000..74d6719 --- /dev/null +++ b/lib/ldb/ABI/pyldb-util-1.2.0.sigs @@ -0,0 +1,2 @@ +pyldb_Dn_FromDn: PyObject *(struct ldb_dn *) +pyldb_Object_AsDn: bool (TALLOC_CTX *, PyObject *, struct ldb_context *, struct ldb_dn **) diff --git a/lib/ldb/common/ldb_match.c b/lib/ldb/common/ldb_match.c index 7918aec..d744258 100644 --- a/lib/ldb/common/ldb_match.c +++ b/lib/ldb/common/ldb_match.c @@ -214,18 +214,10 @@ static int ldb_match_equality(struct ldb_context *ldb, } for (i=0;inum_values;i++) { - if (a->syntax->operator_fn) { - ret = a->syntax->operator_fn(ldb, LDB_OP_EQUALITY, a, - &tree->u.equality.value, &el->values[i], matched); - if (ret != LDB_SUCCESS) return ret; - if (*matched) return LDB_SUCCESS; - } else { - if (a->syntax->comparison_fn(ldb, ldb, &tree->u.equality.value, - &el->values[i]) == 0) { - *matched = true; - return LDB_SUCCESS; - } - } + ret = ldb_val_equal_schema(ldb, a, + &tree->u.equality.value, &el->values[i], matched); + if (ret != LDB_SUCCESS) return ret; + if (*matched) return LDB_SUCCESS; } *matched = false; diff --git a/lib/ldb/common/ldb_msg.c b/lib/ldb/common/ldb_msg.c index bbed284..4726117 100644 --- a/lib/ldb/common/ldb_msg.c +++ b/lib/ldb/common/ldb_msg.c @@ -74,6 +74,30 @@ int ldb_val_equal_exact(const struct ldb_val *v1, const struct ldb_val *v2) } /* + see if two ldb_val structures contain exactly the same data in respect to + schema equivalence. + set *matched on match, returns LDB error codes +*/ +int ldb_val_equal_schema(struct ldb_context *ldb, + const struct ldb_schema_attribute *a, + const struct ldb_val *v1, const struct ldb_val *v2, + bool *matched) +{ + if (a->syntax->operator_fn) { + return a->syntax->operator_fn(ldb, LDB_OP_EQUALITY, a, + v1, v2, matched); + } else { + int ret = a->syntax->comparison_fn(ldb, ldb, v1, v2); + if (ret == 0) { + *matched = true; + } else { + *matched = false; + } + } + return LDB_SUCCESS; +} + +/* find a value in an element assumes case sensitive comparison */ @@ -90,6 +114,47 @@ struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el, } /* + find a value in an element + assumes schema exact comparison. + This returns LDB_ERR_COMPARE_TRUE if a matched + value is returned and LDB_ERR_COMPARE_FALSE if not. + Other return values is are errors. +*/ +int ldb_msg_find_val_schema(struct ldb_context *ldb, + const struct ldb_schema_attribute *a, + const struct ldb_message_element *el, + const struct ldb_val *val, + struct ldb_val **matched_val) +{ + unsigned int i; + + if (matched_val != NULL) { + *matched_val = NULL; + } + + for (i = 0; i < el->num_values; i++) { + int ret; + bool match; + + ret = ldb_val_equal_schema(ldb, a, val, &el->values[i], &match); + if (ret != LDB_SUCCESS) { + return ret; + } + + if (!match) { + continue; + } + + if (matched_val) { + *matched_val = &el->values[i]; + } + return LDB_ERR_COMPARE_TRUE; + } + + return LDB_ERR_COMPARE_FALSE; +} + +/* duplicate a ldb_val structure */ struct ldb_val ldb_val_dup(TALLOC_CTX *mem_ctx, const struct ldb_val *v) diff --git a/lib/ldb/include/ldb.h b/lib/ldb/include/ldb.h index be73070..07b0919 100644 --- a/lib/ldb/include/ldb.h +++ b/lib/ldb/include/ldb.h @@ -1881,17 +1881,49 @@ struct ldb_message_element *ldb_msg_find_element(const struct ldb_message *msg, int ldb_val_equal_exact(const struct ldb_val *v1, const struct ldb_val *v2); /** + Compare two ldb_val values in respect to the schema + + \param v1 first ldb_val structure to be tested + \param v2 second ldb_val structure to be tested + + \param a the schema attribute to be used for the test + \param *matched Return true here if there was a match, false otherwise + + \return LDB error codes or LDB_SUCCESS +*/ +int ldb_val_equal_schema(struct ldb_context *ldb, + const struct ldb_schema_attribute *a, + const struct ldb_val *v1, const struct ldb_val *v2, + bool *matched); + +/** find a value within an ldb_message_element \param el the element to search \param val the value to search for - \note This search is case sensitive + \return LDB error codes or LDB_ERR_COMPARE_TRUE/LDB_ERR_COMPARE_FALSE + + \note This search is case sensitive (ldb_val_equal_exact()) */ struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el, const struct ldb_val *val); /** + find a value within an ldb_message_element + + \param el the element to search + \param val the value to search for + + \note This search is based on schema comparison (ldb_val_equal_schema()) +*/ +int ldb_msg_find_val_schema(struct ldb_context *ldb, + const struct ldb_schema_attribute *a, + const struct ldb_message_element *el, + const struct ldb_val *val, + struct ldb_val **matched_val); + +/** add a new empty element to a ldb_message */ int ldb_msg_add_empty(struct ldb_message *msg, diff --git a/lib/ldb/modules/rdn_name.c b/lib/ldb/modules/rdn_name.c index 50b63ae..e112f13 100644 --- a/lib/ldb/modules/rdn_name.c +++ b/lib/ldb/modules/rdn_name.c @@ -160,14 +160,9 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) /* normalise attribute value */ for (i = 0; i < attribute->num_values; i++) { bool matched; - if (a->syntax->operator_fn) { - ret = a->syntax->operator_fn(ldb, LDB_OP_EQUALITY, a, - &rdn_val, &attribute->values[i], &matched); - if (ret != LDB_SUCCESS) return ret; - } else { - matched = (a->syntax->comparison_fn(ldb, msg, - &rdn_val, &attribute->values[i]) == 0); - } + ret = ldb_val_equal_schema(ldb, a, + &rdn_val, &attribute->values[i], &matched); + if (ret != LDB_SUCCESS) return ret; if (matched) { /* overwrite so it matches in case */ attribute->values[i] = rdn_val; diff --git a/lib/ldb/wscript b/lib/ldb/wscript index 071038c..c437560 100755 --- a/lib/ldb/wscript +++ b/lib/ldb/wscript @@ -1,7 +1,7 @@ #!/usr/bin/env python APPNAME = 'ldb' -VERSION = '1.1.16' +VERSION = '1.2.0' blddir = 'bin' -- 1.7.9.5 From eb32f01dd5fa25db3959f7717ff625788bf44060 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 11 May 2012 10:00:29 +0200 Subject: [PATCH 11/12] lib/ldb: switch ldb_tdb to schema-based attribute comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on an earlier patch by Matthias Dieter Wallnöfer This is necessary to perform correct schema enforcement, becuase we must enforce uniquiness based on the schema matching rules. Bug: https://bugzilla.samba.org/show_bug.cgi?id=7485 Bug: https://bugzilla.samba.org/show_bug.cgi?id=8929 Andrew Bartlett Small fix by Matthias Dieter Wallnöfer Signed-off-by: Andrew Bartlett Signed-off-by: Matthias Dieter Wallnöfer Signed-off-by: Stefan Metzmacher Reviewed-by: Stefan Metzmacher --- lib/ldb/ldb_tdb/ldb_tdb.c | 69 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 11 deletions(-) diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c index a8c6e97..8748d1e 100644 --- a/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/lib/ldb/ldb_tdb/ldb_tdb.c @@ -369,7 +369,22 @@ static int ltdb_add_internal(struct ldb_module *module, /* TODO: This is O(n^2) - replace with more efficient check */ for (j=0; jnum_values; j++) { - if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) { + struct ldb_val *found_val; + + ret = ldb_msg_find_val_schema(ldb, a, el, + &el->values[j], &found_val); + if (ret == LDB_ERR_COMPARE_FALSE) { + /* + * Something went completely wrong + * This must find the value itself!!! + */ + return ldb_operr(ldb); + } + if (ret != LDB_ERR_COMPARE_TRUE) { + return ret; + } + + if (found_val != &el->values[j]) { ldb_asprintf_errstring(ldb, "attribute '%s': value #%u on '%s' provided more than once", el->name, j, ldb_dn_get_linearized(msg->dn)); @@ -634,13 +649,9 @@ static int msg_delete_element(struct ldb_module *module, for (i=0;inum_values;i++) { bool matched; - if (a->syntax->operator_fn) { - ret = a->syntax->operator_fn(ldb, LDB_OP_EQUALITY, a, - &el->values[i], val, &matched); - if (ret != LDB_SUCCESS) return ret; - } else { - matched = (a->syntax->comparison_fn(ldb, ldb, - &el->values[i], val) == 0); + ret = ldb_val_equal_schema(ldb, a, &el->values[i], val, &matched); + if (ret != LDB_SUCCESS) { + return ret; } if (matched) { if (el->num_values == 1) { @@ -823,7 +834,15 @@ int ltdb_modify_internal(struct ldb_module *module, valued attributes or aren't provided twice */ /* TODO: This is O(n^2) - replace with more efficient check */ for (j = 0; j < el->num_values; j++) { - if (ldb_msg_find_val(el2, &el->values[j]) != NULL) { + struct ldb_val *matched_val = NULL; + + ret = ldb_msg_find_val_schema(ldb, a, el2, + &el->values[j], NULL); + if (ret != LDB_ERR_COMPARE_FALSE && + ret != LDB_ERR_COMPARE_TRUE) { + return ret; + } + if (ret == LDB_ERR_COMPARE_TRUE) { if (control_permissive) { /* remove this one as if it was never added */ el->num_values--; @@ -841,7 +860,21 @@ int ltdb_modify_internal(struct ldb_module *module, ret = LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS; goto done; } - if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) { + + ret = ldb_msg_find_val_schema(ldb, a, el, + &el->values[j], &matched_val); + if (ret == LDB_ERR_COMPARE_FALSE) { + /* + * Something went completely wrong + * This must find the value itself!!! + */ + return ldb_operr(ldb); + } + if (ret != LDB_ERR_COMPARE_TRUE) { + return ret; + } + + if (matched_val != &el->values[j]) { ldb_asprintf_errstring(ldb, "attribute '%s': value #%u on '%s' provided more than once", el->name, j, ldb_dn_get_linearized(msg2->dn)); @@ -888,7 +921,21 @@ int ltdb_modify_internal(struct ldb_module *module, /* TODO: This is O(n^2) - replace with more efficient check */ for (j=0; jnum_values; j++) { - if (ldb_msg_find_val(el, &el->values[j]) != &el->values[j]) { + struct ldb_val *matched_val; + ret = ldb_msg_find_val_schema(ldb, a, el, + &el->values[j], &matched_val); + if (ret == LDB_ERR_COMPARE_FALSE) { + /* + * Something went completely wrong + * This must find the value itself!!! + */ + return ldb_operr(ldb); + } + if (ret != LDB_ERR_COMPARE_TRUE) { + return ret; + } + + if (matched_val != &el->values[j]) { ldb_asprintf_errstring(ldb, "attribute '%s': value #%u on '%s' provided more than once", el->name, j, ldb_dn_get_linearized(msg2->dn)); -- 1.7.9.5 From 51f27b132373cef410b7c981d8a42113f77d7e46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Dieter=20Walln=C3=B6fer?= Date: Thu, 24 May 2012 22:27:46 +0200 Subject: [PATCH 12/12] s4:sam.py - "servicePrincipalName" - test for case-insensitiveness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After the LDB TDB changes regarding the use of schema comparison functions rather than bitwise checks this finally works as it should. Bug: https://bugzilla.samba.org/show_bug.cgi?id=8929 Signed-off-by: Matthias Dieter Wallnöfer Reviewed-by: Andrew Bartlett Reviewed-by: Stefan Metzmacher --- source4/dsdb/tests/python/sam.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/source4/dsdb/tests/python/sam.py b/source4/dsdb/tests/python/sam.py index 754096a..6994934 100755 --- a/source4/dsdb/tests/python/sam.py +++ b/source4/dsdb/tests/python/sam.py @@ -2566,6 +2566,17 @@ class SamTests(samba.tests.TestCase): except LdbError, (num, _): self.assertEquals(num, ERR_ATTRIBUTE_OR_VALUE_EXISTS) + # test for case-insensitiveness + m = Message() + m.dn = Dn(ldb, "cn=ldaptestcomputer,cn=computers," + self.base_dn) + m["servicePrincipalName"] = MessageElement("HOST/TESTNAME2.TESTDOM", + FLAG_MOD_ADD, "servicePrincipalName") + try: + ldb.modify(m) + self.fail() + except LdbError, (num, _): + self.assertEquals(num, ERR_ATTRIBUTE_OR_VALUE_EXISTS) + m = Message() m.dn = Dn(ldb, "cn=ldaptestcomputer,cn=computers," + self.base_dn) m["servicePrincipalName"] = MessageElement("HOST/testname3", -- 1.7.9.5