Connecting to Active Directory Application Mode from Perl

Posted by Khurram Aziz on Stack Overflow See other posts from Stack Overflow or by Khurram Aziz
Published on 2010-04-18T09:25:14Z Indexed on 2010/04/18 9:33 UTC
Read the original article Hit count: 574

Filed under:
|
|

I am trying to connect to Active Directory Application Mode instance. The instance is conenctable from third party LDAP clients like Softerra LDAP Browser. But I am getting the following error when connecting from Perl

Net::LDAP=HASH(0x876d8e4) sending:
Net::LDAP=HASH(0x876d8e4) received:

30 84 00 00 00 A7 02 01 02 65 84 00 00 00 9E 0A 0........e......
01 01 04 00 04 84 00 00 00 93 30 30 30 30 30 34 ..........000004
44 43 3A 20 4C 64 61 70 45 72 72 3A 20 44 53 49 DC: LdapErr: DSI
44 2D 30 43 30 39 30 36 32 42 2C 20 63 6F 6D 6D D-0C09062B, comm
65 6E 74 3A 20 49 6E 20 6F 72 64 65 72 20 74 6F ent: In order to
20 70 65 72 66 6F 72 6D 20 74 68 69 73 20 6F 70  perform this op
65 72 61 74 69 6F 6E 20 61 20 73 75 63 63 65 73 eration a succes
73 66 75 6C 20 62 69 6E 64 20 6D 75 73 74 20 62 sful bind must b
65 20 63 6F 6D 70 6C 65 74 65 64 20 6F 6E 20 74 e completed on t
68 65 20 63 6F 6E 6E 65 63 74 69 6F 6E 2E 2C 20 he connection.,
64 61 74 61 20 30 2C 20 76 65 63 65 00 __ __ __ data 0, vece.`

My directory structure is

Partition: CN=Apps,DC=MyCo,DC=COM
User exists as CN=myuser,CN=Apps,DC=MyCo,DC=COM

I have couple of other entries of the custom class which I am interested to browse; those instances appear fine in ADSI Edit, Softerra LDAP Browser etc.

I am new to Perl....My perl code is

#!/usr/bin/perl
use Net::LDAP;
$ldap = Net::LDAP->new("127.0.0.1", debug => 2,
  user => "CN=myuser,CN=Apps,DC=MyCo,DC=COM",
  password => "secret"
 ) or die "$@";
$ldap->bind(version => 3) or die "$@";
print "Connected to ldap\n";
$mesg = $ldap->search(
  filter => "(objectClass=*)"
 ) or die ("Failed on search.$!");
my $max = $mesg->count;
print "$max records found!\n";
for( my $index = 0 ; $index < $max ; $index++)
{
 my $entry = $mesg->entry($index);
 my $dn = $entry->dn;
 @attrs = $entry->attributes;
 foreach my $var (@attrs)
 {
  $attr = $entry->get_value( $var, asref => 1 );
  if ( defined($attr) )
  {
   foreach my $value ( @$attr )
   {
    print "$var: $value\n";
   }
  }
 }
}
$ldap->unbind();

© Stack Overflow or respective owner

Related posts about perl

Related posts about ldap