summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins/hbacrule.py
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2012-02-01 16:20:54 -0500
committerMartin Kosek <mkosek@redhat.com>2012-02-08 09:12:53 +0100
commit304b70843a96ce2e4effbc1d45144f79fd761d63 (patch)
treedcaae35d8789699867f43f30112ce397f4d2a31b /ipalib/plugins/hbacrule.py
parentcca80c7c8c28b08f29d20ca0ca06d98d61247051 (diff)
downloadfreeipa-304b70843a96ce2e4effbc1d45144f79fd761d63.tar.gz
freeipa-304b70843a96ce2e4effbc1d45144f79fd761d63.tar.xz
freeipa-304b70843a96ce2e4effbc1d45144f79fd761d63.zip
Consolidate external member code into two functions in baseldap.py
External members (users and hosts) are assumed when doing member management on certain attributes. If the member isn't in IPA it is assumed to be external. When doing member management we need to sift through the list of failures and pull out all those that were simply not found in IPA. https://fedorahosted.org/freeipa/ticket/1734
Diffstat (limited to 'ipalib/plugins/hbacrule.py')
-rw-r--r--ipalib/plugins/hbacrule.py51
1 files changed, 2 insertions, 49 deletions
diff --git a/ipalib/plugins/hbacrule.py b/ipalib/plugins/hbacrule.py
index 53d25aac6..c83305738 100644
--- a/ipalib/plugins/hbacrule.py
+++ b/ipalib/plugins/hbacrule.py
@@ -501,32 +501,7 @@ class hbacrule_add_sourcehost(LDAPAddMember):
return dn
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
- completed_external = 0
- # Sift through the host failures. We assume that these are all
- # hosts that aren't stored in IPA, aka external hosts.
- if 'sourcehost' in failed and 'host' in failed['sourcehost']:
- (dn, entry_attrs_) = ldap.get_entry(dn, ['externalhost'])
- members = entry_attrs.get('sourcehost', [])
- external_hosts = entry_attrs_.get('externalhost', [])
- failed_hosts = []
- for host in failed['sourcehost']['host']:
- hostname = host[0].lower()
- host_dn = self.api.Object['host'].get_dn(hostname)
- if hostname in external_hosts:
- failed_hosts.append((hostname, unicode(errors.AlreadyGroupMember())))
- elif hostname not in external_hosts and host_dn not in members:
- external_hosts.append(hostname)
- completed_external += 1
- else:
- failed_hosts.append((hostname, unicode(errors.NotFound())))
- if completed_external:
- try:
- ldap.update_entry(dn, {'externalhost': external_hosts})
- except errors.EmptyModlist:
- pass
- entry_attrs['externalhost'] = external_hosts
- failed['sourcehost']['host'] = failed_hosts
- return (completed + completed_external, dn)
+ return add_external_post_callback('sourcehost', 'host', 'externalhost', ldap, completed, failed, dn, entry_attrs, keys, options)
api.register(hbacrule_add_sourcehost)
@@ -538,29 +513,7 @@ class hbacrule_remove_sourcehost(LDAPRemoveMember):
member_count_out = ('%i object removed.', '%i objects removed.')
def post_callback(self, ldap, completed, failed, dn, entry_attrs, *keys, **options):
- # Run through the host failures and gracefully remove any defined as
- # as an externalhost.
- if 'sourcehost' in failed and 'host' in failed['sourcehost']:
- (dn, entry_attrs_) = ldap.get_entry(dn, ['externalhost'])
- external_hosts = entry_attrs_.get('externalhost', [])
- failed_hosts = []
- completed_external = 0
- for host in failed['sourcehost']['host']:
- hostname = host[0].lower()
- if hostname in external_hosts:
- external_hosts.remove(hostname)
- completed_external += 1
- else:
- failed_hosts.append(hostname)
- if completed_external:
- try:
- ldap.update_entry(dn, {'externalhost': external_hosts})
- except errors.EmptyModlist:
- pass
- failed['sourcehost']['host'] = failed_hosts
- entry_attrs['externalhost'] = external_hosts
- return (completed + completed_external, dn)
-
+ return remove_external_post_callback('sourcehost', 'host', 'externalhost', ldap, completed, failed, dn, entry_attrs, keys, options)
api.register(hbacrule_remove_sourcehost)