summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-08 12:34:15 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-08 12:34:15 +0100
commit70b58cf367d521696ad0094561fa6c3a2418afb7 (patch)
tree0701d2b8fa94febe07215d6483221f8a3899103e /apps/user_ldap/lib
parent2c76b77c763a97660416cde1d04059e3975436b9 (diff)
parent86fcb0874582d48c0a0460579c6e8c94bb773645 (diff)
downloadnextcloud-server-70b58cf367d521696ad0094561fa6c3a2418afb7.tar.gz
nextcloud-server-70b58cf367d521696ad0094561fa6c3a2418afb7.zip
Merge pull request #17924 from owncloud/ldap-fix-appending-port
ensure an LDAP URL is used, append the port to the host URL when necessary, and just in one place
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r--apps/user_ldap/lib/connection.php7
-rw-r--r--apps/user_ldap/lib/ldap.php9
-rw-r--r--apps/user_ldap/lib/wizard.php17
3 files changed, 15 insertions, 18 deletions
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 3f3953bb28b..67918bca409 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -570,15 +570,12 @@ class Connection extends LDAPUtility {
* @param string $host
* @param string $port
* @return false|void
+ * @throws \OC\ServerNotAvailableException
*/
private function doConnect($host, $port) {
if(empty($host)) {
return false;
}
- if(strpos($host, '://') !== false) {
- //ldap_connect ignores port parameter when URLs are passed
- $host .= ':' . $port;
- }
$this->ldapConnectionRes = $this->ldap->connect($host, $port);
if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
if($this->ldap->setOption($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
@@ -586,6 +583,8 @@ class Connection extends LDAPUtility {
$this->ldap->startTls($this->ldapConnectionRes);
}
}
+ } else {
+ throw new \OC\ServerNotAvailableException('Could not set required LDAP Protocol version.');
}
}
diff --git a/apps/user_ldap/lib/ldap.php b/apps/user_ldap/lib/ldap.php
index 4d45db2e155..e730bff82c3 100644
--- a/apps/user_ldap/lib/ldap.php
+++ b/apps/user_ldap/lib/ldap.php
@@ -48,7 +48,14 @@ class LDAP implements ILDAPWrapper {
* @return mixed
*/
public function connect($host, $port) {
- return $this->invokeLDAPMethod('connect', $host, $port);
+ if(strpos($host, '://') === false) {
+ $host = 'ldap://' . $host;
+ }
+ if(strpos($host, ':', strpos($host, '://') + 1) === false) {
+ //ldap_connect ignores port parameter when URLs are passed
+ $host .= ':' . $port;
+ }
+ return $this->invokeLDAPMethod('connect', $host);
}
/**
diff --git a/apps/user_ldap/lib/wizard.php b/apps/user_ldap/lib/wizard.php
index e53ff35cfd6..20926fb06a4 100644
--- a/apps/user_ldap/lib/wizard.php
+++ b/apps/user_ldap/lib/wizard.php
@@ -1035,13 +1035,6 @@ class Wizard extends LDAPUtility {
if(!$hostInfo) {
throw new \Exception($this->l->t('Invalid Host'));
}
- if(isset($hostInfo['scheme'])) {
- if(isset($hostInfo['port'])) {
- //problem
- } else {
- $host .= ':' . $port;
- }
- }
\OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', \OCP\Util::DEBUG);
$cr = $this->ldap->connect($host, $port);
if(!is_resource($cr)) {
@@ -1291,12 +1284,10 @@ class Wizard extends LDAPUtility {
return $this->cr;
}
- $host = $this->configuration->ldapHost;
- if(strpos($host, '://') !== false) {
- //ldap_connect ignores port parameter when URLs are passed
- $host .= ':' . $this->configuration->ldapPort;
- }
- $cr = $this->ldap->connect($host, $this->configuration->ldapPort);
+ $cr = $this->ldap->connect(
+ $this->configuration->ldapHost,
+ $this->configuration->ldapPort
+ );
$this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3);
$this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0);