mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-27 16:46:42 -06:00
Sort LDAP updates properly
LDAP updates were sorted by number of RDNs in DN. This, however, sometimes caused updates to be executed before cn=schema updates. If the update required an objectClass or attributeType added during the cn=schema update, the update operation failed. Fix the sorting so that the cn=schema updates are always run first and then the other updates sorted by RDN count. https://fedorahosted.org/freeipa/ticket/3342
This commit is contained in:
parent
79bcf904a5
commit
1d2d1e1af1
@ -893,26 +893,23 @@ class LDAPUpdate:
|
||||
|
||||
def _run_updates(self, all_updates):
|
||||
# For adds and updates we want to apply updates from shortest
|
||||
# to greatest length of the DN. For deletes we want the reverse.
|
||||
|
||||
dn_by_rdn_count = {}
|
||||
for dn in all_updates.keys():
|
||||
# to greatest length of the DN. cn=schema must always go first to add
|
||||
# new objectClasses and attributeTypes
|
||||
# For deletes we want the reverse
|
||||
def update_sort_key(dn_update):
|
||||
dn, update = dn_update
|
||||
assert isinstance(dn, DN)
|
||||
rdn_count = len(dn)
|
||||
rdn_count_list = dn_by_rdn_count.setdefault(rdn_count, [])
|
||||
if dn not in rdn_count_list:
|
||||
rdn_count_list.append(dn)
|
||||
return dn != DN(('cn', 'schema')), len(dn)
|
||||
|
||||
sortedkeys = dn_by_rdn_count.keys()
|
||||
sortedkeys.sort()
|
||||
for rdn_count in sortedkeys:
|
||||
for dn in dn_by_rdn_count[rdn_count]:
|
||||
self._update_record(all_updates[dn])
|
||||
sorted_updates = sorted(all_updates.iteritems(), key=update_sort_key)
|
||||
|
||||
sortedkeys.reverse()
|
||||
for rdn_count in sortedkeys:
|
||||
for dn in dn_by_rdn_count[rdn_count]:
|
||||
self._delete_record(all_updates[dn])
|
||||
for dn, update in sorted_updates:
|
||||
self._update_record(update)
|
||||
|
||||
# Now run the deletes in reversed order
|
||||
sorted_updates.reverse()
|
||||
for dn, update in sorted_updates:
|
||||
self._delete_record(update)
|
||||
|
||||
def update(self, files):
|
||||
"""Execute the update. files is a list of the update files to use.
|
||||
|
Loading…
Reference in New Issue
Block a user