From 56b90acbf6ada4c9e2565770918673419b708479 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Dec 2009 22:45:36 +1100 Subject: s4-ldb: sort the linearized extended DN by component name This will make life easier when handling deleted linked attributes --- source4/lib/ldb/common/ldb_dn.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source4') diff --git a/source4/lib/ldb/common/ldb_dn.c b/source4/lib/ldb/common/ldb_dn.c index 59a6dc0594..bd42bd5f18 100644 --- a/source4/lib/ldb/common/ldb_dn.c +++ b/source4/lib/ldb/common/ldb_dn.c @@ -789,6 +789,13 @@ const char *ldb_dn_get_linearized(struct ldb_dn *dn) return dn->linearized; } +static int ldb_dn_extended_component_compare(const void *p1, const void *p2) +{ + const struct ldb_dn_ext_component *ec1 = (const struct ldb_dn_ext_component *)p1; + const struct ldb_dn_ext_component *ec2 = (const struct ldb_dn_ext_component *)p2; + return strcmp(ec1->name, ec2->name); +} + char *ldb_dn_get_extended_linearized(void *mem_ctx, struct ldb_dn *dn, int mode) { const char *linearized = ldb_dn_get_linearized(dn); @@ -807,6 +814,13 @@ char *ldb_dn_get_extended_linearized(void *mem_ctx, struct ldb_dn *dn, int mode) return NULL; } + /* sort the extended components by name. The idea is to make + * the resulting DNs consistent, plus to ensure that we put + * 'DELETED' first, so it can be very quickly recognised + */ + qsort(dn->ext_components, dn->ext_comp_num, sizeof(dn->ext_components[0]), + ldb_dn_extended_component_compare); + for (i = 0; i < dn->ext_comp_num; i++) { const struct ldb_dn_extended_syntax *ext_syntax; const char *name = dn->ext_components[i].name; -- cgit