Chinaunix

标题: perl ldap search 错误 [打印本页]

作者: cduedu    时间: 2009-12-13 23:19
标题: perl ldap search 错误
今天晚上把ldap 模块装上了,写了一个脚本来进行search,但无论怎么改条件就是等到没有这个object:
#!/usr/bin/perl -w
use Net::LDAP;

my $targetHost = '192.168.1.4';
my $targetHostPort = '12389';
my $targetUser = 'uid=xhphuyu,ou=People,dc=example,dc=com';
my $targetPassword = '123456';


my $targethost='localhost';
my $ports='12389';

# Open connection to target LDAP
my $ldap = Net::LDAP->new( $targetHost, port => $targetHostPort ) or die "Error: Could not connect to Direcotry Server: $@";
# Bind or die trying
my $mesg = $ldap->bind( $targetUser, password => $targetPassword);
#my $mesg = $ldap->bind();
$mesg->code && die "Error: Could not bind:" . $mesg->error;

# see your LDAP administrator for information concerning the
# user authentication setup at your site.
my $result = $ldap->search( base => 'ou=pepole,dc=exapmle,dc=com',filter =>"(&(uid=xhphuyu))");
#my $result = $ldap->delete('uid=bfree,ou=People,dc=example,dc=com');
$result->code && warn " Warnning: Failed to search entry: ", $result->error;
$mesg = $ldap->unbind;

那位帮忙看看是什么地方出了问题,我试了删除一条记录是没有问题的,但search总是会错,郁闷死我了:
[13/Dec/2009:23:05:39 +0800] conn=92 op=0 msgId=1 - BIND dn="uid=xhphuyu,ou=People,dc=example,dc=com" method=128 version=3
[13/Dec/2009:23:05:39 +0800] conn=92 op=0 msgId=1 - RESULT err=0 tag=97 nentries=0 etime=0 dn="uid=xhphuyu,ou=people,dc=example,dc=com"
[13/Dec/2009:23:05:39 +0800] conn=92 op=1 msgId=2 - SRCH base="ou=pepole,dc=exapmle,dc=com" scope=2 filter="(uid=xhphuyu)" attrs=ALL
[13/Dec/2009:23:05:39 +0800] conn=92 op=1 msgId=2 - RESULT err=32 tag=101 nentries=0 etime=0
[13/Dec/2009:23:05:39 +0800] conn=92 op=2 msgId=3 - UNBIND
[13/Dec/2009:23:05:39 +0800] conn=92 op=2 msgId=-1 - closing from 192.168.1.4:33608 - U1 - Connection closed by unbind client -
[13/Dec/2009:23:05:40 +0800] conn=92 op=-1 msgId=-1 - closed.

[ 本帖最后由 cduedu 于 2009-12-13 23:21 编辑 ]
作者: ulmer    时间: 2009-12-14 00:39
原帖由 cduedu 于 2009-12-13 23:19 发表
今天晚上把ldap 模块装上了,写了一个脚本来进行search,但无论怎么改条件就是等到没有这个object:
#!/usr/bin/perl -w
use Net::LDAP;

my $targetHost = '192.168.1.4';
my $targetHostPort = '12389';
...
my $result = $ldap->search( base => 'ou=pepole,dc=exapmle,dc=com',filter =>"(&(uid=xhphuyu))");
....


Check your ldap filter operation!
LDAP filter "AND" condition's operater: (&(<attibute>)(<attribute>)...)

try this: filter => '(uid=xhphuyu)'




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2