diff options
-rw-r--r-- | ipalib/frontend.py | 17 | ||||
-rw-r--r-- | ipalib/plugins/baseldap.py | 58 |
2 files changed, 40 insertions, 35 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py index d320f02e0..1c4fea8cb 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -519,11 +519,12 @@ class Command(HasParam): if len(value) == 0: # None means "delete this attribute" value = None - if attr not in self.params: - if append and attr in newdict: - newdict[attr].append(value) - else: - newdict[attr] = [value] + if attr in self.params: + value = self.params[attr](value) + if append and attr in newdict: + newdict[attr].append(value) + else: + newdict[attr] = [value] return newdict def __attributes_2_entry(self, kw): @@ -540,7 +541,11 @@ class Command(HasParam): adddict = self.__convert_2_dict(kw['setattr'], append=False) if kw.get('addattr'): - adddict.update(self.__convert_2_dict(kw['addattr'])) + for (k, v) in self.__convert_2_dict(kw['addattr']).iteritems(): + if k in adddict: + adddict[k] += v + else: + adddict[k] = v for name in adddict: value = adddict[name] diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py index 43fafe32a..f3e5b0fe2 100644 --- a/ipalib/plugins/baseldap.py +++ b/ipalib/plugins/baseldap.py @@ -419,6 +419,35 @@ class LDAPUpdate(LDAPQuery, crud.Update): entry_attrs = self.args_options_2_entry(**options) + """ + Some special handling is needed because we need to update the + values here rather than letting ldap.update_entry() do the work. We + have to do the work of adding new values to an existing attribute + because if we pass just what is addded only the new values get + set. + """ + if 'addattr' in options: + setset = set(get_attributes(options.get('setattr', []))) + addset = set(get_attributes(options.get('addattr', []))) + difflist = list(addset.difference(setset)) + if difflist: + try: + (dn, old_entry) = ldap.get_entry( + dn, difflist, normalize=self.obj.normalize_dn + ) + except errors.ExecutionError, e: + try: + (dn, old_entry) = self._call_exc_callbacks( + keys, options, e, ldap.get_entry, dn, attrs_list, + normalize=self.obj.normalize_dn + ) + except errors.NotFound: + self.obj.handle_not_found(*keys) + for a in old_entry: + if not isinstance(entry_attrs[a], (list, tuple)): + entry_attrs[a] = [entry_attrs[a]] + entry_attrs[a] += old_entry[a] + if options.get('all', False): attrs_list = ['*'] else: @@ -436,35 +465,6 @@ class LDAPUpdate(LDAPQuery, crud.Update): self, ldap, dn, entry_attrs, attrs_list, *keys, **options ) - """ - Some special handling is needed because we need to update the - values here rather than letting ldap.update_entry() do the work. We - have to do the work of adding new values to an existing attribute - because if we pass just what is addded only the new values get - set. - """ - if 'addattr' in options: - try: - (dn, old_entry) = ldap.get_entry( - dn, attrs_list, normalize=self.obj.normalize_dn - ) - except errors.ExecutionError, e: - try: - (dn, old_entry) = self._call_exc_callbacks( - keys, options, e, ldap.get_entry, dn, attrs_list, - normalize=self.obj.normalize_dn - ) - except errors.NotFound: - self.obj.handle_not_found(*keys) - attrlist = get_attributes(options['addattr']) - for attr in attrlist: - if attr in old_entry: - if type(entry_attrs[attr]) in (tuple,list): - entry_attrs[attr] = old_entry[attr] + entry_attrs[attr] - else: - old_entry[attr].append(entry_attrs[attr]) - entry_attrs[attr] = old_entry[attr] - try: ldap.update_entry(dn, entry_attrs, normalize=self.obj.normalize_dn) except errors.ExecutionError, e: |