try to start TLS, fall back to standard connection if it failed

This commit is contained in:
Roland Gruber 2003-08-16 16:54:11 +00:00
parent 197f5169be
commit dff993dcea
1 changed files with 10 additions and 1 deletions

View File

@ -97,7 +97,16 @@ class Ldap{
// use LDAPv3
ldap_set_option($this->server, LDAP_OPT_PROTOCOL_VERSION, 3);
// start TLS if possible
//if (function_exists('ldap_start_tls')) ldap_start_tls($this->server);
if (function_exists('ldap_start_tls')) {
@ldap_start_tls($this->server);
// connect without TLS if it failed
if (ldap_errno($this->server) > 0) {
@ldap_close($this->server);
$this->server = @ldap_connect($this->conf->get_ServerURL());
ldap_set_option($this->server, LDAP_OPT_PROTOCOL_VERSION, 3);
}
}
//echo ldap_error($this->server) . " | " . ldap_errno($this->server);
$bind = @ldap_bind($this->server, $user, $passwd);
if ($bind) {
// return server handle