function ldap_server::connect in Lightweight Directory Access Protocol (LDAP) 6
Connect Method
1 call to ldap_server::connect()
- ldap_server::__invoke in includes/
ldap.server.inc - Invoke Method
File
- includes/
ldap.server.inc, line 111 - Defines server classes and related functions.
Class
- ldap_server
- LDAP Server Class
Code
function connect() {
if (!($con = ldap_connect($this->server_addr, $this->port))) {
watchdog('user', 'LDAP Connect failure to ' . $this->server_addr . ':' . $this->port);
return FALSE;
}
ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($con, LDAP_OPT_REFERRALS, 0);
// Use TLS if we are configured and able to.
if ($this->tls) {
ldap_get_option($con, LDAP_OPT_PROTOCOL_VERSION, $vers);
if ($vers == -1) {
watchdog('user', 'Could not get LDAP protocol version.');
return FALSE;
}
if ($vers != 3) {
watchdog('user', 'Could not start TLS, only supported by LDAP v3.');
return FALSE;
}
elseif (!function_exists('ldap_start_tls')) {
watchdog('user', 'Could not start TLS. It does not seem to be supported by this PHP setup.');
return FALSE;
}
elseif (!ldap_start_tls($con)) {
watchdog('user', t("Could not start TLS. (Error %errno: %error).", array(
'%errno' => ldap_errno($con),
'%error' => ldap_error($con),
)));
return FALSE;
}
}
// Store the resulting resource
$this->connection = $con;
return TRUE;
}