免费注册 查看新帖 |

Chinaunix

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

perl net:ldap嵌套OU查询报错 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-09-12 18:06 |只看该作者 |倒序浏览
我发现如果将$LDAP_BASE再多写一层OU就可以了,如:$LDAP_BASE = 'OU=BB,OU=Aaa,DC=internal,DC=aaa,DC=com';
是否能是这两个原因之一:
1、再上一层OU=Aaa下查询出的人过多(2W多),所以改成BB时就可以了
2、只能查询一层OU。但是我已经scope => 'sub'了

求高手给分析下原因
# LDAP server
my $LDAP_BASE = 'OU=Aaa,DC=internal,DC=aaa,DC=com';   # LDAP search base
my $LDAP_SERVER = 'xxx-yyy.zzz.aaa.com';
my $LDAP_DN = 'readonly';
my $LDAP_PASSWORD = 'passwd';
my $filter = "(&(objectClass=person))";


# connect to LDAP server
my $ldap = Net::LDAP->new($LDAP_SERVER, onerror => \&sendMail);
if (!defined($ldap)) {
    &sendMail("Failed to connect to LDAP Server [$LDAP_SERVER]");
}


# bind account
my $result = $ldap->bind($LDAP_DN, password => $LDAP_PASSWORD);
if ($result->code()) {
    &sendMail("AD bind failed");
}

#调试脚本是在这里停了
# get account information
$result = $ldap->search(
    base => $LDAP_BASE,
    scope => 'sub',             # entire tree
    timelimit => 600,
    filter => $filter,
    attrs => ['sAMAccountName','mail'],
    );

给出的异常是Net::LDAP::Search=HASH(0xaba3d0)这种。

论坛徽章:
0
2 [报告]
发表于 2013-09-12 20:13 |只看该作者
根据提示,应该是你后面在用$result时错了,看下后面的。

论坛徽章:
0
3 [报告]
发表于 2013-09-13 16:04 |只看该作者

    if ($result->code()) {          # failed
        &sendMail("Could not get the account info!");
    }   
ttt4011 发表于 2013-09-12 20:13
根据提示,应该是你后面在用$result时错了,看下后面的。

论坛徽章:
0
4 [报告]
发表于 2013-09-13 16:06 |只看该作者
再然后是这个,然后就没用到$result了
# open log
    open(LOG, ">>", $logfile) || &sendMail("failed to create log file");
   
    print LOG '#' x 20 . "\n";
    print LOG "# AD $OU_array[$i] users" . "\n";
    print LOG '#' x 20 . "\n";
   
    my %adusers;
    while (my $entry = $result->shift_entry) {
        my $sam = $entry->get_value('sAMAccountName');
        my $mail = $entry->get_value('mail');
        if (!defined($sam) || $sam eq "") {
            next;
        }   
        if (!defined($mail) || $mail eq "") {
            next;
        }   
        if ($sam !~ /^[a-zA-Z0-9._-]+$/) {
            next;
        }

        print LOG $sam . ", " . $mail . "\n";

        my $user = [];
        @{$user}[0] = $sam;
        @{$user}[1] = $mail;
        $adusers{$sam} = $user;
        $adcounter++;
    }

    close(LOG);

    $ldap->unbind(dn => $LDAP_DN, password => $LDAP_PASSWORD);
ttt4011 发表于 2013-09-12 20:13
根据提示,应该是你后面在用$result时错了,看下后面的。

论坛徽章:
0
5 [报告]
发表于 2013-09-13 17:20 |只看该作者
代码没发现什么问题,你可以看下ldap服务器的日志,看那里面有什么提示没。回复 4# yuliu1212


   

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
6 [报告]
发表于 2013-09-16 07:48 |只看该作者
回复 1# yuliu1212

1. 在你提到的“1”中。如果是这样,你的$ldap->search是能看到提示的。
2. 在你提到的“2”中,不知道是你写错了还是你理解错了。scope你写sub就是会出来很多结果,改成base
3. “#调试脚本是在这里停了”。程序不会在这里停。。。唯一可能的就是$ldap->search这里,$ldap->search有没有结果?读结果看看http://search.cpan.org/~marschap ... Net/LDAP/Search.pod
4. 调试LDAP的程序要排除环境因素,LDAP服务器的设置直接影响你的结果。在写程序之前,一定要先用ldapsearch
   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP