Skip to content
Snippets Groups Projects
Commit 3c9919e4 authored by Arthur Schiwon's avatar Arthur Schiwon
Browse files

LDAP: check if php-ldap is installed. If not, give an error output. FIX: blank...

LDAP: check if php-ldap is installed. If not, give an error output. FIX: blank Users page when the module is not installed.
parent 9b0870bb
No related branches found
No related tags found
No related merge requests found
...@@ -440,6 +440,10 @@ class OC_LDAP { ...@@ -440,6 +440,10 @@ class OC_LDAP {
*/ */
static public function readAttribute($dn, $attr) { static public function readAttribute($dn, $attr) {
$cr = self::getConnectionResource(); $cr = self::getConnectionResource();
if(!is_resource($cr)) {
//LDAP not available
return false;
}
$rr = ldap_read($cr, $dn, 'objectClass=*', array($attr)); $rr = ldap_read($cr, $dn, 'objectClass=*', array($attr));
$er = ldap_first_entry($cr, $rr); $er = ldap_first_entry($cr, $rr);
//LDAP attributes are not case sensitive //LDAP attributes are not case sensitive
...@@ -495,6 +499,11 @@ class OC_LDAP { ...@@ -495,6 +499,11 @@ class OC_LDAP {
if(!is_null($attr) && !is_array($attr)) { if(!is_null($attr) && !is_array($attr)) {
$attr = array(strtolower($attr)); $attr = array(strtolower($attr));
} }
$cr = self::getConnectionResource();
if(!is_resource($cr)) {
//LDAP not available
return array();
}
$sr = @ldap_search(self::getConnectionResource(), $base, $filter, $attr); $sr = @ldap_search(self::getConnectionResource(), $base, $filter, $attr);
$findings = @ldap_get_entries(self::getConnectionResource(), $sr ); $findings = @ldap_get_entries(self::getConnectionResource(), $sr );
// if we're here, probably no connection ressource is returned. // if we're here, probably no connection ressource is returned.
...@@ -686,11 +695,22 @@ class OC_LDAP { ...@@ -686,11 +695,22 @@ class OC_LDAP {
* Connects and Binds to LDAP * Connects and Binds to LDAP
*/ */
static private function establishConnection() { static private function establishConnection() {
static $phpLDAPinstalled = true;
if(!$phpLDAPinstalled) {
return false;
}
if(!self::$configured) { if(!self::$configured) {
OCP\Util::writeLog('ldap', 'Configuration is invalid, cannot connect', OCP\Util::INFO); OCP\Util::writeLog('ldap', 'Configuration is invalid, cannot connect', OCP\Util::INFO);
return false; return false;
} }
if(!self::$ldapConnectionRes) { if(!self::$ldapConnectionRes) {
//check if php-ldap is installed
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;
}
self::$ldapConnectionRes = ldap_connect(self::$ldapHost, self::$ldapPort); self::$ldapConnectionRes = ldap_connect(self::$ldapHost, self::$ldapPort);
if(ldap_set_option(self::$ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) { if(ldap_set_option(self::$ldapConnectionRes, LDAP_OPT_PROTOCOL_VERSION, 3)) {
if(ldap_set_option(self::$ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) { if(ldap_set_option(self::$ldapConnectionRes, LDAP_OPT_REFERRALS, 0)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment