diff options
author | Pavel Zuna <pzuna@redhat.com> | 2009-06-12 15:11:28 +0200 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2009-06-15 13:11:44 -0400 |
commit | 79ac9c6c788d7c98f1595f97f9060690c84e2774 (patch) | |
tree | a9d8b90e572f77e092d2f4c3b0a121543ba54f86 /ipaserver/plugins | |
parent | 2ff4b3906ffbcd89330e40fa7f69f5c668996b72 (diff) | |
download | freeipa.git-79ac9c6c788d7c98f1595f97f9060690c84e2774.tar.gz freeipa.git-79ac9c6c788d7c98f1595f97f9060690c84e2774.tar.xz freeipa.git-79ac9c6c788d7c98f1595f97f9060690c84e2774.zip |
Add conversion of attribute name synonyms when generating modlists.
Diffstat (limited to 'ipaserver/plugins')
-rw-r--r-- | ipaserver/plugins/ldap2.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ipaserver/plugins/ldap2.py b/ipaserver/plugins/ldap2.py index 7697a153..97c02d1c 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 = [] |