2011-01-06 8 views
1

私はこのコードを使用しています。これはLDAP機能で実行できますか?

#!/usr/bin/perl 

use warnings; 
use strict; 
use Net::LDAP; 
use Data::Dumper; 

my $dn="..."; 
my $password="..."; 

my $ldap = Net::LDAP->new('...') or die "[email protected]"; 
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') 
      ], 

答えて

2
push @ad, $_->get_value('sAMAccountName'); 
関連する問題