summaryrefslogtreecommitdiffstats
path: root/ipa-python
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2007-10-22 17:06:52 -0400
committerRob Crittenden <rcritten@redhat.com>2007-10-22 17:06:52 -0400
commit04636b8ae7b759291fe0c49991b3df760d6ad4c2 (patch)
tree5ef85e2b057c2dc94c5744492ddd83f70efa3a2b /ipa-python
parenta47f893957a2b07b87f26429183f61d781a257fc (diff)
downloadfreeipa-04636b8ae7b759291fe0c49991b3df760d6ad4c2.tar.gz
freeipa-04636b8ae7b759291fe0c49991b3df760d6ad4c2.tar.xz
freeipa-04636b8ae7b759291fe0c49991b3df760d6ad4c2.zip
Add an LDAP attribute -> label mapping function to XML-RPC layer
Move some ACI functions around in preparation for cli delegation
Diffstat (limited to 'ipa-python')
-rw-r--r--ipa-python/aci.py26
-rw-r--r--ipa-python/ipaclient.py5
-rw-r--r--ipa-python/rpcclient.py13
3 files changed, 44 insertions, 0 deletions
diff --git a/ipa-python/aci.py b/ipa-python/aci.py
index 092285e2..60e19075 100644
--- a/ipa-python/aci.py
+++ b/ipa-python/aci.py
@@ -17,6 +17,7 @@
import re
import urllib
+import ldap
import ipa.ipautil
@@ -129,3 +130,28 @@ class ACI:
acistr = self._match(';)', acistr)
if len(acistr) > 0:
raise SyntaxError, "unexpected aci suffix at '%s'" % acistr
+
+def extract_group_cns(aci_list, client):
+ """Extracts all the cn's from a list of aci's and returns them as a hash
+ from group_dn to group_cn.
+
+ It first tries to cheat by looking at the first rdn for the
+ group dn. If that's not cn for some reason, it looks up the group."""
+ group_dn_to_cn = {}
+ for aci in aci_list:
+ for dn in (aci.source_group, aci.dest_group):
+ if not group_dn_to_cn.has_key(dn):
+ rdn_list = ldap.dn.str2dn(dn)
+ first_rdn = rdn_list[0]
+ for (type,value,junk) in first_rdn:
+ if type == "cn":
+ group_dn_to_cn[dn] = value
+ break;
+ else:
+ try:
+ group = client.get_entry_by_dn(dn, ['cn'])
+ group_dn_to_cn[dn] = group.getValue('cn')
+ except ipaerror.IPAError, e:
+ group_dn_to_cn[dn] = 'unknown'
+
+ return group_dn_to_cn
diff --git a/ipa-python/ipaclient.py b/ipa-python/ipaclient.py
index b9439ecd..a7bd8183 100644
--- a/ipa-python/ipaclient.py
+++ b/ipa-python/ipaclient.py
@@ -311,3 +311,8 @@ class IPAClient:
"""
return self.transport.add_group_to_group(group_cn, tgroup_cn)
+
+ def attrs_to_labels(self,attrs):
+ """Convert a list of LDAP attributes into a more readable form."""
+
+ return self.transport.attrs_to_labels(attrs)
diff --git a/ipa-python/rpcclient.py b/ipa-python/rpcclient.py
index 53fb690b..615f4a0a 100644
--- a/ipa-python/rpcclient.py
+++ b/ipa-python/rpcclient.py
@@ -561,3 +561,16 @@ class RPCClient:
raise xmlrpclib.Fault(value, msg)
return ipautil.unwrap_binary_data(result)
+
+ def attrs_to_labels(self,attrs):
+ """Convert a list of LDAP attributes into a more readable form."""
+
+ server = self.setup_server()
+ try:
+ result = server.attrs_to_labels(attrs)
+ except xmlrpclib.Fault, fault:
+ raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
+ except socket.error, (value, msg):
+ raise xmlrpclib.Fault(value, msg)
+
+ return ipautil.unwrap_binary_data(result)