summaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib/connection.php
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@owncloud.com>2013-02-06 14:32:00 +0100
committerArthur Schiwon <blizzz@owncloud.com>2013-02-06 14:32:00 +0100
commit781d247b39930e54d4e40c2c197c80367827b852 (patch)
tree897598083396c7522d27dd074f65d446826d82b5 /apps/user_ldap/lib/connection.php
parente122fdbcb63cc4e36982dc23bd2a38c904417447 (diff)
downloadnextcloud-server-781d247b39930e54d4e40c2c197c80367827b852.tar.gz
nextcloud-server-781d247b39930e54d4e40c2c197c80367827b852.zip
LDAP: better detect timeouts. do not try to reconnect. do not try to bind when connection failed. makes ownCloud more responsive, esp. with multiple server connections configured
Diffstat (limited to 'apps/user_ldap/lib/connection.php')
-rw-r--r--apps/user_ldap/lib/connection.php13
1 files changed, 10 insertions, 3 deletions
diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php
index 38b2b131e50..9b440da4f9f 100644
--- a/apps/user_ldap/lib/connection.php
+++ b/apps/user_ldap/lib/connection.php
@@ -528,7 +528,7 @@ class Connection {
if(!$this->config['ldapOverrideMainServer'] && !$this->getFromCache('overrideMainServer')) {
$this->doConnect($this->config['ldapHost'], $this->config['ldapPort']);
$bindStatus = $this->bind();
- $error = ldap_errno($this->ldapConnectionRes);
+ $error = is_resource($this->ldapConnectionRes) ? ldap_errno($this->ldapConnectionRes) : -1;
} else {
$bindStatus = false;
$error = null;
@@ -552,6 +552,9 @@ class Connection {
}
private function doConnect($host, $port) {
+ if(empty($host)) {
+ return false;
+ }
$this->ldapConnectionRes = ldap_connect($host, $port);
if(ldap_set_option($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
if(ldap_set_option($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
@@ -569,9 +572,13 @@ class Connection {
if(!$this->config['ldapConfigurationActive']) {
return false;
}
- $ldapLogin = @ldap_bind($this->getConnectionResource(), $this->config['ldapAgentName'], $this->config['ldapAgentPassword']);
+ $cr = $this->getConnectionResource();
+ if(!is_resource($cr)) {
+ return false;
+ }
+ $ldapLogin = @ldap_bind($cr, $this->config['ldapAgentName'], $this->config['ldapAgentPassword']);
if(!$ldapLogin) {
- \OCP\Util::writeLog('user_ldap', 'Bind failed: ' . ldap_errno($this->ldapConnectionRes) . ': ' . ldap_error($this->ldapConnectionRes), \OCP\Util::ERROR);
+ \OCP\Util::writeLog('user_ldap', 'Bind failed: ' . ldap_errno($cr) . ': ' . ldap_error($cr), \OCP\Util::ERROR);
$this->ldapConnectionRes = null;
return false;
}