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') 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