[Date Prev][Date Next] [Chronological] [Thread] [Top]

ldap_sort_entries(by DN) -> parent first



I'd like to modify ldap_sort_entries() so that when sorting by DN,
it (usually) sorts parents before their children.

This slow down a sort somewhat though.  Maybe a magic value
'compare-function=NULL' could be passed when sorting DNs to mean
that they shall (not) be sorted this way.

Anyway, there are two obvious ways to do it:

1. Sort by number of RDNs in the DN before by the DN.

   This will always work, so on can e.g. feed the output to ldapadd.
   However the ordering may not be pretty to a human reader.
   The output is neither alphabetical nor grouped by subtree.

   Requires a new value in 'struct everything' in libldap/sort.c.

2. Reverse the DNs while sorting, so 'dc=example,dc=com'
   is sorted as {"dc=com", "dc=example"}.

   This will normally return the entries with subtrees grouped together,
   but can fail (put children in front of parents) if the parent DN is
   represented differently from the parent DN component of the child.

Or the combination would also always work, and maybe give somewhat
better ordering than #1 to a human reader.

Opinions?  Objections?

-- 
Regards,
Hallvard