MDL-31540 Try to remove duplicates before storing LDAP search contexts
authorIñaki Arenaza <iarenaza@mondragon.edu>
Fri, 2 Mar 2012 00:19:04 +0000 (01:19 +0100)
committerIñaki Arenaza <iarenaza@mondragon.edu>
Thu, 8 Mar 2012 20:57:59 +0000 (21:57 +0100)
commitca769fa7f8e2d00fa5283e6a802b6d14eb47bc45
tree77af1593f751d5c92d240766eafc2da8f41f9cc6
parent5bbf3cb72b1a55d41a419299c279bd75f697d90a
MDL-31540 Try to remove duplicates before storing LDAP search contexts

If the user specifies the same LDAP search context more than once,
when we sync users we retrieve the same set of users twice. When we
try to insert the "duplicated" user in the temp table again, the db
barfs and the db layer aborts the whole transaction.

So we try to detect and remove duplicates. This is a bit tricky (LDAP
is such a complex and wonderful protocol) as the contexts are
distinguished names and the matching/comparison rules are complex. But
assuming that we only use the attribute types used in 99.999% of the
distinguished names used for contexts out there (that is: dc, ou, cn,
o, l and c), and also assuming that the user is not using different
encodings/escapings for the same context, we can lower case the
contexts to compare them (and remove duplicates).

This is safe according to RFC-4517 (section 4.2.15. distinguishedNameMatch)
and RFC-4519 (where the EQUAILITY property is defined for the
different user application attribute types).

This shouldn't break any configuration that wasn't broken before :)

Signed-off-by: Iñaki Arenaza <iarenaza@mondragon.edu>
auth/ldap/auth.php