Hi
I am getting user group from active directory. I am using the follow sample code with correct values.
But I getting an error.
Can't call method "bind" without a packake ....
Please help ..
use strict;
use Net::LDAP;
my $ldap = Net::LDAP->new('IPADDRESS', debug =>0, timeout=>5) or die "$@";
#must bind as administrator to retrieve all user attributes in LDAP
my $admin = 'cn=administrator, cn=Users, dc=my, dc=domain, dc=name, dc=com';
my %bindargs;
$bindargs{password} = 'password';
$bindargs{version} = 3;
$ldap->bind ;
my $mesg = $ldap->bind( $admin, %bindargs);
#make sure we binded correctly with the username and password specified
if ($mesg->code != 0)
{
if ($mesg->code ==49)
{
printf("Password not correct");
}
else
{
printf("Error in binding");
}
}
#LDAP search filter that lists all the entries for "Users"
my $mesg = $ldap->search ( # perform a search
base => "CN=Users, dc=my, dc=domain, dc=name, dc=com",
scope => "1",
filter => "objectclass=*",
);
my $count = $mesg->count();
print "Total #attributes retrived: $count";
#name of attribute to get
my $attr1 = "userPrincipalName";
$mesg->code && die $mesg->error;
my
@usernames;
my $max = $mesg->count;
for(my $i = 0 ; $i < $max ; $i++)
{
my $entry = $mesg->entry($i);
if ($entry->get($attr1) ne "")
{
push(
@usernames,$entry->get($attr1));
}
}
foreach my $x (
@usernames) {
print "\n$x";
}
$ldap->unbind; # take down session
Regards,
ravi