mirror of
https://github.com/cwinfo/powerdns-admin.git
synced 2025-01-02 16:35:40 +00:00
Merge branch 'hotfix-ldap' into development
This commit is contained in:
commit
cecc0ac9df
@ -8,6 +8,7 @@ import traceback
|
|||||||
import pyotp
|
import pyotp
|
||||||
import re
|
import re
|
||||||
import dns.reversename
|
import dns.reversename
|
||||||
|
import sys
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
@ -188,11 +189,13 @@ class User(db.Model):
|
|||||||
logging.error('LDAP authentication is disabled')
|
logging.error('LDAP authentication is disabled')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
searchFilter = "(&(objectcategory=person)(samaccountname=%s))" % self.username
|
if LDAP_TYPE == 'ad':
|
||||||
if LDAP_TYPE == 'ldap':
|
searchFilter = "(&(objectcategory=person)(%s=%s)(%s))" % (LDAP_USERNAMEFIELD, self.username, LDAP_FILTER)
|
||||||
searchFilter = "(&(%s=%s)%s)" % (LDAP_USERNAMEFIELD, self.username, LDAP_FILTER)
|
|
||||||
logging.info('Ldap searchFilter "%s"' % searchFilter)
|
|
||||||
|
|
||||||
|
elif LDAP_TYPE == 'ldap':
|
||||||
|
searchFilter = "(&(%s=%s)(%s))" % (LDAP_USERNAMEFIELD, self.username, LDAP_FILTER)
|
||||||
|
|
||||||
|
logging.info('Ldap searchFilter "%s"' % searchFilter)
|
||||||
result = self.ldap_search(searchFilter, LDAP_SEARCH_BASE)
|
result = self.ldap_search(searchFilter, LDAP_SEARCH_BASE)
|
||||||
if not result:
|
if not result:
|
||||||
logging.warning('User "%s" does not exist' % self.username)
|
logging.warning('User "%s" does not exist' % self.username)
|
||||||
@ -223,6 +226,12 @@ class User(db.Model):
|
|||||||
self.firstname = result[0][0][1]['givenName'][0]
|
self.firstname = result[0][0][1]['givenName'][0]
|
||||||
self.lastname = result[0][0][1]['sn'][0]
|
self.lastname = result[0][0][1]['sn'][0]
|
||||||
self.email = result[0][0][1]['mail'][0]
|
self.email = result[0][0][1]['mail'][0]
|
||||||
|
|
||||||
|
if sys.version_info < (3,):
|
||||||
|
if isinstance(self.firstname, str):
|
||||||
|
self.firstname = self.firstname.decode('utf-8')
|
||||||
|
if isinstance(self.lastname, str):
|
||||||
|
self.lastname = self.lastname.decode('utf-8')
|
||||||
except Exception:
|
except Exception:
|
||||||
self.firstname = self.username
|
self.firstname = self.username
|
||||||
self.lastname = ''
|
self.lastname = ''
|
||||||
|
Loading…
Reference in New Issue
Block a user