ldap import: avoid duplicated entries.

This commit is contained in:
Antoine Nguyen
2020-04-02 09:55:34 +02:00
parent 5b9b494593
commit c4f876e0c1
+12 -10
View File
@@ -202,18 +202,20 @@ def import_accounts_from_ldap(config):
role = "DomainAdmins"
break
username = force_str(entry[config["ldap_import_username_attr"]][0])
if role == "SimpleUsers":
lpart, domain = split_mailbox(username)
if domain is None:
# Try to find associated email
username = None
for attr in ["mail", "userPrincipalName"]:
if attr in entry:
username = force_str(entry[attr][0])
break
if username is None:
lpart, domain = split_mailbox(username)
if domain is None:
# Try to find associated email
email = None
for attr in ["mail", "userPrincipalName"]:
if attr in entry:
email = force_str(entry[attr][0])
break
if email is None:
if grp == "SimpleUsers":
print("Skipping {} because no email found".format(dn))
continue
else:
username = email
defaults = {
"username": username.lower(),
"is_local": False,