您的位置:首页 > 其它

Net::LDAP

2016-05-24 16:04 656 查看
LDAP version 3..可以查询基本资料、验证密码。

#!/usr/bin/perl
use Net::LDAP;

## get a object of ldap
$ldap = Net::LDAP->new("1.1.1.1", port =>"389", version => 3) or die "$@";
# object of Net::LDAP::Message
$mesg = $ldap->bind($_cer_id, password => $_cer_pw); # 查詢用的ID/PASSWD
if($mesg->is_error) {die $mesg->error;}
$mesg = $ldap->search(
base => "o=abc,c=tt", # 起始點
scope => "sub", # 範圍
filter => "(uid=apile)", # 條件
attrs => ["cn"], # 要取得的attribute
typesonly => 0   );

my $max_len = $mesg->count; ## get number of entry

#--取得中文姓名,可能不只一筆
for($i=0;$i<$max_len;$i++){
$entry = $mesg->entry($i);
$cname = $entry->get_value("cn"); # get chinese name
}

#--作密码验证
$mesg = $ldap->bind($entry->dn, password => "abc", version => 3)
||die "can't connect to ldap";
if($mesg->code) { print "verification is failed"}
else{ print "success"}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: