I'm new to python LDAP and need to do a search in LDAP, but
When the user's CN and DisplayName are different, I can only connect with
Domain\user
.
See below:
ldap3.Connection(s, user=user_cn, ....
Failed,ldap3.Connection(s, user=user_domain, ....
Succeeded
>>> import ldap3
>>>
>>> ADDRESS = 'LDAP://192.168.26.10:389'
>>> user_cn = 'xxx test'
>>> user_domain = 'domain\xxx.test'
>>> password = 'password'
>>> s = ldap3.Server(ADDRESS, get_info=ldap3.ALL)
>>> c = ldap3.Connection(s, user=user_cn, password=password, auto_bind=True)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/ldap3/core/connection.py", line 325, in __init__
self.do_auto_bind()
File "/usr/local/lib/python3.5/dist-packages/ldap3/core/connection.py", line 353, in do_auto_bind
raise LDAPBindError(self.last_error)
ldap3.core.exceptions.LDAPBindError: automatic bind not successful - invalidCredentials
>>> c.extend.standard.who_am_i()
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'c' is not defined
>>>
>>> c = ldap3.Connection(s, user=user_domain, authentication = ldap3.NTLM,password=password, auto_bind=True)
>>> c.extend.standard.who_am_i()
'u:domain\\xxx.test'
>>>
It's ok to use domain/user to connect and bind(),
but when I do the search, I still need the CN in search_base.
Too much trouble to ask user's domain & CN & password, is there anyone can help me.
Thanks!
ldap3 = 2.6
Python = 3.5.2