From 79ac9c6c788d7c98f1595f97f9060690c84e2774 Mon Sep 17 00:00:00 2001 From: Pavel Zuna Date: Fri, 12 Jun 2009 15:11:28 +0200 Subject: Add conversion of attribute name synonyms when generating modlists. --- ipaserver/plugins/ldap2.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ipaserver/plugins/ldap2.py b/ipaserver/plugins/ldap2.py index 7697a153e..97c02d1c7 100644 --- a/ipaserver/plugins/ldap2.py +++ b/ipaserver/plugins/ldap2.py @@ -288,6 +288,32 @@ class ldap2(CrudBackend, Encoder): rdn = self.make_rdn_from_attr(primary_key, entry_attrs[primary_key]) return self.make_dn_from_rdn(rdn, parent_dn) + def convert_attr_synonyms(self, entry_attrs, preferred_names=None): + """ + Convert attribute names in entry_attrs to preferred synonyms. + + Keyword arguments: + preferred_names -- list of preferred synomyms or None for defaults + (default None) + """ + if preferred_names: + for n in preferred_names: + attr = self._schema.get_obj(_ldap.schema.AttributeType, n) + synonyms = [v.lower() for v in attr.names] + synonyms.remove(n) + for s in synonyms: + if s in entry_attrs: + entry_attrs[n] = entry_attrs[s] + del entry_attrs[s] + else: + for (k, v) in entry_attrs.items(): + attr = self._schema.get_obj(_ldap.schema.AttributeType, k) + synonyms = [v.lower() for v in attr.names] + preferred_name = synonyms[0] + if k in synonyms[1:]: + entry_attrs[preferred_name] = v + del entry_attrs[k] + @encode_args(1, 2) def add_entry(self, dn, entry_attrs): """Create a new entry.""" @@ -478,6 +504,8 @@ class ldap2(CrudBackend, Encoder): # we could call search_s directly, but this saves a lot of code at # the expense of a little bit of performace entry_attrs_old = self.encode(entry_attrs_old) + # we also need to make sure that attribute names match + self.convert_attr_synonyms(entry_attrs_old, entry_attrs.keys()) # generate modlist, we don't want any MOD_REPLACE operations # to handle simultaneous updates better modlist = [] -- cgit