from ldap3 import BASE, LEVEL, SUBTREE, DEREF_NEVER, DEREF_SEARCH, DEREF_BASE, DEREF_ALWAYS
from ldap3 import ALL_ATTRIBUTES, ALL_OPERATIONAL_ATTRIBUTES
from ldap3 import MODIFY_ADD, MODIFY_DELETE, MODIFY_REPLACE
+from ldap3.core.exceptions import LDAPInvalidDnError
from ldap3.core.exceptions import LDAPException
from .idict import CaseInsensitiveDict
from .istringset import CaseInsensitiveStringSet
-__version__ = '0.8.10'
+__version__ = '0.8.11'
LOG = logging.getLogger(__name__)
CFG_BASENAME = 'ldap-migration.ini'
re_dn_split = re.compile(r'\s*,\s*')
re_token_split = re.compile(r'^\s*([a-z0-9]+)\s*=\s*(\S(?:.*\S)?)\s*$', re.IGNORECASE)
+ re_plus_in_cn = re.compile(r'(?P<before>\S)(?:\s+\+\s+|\s+\+|\+\s+)\s*(?P<after>\S)')
tz = get_localzone()
msg = "Trying to get source LDAP item {!r} ...".format(tgt_dn)
LOG.debug(msg)
- src_status, src_result, src_response, _ = self.source.search(
- search_base=tgt_dn, search_scope=BASE, search_filter=sfilter,
- attributes=src_attrs, time_limit=self.config.timeout)
+ try:
+ src_status, src_result, src_response, _ = self.source.search(
+ search_base=tgt_dn, search_scope=BASE, search_filter=sfilter,
+ attributes=src_attrs, time_limit=self.config.timeout)
+ except LDAPInvalidDnError as e:
+ msg = "Could not retrieve entry with DN {dn!r}: {e}".format(dn=tgt_dn, e=e)
+ raise ReadLDAPItemError(msg)
if not src_status:
msg = "Error retrieving source LDAP item {dn!r}: {res}".format(
msg = "F***, Whats that?"
raise CommonLDAPMigrationError(msg)
value = match.group(2)
+ if key.lower() in ('cn', 'commonname' ):
+ if self.re_plus_in_cn.search(value):
+ newval = self.re_plus_in_cn.sub(r'\g<before>+\g<after>', value)
+ msg = "Mangling commonName {old!r} => {new!r}.".format(
+ old=value, new=newval)
+ LOG.debug(msg)
+ return "{key}={val}".format(key=new_key, val=newval)
return "{key}={val}".format(key=new_key, val=value)
new_token = self.mangle_dn_token(old_token)
new_parts.append(new_token)
- return ','.join(parts)
+ return ','.join(new_parts)
# -------------------------------------------------------------------------
def get_reverse_dn(self, dn):