From: Chris R. <C.G...@Br...> - 2002-11-04 12:00:25
|
This confused me for a while too when I got started with LDAP. I now use the following two functions so I can test by true or false in my main loop plus print meaningful error codes: sub LDAPConnect { my ($Server, $Account, $Password) = @_; my $LDAP; $LDAP = Net::LDAP->new($Server) || die "Cannot connect to $Server\n"; my $mesg = $LDAP->bind(dn => $Account, password => $Password); LDAPError("Binding", $mesg) if $mesg->code(); return 0 if $mesg->code(); return $LDAP; } sub LDAPError { my ($from, $mesg) = @_; print STDERR "\n"; print STDERR "Return code: ", $mesg->code . "\n"; print STDERR "Message: ", ldap_error_name($mesg->code); print STDERR " : ", ldap_error_text($mesg->code); print STDERR "MessageID: ", $mesg->mesg_id . "\n"; print STDERR "DN: ", $mesg->dn; print STDERR "\n"; } HTH, Chris. -----Original Message----- From: per...@li... [mailto:per...@li...]On Behalf Of Capacio, Paula J Sent: 01 November 2002 16:28 To: Perl-LDAP Mail list (E-mail) Subject: RE: How to check results of BIND On Fri, Nov 01, 2002 at 09:40:33AM -0600, Capacio, Paula J wrote: >> Hi, >> What's the best way to see if the BIND was successful? >> I coded... >> $ldapAsME->bind( dn => $entry, password => $myPWD) or die "$@"; >> ###I'm not dying when I pass a bad PWD....why ??? >> >On Friday, November 01, 2002 10:11 AM, Graham Barr wrote: >Because your code is wrong. ->bind does not return a true/false result. >All methods return a message object which you must use to determine >sucess by looking at the code. > > http://search.cpan.org/author/GBARR/perl-ldap-0.26/lib/Net/LDAP.pod#METHODS > Thanks Graham! I do check the $mesg code on all other calls, I didn't realize it applied to the bind as well! Thanks, my code works like a charm now! ------------------------------------------------------- This sf.net email is sponsored by: See the NEW Palm Tungsten T handheld. Power & Color in a compact size! http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en |