You are here

function LDAPInterface::initConnection in LDAP integration 6

Same name and namespace in other branches
  1. 5.2 ldap_integration/LDAPInterface.php \LDAPInterface::initConnection()
  2. 5 ldap_integration/LDAPInterface.php \LDAPInterface::initConnection()
1 call to LDAPInterface::initConnection()
LDAPInterface::connectAndBind in includes/LDAPInterface.inc

File

includes/LDAPInterface.inc, line 148
LDAPInterface class definition.

Class

LDAPInterface
@file LDAPInterface class definition.

Code

function initConnection() {
  if (!($this->connection = ldap_connect($this->server, $this->port))) {
    watchdog('ldap', 'LDAP Connect failure to @server:@port', array(
      '@server' => $this->server,
      '@port' => $this->port,
    ), WATCHDOG_ERROR);
    return;
  }
  ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, 3);
  ldap_set_option($this->connection, LDAP_OPT_REFERRALS, 0);

  // TLS encryption contributed by sfrancis@drupal.org
  if ($this->tls) {
    ldap_get_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, $vers);
    if ($vers == -1) {
      watchdog('ldap', 'Could not get LDAP protocol version.', array(), WATCHDOG_ERROR);
      return;
    }
    if ($vers != 3) {
      watchdog('ldap', 'Could not start TLS, only supported by LDAP v3.', array(), WATCHDOG_ERROR);
      return;
    }
    elseif (!function_exists('ldap_start_tls')) {
      watchdog('ldap', 'Could not start TLS. It does not seem to be supported by this PHP setup.', array(), WATCHDOG_ERROR);
      return;
    }
    elseif (!ldap_start_tls($this->connection)) {
      watchdog('ldap', 'Could not start TLS. (Error %errno: %error).', array(
        '%errno' => ldap_errno($this->connection),
        '%error' => ldap_error($this->connection),
      ), WATCHDOG_ERROR);
      return;
    }
  }
}