From b94631de0cf16d0ffc83dd2e805efe275d119be6 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 25 Jul 2012 18:40:48 +0200 Subject: [PATCH] LDAP: check if php-ldap is installed. If not, give an error output. FIX: blank Users page when the module is not installed. --- apps/user_ldap/lib/access.php | 4 ++++ apps/user_ldap/lib/connection.php | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/apps/user_ldap/lib/access.php b/apps/user_ldap/lib/access.php index 870f6330ed..19122b34c7 100644 --- a/apps/user_ldap/lib/access.php +++ b/apps/user_ldap/lib/access.php @@ -48,6 +48,10 @@ abstract class Access { return false; } $cr = $this->connection->getConnectionResource(); + if(!is_resource($cr)) { + //LDAP not available + return false; + } $rr = @ldap_read($cr, $dn, 'objectClass=*', array($attr)); if(!is_resource($rr)) { \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG); diff --git a/apps/user_ldap/lib/connection.php b/apps/user_ldap/lib/connection.php index c8ba9dad70..e54a8e2b24 100644 --- a/apps/user_ldap/lib/connection.php +++ b/apps/user_ldap/lib/connection.php @@ -211,11 +211,21 @@ class Connection { * Connects and Binds to LDAP */ private function establishConnection() { + static $phpLDAPinstalled = true; + if(!$phpLDAPinstalled) { + return false; + } if(!$this->configured) { \OCP\Util::writeLog('user_ldap', 'Configuration is invalid, cannot connect', \OCP\Util::WARN); return false; } if(!$this->ldapConnectionRes) { + if(!function_exists('ldap_connect')) { + $phpLDAPinstalled = false; + \OCP\Util::writeLog('user_ldap', 'function ldap_connect is not available. Make sure that the PHP ldap module is installed.', \OCP\Util::ERROR); + + return false; + } $this->ldapConnectionRes = ldap_connect($this->config['ldapHost'], $this->config['ldapPort']); if(ldap_set_option($this->ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { if(ldap_set_option($this->ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {