【发布时间】:2013-11-13 01:52:08
【问题描述】:
幸运的是,这段代码仅用于测试,并且足够短,只需在此处完整复制/粘贴即可。基本上,我需要绑定到一个 dn 才能获得我的搜索的具体细节。否则,如果不绑定,它会匿名绑定,然后我只能获取准系统信息。除非我在绑定后显式运行 whoami_s(),否则我似乎无法成功绑定。
不起作用的代码(匿名绑定):
l = ldap.initialize("ldap://myldapserver")
l.simple_bind("cn=test,ou=profile,dc=site,dc=com", "abc123")
basedn = "ou=people,dc=site,dc=com"
filter = "uid=bob"
results = l.search_st(basedn, ldap.SCOPE_SUBTREE, filter)
for entry in results:
print entry
有效的代码(成功绑定并提供所有可能的细节):
l = ldap.initialize("ldap://myldapserver")
l.simple_bind("cn=test,ou=profile,dc=site,dc=com", "abc123")
l.whoami_s() ### <---- This is the only difference ###
basedn = "ou=people,dc=site,dc=com"
filter = "uid=bob"
results = l.search_st(basedn, ldap.SCOPE_SUBTREE, filter)
for entry in results:
print entry
我发现关于 LDAP 模块的文档非常缺乏(例如,我找不到详细说明 bind、bind_s、simple_bind 和 simple_bind_s 之间的确切区别的任何内容,但这是另一天的问题。)。我找不到任何明确说明您需要使用 whoami_s() 或任何东西来完成绑定的内容。我应该接受它,还是应该担心?
Python: 2.6.9
LDAP module: 2.4.13
【问题讨论】:
标签: python ldap bind ldap-query