LDAP 系统用户uid 查找用户邮箱地址


#!/tools/cfr/bin/perl
#this is a module that will find user's mailbox using UID:
#contact [email protected]
#8/17/2012

sub get_mailaddress{
use Net::LDAP;
$LDAPServer = 'ldap.lsil.com';
#$argString = join("*", @ARGV);
my $ldap = Net::LDAP->new("$LDAPServer") or die "$@";
$ldap->bind ;    # an anonymous bind
 $mesg = $ldap->search (  # perform a search
  base   => "ou=lsil.com,o=lsi logic",
  filter => "| (uid=*$uid*) $extraFilter ",
  attrs  => ['mail'],
             );
$mesg->code && die $mesg->error;
my $max = $mesg->count;
for ($i =0; $i < $max; $i++) {
  my $entry = $mesg->entry($i);
# build an array of attributes
  foreach my $attr ($entry->attributes) {
    print $entry->get_value($attr),"\n";
  }
}

$ldap->unbind;   # take down session
exit;
}
$uid="ricwang";
& get_mailaddress ($uid);
 

你可能感兴趣的:(perl,search,LDAP,uid,and,mailbox)