Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Correct usage
I have a general question on how the first parts of the connect (the new() a
nd bind()) calls should be used.
 
The first question is on the usage of the new method. Now, I'm assuming that
 new() is actually trying to establish a connection to the server, so if tha
t fails then the server is unavailable? The reason I ask is that we have sev
eral LDAP servers that I want to perform searches against, if one is down th
en move on to the next, if they're all down, explode.
 
Is this the correct way to perform the new():
 
    if ( $ldap = Net::LDAP->new($host, => timeout=>$timeout, version=>$ldapv
er)) { 
        logmsg("$name: established LDAP connection to $host");
    } else { 
        logmsg("$name: FAILED to estblish LDAP connection to $host");
        return(0); 
    }
 
Now, for the bind() call. Does it return true/false or do I need to evaluate
 the code() or error() from it? In the same code, I'm doing this:
 
    if ( $mesg = $ldap->bind( $binddn, password => $bindpw ) ) {
        logmsg("$name: successful bind to $conn"); 
    } else { 
        logmsg("$name: FAILED to bind to LDAP server $conn as $binddn"); 
        logmsg("$name: LDAP error code is " . $ldap->code); 
        logmsg("$name: LDAP error text is " . $ldap->error); 
        return(0); 
    }
 
then I do this:

    if ( $mesg->code ) { 
        logmsg("$name: FAILED to bind to $conn"); 
        logmsg("$name: LDAP error is: " . $mesg->error); 
        return(0);
    } else {
        logmsg("$name: bind was successful");
        logmsg("$name: performing search");
    }

Is the second part just overly redundant?

Any clarification on how new() and bind() actually work would be wonderful. 
Pointers to other resources or answers would be great. Did the perldoc on it
, got me this far..

Thanks in advance,

Darren Young 
Senior UNIX Administrator
University of Chicago
Graduate School of Business
http://www.chicagogsb.edu
darren.young@gsb.uchicago.edu


Report this thread to moderator Post Follow-up to this message
Old Post
Darren Young
04-14-05 09:01 AM


Re: Correct usage
Hi Darren,

On Thursday 14 April 2005 03:43, Young, Darren wrote:
> I have a general question on how the first parts of the connect (the new()
> and bind()) calls should be used.
>
> The first question is on the usage of the new method. Now, I'm assuming
> that new() is actually trying to establish a connection to the server, so
> if that fails then the server is unavailable? The reason I ask is that we
> have several LDAP servers that I want to perform searches against, if one
> is down then move on to the next, if they're all down, explode.
>
> Is this the correct way to perform the new():
>
>     if ( $ldap = Net::LDAP->new($host, => timeout=>$timeout,
> version=>$ldapver)) { logmsg("$name: established LDAP connection to
> $host");
>     } else {
>         logmsg("$name: FAILED to estblish LDAP connection to $host");
>         return(0);
>     }

Correct new() either returns an object or undef. In the latter case the
variable $@ gives more information about the error.

> Now, for the bind() call. Does it return true/false or do I need to
> evaluate the code() or error() from it? In the same code, I'm doing this:
>
>     if ( $mesg = $ldap->bind( $binddn, password => $bindpw ) ) {
>         logmsg("$name: successful bind to $conn");
>     } else {
>         logmsg("$name: FAILED to bind to LDAP server $conn as $binddn");
>         logmsg("$name: LDAP error code is " . $ldap->code);
>         logmsg("$name: LDAP error text is " . $ldap->error);
>         return(0);
>     }

This is wrong:
Simply do:
$mesg = $ldap->bind( $binddn, password => $bindpw);

The bind() method returns an object no matter if the bind was successful
or not. This resulting object then needs to be checked to find out whether
the bind() was successful.

>     if ( $mesg->code ) {
>         logmsg("$name: FAILED to bind to $conn");
>         logmsg("$name: LDAP error is: " . $mesg->error);
>         return(0);
>     } else {
>         logmsg("$name: bind was successful");
>         logmsg("$name: performing search");
>     }

This is O.K.

> Is the second part just overly redundant?

No, the first part was ;-)

Hope it helps
Peter
--
Peter Marschall
eMail: peter@adpm.de

Report this thread to moderator Post Follow-up to this message
Old Post
Peter Marschall
04-19-05 09:05 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

LDAP archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:12 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.