Re: First LDAP-Perl Script

Chris Ridd <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.ldap
Message-ID <[email protected]>
On 20 Sep 2009, at 18:44, Parag Kalra wrote:

> I think I got what was going wrong...If I am not wrong 'bind' method  
> uses
> authentication hence credentials only while making any changes
> (add/modify/delete) to ldap server.
>
> So if I will use wrong credentials to modify ldap database then it  
> will
> surely shout...

Not quite.

All the 'operation' methods like bind(), add(), modify(), search(),  
etc return undef if there was a problem sending the operation to the  
server. They do *not* return undef if the server fails the operation.

To check if the server fails the operation, you need to get the result  
of the operation, and test the result code inside that. This is  
commonly done like this:

---
$res = $ldap->some-operation-here(with-lots-of-arguments) or die  
"Cannot send some-operation-here";

die "Some operation failed (", $res->error_name, ")" if $res->code;
---

This works because an LDAP OK result is numeric 0. Note operations can  
return other codes which your application might also consider to be  
"OK" in some sense, so you will need to modify the above logic a  
little in those cases.

Read the Net::LDAP::Message documentation to find out more things you  
can do with $res.

Cheers,

Chris
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.