0

I need to connect my application to an external LDAP system. I've managed to connect my application to a local OpenLDAP. But when I try to connect the external one over SSL I get some troubles.

My code:

 public static function ldapConnection($server, $port, $version, $auth_user, 
                     $auth_pass, $base_dn, $search_filter, $attributes=null)
 {
   if(!extension_loaded('ldap'))
   {
     echo "This php version does not seem comptible with LDAP. Please install the 
           php5-ldap module";
     Yii::app()->end();
   }
   if (!($connect = @ldap_connect("ldaps://ldap.unil.ch", 636)))
   {
     echo "Unable to connect to server ".$server."";
     Yii::app()->end();
   }
   if ($version == 3)
   {
     @ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
   }
   if (!(@ldap_bind($connect, $auth_user, $auth_pass)))
   {
     return false;
   }
   ...
   ...
 }

My problem:

The "ldap_bind" function always returns false.

I'm sure about username, password and LDAP adress informations (I tried them in a LDAP client GUI). The apache "ssl_module" is activated.

I'm aware I have to manage something with the LDAP server certificate. I've spent time on google but I am still stuck on this problem.

So, Could anyone tell me how to succeed this connection?.

BKM
  • 6,949
  • 7
  • 30
  • 45
Michaël
  • 1,120
  • 1
  • 15
  • 30
  • 2
    If you're getting false, then you should be checking ldap_error()/ldap_errno() to see what the reason for the failure is. – Marc B Aug 26 '13 at 20:25
  • 1
    Don't use '@' for errors muting, it's a very bad habit. – OZ_ Aug 26 '13 at 20:28
  • Do not suppress error messages. Taking away this error suppression might reveal your problem – Daryl Gill Aug 26 '13 at 20:36
  • My gut tells me this will be related to SSL certificate not being present on your server... And `ldap_bind` returns false because `ldap_connect` failed on you and you did not even notice thanks to those **@** error suppressors. PS. I don't see it exactly as a bad habit of using them, it's only bad habit of using them **before** you know things work under all circumstances as you would expect. – Robert Rossmann Aug 26 '13 at 23:47

1 Answers1

0

I faced the same problem, for me the solution was to add a port to the server

$ad = @ldap_connect("ldaps://serverName:636", 636);