- 论坛徽章:
- 0
|
我已经配置好了我的ubuntu610可以登录Windows2003AD了,但是运行我的Python连接LDAP的脚本怎么都是失败,错误信息:
root@ubuntu6s:/home/temp# python adtest2.py
<ldap.ldapobject.SimpleLDAPObject instance at 0xb7d176ec>
1
Successfully bound to server.
Searching..
{'info': '00000000: LdapErr: DSID-0C090627, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, vece', 'desc': 'Operations error'}
在Windows2003AD上已经可以看到我ubuntu的计算机名
Python源代码如下:
#!/usr/bin/python
#-*- coding:utf-8 -*-
import ldap
def main():
server = "192.168.100.150"
who = "administrator"
cred = "123456"
keyword = "ffb"
try:
#l = ldap.open(server)
l = ldap.initialize('ldap://192.168.100.150')
print l
b = l.bind('cn=administrator,o=MyDOMAIN','PASSWORD',ldap.AUTH_SIMPLE)
print b
#l.bind_s(who, cred, ldap.AUTH_SIMPLE)
print "Successfully bound to server.\n"
print "Searching..\n"
my_search(l, keyword)
except ldap.LDAPError, error_message:
print "Couldn't Connect. %s " % error_message
def my_search(l, keyword):
base = ""
scope = ldap.SCOPE_SUBTREE
filter = "cn=" + "*" + keyword + "*"
retrieve_attributes = None
count = 0
result_set = []
timeout = 0
try:
result_id = l.search(base, scope, filter, retrieve_attributes)
while 1:
result_type, result_data = l.result(result_id, timeout)
if (result_data == []):
break
else:
result_type
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(result_data)
if len(result_set) == 0:
print "No Results."
return
for i in range(len(result_set)):
result_set
for entry in result_set:
try:
name = entry[1]['cn'][0]
email = entry[1]['mail'][0]
phone = entry[1]['telephonenumber'][0]
desc = entry[1]['description'][0]
count = count + 1
print "%d.\nName: %s\nDescription: %s\nE-mail: %s\nPhone: %s\n" %\
(count, name, desc, email, phone)
except:
pass
except ldap.LDAPError, error_message:
print error_message
if __name__=='__main__':
main()
还用PHP和C#做了试验,全部不能成功,但是找了一个叫ADModify的软件就可以从AD上取得一切信息(如组什么的)
折腾了好几天了,极度郁闷 |
|