首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当CN和ldap3不同时,DisplayName绑定失败

当CN和ldap3不同时,DisplayName绑定失败
EN

Stack Overflow用户
提问于 2019-11-18 01:52:28
回答 1查看 4.1K关注 0票数 0

我刚接触python,需要在LDAP中进行搜索,但是

当用户的CN和DisplayName不同时,我只能与Domain\user连接。

见下文:

  • ldap3.Connection(s, user=user_cn, ....失败,
  • ldap3.Connection(s, user=user_domain, ....接替

代码语言:javascript
复制
>>> 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。

问用户的域名和密码太麻烦了,有人能帮我吗?

谢谢!

ldap3 = 2.6

Python = 3.5.2

EN

回答 1

Stack Overflow用户

发布于 2020-02-13 11:53:26

您可以尝试使用以下内容来更改user=user_cn(user_domain):

user="{}\\{}".format("domain", username)

至少在我的版本中,这是我能够解决这个问题的方法:

代码语言:javascript
复制
    conn1 = Connection(Server('LDAP://xxxxx.xxxx.xxxx.com:389'),
                       auto_bind=True,
                       user="{}\\{}".format("domain", username),
                       password=password)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58907026

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档