免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4891 | 回复: 3

[ldap] 神啊救救我,LDAP程序怎么也运行不了,极度郁闷 [复制链接]

论坛徽章:
0
发表于 2007-12-08 16:04 |显示全部楼层
我已经配置好了我的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上取得一切信息(如组什么的)
折腾了好几天了,极度郁闷

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
发表于 2007-12-09 09:25 |显示全部楼层
没用过Python
但看样子是是连上了,指定一个base 看看

论坛徽章:
0
发表于 2007-12-09 22:15 |显示全部楼层
base = "cn=pyw, CN=users,DC=TECH,DC=com"


加了base也还是不行~,郁闷

论坛徽章:
0
发表于 2007-12-10 18:31 |显示全部楼层
我新建了一个ldif文件
root@ubuntu6s:/home/temp# cat /test.ldif
      dn: dc=tech,dc=com
      objectclass: dcObject
      objectclass: organization
      o: tech
      dc: tech

      dn: cn=users,dc=tech,dc=com
      objectclass: organizationalRole
      cn: aduser

然后
root@ubuntu6s:/home/temp# ps aux |grep slapd
root     20208  0.0  0.2   2796   748 pts/0    R+   04:28   0:00 grep slapd

然后
root@ubuntu6s:/home/temp# ldapadd -x -D "cn=aduser,cn=users,dc=tech,dc=com" -W -f /test.ldif
Enter LDAP Password:
ldap_bind: Can't contact LDAP server (-1)


其中,aduser是Win2003AD上的用户(有DomainAdmin权限)

为什么会出错呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP