Suezy
Suezy

Reputation:

Ldap_bind() ERROR

Good day! How do we know that a LDAP server allows anonymous connections?

When i run my php program: i get this error:

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in /var/www/sue/ldapTest2.php on line 14

This is my simple sample test program:

LDAP query test"; echo "Connecting ..."; $ds=ldap_connect("apserv"); // must be a valid LDAP server! echo "Connect result is ".$ds."

"; if ($ds) { echo "Binding ..."; $r=ldap_bind($ds); // this is an "anonymous" bind, typically // read-only access } echo "Bind result is ".$r."

"; ?>

OUTPUTS:

LDAP query test Connecting ...Connect result is Resource id #2

Binding ... Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in /var/www/sue/ldapTest2.php on line 14 Bind result is

Need help.. THANKS.. =)

Upvotes: 1

Views: 7292

Answers (3)

Stefan Gehrig
Stefan Gehrig

Reputation: 83672

Are you trying to check whether your specific server supports anonymous binds (1) or are you looking for a generic way to determine if some LDAP server supports anonymous binds (2)?

(1) What server are you testing against? OpenLDAP provides the following configuration settings:

  • disallow bind_anon: dissallows anonymous binds; enabled by default
  • allow bind_anon_cred: allows so called unauthenticated binds (username but no password provided); disabled by default
  • disallow bind_simple_unprotected: disallow simple binds over non-TLS-connections; enabled by default
  • disallow bind_simple: disallow simple binds completely; enabled by default

So you should check if your server configuration disbales anonymous binds.

(2) A generic way to check for anonymous bind support would be to suppress warnings on ldap_bind() and check the result:

function isAnonymousBindSupported($ldap)
{
    return @ldap_bind($ldap)
}

Your error message

Warning: ldap_bind() [function.ldap-bind]: Unable to bind to server: Can't contact LDAP server in /var/www/sue/ldapTest2.php on line 14

though is actually a clear sign that there is some sort of connection problem between the computer running your script and the LDAP server. Connection errors are not reported on a call to ldap_connect() as no connection attempt is made prior to calling ldap_bind() - all connection errors will therefore be raised on ldap_bind().

Please check the following:

  • Is the computer running your script able to resolve the name apserv via DNS? You can test this by pinging apserv by its name or by running nslookup.
  • Can you ping the IP address of apserv?
  • Can you connect to the server using its IP address?
  • Is there a firewall that blocks access to port 389 of the target machine?
  • Are you able to connect to the LDAP server with some sort of LDAP tool?

Upvotes: 1

geoffc
geoffc

Reputation: 4100

Here is a fun one! As far as I understand it, according to the LDAP standard, a bind with a username, but no password counts as an anonymous bind.

So connect with a valid user, but no password, and see if you get connected and access. If so, it allows Anonymous binds, if not, you should get back something like LDAP -13 confidentiality required.

Upvotes: 0

ThirdOne
ThirdOne

Reputation: 1248

Is your server up? Verify that it is up by telneting to port 389 first. This looks like a server not running issue.

Upvotes: 3

Related Questions