Well, since LDAP saves the data in a tree-like-structure, you'll need to know where a user is located to find his distinguishedName (= path and unique key to that user object).
If you save all your users in one container of the tree (Well, then you seem to loose the structure, but you can also save it as an attribute or referal to a department object...), e.g.
c=org
co=MyCompany
cn=Users
cn=Mickey Mouse id456
cn=Donald Duck id123
cn=Tim Towdi id111
it becomes rather easy, then your distinguishedName (=dn) looks like
x) cn=Donald Duck id123,cn=Users,co=MyCompany,c=org
x) cn=Mickey Mouse id456 ,cn=Users,co=MyCompany,c=org
then you can build your bindDn very easily (the id is here to get everything unique; if you use another way to make sure an object is unique); if not, you first have to do a search for it, e.g. by an anonymous bind, e.g.
use Net::LDAP;
my $ldap = Net::LDAP->new($ldapServer) or die "Error: $@";
my $result = $ldap->bind(); # anonymous bind first
die ("Error in bind: ", $result->error) if $result->code;
$result = $ldap->search
( base => 'cn=Users,co=MyCompany,c=org',
filter => "(&(sn=$surname)(givenName=$givenName))", # & is for an
+AND
scope => 'sub', # start from base and search to the bottom
attributes => []
);
die ("Error in search: ", $result->error) if $result->code;
foreach my $entry ($result->entries) {
print "DN: ", $entry->dn(), "\n";
}
}
$ldap->unbind();
if you only get back one user, try to bind as this user and his password:
use Net::LDAP;
my $ldap = Net::LDAP->new($ldapServer) or die "Error: $@";
my $success = $ldap->bind($dn, -password => $userPassword);
if ($success->code) {
print "Error\n";
}
else {
print "Ok\n";
$ldap->unbind();
}
the following perldoc's give you some code examples:
perldoc Net::LDAP::FAQ
perldoc Net::LDAP::Examples
These codes are note tested, and maybe you need a completely different structure
Best regards,
perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"
|