我是 python LDAP 的新手,需要在 LDAP 中进行搜索,但是
当用户的 CN 和 DisplayName 不同时,我只能连接
Domain\user
.
见下文:
ldap3.Connection(s, user=user_cn, ....
失败的,ldap3.Connection(s, user=user_domain, ....
成功
>>> 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'
>>>
使用域/用户连接和绑定()是可以的,
但是当我进行搜索时,我仍然需要search_base中的CN。
问用户的域名&CN&密码太麻烦了,有没有人可以帮帮我。
谢谢!
ldap3 = 2.6
Python = 3.5.2