summaryrefslogtreecommitdiffstats
path: root/ipaserver/ipaldap.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2013-01-18 04:51:41 -0500
committerMartin Kosek <mkosek@redhat.com>2013-03-01 16:59:43 +0100
commit6fb115751c6575b7491a123e04a5a34738ea8ff6 (patch)
tree020120dda276060752542b4c235d409dafec90c8 /ipaserver/ipaldap.py
parent44e15206d03e7e1a47af4280f4d99ce86301d6f3 (diff)
downloadfreeipa.git-6fb115751c6575b7491a123e04a5a34738ea8ff6.tar.gz
freeipa.git-6fb115751c6575b7491a123e04a5a34738ea8ff6.tar.xz
freeipa.git-6fb115751c6575b7491a123e04a5a34738ea8ff6.zip
Move DN handling methods to LDAPConnection
ldap2 has "DN normalization" functionality, which silently adds the base DN to DNs that don't already end with it. This functionality is left in the ldap2 class only. Part of the work for: https://fedorahosted.org/freeipa/ticket/2660
Diffstat (limited to 'ipaserver/ipaldap.py')
-rw-r--r--ipaserver/ipaldap.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/ipaserver/ipaldap.py b/ipaserver/ipaldap.py
index 3e115e3b..20da4418 100644
--- a/ipaserver/ipaldap.py
+++ b/ipaserver/ipaldap.py
@@ -902,6 +902,44 @@ class LDAPConnection(object):
obj = self.schema.get_obj(_ldap.schema.AttributeType, attr)
return obj and obj.single_value
+ def normalize_dn(self, dn):
+ """Override to normalize all DNs passed to LDAPConnection methods"""
+ assert isinstance(dn, DN)
+ return dn
+
+ def make_dn_from_attr(self, attr, value, parent_dn=None):
+ """
+ Make distinguished name from attribute.
+
+ Keyword arguments:
+ parent_dn -- DN of the parent entry (default '')
+ """
+ if parent_dn is None:
+ parent_dn = DN()
+ parent_dn = self.normalize_dn(parent_dn)
+
+ if isinstance(value, (list, tuple)):
+ value = value[0]
+
+ return DN((attr, value), parent_dn)
+
+ def make_dn(self, entry_attrs, primary_key='cn', parent_dn=None):
+ """
+ Make distinguished name from entry attributes.
+
+ Keyword arguments:
+ primary_key -- attribute from which to make RDN (default 'cn')
+ parent_dn -- DN of the parent entry (default '')
+ """
+
+ assert primary_key in entry_attrs
+
+ if parent_dn is None:
+ parent_dn = DN()
+
+ parent_dn = self.normalize_dn(parent_dn)
+ return DN((primary_key, entry_attrs[primary_key]), parent_dn)
+
class IPAdmin(LDAPConnection):