From 5426e57898b2b60b7def1af24050df10b1394c9e Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 19 Sep 2013 10:41:16 -0700 Subject: Fix DN RDN case in partition names Move fix_dn from extended_dn_out.c to util.c Signed-off-by: Howard Chu Reviewed-by: Andrew Bartlett Reviewed-by: Nadezhda Ivanova Autobuild-User(master): Nadezhda Ivanova Autobuild-Date(master): Tue Sep 24 07:43:39 CEST 2013 on sn-devel-104 --- source4/dsdb/samdb/ldb_modules/extended_dn_out.c | 33 ++---------------------- source4/dsdb/samdb/ldb_modules/partition_init.c | 7 +++++ source4/dsdb/samdb/ldb_modules/util.c | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+), 31 deletions(-) (limited to 'source4/dsdb') diff --git a/source4/dsdb/samdb/ldb_modules/extended_dn_out.c b/source4/dsdb/samdb/ldb_modules/extended_dn_out.c index b1eacf59eb..70835226b7 100644 --- a/source4/dsdb/samdb/ldb_modules/extended_dn_out.c +++ b/source4/dsdb/samdb/ldb_modules/extended_dn_out.c @@ -140,35 +140,6 @@ static bool add_attrs(void *mem_ctx, char ***attrs, const char *attr) return true; } -/* Fix the DN so that the relative attribute names are in upper case so that the DN: - cn=Adminstrator,cn=users,dc=samba,dc=example,dc=com becomes - CN=Adminstrator,CN=users,DC=samba,DC=example,DC=com -*/ -static int fix_dn(struct ldb_context *ldb, struct ldb_dn *dn) -{ - int i, ret; - char *upper_rdn_attr; - - for (i=0; i < ldb_dn_get_comp_num(dn); i++) { - /* We need the attribute name in upper case */ - upper_rdn_attr = strupper_talloc(dn, - ldb_dn_get_component_name(dn, i)); - if (!upper_rdn_attr) { - return ldb_oom(ldb); - } - - /* And replace it with CN=foo (we need the attribute in upper case */ - ret = ldb_dn_set_component(dn, i, upper_rdn_attr, - *ldb_dn_get_component_val(dn, i)); - talloc_free(upper_rdn_attr); - if (ret != LDB_SUCCESS) { - return ret; - } - } - return LDB_SUCCESS; -} - - /* Inject the extended DN components, so the DN cn=Adminstrator,cn=users,dc=samba,dc=example,dc=com becomes ;;cn=Adminstrator,cn=users,dc=samba,dc=example,dc=com */ @@ -458,7 +429,7 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares, } if (p && p->normalise) { - ret = fix_dn(ldb, ares->message->dn); + ret = dsdb_fix_dn_rdncase(ldb, ares->message->dn); if (ret != LDB_SUCCESS) { return ldb_module_done(ac->req, NULL, NULL, ret); } @@ -600,7 +571,7 @@ static int extended_callback(struct ldb_request *req, struct ldb_reply *ares, } if (p->normalise) { - ret = fix_dn(ldb, dn); + ret = dsdb_fix_dn_rdncase(ldb, dn); if (ret != LDB_SUCCESS) { talloc_free(dsdb_dn); return ldb_module_done(ac->req, NULL, NULL, ret); diff --git a/source4/dsdb/samdb/ldb_modules/partition_init.c b/source4/dsdb/samdb/ldb_modules/partition_init.c index 98896a7a84..3e2648efa1 100644 --- a/source4/dsdb/samdb/ldb_modules/partition_init.c +++ b/source4/dsdb/samdb/ldb_modules/partition_init.c @@ -516,6 +516,13 @@ int partition_reload_if_required(struct ldb_module *module, talloc_free(partition->ctrl->dn); partition->ctrl->dn = talloc_steal(partition->ctrl, dn_res->msgs[0]->dn); talloc_free(dn_res); + if (data->ldapBackend) { + ret = dsdb_fix_dn_rdncase(ldb, partition->ctrl->dn); + if (ret) { + talloc_free(mem_ctx); + return ret; + } + } } else if (ret != LDB_ERR_NO_SUCH_OBJECT) { ldb_asprintf_errstring(ldb, "Failed to search for partition base %s in new partition at %s: %s", diff --git a/source4/dsdb/samdb/ldb_modules/util.c b/source4/dsdb/samdb/ldb_modules/util.c index 8d587a4cb3..147e357847 100644 --- a/source4/dsdb/samdb/ldb_modules/util.c +++ b/source4/dsdb/samdb/ldb_modules/util.c @@ -1419,3 +1419,29 @@ const struct dsdb_class *dsdb_get_structural_oc_from_msg(const struct dsdb_schem return dsdb_get_last_structural_class(schema, oc_el); } + +/* Fix the DN so that the relative attribute names are in upper case so that the DN: + cn=Adminstrator,cn=users,dc=samba,dc=example,dc=com becomes + CN=Adminstrator,CN=users,DC=samba,DC=example,DC=com +*/ +int dsdb_fix_dn_rdncase(struct ldb_context *ldb, struct ldb_dn *dn) +{ + int i, ret; + char *upper_rdn_attr; + + for (i=0; i < ldb_dn_get_comp_num(dn); i++) { + /* We need the attribute name in upper case */ + upper_rdn_attr = strupper_talloc(dn, + ldb_dn_get_component_name(dn, i)); + if (!upper_rdn_attr) { + return ldb_oom(ldb); + } + ret = ldb_dn_set_component(dn, i, upper_rdn_attr, + *ldb_dn_get_component_val(dn, i)); + talloc_free(upper_rdn_attr); + if (ret != LDB_SUCCESS) { + return ret; + } + } + return LDB_SUCCESS; +} -- cgit