Skip to content

Commit

Permalink
Fix: better compatibility with all hostname syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Mar 19, 2018
1 parent 73eba91 commit 4767819
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions htdocs/core/class/ldap.class.php
Expand Up @@ -177,20 +177,10 @@ function connect_bind()
if ($connected) break;
if (empty($host)) continue;

if (preg_match('/^ldap/',$host))
{
if ($this->serverPing($host) === true) {
$this->connection = ldap_connect($host);
}
else continue;
}
else
{
if ($this->serverPing($host, $this->serverPort) === true) {
$this->connection = ldap_connect($host,$this->serverPort);
}
else continue;
if ($this->serverPing($host, $this->serverPort) === true) {
$this->connection = ldap_connect($host, $this->serverPort);
}
else continue;

if (is_resource($this->connection))
{
Expand Down Expand Up @@ -742,6 +732,10 @@ function serverPing($host, $port=389, $timeout=1)
if (preg_match('/^ldaps:\/\/([^\/]+)\/?$/',$host, $regs)) {
$host = 'ssl://'.$regs[1];
}
// Remove ldap://
if (preg_match('/^ldap:\/\/([^\/]+)\/?$/',$host, $regs)) {
$host = $regs[1];
}
$op = @fsockopen($host, $port, $errno, $errstr, $timeout);
if (!$op) return false; //DC is N/A
else {
Expand Down

0 comments on commit 4767819

Please sign in to comment.