免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3954 | 回复: 0
打印 上一主题 下一主题

[ldap] openldap连接ad的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-08-14 20:08 |只看该作者 |倒序浏览
我在windows2003上搭建了一个AD,在Linux下使用如下命令:
  1. ldapsearch -x -W -D "cn=test,cn=users,dc=test,dc=test2,dc=com" -b "cn=users,dc=test,dc=test2,dc=com" -h 192.168.1.100 "cn=haha"
复制代码

可以得到haha用户的信息。我写了一个测试程序,为什么会出错呢?

  1.    #include <ldap.h>

  2.    main()
  3.    {
  4.            LDAP            *ld;
  5.            LDAPMessage     *res, *e;
  6.            int             i;
  7.            char            *a, *dn;
  8.            void            *ptr;
  9.            char            **vals;

  10.            if ( (ld = ldap_open( "192.168.1.100", LDAP_PORT ))
  11.                    == NULL )
  12.                    exit( 1 );

  13.            if ( ldap_simple_bind_s( ld, "cn=haha,cn=users,dc=test,dc=test2,dc=com", "123$%^aaaAAA") != LDAP_SUCCESS ) {
  14.                    ldap_perror( ld, "ldap_simple_bind_s" );
  15.                    exit( 1 );
  16.            }

  17.            if ( ldap_search_s( ld, "o=test.test2, c=com",
  18.                LDAP_SCOPE_SUBTREE, "(cn=haha)", NULL, 0, &res )
  19.                != LDAP_SUCCESS ) {
  20.                    ldap_perror( ld, "ldap_search_s" );
  21.                    exit( 1 );
  22.            }

  23.            for ( e = ldap_first_entry( ld, res ); e != NULL;
  24.                e = ldap_next_entry( ld, e ) ) {
  25.                    dn = ldap_get_dn( ld, e );
  26.                    printf( "dn: %s", dn );
  27.                    free( dn );

  28.                    for ( a = ldap_first_attribute( ld, e, &ptr );
  29.                            a != NULL;
  30.                        a = ldap_next_attribute( ld, e, ptr ) ) {
  31.                            printf( "attribute: %s", a );

  32.                            vals = ldap_get_values( ld, e, a );
  33.                            for ( i = 0; vals[i] != NULL; i++ ) {
  34.                                    printf( "value: %s", vals[i] );
  35.                            }
  36.                            ldap_value_free( vals );
  37.                    }
  38.            }
  39.            ldap_msgfree( res );

  40.            ldap_unbind( ld );
  41.    }
复制代码

执行结果如下:

  1. ldap_search_s: Operations error (1)
  2.         additional info: 000020D6: SvcErr: DSID-031006CC, problem 5012 (DIR_ERROR), data 0
复制代码

[ 本帖最后由 苦中作乐 于 2007-8-14 20:12 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP