我有这个代码可以使用。
#!/usr/bin/perl
use warnings;
use strict;
use Net::LDAP;
use Data::Dumper;
my $dn="...";
my $password="...";
my $ldap = Net::LDAP->new('...') or die "$@";
my $mesg = $ldap->bind($dn, password => $password);
if ($mesg->code) { die "uuuu $mesg"; }
$mesg = $ldap->search(
base => "...",
scope => 'one',
filter => '(groupType=-2147483646)',
attrs => ['sAMAccountName'],
);
my @ad = ( );
foreach ($mesg->entries) {
push @ad, $_->asn->{attributes}[0]->{vals}[0];
}
foreach (@ad) {
print;
print "\n";
}
并输出安全组的名称。
所以我想知道,如果LDAP(Active Directory)具有从树中提取值的功能,而不是像我在
那样使用数组和散列来硬编码路径push @ad, $_->asn->{attributes}[0]->{vals}[0];
树看起来像这样
'entries' => [
bless( {
'changes' => [],
'changetype' => 'modify',
'asn' => {
'objectName' => '...',
'attributes' => [
{
'type' => 'sAMAccountName',
'vals' => [
'test-group-1'
]
}
]
}
}, 'Net::LDAP::Entry' ),
bless( {
'changes' => [],
'changetype' => 'modify',
'asn' => {
'objectName' => '...',
'attributes' => [
{
'type' => 'sAMAccountName',
'vals' => [
'test-group-3'
]
}
]
}
}, 'Net::LDAP::Entry' )
],
答案 0 :(得分:2)
push @ad, $_->get_value('sAMAccountName');