From 2a0cf520e3255d8e1bdec1bedd710489619de614 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 21 Jul 2005 07:59:01 +0000 Subject: r8667: Further simply the provision script, by removing the 'name' attribute. This is now calculated on the fly for every add and modify. Andrew Bartlett (This used to be commit ed1f2e029c840d2b3ecb49dbe6e8cd67588eeeed) --- source4/lib/ldb/modules/rdn_name.c | 276 +++++++++++++++++++++++++++++++++++++ 1 file changed, 276 insertions(+) create mode 100644 source4/lib/ldb/modules/rdn_name.c (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c new file mode 100644 index 0000000000..6a11ab87fe --- /dev/null +++ b/source4/lib/ldb/modules/rdn_name.c @@ -0,0 +1,276 @@ +/* + ldb database library + + Copyright (C) Simo Sorce 2004 + + ** NOTE! The following LGPL license applies to the ldb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +/* + * Name: ldb + * + * Component: ldb objectguid module + * + * Description: add a unique objectGUID onto every new record + * + * Author: Simo Sorce + */ + +#include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" +#include + +struct private_data { + const char *error_string; +}; + +static int rdn_name_search(struct ldb_module *module, const char *base, + enum ldb_scope scope, const char *expression, + const char * const *attrs, struct ldb_message ***res) +{ + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_search\n"); + return ldb_next_search(module, base, scope, expression, attrs, res); +} + +static int rdn_name_search_bytree(struct ldb_module *module, const char *base, + enum ldb_scope scope, struct ldb_parse_tree *tree, + const char * const *attrs, struct ldb_message ***res) +{ + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_search\n"); + return ldb_next_search_bytree(module, base, scope, tree, attrs, res); +} + +static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_message *msg, const char *name) +{ + int i; + + for (i = 0; i < msg->num_elements; i++) { + if (ldb_attr_cmp(name, msg->elements[i].name) == 0) { + return &msg->elements[i]; + } + } + + return NULL; +} + +static struct ldb_dn_component *get_rdn(void *mem_ctx, const char *dn) +{ + struct ldb_dn *dn_exploded = ldb_dn_explode(mem_ctx, dn); + + if (!dn_exploded) { + return NULL; + } + + if (dn_exploded->comp_num < 1) { + return NULL; + } + + return &dn_exploded->components[0]; +} + +/* add_record: add crateTimestamp/modifyTimestamp attributes */ +static int rdn_name_add_record(struct ldb_module *module, const struct ldb_message *msg) +{ + struct ldb_message *msg2; + struct ldb_message_element *attribute; + struct ldb_dn_component *rdn; + int ret, i; + + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_add_record\n"); + + if (msg->dn[0] == '@') { /* do not manipulate our control entries */ + return ldb_next_add_record(module, msg); + } + + /* Perhaps someone above us knows better */ + if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { + return ldb_next_add_record(module, msg); + } + + msg2 = talloc(module, struct ldb_message); + if (!msg2) { + return -1; + } + + msg2->dn = msg->dn; + msg2->num_elements = msg->num_elements; + msg2->private_data = msg->private_data; + msg2->elements = talloc_array(msg2, struct ldb_message_element, msg2->num_elements); + for (i = 0; i < msg2->num_elements; i++) { + msg2->elements[i] = msg->elements[i]; + } + + rdn = get_rdn(msg2, msg2->dn); + if (!rdn) { + return -1; + } + + if (ldb_msg_add_value(module->ldb, msg2, "name", &rdn->value) != 0) { + return -1; + } + + ret = ldb_next_add_record(module, msg2); + talloc_free(msg2); + + return ret; +} + +/* modify_record: change modifyTimestamp as well */ +static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_message *msg) +{ + struct ldb_message *msg2; + struct ldb_message_element *attribute; + struct ldb_dn_component *rdn; + int ret, i; + + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_modify_record\n"); + + /* Perhaps someone above us knows better */ + if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { + return ldb_next_add_record(module, msg); + } + + msg2 = talloc(module, struct ldb_message); + if (!msg2) { + return -1; + } + + msg2->dn = msg->dn; + msg2->num_elements = msg->num_elements; + msg2->private_data = msg->private_data; + msg2->elements = talloc_array(msg2, struct ldb_message_element, msg2->num_elements); + for (i = 0; i < msg2->num_elements; i++) { + msg2->elements[i] = msg->elements[i]; + } + + rdn = get_rdn(msg2, msg2->dn); + if (!rdn) { + return -1; + } + + if (ldb_msg_add_value(module->ldb, msg2, "name", &rdn->value) != 0) { + return -1; + } + + attribute = rdn_name_find_attribute(msg2, "name"); + if (!attribute) { + return -1; + } + + attribute->flags = LDB_FLAG_MOD_REPLACE; + + ret = ldb_next_modify_record(module, msg2); + talloc_free(msg2); + + return ret; +} + +static int rdn_name_delete_record(struct ldb_module *module, const char *dn) +{ + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_delete_record\n"); + return ldb_next_delete_record(module, dn); +} + +static int rdn_name_rename_record(struct ldb_module *module, const char *olddn, const char *newdn) +{ + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_rename_record\n"); + return ldb_next_rename_record(module, olddn, newdn); +} + +static int rdn_name_lock(struct ldb_module *module, const char *lockname) +{ + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_lock\n"); + return ldb_next_named_lock(module, lockname); +} + +static int rdn_name_unlock(struct ldb_module *module, const char *lockname) +{ + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_unlock\n"); + return ldb_next_named_unlock(module, lockname); +} + +/* return extended error information */ +static const char *rdn_name_errstring(struct ldb_module *module) +{ + struct private_data *data = (struct private_data *)module->private_data; + + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_errstring\n"); + if (data->error_string) { + const char *error; + + error = data->error_string; + data->error_string = NULL; + return error; + } + + return ldb_next_errstring(module); +} + +static int rdn_name_destructor(void *module_ctx) +{ + /* struct ldb_module *ctx = module_ctx; */ + /* put your clean-up functions here */ + return 0; +} + +static const struct ldb_module_ops rdn_name_ops = { + .name = "rdn_name", + .search = rdn_name_search, + .search_bytree = rdn_name_search_bytree, + .add_record = rdn_name_add_record, + .modify_record = rdn_name_modify_record, + .delete_record = rdn_name_delete_record, + .rename_record = rdn_name_rename_record, + .named_lock = rdn_name_lock, + .named_unlock = rdn_name_unlock, + .errstring = rdn_name_errstring +}; + + +/* the init function */ +#ifdef HAVE_DLOPEN_DISABLED + struct ldb_module *init_module(struct ldb_context *ldb, const char *options[]) +#else +struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *options[]) +#endif +{ + struct ldb_module *ctx; + struct private_data *data; + + ctx = talloc(ldb, struct ldb_module); + if (!ctx) + return NULL; + + data = talloc(ctx, struct private_data); + if (!data) { + talloc_free(ctx); + return NULL; + } + + data->error_string = NULL; + ctx->private_data = data; + ctx->ldb = ldb; + ctx->prev = ctx->next = NULL; + ctx->ops = &rdn_name_ops; + + talloc_set_destructor (ctx, rdn_name_destructor); + + return ctx; +} -- cgit From a7f9d9c5b8e77e0530ace68bd2ed4a7c374bf0fa Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 25 Jul 2005 01:17:09 +0000 Subject: r8740: Extend the rdn_name module to handle adding the rdn as an attribute. ie: dn: cn=foo,ou=bar objectClass: person implies dn: cn=foo,ou=bar objectClass: person cn: foo (as well as a pile more default attributes) We also correct the case in the attirbute to match that in the DN (win2k3 behaviour) and I have a testsuite (in ejs) to prove it. This module also found a bug in our provision.ldif, so and reduces code complexity in the samdb module. Andrew Bartlett (This used to be commit 0cc58f5c3cce12341ad0f7a90cdd85a3fab786b3) --- source4/lib/ldb/modules/rdn_name.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 6a11ab87fe..89cc49eb3e 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -88,10 +88,12 @@ static struct ldb_dn_component *get_rdn(void *mem_ctx, const char *dn) /* add_record: add crateTimestamp/modifyTimestamp attributes */ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_message *msg) { + struct private_data *data = (struct private_data *)module->private_data; + struct ldb_message *msg2; struct ldb_message_element *attribute; struct ldb_dn_component *rdn; - int ret, i; + int i, ret; ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_add_record\n"); @@ -126,6 +128,29 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa return -1; } + attribute = rdn_name_find_attribute(msg2, rdn->name); + + if (!attribute) { + if (ldb_msg_add_value(module->ldb, msg2, rdn->name, &rdn->value) != 0) { + return -1; + } + } else { + const struct ldb_attrib_handler *handler + = ldb_attrib_handler(module->ldb, rdn->name); + for (i=0; i < attribute->num_values; i++) { + if (handler->comparison_fn(module->ldb, msg2, &rdn->value, &attribute->values[i]) == 0) { + /* overwrite so it matches in case */ + attribute->values[i] = rdn->value; + break; + } + } + if (i == attribute->num_values) { + data->error_string = talloc_asprintf(data, "RDN mismatch on %s: %s", msg2->dn, rdn->name); + ldb_debug(module->ldb, LDB_DEBUG_FATAL, "%s\n", data->error_string); + return -1; + } + } + ret = ldb_next_add_record(module, msg2); talloc_free(msg2); -- cgit From 3e4c4cff2177af33efdb15f03a1bbcb639505cee Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 18 Aug 2005 15:02:01 +0000 Subject: r9391: Convert all the code to use struct ldb_dn to ohandle ldap like distinguished names Provide more functions to handle DNs in this form (This used to be commit 692e35b7797e39533dd2a1c4b63d9da30f1eb5ba) --- source4/lib/ldb/modules/rdn_name.c | 44 ++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 23 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 89cc49eb3e..d59205c6e4 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -41,7 +41,7 @@ struct private_data { const char *error_string; }; -static int rdn_name_search(struct ldb_module *module, const char *base, +static int rdn_name_search(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, const char *expression, const char * const *attrs, struct ldb_message ***res) { @@ -49,7 +49,7 @@ static int rdn_name_search(struct ldb_module *module, const char *base, return ldb_next_search(module, base, scope, expression, attrs, res); } -static int rdn_name_search_bytree(struct ldb_module *module, const char *base, +static int rdn_name_search_bytree(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, struct ldb_parse_tree *tree, const char * const *attrs, struct ldb_message ***res) { @@ -70,21 +70,6 @@ static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_mess return NULL; } -static struct ldb_dn_component *get_rdn(void *mem_ctx, const char *dn) -{ - struct ldb_dn *dn_exploded = ldb_dn_explode(mem_ctx, dn); - - if (!dn_exploded) { - return NULL; - } - - if (dn_exploded->comp_num < 1) { - return NULL; - } - - return &dn_exploded->components[0]; -} - /* add_record: add crateTimestamp/modifyTimestamp attributes */ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_message *msg) { @@ -97,7 +82,8 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_add_record\n"); - if (msg->dn[0] == '@') { /* do not manipulate our control entries */ + /* do not manipulate our control entries */ + if (ldb_dn_is_special(msg->dn)) { return ldb_next_add_record(module, msg); } @@ -119,12 +105,14 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa msg2->elements[i] = msg->elements[i]; } - rdn = get_rdn(msg2, msg2->dn); + rdn = ldb_dn_get_rdn(msg2, msg2->dn); if (!rdn) { + talloc_free(msg2); return -1; } if (ldb_msg_add_value(module->ldb, msg2, "name", &rdn->value) != 0) { + talloc_free(msg2); return -1; } @@ -132,6 +120,7 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa if (!attribute) { if (ldb_msg_add_value(module->ldb, msg2, rdn->name, &rdn->value) != 0) { + talloc_free(msg2); return -1; } } else { @@ -145,8 +134,9 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa } } if (i == attribute->num_values) { - data->error_string = talloc_asprintf(data, "RDN mismatch on %s: %s", msg2->dn, rdn->name); + data->error_string = talloc_asprintf(data, "RDN mismatch on %s: %s", ldb_dn_linearize(msg2, msg2->dn), rdn->name); ldb_debug(module->ldb, LDB_DEBUG_FATAL, "%s\n", data->error_string); + talloc_free(msg2); return -1; } } @@ -167,6 +157,11 @@ static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_me ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_modify_record\n"); + /* do not manipulate our control entries */ + if (ldb_dn_is_special(msg->dn)) { + return ldb_next_add_record(module, msg); + } + /* Perhaps someone above us knows better */ if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { return ldb_next_add_record(module, msg); @@ -185,17 +180,20 @@ static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_me msg2->elements[i] = msg->elements[i]; } - rdn = get_rdn(msg2, msg2->dn); + rdn = ldb_dn_get_rdn(msg2, msg2->dn); if (!rdn) { + talloc_free(msg2); return -1; } if (ldb_msg_add_value(module->ldb, msg2, "name", &rdn->value) != 0) { + talloc_free(msg2); return -1; } attribute = rdn_name_find_attribute(msg2, "name"); if (!attribute) { + talloc_free(msg2); return -1; } @@ -207,13 +205,13 @@ static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_me return ret; } -static int rdn_name_delete_record(struct ldb_module *module, const char *dn) +static int rdn_name_delete_record(struct ldb_module *module, const struct ldb_dn *dn) { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_delete_record\n"); return ldb_next_delete_record(module, dn); } -static int rdn_name_rename_record(struct ldb_module *module, const char *olddn, const char *newdn) +static int rdn_name_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_rename_record\n"); return ldb_next_rename_record(module, olddn, newdn); -- cgit From f14f4fd7068e0ce55350c713d1925680876606bb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 1 Sep 2005 21:32:43 +0000 Subject: r9918: Fix two copy-n-paste bugs that were preventing the modification of special DN's when the rdn_name or timestamps modules were in use. (This used to be commit c61efb2ff851f8f55b4747c8068c7e780083e35c) --- source4/lib/ldb/modules/rdn_name.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index d59205c6e4..09e9c72811 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -159,12 +159,12 @@ static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_me /* do not manipulate our control entries */ if (ldb_dn_is_special(msg->dn)) { - return ldb_next_add_record(module, msg); + return ldb_next_modify_record(module, msg); } /* Perhaps someone above us knows better */ if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { - return ldb_next_add_record(module, msg); + return ldb_next_modify_record(module, msg); } msg2 = talloc(module, struct ldb_message); -- cgit From 8919d6bf9a88ce9ac43dae61989c33082c984b66 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 17 Sep 2005 19:25:50 +0000 Subject: r10299: remove the public (un)lock functions and introduce a transaction based private ldb API ldb_sqlite3 is already working with this model and ldb_tdb will do as soon as tridge finishes the tdb transaction code. currently the transactions are always implicit and wrap any single ldb API call except searching, the transaction functions are currently not made public on purpose. Simo. (This used to be commit 1da4ac2cdcb7e54076f85242a93784260dced918) --- source4/lib/ldb/modules/rdn_name.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 09e9c72811..ed5400176c 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -217,16 +217,16 @@ static int rdn_name_rename_record(struct ldb_module *module, const struct ldb_dn return ldb_next_rename_record(module, olddn, newdn); } -static int rdn_name_lock(struct ldb_module *module, const char *lockname) +static int rdn_start_trans(struct ldb_module *module) { - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_lock\n"); - return ldb_next_named_lock(module, lockname); + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_start_trans\n"); + return ldb_next_start_trans(module); } -static int rdn_name_unlock(struct ldb_module *module, const char *lockname) +static int rdn_end_trans(struct ldb_module *module, int status) { - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_unlock\n"); - return ldb_next_named_unlock(module, lockname); + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_end_trans\n"); + return ldb_next_end_trans(module, status); } /* return extended error information */ @@ -254,16 +254,16 @@ static int rdn_name_destructor(void *module_ctx) } static const struct ldb_module_ops rdn_name_ops = { - .name = "rdn_name", - .search = rdn_name_search, - .search_bytree = rdn_name_search_bytree, - .add_record = rdn_name_add_record, - .modify_record = rdn_name_modify_record, - .delete_record = rdn_name_delete_record, - .rename_record = rdn_name_rename_record, - .named_lock = rdn_name_lock, - .named_unlock = rdn_name_unlock, - .errstring = rdn_name_errstring + .name = "rdn_name", + .search = rdn_name_search, + .search_bytree = rdn_name_search_bytree, + .add_record = rdn_name_add_record, + .modify_record = rdn_name_modify_record, + .delete_record = rdn_name_delete_record, + .rename_record = rdn_name_rename_record, + .start_transaction = rdn_start_trans, + .end_transaction = rdn_end_trans, + .errstring = rdn_name_errstring }; -- cgit From 16aff2a184f7fab64d718b356056070e305e99e9 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 18 Sep 2005 18:49:06 +0000 Subject: r10305: start implementing better error handling changed the prioivate modules API error string are now not spread over all modules but are kept in a single place. This allows a better control of memory and error reporting. (This used to be commit 3fc676ac1d6f59d08bedbbd9377986154cf84ce4) --- source4/lib/ldb/modules/rdn_name.c | 43 +++++++------------------------------- 1 file changed, 7 insertions(+), 36 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index ed5400176c..c1a0c0852a 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -37,10 +37,6 @@ #include "ldb/include/ldb_private.h" #include -struct private_data { - const char *error_string; -}; - static int rdn_name_search(struct ldb_module *module, const struct ldb_dn *base, enum ldb_scope scope, const char *expression, const char * const *attrs, struct ldb_message ***res) @@ -73,8 +69,6 @@ static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_mess /* add_record: add crateTimestamp/modifyTimestamp attributes */ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_message *msg) { - struct private_data *data = (struct private_data *)module->private_data; - struct ldb_message *msg2; struct ldb_message_element *attribute; struct ldb_dn_component *rdn; @@ -134,8 +128,11 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa } } if (i == attribute->num_values) { - data->error_string = talloc_asprintf(data, "RDN mismatch on %s: %s", ldb_dn_linearize(msg2, msg2->dn), rdn->name); - ldb_debug(module->ldb, LDB_DEBUG_FATAL, "%s\n", data->error_string); + char *error_string = talloc_asprintf(module, "RDN mismatch on %s: %s", ldb_dn_linearize(msg2, msg2->dn), rdn->name); + if (error_string) { + ldb_set_errstring(module, error_string); + ldb_debug(module->ldb, LDB_DEBUG_FATAL, "%s\n", error_string); + } talloc_free(msg2); return -1; } @@ -229,23 +226,6 @@ static int rdn_end_trans(struct ldb_module *module, int status) return ldb_next_end_trans(module, status); } -/* return extended error information */ -static const char *rdn_name_errstring(struct ldb_module *module) -{ - struct private_data *data = (struct private_data *)module->private_data; - - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_errstring\n"); - if (data->error_string) { - const char *error; - - error = data->error_string; - data->error_string = NULL; - return error; - } - - return ldb_next_errstring(module); -} - static int rdn_name_destructor(void *module_ctx) { /* struct ldb_module *ctx = module_ctx; */ @@ -262,8 +242,7 @@ static const struct ldb_module_ops rdn_name_ops = { .delete_record = rdn_name_delete_record, .rename_record = rdn_name_rename_record, .start_transaction = rdn_start_trans, - .end_transaction = rdn_end_trans, - .errstring = rdn_name_errstring + .end_transaction = rdn_end_trans }; @@ -275,20 +254,12 @@ struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *opt #endif { struct ldb_module *ctx; - struct private_data *data; ctx = talloc(ldb, struct ldb_module); if (!ctx) return NULL; - data = talloc(ctx, struct private_data); - if (!data) { - talloc_free(ctx); - return NULL; - } - - data->error_string = NULL; - ctx->private_data = data; + ctx->private_data = NULL; ctx->ldb = ldb; ctx->prev = ctx->next = NULL; ctx->ops = &rdn_name_ops; -- cgit From 63b43dd12fb579aaaccedd07aaa630cb1cd7aa88 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 24 Sep 2005 15:42:15 +0000 Subject: r10477: expose transactions outside ldb and change the API once more do not autostart transactions on ldb operations if a transaction is already in place test transactions on winsdb all my tests passes so far tridge please confirm this is ok for you (This used to be commit c2bb2a36bdbe0ec7519697a9a9ba7526a0defac2) --- source4/lib/ldb/modules/rdn_name.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index c1a0c0852a..3e3fbd544f 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -220,10 +220,16 @@ static int rdn_start_trans(struct ldb_module *module) return ldb_next_start_trans(module); } -static int rdn_end_trans(struct ldb_module *module, int status) +static int rdn_end_trans(struct ldb_module *module) { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_end_trans\n"); - return ldb_next_end_trans(module, status); + return ldb_next_end_trans(module); +} + +static int rdn_del_trans(struct ldb_module *module) +{ + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_del_trans\n"); + return ldb_next_del_trans(module); } static int rdn_name_destructor(void *module_ctx) @@ -242,7 +248,8 @@ static const struct ldb_module_ops rdn_name_ops = { .delete_record = rdn_name_delete_record, .rename_record = rdn_name_rename_record, .start_transaction = rdn_start_trans, - .end_transaction = rdn_end_trans + .end_transaction = rdn_end_trans, + .del_transaction = rdn_del_trans }; -- cgit From 5fd031c97daaa1bf09a7ad80550753acd434075f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Oct 2005 05:24:46 +0000 Subject: r10753: don't require every ldb module to implement both a search_bytree() and a search() function, instead each module now only implements the bytree method, and the expression based search is handled generically by the modules code. This makes for more consistency and less code duplication. fixed the tdb backend to handle BASE searches much more efficiently. They now always only lookup one record, regardless of the search expression (This used to be commit 7e44f9153c5578624e2fca04cdc0a00af0fd9eb4) --- source4/lib/ldb/modules/rdn_name.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 3e3fbd544f..0275952780 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -37,17 +37,9 @@ #include "ldb/include/ldb_private.h" #include -static int rdn_name_search(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, const char *expression, - const char * const *attrs, struct ldb_message ***res) -{ - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_search\n"); - return ldb_next_search(module, base, scope, expression, attrs, res); -} - static int rdn_name_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_message ***res) + enum ldb_scope scope, struct ldb_parse_tree *tree, + const char * const *attrs, struct ldb_message ***res) { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_search\n"); return ldb_next_search_bytree(module, base, scope, tree, attrs, res); @@ -241,7 +233,6 @@ static int rdn_name_destructor(void *module_ctx) static const struct ldb_module_ops rdn_name_ops = { .name = "rdn_name", - .search = rdn_name_search, .search_bytree = rdn_name_search_bytree, .add_record = rdn_name_add_record, .modify_record = rdn_name_modify_record, -- cgit From 78d0e79c9f9263e7f3798aa2e174a347ea1a3df1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Oct 2005 06:57:09 +0000 Subject: r10759: make modules easier to write by allowing modules to only implement the functions they care about, instead of all functions. This also makes it more likely that future changes to ldb will not break existing modules (This used to be commit 45f0c967b58e7c1b2e900a4d74cfde2a2c527dfa) --- source4/lib/ldb/modules/rdn_name.c | 39 +------------------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 0275952780..40ff75744e 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -194,53 +194,18 @@ static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_me return ret; } -static int rdn_name_delete_record(struct ldb_module *module, const struct ldb_dn *dn) -{ - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_delete_record\n"); - return ldb_next_delete_record(module, dn); -} - static int rdn_name_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) { ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_rename_record\n"); return ldb_next_rename_record(module, olddn, newdn); } -static int rdn_start_trans(struct ldb_module *module) -{ - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_start_trans\n"); - return ldb_next_start_trans(module); -} - -static int rdn_end_trans(struct ldb_module *module) -{ - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_end_trans\n"); - return ldb_next_end_trans(module); -} - -static int rdn_del_trans(struct ldb_module *module) -{ - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_del_trans\n"); - return ldb_next_del_trans(module); -} - -static int rdn_name_destructor(void *module_ctx) -{ - /* struct ldb_module *ctx = module_ctx; */ - /* put your clean-up functions here */ - return 0; -} - static const struct ldb_module_ops rdn_name_ops = { .name = "rdn_name", .search_bytree = rdn_name_search_bytree, .add_record = rdn_name_add_record, .modify_record = rdn_name_modify_record, - .delete_record = rdn_name_delete_record, - .rename_record = rdn_name_rename_record, - .start_transaction = rdn_start_trans, - .end_transaction = rdn_end_trans, - .del_transaction = rdn_del_trans + .rename_record = rdn_name_rename_record }; @@ -262,7 +227,5 @@ struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *opt ctx->prev = ctx->next = NULL; ctx->ops = &rdn_name_ops; - talloc_set_destructor (ctx, rdn_name_destructor); - return ctx; } -- cgit From a599edf04cbdeef9014923ba0d3713b8ff84f266 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 12 Oct 2005 06:10:23 +0000 Subject: r10913: This patch isn't as big as it looks ... most of the changes are fixes to make all the ldb code compile without warnings on gcc4. Unfortunately That required a lot of casts :-( I have also added the start of an 'operational' module, which will replace the timestamp module, plus add support for some other operational attributes In ldb_msg_*() I added some new utility functions to make the operational module sane, and remove the 'ldb' argument from the ldb_msg_add_*() functions. That argument was only needed back in the early days of ldb when we didn't use the hierarchical talloc and thus needed a place to get the allocation function from. Now its just a pain to pass around everywhere. Also added a ldb_debug_set() function that calls ldb_debug() plus sets the result using ldb_set_errstring(). That saves on some awkward coding in a few places. (This used to be commit f6818daecca95760c12f79fd307770cbe3346f57) --- source4/lib/ldb/modules/rdn_name.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 40ff75744e..c8f2ebaabd 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -97,7 +97,7 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa return -1; } - if (ldb_msg_add_value(module->ldb, msg2, "name", &rdn->value) != 0) { + if (ldb_msg_add_value(msg2, "name", &rdn->value) != 0) { talloc_free(msg2); return -1; } @@ -105,7 +105,7 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa attribute = rdn_name_find_attribute(msg2, rdn->name); if (!attribute) { - if (ldb_msg_add_value(module->ldb, msg2, rdn->name, &rdn->value) != 0) { + if (ldb_msg_add_value(msg2, rdn->name, &rdn->value) != 0) { talloc_free(msg2); return -1; } @@ -175,7 +175,7 @@ static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_me return -1; } - if (ldb_msg_add_value(module->ldb, msg2, "name", &rdn->value) != 0) { + if (ldb_msg_add_value(msg2, "name", &rdn->value) != 0) { talloc_free(msg2); return -1; } -- cgit From 35720734911169acde6bf9f2c9a1f83336744f6f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 12 Oct 2005 07:57:39 +0000 Subject: r10916: - finished the 'operational' ldb module - removed the timestamps module, replacing it with the operational module - added a ldb_msg_copy_shallow() function which should be used when a module wants to add new elements to a message on add/modify. This is needed because the caller might be using a constant structure, or may want to re-use the structure again - enabled the UTC time attribute syntaxes in the operational module (This used to be commit 61e8b010223ac6a0573185008f3719ba29574688) --- source4/lib/ldb/modules/rdn_name.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index c8f2ebaabd..c51aa74244 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -120,11 +120,9 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa } } if (i == attribute->num_values) { - char *error_string = talloc_asprintf(module, "RDN mismatch on %s: %s", ldb_dn_linearize(msg2, msg2->dn), rdn->name); - if (error_string) { - ldb_set_errstring(module, error_string); - ldb_debug(module->ldb, LDB_DEBUG_FATAL, "%s\n", error_string); - } + ldb_debug_set(module->ldb, LDB_DEBUG_FATAL, + "RDN mismatch on %s: %s", + ldb_dn_linearize(msg2, msg2->dn), rdn->name); talloc_free(msg2); return -1; } -- cgit From 5c9590587197dcb95007fdc54318187d5716c7c6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 8 Nov 2005 00:11:45 +0000 Subject: r11567: Ldb API change patch. This patch changes the way lsb_search is called and the meaning of the returned integer. The last argument of ldb_search is changed from struct ldb_message to struct ldb_result which contains a pointer to a struct ldb_message list and a count of the number of messages. The return is not the count of messages anymore but instead it is an ldb error value. I tryed to keep the patch as tiny as possible bu as you can guess I had to change a good amount of places. I also tried to double check all my changes being sure that the calling functions would still behave as before. But this patch is big enough that I fear some bug may have been introduced anyway even if it passes the test suite. So if you are currently working on any file being touched please give it a deep look and blame me for any error. Simo. (This used to be commit 22c8c97e6fb466b41859e090e959d7f1134be780) --- source4/lib/ldb/modules/rdn_name.c | 56 +++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 25 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index c51aa74244..42faf6629c 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -37,14 +37,6 @@ #include "ldb/include/ldb_private.h" #include -static int rdn_name_search_bytree(struct ldb_module *module, const struct ldb_dn *base, - enum ldb_scope scope, struct ldb_parse_tree *tree, - const char * const *attrs, struct ldb_message ***res) -{ - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_search\n"); - return ldb_next_search_bytree(module, base, scope, tree, attrs, res); -} - static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_message *msg, const char *name) { int i; @@ -58,9 +50,9 @@ static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_mess return NULL; } -/* add_record: add crateTimestamp/modifyTimestamp attributes */ -static int rdn_name_add_record(struct ldb_module *module, const struct ldb_message *msg) +static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_message *msg = req->op.add.message; struct ldb_message *msg2; struct ldb_message_element *attribute; struct ldb_dn_component *rdn; @@ -70,12 +62,12 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa /* do not manipulate our control entries */ if (ldb_dn_is_special(msg->dn)) { - return ldb_next_add_record(module, msg); + return ldb_next_request(module, req); } /* Perhaps someone above us knows better */ if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { - return ldb_next_add_record(module, msg); + return ldb_next_request(module, req); } msg2 = talloc(module, struct ldb_message); @@ -128,15 +120,18 @@ static int rdn_name_add_record(struct ldb_module *module, const struct ldb_messa } } - ret = ldb_next_add_record(module, msg2); + req->op.add.message = msg2; + ret = ldb_next_request(module, req); + req->op.add.message = msg; + talloc_free(msg2); return ret; } -/* modify_record: change modifyTimestamp as well */ -static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_message *msg) +static int rdn_name_modify(struct ldb_module *module, struct ldb_request *req) { + const struct ldb_message *msg = req->op.mod.message; struct ldb_message *msg2; struct ldb_message_element *attribute; struct ldb_dn_component *rdn; @@ -146,12 +141,12 @@ static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_me /* do not manipulate our control entries */ if (ldb_dn_is_special(msg->dn)) { - return ldb_next_modify_record(module, msg); + return ldb_next_request(module, req); } /* Perhaps someone above us knows better */ if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { - return ldb_next_modify_record(module, msg); + return ldb_next_request(module, req); } msg2 = talloc(module, struct ldb_message); @@ -186,24 +181,35 @@ static int rdn_name_modify_record(struct ldb_module *module, const struct ldb_me attribute->flags = LDB_FLAG_MOD_REPLACE; - ret = ldb_next_modify_record(module, msg2); + req->op.add.message = msg2; + ret = ldb_next_request(module, req); + req->op.add.message = msg; + talloc_free(msg2); return ret; } -static int rdn_name_rename_record(struct ldb_module *module, const struct ldb_dn *olddn, const struct ldb_dn *newdn) +static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) { - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_rename_record\n"); - return ldb_next_rename_record(module, olddn, newdn); + switch (req->operation) { + + case LDB_REQ_ADD: + return rdn_name_add(module, req); + + case LDB_REQ_MODIFY: + return rdn_name_modify(module, req); + + + default: + return ldb_next_request(module, req); + + } } static const struct ldb_module_ops rdn_name_ops = { .name = "rdn_name", - .search_bytree = rdn_name_search_bytree, - .add_record = rdn_name_add_record, - .modify_record = rdn_name_modify_record, - .rename_record = rdn_name_rename_record + .request = rdn_name_request }; -- cgit From 3b99d9c5bd563203adc4b017d6e6599dd84b8d57 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 1 Jan 2006 17:32:10 +0000 Subject: r12658: Couple of fixes related to shared module builds. (This used to be commit c297c93faf3b748de68679f5a4be50845ebe25fe) --- source4/lib/ldb/modules/rdn_name.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 42faf6629c..f35cff916c 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -214,11 +214,7 @@ static const struct ldb_module_ops rdn_name_ops = { /* the init function */ -#ifdef HAVE_DLOPEN_DISABLED - struct ldb_module *init_module(struct ldb_context *ldb, const char *options[]) -#else struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *options[]) -#endif { struct ldb_module *ctx; -- cgit From c908d0b2aa111659e57a73efb8c33c413965c846 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 04:01:23 +0000 Subject: r12733: Merge ldap/ldb controls into main tree There's still lot of work to do but the patch is stable enough to be pushed into the main samba4 tree. Simo. (This used to be commit 77125feaff252cab44d26593093a9c211c846ce8) --- source4/lib/ldb/modules/rdn_name.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index f35cff916c..f6dbc38740 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -214,10 +214,12 @@ static const struct ldb_module_ops rdn_name_ops = { /* the init function */ -struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *options[]) +struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, int stage, const char *options[]) { struct ldb_module *ctx; + if (stage != LDB_MODULES_INIT_STAGE_1) return NULL; + ctx = talloc(ldb, struct ldb_module); if (!ctx) return NULL; -- cgit From dbef4d76de92c3388f4e1819a76d6febf90be290 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 6 Jan 2006 16:12:45 +0000 Subject: r12743: Remove the ugly way we had to make a second stage init and introduce a second_stage_init private function for modules that need a second stage init. Simo. (This used to be commit 5e8b365fa2d93801a5de1d9ea76ce9d5546bd248) --- source4/lib/ldb/modules/rdn_name.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index f6dbc38740..f35cff916c 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -214,12 +214,10 @@ static const struct ldb_module_ops rdn_name_ops = { /* the init function */ -struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, int stage, const char *options[]) +struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *options[]) { struct ldb_module *ctx; - if (stage != LDB_MODULES_INIT_STAGE_1) return NULL; - ctx = talloc(ldb, struct ldb_module); if (!ctx) return NULL; -- cgit From 4d1c5a023cf6680474bd8d8be73f576d155cfe81 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 10 Jan 2006 16:48:32 +0000 Subject: r12829: fix ldb headers, to not include '<...>' files in .c files this helps in getting symbol -fvisibility=hidden (GCC 4 feature) working later. metze (This used to be commit 380938e97f31c7860aed1e73cc0110c6e17b472e) --- source4/lib/ldb/modules/rdn_name.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index f35cff916c..1ac404bea6 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -33,9 +33,7 @@ */ #include "includes.h" -#include "ldb/include/ldb.h" -#include "ldb/include/ldb_private.h" -#include +#include "ldb/include/includes.h" static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_message *msg, const char *name) { -- cgit From 2a187c94f05ab6e1c1dd8db4d04b422d8bb132b4 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 18 Jan 2006 11:21:52 +0000 Subject: r12995: Don't allow overrides on "name" from above, as it can't be correct. Andrew Bartlett (This used to be commit 4a50bf95b93310f640a4ba28990f054e85215551) --- source4/lib/ldb/modules/rdn_name.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 1ac404bea6..2e4e250755 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -63,11 +63,6 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) return ldb_next_request(module, req); } - /* Perhaps someone above us knows better */ - if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { - return ldb_next_request(module, req); - } - msg2 = talloc(module, struct ldb_message); if (!msg2) { return -1; @@ -87,6 +82,11 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) return -1; } + /* Perhaps someone above us tried to set this? */ + if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { + attribute->num_values = 0; + } + if (ldb_msg_add_value(msg2, "name", &rdn->value) != 0) { talloc_free(msg2); return -1; -- cgit From 26af14c39b88b0e7eb53657b89be65d865804688 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 2 Mar 2006 16:32:53 +0000 Subject: r13786: [merge] Add registration functions for LDB modules Applications that use LDB modules will now have to run ldb_global_init() before they can use LDB. The next step will be adding support for loading LDB modules from .so files. This will also allow us to use one LDB without difference between the standalone and the Samba-specific build (This used to be commit 52a235650514039bf8ffee99a784bbc1b6ae6b92) --- source4/lib/ldb/modules/rdn_name.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 2e4e250755..59930046ce 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -211,19 +211,7 @@ static const struct ldb_module_ops rdn_name_ops = { }; -/* the init function */ -struct ldb_module *rdn_name_module_init(struct ldb_context *ldb, const char *options[]) +int ldb_rdn_name_init(void) { - struct ldb_module *ctx; - - ctx = talloc(ldb, struct ldb_module); - if (!ctx) - return NULL; - - ctx->private_data = NULL; - ctx->ldb = ldb; - ctx->prev = ctx->next = NULL; - ctx->ops = &rdn_name_ops; - - return ctx; + return ldb_register_module(&rdn_name_ops); } -- cgit From 2d774763f095cdf9d72ee6efc69755404f380890 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 14 Mar 2006 17:39:58 +0000 Subject: r14391: rdn_name -> async (This used to be commit 0bc3caa9187e992b09bf797e7de507cca9734ab2) --- source4/lib/ldb/modules/rdn_name.c | 179 +++++++++++++++++++++++++++++++++++-- 1 file changed, 174 insertions(+), 5 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 59930046ce..24e3430254 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -1,7 +1,8 @@ /* ldb database library - Copyright (C) Simo Sorce 2004 + Copyright (C) Andrew Bartlet 2005 + Copyright (C) Simo Sorce 2006 ** NOTE! The following LGPL license applies to the ldb ** library. This does NOT imply that all of Samba is released @@ -23,13 +24,17 @@ */ /* - * Name: ldb + * Name: rdb_name * - * Component: ldb objectguid module + * Component: ldb rdn name module * - * Description: add a unique objectGUID onto every new record + * Description: keep a consistent name attribute on objects manpulations * - * Author: Simo Sorce + * Author: Andrew Bartlet + * + * Modifications: + * - made the module async + * Simo Sorce Mar 2006 */ #include "includes.h" @@ -188,6 +193,165 @@ static int rdn_name_modify(struct ldb_module *module, struct ldb_request *req) return ret; } +static int rdn_name_add_async(struct ldb_module *module, struct ldb_request *req) +{ + struct ldb_request *down_req; + struct ldb_message *msg; + struct ldb_message_element *attribute; + struct ldb_dn_component *rdn; + int i, ret; + + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_add_record\n"); + + /* do not manipulate our control entries */ + if (ldb_dn_is_special(req->op.add.message->dn)) { + return ldb_next_request(module, req); + } + + down_req = talloc(module, struct ldb_request); + if (down_req == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + msg = ldb_msg_copy_shallow(down_req, req->op.add.message); + if (msg == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + rdn = ldb_dn_get_rdn(msg, msg->dn); + if (rdn == NULL) { + talloc_free(down_req); + return LDB_ERR_OPERATIONS_ERROR; + } + + /* Perhaps someone above us tried to set this? */ + if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { + attribute->num_values = 0; + } + + if (ldb_msg_add_value(msg, "name", &rdn->value) != 0) { + talloc_free(down_req); + return LDB_ERR_OPERATIONS_ERROR; + } + + attribute = rdn_name_find_attribute(msg, rdn->name); + + if (!attribute) { + if (ldb_msg_add_value(msg, rdn->name, &rdn->value) != 0) { + talloc_free(down_req); + return LDB_ERR_OPERATIONS_ERROR; + } + } else { + const struct ldb_attrib_handler *handler = ldb_attrib_handler(module->ldb, rdn->name); + + for (i = 0; i < attribute->num_values; i++) { + if (handler->comparison_fn(module->ldb, msg, &rdn->value, &attribute->values[i]) == 0) { + /* overwrite so it matches in case */ + attribute->values[i] = rdn->value; + break; + } + } + if (i == attribute->num_values) { + ldb_debug_set(module->ldb, LDB_DEBUG_FATAL, + "RDN mismatch on %s: %s", + ldb_dn_linearize(msg, msg->dn), rdn->name); + talloc_free(down_req); + return LDB_ERR_OPERATIONS_ERROR; + } + } + + down_req->op.add.message = msg; + + down_req->controls = req->controls; + down_req->creds = req->creds; + + down_req->async.context = req->async.context; + down_req->async.callback = req->async.callback; + down_req->async.timeout = req->async.timeout; + + /* go on with the call chain */ + ret = ldb_next_request(module, down_req); + + /* do not free down_req as the call results may be linked to it, + * it will be freed when the upper level request get freed */ + if (ret == LDB_SUCCESS) { + req->async.handle = down_req->async.handle; + } + + return ret; +} + +static int rdn_name_modify_async(struct ldb_module *module, struct ldb_request *req) +{ + struct ldb_request *down_req; + struct ldb_message *msg; + struct ldb_message_element *attribute; + struct ldb_dn_component *rdn; + int ret; + + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_modify_record\n"); + + /* do not manipulate our control entries */ + if (ldb_dn_is_special(req->op.mod.message->dn)) { + return ldb_next_request(module, req); + } + + /* Perhaps someone above us knows better */ + if ((attribute = rdn_name_find_attribute(req->op.mod.message, "name")) != NULL ) { + return ldb_next_request(module, req); + } + + /* FIXME: are we sure we wont to change "name" on each and every modify operation ?? */ + down_req = talloc(module, struct ldb_request); + if (down_req == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + msg = ldb_msg_copy_shallow(down_req, req->op.add.message); + if (msg == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + rdn = ldb_dn_get_rdn(msg, msg->dn); + if (rdn == NULL) { + talloc_free(down_req); + return LDB_ERR_OPERATIONS_ERROR; + } + + if (ldb_msg_add_value(msg, "name", &rdn->value) != 0) { + talloc_free(down_req); + return LDB_ERR_OPERATIONS_ERROR; + } + + attribute = rdn_name_find_attribute(msg, "name"); + if (!attribute) { + talloc_free(down_req); + return LDB_ERR_OPERATIONS_ERROR; + } + + attribute->flags = LDB_FLAG_MOD_REPLACE; + + down_req->op.add.message = msg; + + down_req->controls = req->controls; + down_req->creds = req->creds; + + down_req->async.context = req->async.context; + down_req->async.callback = req->async.callback; + down_req->async.timeout = req->async.timeout; + + /* go on with the call chain */ + ret = ldb_next_request(module, down_req); + + /* do not free down_req as the call results may be linked to it, + * it will be freed when the upper level request get freed */ + if (ret == LDB_SUCCESS) { + req->async.handle = down_req->async.handle; + } + + return ret; +} + static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) { switch (req->operation) { @@ -198,6 +362,11 @@ static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) case LDB_REQ_MODIFY: return rdn_name_modify(module, req); + case LDB_ASYNC_ADD: + return rdn_name_add_async(module, req); + + case LDB_ASYNC_MODIFY: + return rdn_name_modify_async(module, req); default: return ldb_next_request(module, req); -- cgit From 5e3bb665cad17395f360f83fa1cf0692528c3239 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 20 May 2006 19:38:01 +0000 Subject: r15762: It make no sense for rdn_name to implement modify, it will need to implement rename ... (This used to be commit bf260f2a84f9c1f749798068168a22c86ab2e7b2) --- source4/lib/ldb/modules/rdn_name.c | 138 ------------------------------------- 1 file changed, 138 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 24e3430254..4f0b11cd51 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -132,67 +132,6 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) return ret; } -static int rdn_name_modify(struct ldb_module *module, struct ldb_request *req) -{ - const struct ldb_message *msg = req->op.mod.message; - struct ldb_message *msg2; - struct ldb_message_element *attribute; - struct ldb_dn_component *rdn; - int ret, i; - - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_modify_record\n"); - - /* do not manipulate our control entries */ - if (ldb_dn_is_special(msg->dn)) { - return ldb_next_request(module, req); - } - - /* Perhaps someone above us knows better */ - if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { - return ldb_next_request(module, req); - } - - msg2 = talloc(module, struct ldb_message); - if (!msg2) { - return -1; - } - - msg2->dn = msg->dn; - msg2->num_elements = msg->num_elements; - msg2->private_data = msg->private_data; - msg2->elements = talloc_array(msg2, struct ldb_message_element, msg2->num_elements); - for (i = 0; i < msg2->num_elements; i++) { - msg2->elements[i] = msg->elements[i]; - } - - rdn = ldb_dn_get_rdn(msg2, msg2->dn); - if (!rdn) { - talloc_free(msg2); - return -1; - } - - if (ldb_msg_add_value(msg2, "name", &rdn->value) != 0) { - talloc_free(msg2); - return -1; - } - - attribute = rdn_name_find_attribute(msg2, "name"); - if (!attribute) { - talloc_free(msg2); - return -1; - } - - attribute->flags = LDB_FLAG_MOD_REPLACE; - - req->op.add.message = msg2; - ret = ldb_next_request(module, req); - req->op.add.message = msg; - - talloc_free(msg2); - - return ret; -} - static int rdn_name_add_async(struct ldb_module *module, struct ldb_request *req) { struct ldb_request *down_req; @@ -281,77 +220,6 @@ static int rdn_name_add_async(struct ldb_module *module, struct ldb_request *req return ret; } -static int rdn_name_modify_async(struct ldb_module *module, struct ldb_request *req) -{ - struct ldb_request *down_req; - struct ldb_message *msg; - struct ldb_message_element *attribute; - struct ldb_dn_component *rdn; - int ret; - - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_modify_record\n"); - - /* do not manipulate our control entries */ - if (ldb_dn_is_special(req->op.mod.message->dn)) { - return ldb_next_request(module, req); - } - - /* Perhaps someone above us knows better */ - if ((attribute = rdn_name_find_attribute(req->op.mod.message, "name")) != NULL ) { - return ldb_next_request(module, req); - } - - /* FIXME: are we sure we wont to change "name" on each and every modify operation ?? */ - down_req = talloc(module, struct ldb_request); - if (down_req == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - msg = ldb_msg_copy_shallow(down_req, req->op.add.message); - if (msg == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - - rdn = ldb_dn_get_rdn(msg, msg->dn); - if (rdn == NULL) { - talloc_free(down_req); - return LDB_ERR_OPERATIONS_ERROR; - } - - if (ldb_msg_add_value(msg, "name", &rdn->value) != 0) { - talloc_free(down_req); - return LDB_ERR_OPERATIONS_ERROR; - } - - attribute = rdn_name_find_attribute(msg, "name"); - if (!attribute) { - talloc_free(down_req); - return LDB_ERR_OPERATIONS_ERROR; - } - - attribute->flags = LDB_FLAG_MOD_REPLACE; - - down_req->op.add.message = msg; - - down_req->controls = req->controls; - down_req->creds = req->creds; - - down_req->async.context = req->async.context; - down_req->async.callback = req->async.callback; - down_req->async.timeout = req->async.timeout; - - /* go on with the call chain */ - ret = ldb_next_request(module, down_req); - - /* do not free down_req as the call results may be linked to it, - * it will be freed when the upper level request get freed */ - if (ret == LDB_SUCCESS) { - req->async.handle = down_req->async.handle; - } - - return ret; -} - static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) { switch (req->operation) { @@ -359,15 +227,9 @@ static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) case LDB_REQ_ADD: return rdn_name_add(module, req); - case LDB_REQ_MODIFY: - return rdn_name_modify(module, req); - case LDB_ASYNC_ADD: return rdn_name_add_async(module, req); - case LDB_ASYNC_MODIFY: - return rdn_name_modify_async(module, req); - default: return ldb_next_request(module, req); -- cgit From bc12d3bccc5617943ea866202f0507d11bebcd81 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 21 May 2006 21:24:11 +0000 Subject: r15786: another fix in rdn_name (This used to be commit 202ce2a947626f51467d5c87dfcdb73852282709) --- source4/lib/ldb/modules/rdn_name.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 4f0b11cd51..18ad625ee2 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -152,7 +152,9 @@ static int rdn_name_add_async(struct ldb_module *module, struct ldb_request *req return LDB_ERR_OPERATIONS_ERROR; } - msg = ldb_msg_copy_shallow(down_req, req->op.add.message); + *down_req = *req; + + down_req->op.add.message = msg = ldb_msg_copy_shallow(down_req, req->op.add.message); if (msg == NULL) { return LDB_ERR_OPERATIONS_ERROR; } @@ -199,15 +201,6 @@ static int rdn_name_add_async(struct ldb_module *module, struct ldb_request *req } } - down_req->op.add.message = msg; - - down_req->controls = req->controls; - down_req->creds = req->creds; - - down_req->async.context = req->async.context; - down_req->async.callback = req->async.callback; - down_req->async.timeout = req->async.timeout; - /* go on with the call chain */ ret = ldb_next_request(module, down_req); -- cgit From 90a5e19e03842b77fd7811965fb2603e552261bc Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 28 May 2006 02:10:44 +0000 Subject: r15913: Error passing in the async code is not in agood shape Start enhancing it and fix some problems with incorrect evalutaion of the codes Implement rdn rename (async only) (This used to be commit 6af1d738b9668d4f0eb6194ac0f84af9e73f8c2e) --- source4/lib/ldb/modules/rdn_name.c | 205 +++++++++++++++++++++++++++++++++++-- 1 file changed, 199 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 18ad625ee2..7ce6c29691 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -53,7 +53,7 @@ static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_mess return NULL; } -static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) +static int rdn_name_add_sync(struct ldb_module *module, struct ldb_request *req) { const struct ldb_message *msg = req->op.add.message; struct ldb_message *msg2; @@ -132,7 +132,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) return ret; } -static int rdn_name_add_async(struct ldb_module *module, struct ldb_request *req) +static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) { struct ldb_request *down_req; struct ldb_message *msg; @@ -147,7 +147,7 @@ static int rdn_name_add_async(struct ldb_module *module, struct ldb_request *req return ldb_next_request(module, req); } - down_req = talloc(module, struct ldb_request); + down_req = talloc(req, struct ldb_request); if (down_req == NULL) { return LDB_ERR_OPERATIONS_ERROR; } @@ -213,15 +213,207 @@ static int rdn_name_add_async(struct ldb_module *module, struct ldb_request *req return ret; } +struct rename_async_context { + + enum {RENAME_RENAME, RENAME_MODIFY} step; + struct ldb_request *orig_req; + struct ldb_request *down_req; + struct ldb_request *mod_req; +}; + +static int rdn_name_rename(struct ldb_module *module, struct ldb_request *req) +{ + struct ldb_async_handle *h; + struct rename_async_context *ac; + + ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_rename\n"); + + /* do not manipulate our control entries */ + if (ldb_dn_is_special(req->op.rename.newdn)) { + return ldb_next_request(module, req); + } + + h = talloc_zero(req, struct ldb_async_handle); + if (h == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + h->module = module; + + ac = talloc_zero(h, struct rename_async_context); + if (ac == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + h->private_data = (void *)ac; + + h->state = LDB_ASYNC_INIT; + h->status = LDB_SUCCESS; + + ac->orig_req = req; + ac->down_req = talloc(req, struct ldb_request); + if (ac->down_req == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + *(ac->down_req) = *req; + + ac->step = RENAME_RENAME; + + req->async.handle = h; + + /* rename first, modify "name" if rename is ok */ + return ldb_next_request(module, ac->down_req); +} + +static int rdn_name_rename_do_mod(struct ldb_async_handle *h) { + + struct rename_async_context *ac; + struct ldb_dn_component *rdn; + struct ldb_message *msg; + + ac = talloc_get_type(h->private_data, struct rename_async_context); + + rdn = ldb_dn_get_rdn(ac, ac->orig_req->op.rename.newdn); + if (rdn == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ac->mod_req = talloc_zero(ac, struct ldb_request); + + ac->mod_req->operation = LDB_ASYNC_MODIFY; + ac->mod_req->op.mod.message = msg = ldb_msg_new(ac->mod_req); + if (msg == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + msg->dn = ldb_dn_copy(msg, ac->orig_req->op.rename.newdn); + if (msg->dn == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + if (ldb_msg_add_empty(msg, rdn->name, LDB_FLAG_MOD_REPLACE) != 0) { + return LDB_ERR_OPERATIONS_ERROR; + } + if (ldb_msg_add_value(msg, rdn->name, &rdn->value) != 0) { + return LDB_ERR_OPERATIONS_ERROR; + } + if (ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_REPLACE) != 0) { + return LDB_ERR_OPERATIONS_ERROR; + } + if (ldb_msg_add_value(msg, "name", &rdn->value) != 0) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ac->mod_req->async.timeout = ac->orig_req->async.timeout; + + ac->step = RENAME_MODIFY; + + /* do the mod call */ + return ldb_next_request(h->module, ac->mod_req); +} + +static int rename_async_wait(struct ldb_async_handle *handle) +{ + struct rename_async_context *ac; + int ret; + + if (!handle || !handle->private_data) { + return LDB_ERR_OPERATIONS_ERROR; + } + + if (handle->state == LDB_ASYNC_DONE) { + return handle->status; + } + + handle->state = LDB_ASYNC_PENDING; + handle->status = LDB_SUCCESS; + + ac = talloc_get_type(handle->private_data, struct rename_async_context); + + switch(ac->step) { + case RENAME_RENAME: + ret = ldb_async_wait(ac->down_req->async.handle, LDB_WAIT_NONE); + if (ret != LDB_SUCCESS) { + handle->status = ret; + goto done; + } + if (ac->down_req->async.handle->status != LDB_SUCCESS) { + handle->status = ac->down_req->async.handle->status; + goto done; + } + + if (ac->down_req->async.handle->state != LDB_ASYNC_DONE) { + return LDB_SUCCESS; + } + + /* rename operation done */ + return rdn_name_rename_do_mod(handle); + + case RENAME_MODIFY: + ret = ldb_async_wait(ac->mod_req->async.handle, LDB_WAIT_NONE); + if (ret != LDB_SUCCESS) { + handle->status = ret; + goto done; + } + if (ac->mod_req->async.handle->status != LDB_SUCCESS) { + handle->status = ac->mod_req->async.handle->status; + goto done; + } + + if (ac->mod_req->async.handle->state != LDB_ASYNC_DONE) { + return LDB_SUCCESS; + } + + break; + + default: + ret = LDB_ERR_OPERATIONS_ERROR; + goto done; + } + + ret = LDB_SUCCESS; + +done: + handle->state = LDB_ASYNC_DONE; + return ret; +} + +static int rename_async_wait_all(struct ldb_async_handle *handle) { + + int ret; + + while (handle->state != LDB_ASYNC_DONE) { + ret = rename_async_wait(handle); + if (ret != LDB_SUCCESS) { + return ret; + } + } + + return handle->status; +} + +static int rdn_name_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +{ + if (type == LDB_WAIT_ALL) { + return rename_async_wait_all(handle); + } else { + return rename_async_wait(handle); + } +} + static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) { switch (req->operation) { case LDB_REQ_ADD: - return rdn_name_add(module, req); + return rdn_name_add_sync(module, req); case LDB_ASYNC_ADD: - return rdn_name_add_async(module, req); + return rdn_name_add(module, req); + + case LDB_ASYNC_RENAME: + return rdn_name_rename(module, req); default: return ldb_next_request(module, req); @@ -231,7 +423,8 @@ static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) static const struct ldb_module_ops rdn_name_ops = { .name = "rdn_name", - .request = rdn_name_request + .request = rdn_name_request, + .async_wait = rdn_name_async_wait }; -- cgit From 3a4d7eb2c08a06fac89c34d132f1c32751ce7ad5 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 29 May 2006 01:30:02 +0000 Subject: r15927: Optimize ldb module traverse while keeping the API intact. I was sick of jumping inot each module for each request, even the ones not handle by that module. (This used to be commit 7d65105e885a28584e8555453b90232c43a92bf7) --- source4/lib/ldb/modules/rdn_name.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 7ce6c29691..2004002e38 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -310,7 +310,7 @@ static int rdn_name_rename_do_mod(struct ldb_async_handle *h) { ac->step = RENAME_MODIFY; /* do the mod call */ - return ldb_next_request(h->module, ac->mod_req); + return ldb_request(h->module->ldb, ac->mod_req); } static int rename_async_wait(struct ldb_async_handle *handle) @@ -409,12 +409,6 @@ static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) case LDB_REQ_ADD: return rdn_name_add_sync(module, req); - case LDB_ASYNC_ADD: - return rdn_name_add(module, req); - - case LDB_ASYNC_RENAME: - return rdn_name_rename(module, req); - default: return ldb_next_request(module, req); @@ -423,6 +417,8 @@ static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) static const struct ldb_module_ops rdn_name_ops = { .name = "rdn_name", + .add = rdn_name_add, + .rename = rdn_name_rename, .request = rdn_name_request, .async_wait = rdn_name_async_wait }; -- cgit From 0c7b82e5f6063de4114de21cf854ac67346e31f6 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 29 May 2006 23:46:43 +0000 Subject: r15942: Remove the sync internal ldb calls altogether. This means that some modules have been disabled as well as they have not been ported to the async interface One of them is the ugly objectclass module. I hope that the change in samldb module will make the MMC happy without the need of this crappy module, we need proper handling in a decent schema module. proxy and ldb_map have also been disabled ldb_sqlite3 need to be ported as well (currenlty just broken). (This used to be commit 51083de795bdcbf649de926e86969adc20239b6d) --- source4/lib/ldb/modules/rdn_name.c | 93 -------------------------------------- 1 file changed, 93 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 2004002e38..059e7843cd 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -53,85 +53,6 @@ static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_mess return NULL; } -static int rdn_name_add_sync(struct ldb_module *module, struct ldb_request *req) -{ - const struct ldb_message *msg = req->op.add.message; - struct ldb_message *msg2; - struct ldb_message_element *attribute; - struct ldb_dn_component *rdn; - int i, ret; - - ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_add_record\n"); - - /* do not manipulate our control entries */ - if (ldb_dn_is_special(msg->dn)) { - return ldb_next_request(module, req); - } - - msg2 = talloc(module, struct ldb_message); - if (!msg2) { - return -1; - } - - msg2->dn = msg->dn; - msg2->num_elements = msg->num_elements; - msg2->private_data = msg->private_data; - msg2->elements = talloc_array(msg2, struct ldb_message_element, msg2->num_elements); - for (i = 0; i < msg2->num_elements; i++) { - msg2->elements[i] = msg->elements[i]; - } - - rdn = ldb_dn_get_rdn(msg2, msg2->dn); - if (!rdn) { - talloc_free(msg2); - return -1; - } - - /* Perhaps someone above us tried to set this? */ - if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { - attribute->num_values = 0; - } - - if (ldb_msg_add_value(msg2, "name", &rdn->value) != 0) { - talloc_free(msg2); - return -1; - } - - attribute = rdn_name_find_attribute(msg2, rdn->name); - - if (!attribute) { - if (ldb_msg_add_value(msg2, rdn->name, &rdn->value) != 0) { - talloc_free(msg2); - return -1; - } - } else { - const struct ldb_attrib_handler *handler - = ldb_attrib_handler(module->ldb, rdn->name); - for (i=0; i < attribute->num_values; i++) { - if (handler->comparison_fn(module->ldb, msg2, &rdn->value, &attribute->values[i]) == 0) { - /* overwrite so it matches in case */ - attribute->values[i] = rdn->value; - break; - } - } - if (i == attribute->num_values) { - ldb_debug_set(module->ldb, LDB_DEBUG_FATAL, - "RDN mismatch on %s: %s", - ldb_dn_linearize(msg2, msg2->dn), rdn->name); - talloc_free(msg2); - return -1; - } - } - - req->op.add.message = msg2; - ret = ldb_next_request(module, req); - req->op.add.message = msg; - - talloc_free(msg2); - - return ret; -} - static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) { struct ldb_request *down_req; @@ -402,24 +323,10 @@ static int rdn_name_async_wait(struct ldb_async_handle *handle, enum ldb_async_w } } -static int rdn_name_request(struct ldb_module *module, struct ldb_request *req) -{ - switch (req->operation) { - - case LDB_REQ_ADD: - return rdn_name_add_sync(module, req); - - default: - return ldb_next_request(module, req); - - } -} - static const struct ldb_module_ops rdn_name_ops = { .name = "rdn_name", .add = rdn_name_add, .rename = rdn_name_rename, - .request = rdn_name_request, .async_wait = rdn_name_async_wait }; -- cgit From 2d19dca9c80a5e3990296dde67163fce36ac883d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 30 May 2006 00:33:52 +0000 Subject: r15944: rename LDB_ASYNC_ADD -> LDB_ADD, LDB_ASYNC_MODIFY -> LDB_MODIFY, etc... (This used to be commit 55d97ef88f377ef1dbf7b1774a15cf9035e2f320) --- source4/lib/ldb/modules/rdn_name.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 059e7843cd..d6eb0ef13e 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -202,7 +202,7 @@ static int rdn_name_rename_do_mod(struct ldb_async_handle *h) { ac->mod_req = talloc_zero(ac, struct ldb_request); - ac->mod_req->operation = LDB_ASYNC_MODIFY; + ac->mod_req->operation = LDB_MODIFY; ac->mod_req->op.mod.message = msg = ldb_msg_new(ac->mod_req); if (msg == NULL) { return LDB_ERR_OPERATIONS_ERROR; -- cgit From ca5accf224dc3ef998235603797b519866b57b1c Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 4 Jun 2006 05:28:13 +0000 Subject: r16036: Add a couple of new functions to corretly deal with timeouts. Check timeouts are correctly verified. Some minor fixed and removal of unused code. (This used to be commit b52e5d6a0cb1a32e62759eaa49ce3e4cc804cc92) --- source4/lib/ldb/modules/rdn_name.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index d6eb0ef13e..7aedc260ad 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -226,7 +226,7 @@ static int rdn_name_rename_do_mod(struct ldb_async_handle *h) { return LDB_ERR_OPERATIONS_ERROR; } - ac->mod_req->async.timeout = ac->orig_req->async.timeout; + ldb_set_timeout_from_prev_req(h->module->ldb, ac->orig_req, ac->mod_req); ac->step = RENAME_MODIFY; -- cgit From c93817b36d3ff7f44cb7b3e1d1a29e37ec12affe Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 22 Jul 2006 16:56:33 +0000 Subject: r17185: Oh, I wanted to do this for sooo long time. Finally acknowledge that ldb is inherently async and does not have a dual personality anymore Rename all ldb_async_XXX functions to ldb_XXX except for ldb_async_result, it is now ldb_reply to reflect the real function of this structure. Simo. (This used to be commit 25fc7354049d62efeba17681ef1cdd326bc3f2ef) --- source4/lib/ldb/modules/rdn_name.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 7aedc260ad..b005b49c55 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -134,7 +134,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) return ret; } -struct rename_async_context { +struct rename_context { enum {RENAME_RENAME, RENAME_MODIFY} step; struct ldb_request *orig_req; @@ -144,8 +144,8 @@ struct rename_async_context { static int rdn_name_rename(struct ldb_module *module, struct ldb_request *req) { - struct ldb_async_handle *h; - struct rename_async_context *ac; + struct ldb_handle *h; + struct rename_context *ac; ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_rename\n"); @@ -154,14 +154,14 @@ static int rdn_name_rename(struct ldb_module *module, struct ldb_request *req) return ldb_next_request(module, req); } - h = talloc_zero(req, struct ldb_async_handle); + h = talloc_zero(req, struct ldb_handle); if (h == NULL) { return LDB_ERR_OPERATIONS_ERROR; } h->module = module; - ac = talloc_zero(h, struct rename_async_context); + ac = talloc_zero(h, struct rename_context); if (ac == NULL) { return LDB_ERR_OPERATIONS_ERROR; } @@ -187,13 +187,13 @@ static int rdn_name_rename(struct ldb_module *module, struct ldb_request *req) return ldb_next_request(module, ac->down_req); } -static int rdn_name_rename_do_mod(struct ldb_async_handle *h) { +static int rdn_name_rename_do_mod(struct ldb_handle *h) { - struct rename_async_context *ac; + struct rename_context *ac; struct ldb_dn_component *rdn; struct ldb_message *msg; - ac = talloc_get_type(h->private_data, struct rename_async_context); + ac = talloc_get_type(h->private_data, struct rename_context); rdn = ldb_dn_get_rdn(ac, ac->orig_req->op.rename.newdn); if (rdn == NULL) { @@ -234,9 +234,9 @@ static int rdn_name_rename_do_mod(struct ldb_async_handle *h) { return ldb_request(h->module->ldb, ac->mod_req); } -static int rename_async_wait(struct ldb_async_handle *handle) +static int rename_wait(struct ldb_handle *handle) { - struct rename_async_context *ac; + struct rename_context *ac; int ret; if (!handle || !handle->private_data) { @@ -250,11 +250,11 @@ static int rename_async_wait(struct ldb_async_handle *handle) handle->state = LDB_ASYNC_PENDING; handle->status = LDB_SUCCESS; - ac = talloc_get_type(handle->private_data, struct rename_async_context); + ac = talloc_get_type(handle->private_data, struct rename_context); switch(ac->step) { case RENAME_RENAME: - ret = ldb_async_wait(ac->down_req->async.handle, LDB_WAIT_NONE); + ret = ldb_wait(ac->down_req->async.handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; @@ -272,7 +272,7 @@ static int rename_async_wait(struct ldb_async_handle *handle) return rdn_name_rename_do_mod(handle); case RENAME_MODIFY: - ret = ldb_async_wait(ac->mod_req->async.handle, LDB_WAIT_NONE); + ret = ldb_wait(ac->mod_req->async.handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; @@ -300,12 +300,12 @@ done: return ret; } -static int rename_async_wait_all(struct ldb_async_handle *handle) { +static int rename_wait_all(struct ldb_handle *handle) { int ret; while (handle->state != LDB_ASYNC_DONE) { - ret = rename_async_wait(handle); + ret = rename_wait(handle); if (ret != LDB_SUCCESS) { return ret; } @@ -314,12 +314,12 @@ static int rename_async_wait_all(struct ldb_async_handle *handle) { return handle->status; } -static int rdn_name_async_wait(struct ldb_async_handle *handle, enum ldb_async_wait_type type) +static int rdn_name_wait(struct ldb_handle *handle, enum ldb_wait_type type) { if (type == LDB_WAIT_ALL) { - return rename_async_wait_all(handle); + return rename_wait_all(handle); } else { - return rename_async_wait(handle); + return rename_wait(handle); } } @@ -327,7 +327,7 @@ static const struct ldb_module_ops rdn_name_ops = { .name = "rdn_name", .add = rdn_name_add, .rename = rdn_name_rename, - .async_wait = rdn_name_async_wait + .wait = rdn_name_wait }; -- cgit From 49f68caed20d2a7d1850e493005bdf85929d6365 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sat, 22 Jul 2006 17:21:59 +0000 Subject: r17186: "async" word abuse clean-up part 2 (This used to be commit c6aa60c7e69abf1f83efc150b1c3ed02751c45fc) --- source4/lib/ldb/modules/rdn_name.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index b005b49c55..fce1d34ac0 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -128,7 +128,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) /* do not free down_req as the call results may be linked to it, * it will be freed when the upper level request get freed */ if (ret == LDB_SUCCESS) { - req->async.handle = down_req->async.handle; + req->handle = down_req->handle; } return ret; @@ -181,7 +181,7 @@ static int rdn_name_rename(struct ldb_module *module, struct ldb_request *req) ac->step = RENAME_RENAME; - req->async.handle = h; + req->handle = h; /* rename first, modify "name" if rename is ok */ return ldb_next_request(module, ac->down_req); @@ -254,17 +254,17 @@ static int rename_wait(struct ldb_handle *handle) switch(ac->step) { case RENAME_RENAME: - ret = ldb_wait(ac->down_req->async.handle, LDB_WAIT_NONE); + ret = ldb_wait(ac->down_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; } - if (ac->down_req->async.handle->status != LDB_SUCCESS) { - handle->status = ac->down_req->async.handle->status; + if (ac->down_req->handle->status != LDB_SUCCESS) { + handle->status = ac->down_req->handle->status; goto done; } - if (ac->down_req->async.handle->state != LDB_ASYNC_DONE) { + if (ac->down_req->handle->state != LDB_ASYNC_DONE) { return LDB_SUCCESS; } @@ -272,17 +272,17 @@ static int rename_wait(struct ldb_handle *handle) return rdn_name_rename_do_mod(handle); case RENAME_MODIFY: - ret = ldb_wait(ac->mod_req->async.handle, LDB_WAIT_NONE); + ret = ldb_wait(ac->mod_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; } - if (ac->mod_req->async.handle->status != LDB_SUCCESS) { - handle->status = ac->mod_req->async.handle->status; + if (ac->mod_req->handle->status != LDB_SUCCESS) { + handle->status = ac->mod_req->handle->status; goto done; } - if (ac->mod_req->async.handle->state != LDB_ASYNC_DONE) { + if (ac->mod_req->handle->state != LDB_ASYNC_DONE) { return LDB_SUCCESS; } -- cgit From 7f833458ca0083654e34cbfde1c6c6510cab1826 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 25 Oct 2006 01:42:59 +0000 Subject: r19489: Change ldb_msg_add_value and ldb_msg_add_empty to take a foruth argument. This is a pointer to an element pointer. If it is not null it will be filled with the pointer of the manipulated element. Will avoid double searches on the elements list in some cases. (This used to be commit 0fa5d4bc225b83e9f63ac6d75bffc4c08eb6b620) --- source4/lib/ldb/modules/rdn_name.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index fce1d34ac0..510a43dbc9 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -91,7 +91,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) attribute->num_values = 0; } - if (ldb_msg_add_value(msg, "name", &rdn->value) != 0) { + if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) { talloc_free(down_req); return LDB_ERR_OPERATIONS_ERROR; } @@ -99,7 +99,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) attribute = rdn_name_find_attribute(msg, rdn->name); if (!attribute) { - if (ldb_msg_add_value(msg, rdn->name, &rdn->value) != 0) { + if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) { talloc_free(down_req); return LDB_ERR_OPERATIONS_ERROR; } @@ -213,16 +213,16 @@ static int rdn_name_rename_do_mod(struct ldb_handle *h) { return LDB_ERR_OPERATIONS_ERROR; } - if (ldb_msg_add_empty(msg, rdn->name, LDB_FLAG_MOD_REPLACE) != 0) { + if (ldb_msg_add_empty(msg, rdn->name, LDB_FLAG_MOD_REPLACE, NULL) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - if (ldb_msg_add_value(msg, rdn->name, &rdn->value) != 0) { + if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - if (ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_REPLACE) != 0) { + if (ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_REPLACE, NULL) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - if (ldb_msg_add_value(msg, "name", &rdn->value) != 0) { + if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) { return LDB_ERR_OPERATIONS_ERROR; } -- cgit From b7774527faf095f612eb1de48efacec6bd710a87 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 1 Nov 2006 23:31:26 +0000 Subject: r19531: Make struct ldb_dn opaque and local to ldb_dn.c (This used to be commit 889fb983ba1cf8a11424a8b3dc3a5ef76e780082) --- source4/lib/ldb/modules/rdn_name.c | 46 +++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 510a43dbc9..bab5f6a014 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -58,7 +58,8 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) struct ldb_request *down_req; struct ldb_message *msg; struct ldb_message_element *attribute; - struct ldb_dn_component *rdn; + const char *rdn_name; + struct ldb_val rdn_val; int i, ret; ldb_debug(module->ldb, LDB_DEBUG_TRACE, "rdn_name_add_record\n"); @@ -80,43 +81,45 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } - rdn = ldb_dn_get_rdn(msg, msg->dn); - if (rdn == NULL) { + rdn_name = ldb_dn_get_rdn_name(msg->dn); + if (rdn_name == NULL) { talloc_free(down_req); return LDB_ERR_OPERATIONS_ERROR; } + rdn_val = ldb_val_dup(msg, ldb_dn_get_rdn_val(msg->dn)); + /* Perhaps someone above us tried to set this? */ if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { attribute->num_values = 0; } - if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) { + if (ldb_msg_add_value(msg, "name", &rdn_val, NULL) != 0) { talloc_free(down_req); return LDB_ERR_OPERATIONS_ERROR; } - attribute = rdn_name_find_attribute(msg, rdn->name); + attribute = rdn_name_find_attribute(msg, rdn_name); if (!attribute) { - if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) { + if (ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL) != 0) { talloc_free(down_req); return LDB_ERR_OPERATIONS_ERROR; } } else { - const struct ldb_attrib_handler *handler = ldb_attrib_handler(module->ldb, rdn->name); + const struct ldb_attrib_handler *handler = ldb_attrib_handler(module->ldb, rdn_name); for (i = 0; i < attribute->num_values; i++) { - if (handler->comparison_fn(module->ldb, msg, &rdn->value, &attribute->values[i]) == 0) { + if (handler->comparison_fn(module->ldb, msg, &rdn_val, &attribute->values[i]) == 0) { /* overwrite so it matches in case */ - attribute->values[i] = rdn->value; + attribute->values[i] = rdn_val; break; } } if (i == attribute->num_values) { ldb_debug_set(module->ldb, LDB_DEBUG_FATAL, - "RDN mismatch on %s: %s", - ldb_dn_linearize(msg, msg->dn), rdn->name); + "RDN mismatch on %s: %s (%s)", + ldb_dn_linearize(msg, msg->dn), rdn_name, rdn_val.data); talloc_free(down_req); return LDB_ERR_OPERATIONS_ERROR; } @@ -190,16 +193,12 @@ static int rdn_name_rename(struct ldb_module *module, struct ldb_request *req) static int rdn_name_rename_do_mod(struct ldb_handle *h) { struct rename_context *ac; - struct ldb_dn_component *rdn; + const char *rdn_name; + struct ldb_val rdn_val; struct ldb_message *msg; ac = talloc_get_type(h->private_data, struct rename_context); - rdn = ldb_dn_get_rdn(ac, ac->orig_req->op.rename.newdn); - if (rdn == NULL) { - return LDB_ERR_OPERATIONS_ERROR; - } - ac->mod_req = talloc_zero(ac, struct ldb_request); ac->mod_req->operation = LDB_MODIFY; @@ -213,16 +212,23 @@ static int rdn_name_rename_do_mod(struct ldb_handle *h) { return LDB_ERR_OPERATIONS_ERROR; } - if (ldb_msg_add_empty(msg, rdn->name, LDB_FLAG_MOD_REPLACE, NULL) != 0) { + rdn_name = ldb_dn_get_rdn_name(ac->orig_req->op.rename.newdn); + if (rdn_name == NULL) { + return LDB_ERR_OPERATIONS_ERROR; + } + + rdn_val = ldb_val_dup(msg, ldb_dn_get_rdn_val(ac->orig_req->op.rename.newdn)); + + if (ldb_msg_add_empty(msg, rdn_name, LDB_FLAG_MOD_REPLACE, NULL) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - if (ldb_msg_add_value(msg, rdn->name, &rdn->value, NULL) != 0) { + if (ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL) != 0) { return LDB_ERR_OPERATIONS_ERROR; } if (ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_REPLACE, NULL) != 0) { return LDB_ERR_OPERATIONS_ERROR; } - if (ldb_msg_add_value(msg, "name", &rdn->value, NULL) != 0) { + if (ldb_msg_add_value(msg, "name", &rdn_val, NULL) != 0) { return LDB_ERR_OPERATIONS_ERROR; } -- cgit From a9e31b33b55a873c2f01db5e348560176adf863d Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 02:05:19 +0000 Subject: r19832: better prototypes for the linearization functions: - ldb_dn_get_linearized returns a const string - ldb_dn_alloc_linearized allocs astring with the linearized dn (This used to be commit 3929c086d5d0b3f08b1c4f2f3f9602c3f4a9a4bd) --- source4/lib/ldb/modules/rdn_name.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index bab5f6a014..0da8b8f573 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -119,7 +119,7 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) if (i == attribute->num_values) { ldb_debug_set(module->ldb, LDB_DEBUG_FATAL, "RDN mismatch on %s: %s (%s)", - ldb_dn_linearize(msg, msg->dn), rdn_name, rdn_val.data); + ldb_dn_get_linearized(msg->dn), rdn_name, rdn_val.data); talloc_free(down_req); return LDB_ERR_OPERATIONS_ERROR; } -- cgit From c69717755abeaf8bf93e76255d0912e3a24b7cb0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 15 Dec 2006 13:08:57 +0000 Subject: r20184: change ldb_attrib_handler into ldb_schema_attribute, which has a pointer to a ldb_schema_syntax struct. the default attribute handler is now registered dynamicly as "*" attribute, instead of having its own code path. ldb_schema_attribute's can be added to the ldb_schema given a ldb_schema_syntax struct or the syntax name we may also need to introduce a ldb_schema_matching_rule, and add a pointer to a default ldb_schema_matching_rule in the ldb_schema_syntax. metze (This used to be commit b97b8f5dcbce006f005e53ca79df3330e62f117b) --- source4/lib/ldb/modules/rdn_name.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 0da8b8f573..cb5add2875 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -107,10 +107,10 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) return LDB_ERR_OPERATIONS_ERROR; } } else { - const struct ldb_attrib_handler *handler = ldb_attrib_handler(module->ldb, rdn_name); + const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(module->ldb, rdn_name); for (i = 0; i < attribute->num_values; i++) { - if (handler->comparison_fn(module->ldb, msg, &rdn_val, &attribute->values[i]) == 0) { + if (a->syntax->comparison_fn(module->ldb, msg, &rdn_val, &attribute->values[i]) == 0) { /* overwrite so it matches in case */ attribute->values[i] = rdn_val; break; -- cgit From 52fb06edc25e8538c413df1aaabba18c859a00cf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 5 May 2007 18:50:56 +0000 Subject: r22681: Fix standalone ldb build when parent directory name != ldb. (This used to be commit 1093875d59f1ea9b8bd82277d4f9d8366e584952) --- source4/lib/ldb/modules/rdn_name.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index cb5add2875..322f05c00e 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -37,8 +37,7 @@ * Simo Sorce Mar 2006 */ -#include "includes.h" -#include "ldb/include/includes.h" +#include "ldb_includes.h" static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_message *msg, const char *name) { -- cgit From b8d69a7ea2505b706ff7c74d7c97bc89d82dfa07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:46:15 +0000 Subject: r23795: more v2->v3 conversion (This used to be commit 84b468b2f8f2dffda89593f816e8bc6a8b6d42ac) --- source4/lib/ldb/modules/rdn_name.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 322f05c00e..0892357ee6 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -11,7 +11,7 @@ This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + version 3 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -- cgit From 6c973f4e8ccbcb6c9275f8a54e26abb19df7e15a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 03:42:26 +0000 Subject: r23798: updated old Temple Place FSF addresses to new URL (This used to be commit 40c0919aaa9c1b14bbaebb95ecce53eb0380fdbb) --- source4/lib/ldb/modules/rdn_name.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 0892357ee6..4a95efe7d6 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -19,8 +19,7 @@ Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + License along with this library; if not, see . */ /* -- cgit From 5a1433cae7bafe01371663aed8520ce29175cac7 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 24 Dec 2007 01:38:37 -0600 Subject: r26581: Make ldb_wait uniform, so that it is easy to remove it completely from modules later on. (This used to be commit f75ce8c20aa2b466e9ee86fdf1702b2ffda10ddf) --- source4/lib/ldb/modules/rdn_name.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 4a95efe7d6..1a0ddbb3c4 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -238,7 +238,7 @@ static int rdn_name_rename_do_mod(struct ldb_handle *h) { return ldb_request(h->module->ldb, ac->mod_req); } -static int rename_wait(struct ldb_handle *handle) +static int rdn_name_wait_once(struct ldb_handle *handle) { struct rename_context *ac; int ret; @@ -304,27 +304,26 @@ done: return ret; } -static int rename_wait_all(struct ldb_handle *handle) { - +static int rdn_name_wait(struct ldb_handle *handle, enum ldb_wait_type type) +{ int ret; - - while (handle->state != LDB_ASYNC_DONE) { - ret = rename_wait(handle); - if (ret != LDB_SUCCESS) { - return ret; - } + + if (!handle || !handle->private_data) { + return LDB_ERR_OPERATIONS_ERROR; } - return handle->status; -} - -static int rdn_name_wait(struct ldb_handle *handle, enum ldb_wait_type type) -{ if (type == LDB_WAIT_ALL) { - return rename_wait_all(handle); - } else { - return rename_wait(handle); + while (handle->state != LDB_ASYNC_DONE) { + ret = rdn_name_wait_once(handle); + if (ret != LDB_SUCCESS) { + return ret; + } + } + + return handle->status; } + + return rdn_name_wait_once(handle); } static const struct ldb_module_ops rdn_name_ops = { -- cgit From 16109a40c0abd8c30a5eb9bf9ef692bfae9dfc7d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 20 Feb 2008 01:54:32 +0100 Subject: Use struct-based rather than function-based initialization for ldb modules everywhere. (This used to be commit 85c96a325867f7bcdb412ebc53f8a47dbf7cd89b) --- source4/lib/ldb/modules/rdn_name.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index 1a0ddbb3c4..c4de8e8da8 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -326,15 +326,9 @@ static int rdn_name_wait(struct ldb_handle *handle, enum ldb_wait_type type) return rdn_name_wait_once(handle); } -static const struct ldb_module_ops rdn_name_ops = { +const struct ldb_module_ops ldb_rdn_name_module_ops = { .name = "rdn_name", .add = rdn_name_add, .rename = rdn_name_rename, .wait = rdn_name_wait }; - - -int ldb_rdn_name_init(void) -{ - return ldb_register_module(&rdn_name_ops); -} -- cgit From ba94c12bc4a1ab8cfd6270ea69d1aef3d925ee29 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 28 Feb 2008 08:38:53 +1100 Subject: Fix rdn_name errors. Return the correct error when the DN is mismatched with it's RDN attribute (now matches AD). Andrew Bartlett (This used to be commit bf7166e785e5c5d52dbb0c12e5e4206d74e72f4e) --- source4/lib/ldb/modules/rdn_name.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/lib/ldb/modules/rdn_name.c') diff --git a/source4/lib/ldb/modules/rdn_name.c b/source4/lib/ldb/modules/rdn_name.c index c4de8e8da8..65c044c0f4 100644 --- a/source4/lib/ldb/modules/rdn_name.c +++ b/source4/lib/ldb/modules/rdn_name.c @@ -119,7 +119,8 @@ static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) "RDN mismatch on %s: %s (%s)", ldb_dn_get_linearized(msg->dn), rdn_name, rdn_val.data); talloc_free(down_req); - return LDB_ERR_OPERATIONS_ERROR; + /* Match AD's error here */ + return LDB_ERR_INVALID_DN_SYNTAX; } } -- cgit