diff --git a/services/univention-s4-connector/modules/univention/s4connector/s4/__init__.py b/services/univention-s4-connector/modules/univention/s4connector/s4/__init__.py index 6d5fb6c4d2..aa3f8d155f 100644 --- a/services/univention-s4-connector/modules/univention/s4connector/s4/__init__.py +++ b/services/univention-s4-connector/modules/univention/s4connector/s4/__init__.py @@ -353,12 +353,14 @@ def samaccountname_dn_mapping(s4connector, given_object, dn_mapping_stored, ucso newdn = unicode(result[0][0], 'utf8') else: s4_rdn = ldap.dn.str2dn(result[0][0])[0] - new_s4_dn = unicode(ldap.dn.dn2str([s4_rdn] + exploded_dn[1:]), 'utf8') - pos = new_s4_dn.lower().rfind(s4connector.lo_s4.base.lower()) - newdn = new_s4_dn[:pos] + s4connector.lo.base + tmp_dn_string = unicode(ldap.dn.dn2str([s4_rdn] + exploded_dn[1:]), 'utf8') + pos = tmp_dn_string.lower().rfind(s4connector.lo.base.lower()) + newdn = tmp_dn_string[:pos] + s4connector.lo_s4.base else: newdn_rdn = [('cn', fst_rdn_value_utf8, ldap.AVA_STRING)] - newdn = unicode(ldap.dn.dn2str([newdn_rdn] + exploded_dn[1:]), 'utf8') # new object, don't need to change + tmp_dn_string = unicode(ldap.dn.dn2str([newdn_rdn] + exploded_dn[1:]), 'utf8') # new object, don't need to change + pos = tmp_dn_string.lower().rfind(s4connector.lo.base.lower()) + newdn = tmp_dn_string[:pos] + s4connector.lo_s4.base ud.debug(ud.LDAP, ud.INFO, "samaccount_dn_mapping: newdn: %s" % newdn) else: # get the object to read the sAMAccountName in S4 and use it as name @@ -408,7 +410,9 @@ def samaccountname_dn_mapping(s4connector, given_object, dn_mapping_stored, ucso else: newdn_rdn = [(ucsattrib, unicode_to_utf8(samaccountname), ldap.AVA_STRING)] - newdn = unicode(ldap.dn.dn2str([newdn_rdn] + exploded_dn[1:]), 'utf8') # guess the old dn + tmp_dn_string = unicode(ldap.dn.dn2str([newdn_rdn] + exploded_dn[1:]), 'utf8') # guess the old dn + pos = tmp_dn_string.lower().rfind(s4connector.lo_s4.base.lower()) + newdn = tmp_dn_string[:pos] + s4connector.lo.base try: ud.debug(ud.LDAP, ud.INFO, "samaccount_dn_mapping: newdn for key %s:" % dn_key) ud.debug(ud.LDAP, ud.INFO, "samaccount_dn_mapping: olddn: %s" % dn)