Browse Source

LDAP: move is_resource check to ldap wrapper to make it mockable

tags/v6.0.0alpha2
Arthur Schiwon 11 years ago
parent
commit
52454e39b7
3 changed files with 19 additions and 8 deletions
  1. 4
    4
      apps/user_ldap/lib/access.php
  2. 5
    4
      apps/user_ldap/lib/connection.php
  3. 10
    0
      apps/user_ldap/lib/ldap.php

+ 4
- 4
apps/user_ldap/lib/access.php View File

return false; return false;
} }
$cr = $this->connection->getConnectionResource(); $cr = $this->connection->getConnectionResource();
if(!is_resource($cr)) {
if(!$this->ldap->isResource($cr)) {
//LDAP not available //LDAP not available
\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG);
return false; return false;
} }
$dn = $this->DNasBaseParameter($dn); $dn = $this->DNasBaseParameter($dn);
$rr = @$this->ldap->read($cr, $dn, $filter, array($attr)); $rr = @$this->ldap->read($cr, $dn, $filter, array($attr));
if(!is_resource($rr)) {
if(!$this->ldap->isResource($rr)) {
if(!empty($attr)) { if(!empty($attr)) {
//do not throw this message on userExists check, irritates //do not throw this message on userExists check, irritates
\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG);
return array(); return array();
} }
$er = $this->ldap->first_entry($cr, $rr); $er = $this->ldap->first_entry($cr, $rr);
if(!is_resource($er)) {
if(!$this->ldap->isResource($er)) {
//did not match the filter, return false //did not match the filter, return false
return false; return false;
} }


// See if we have a resource, in case not cancel with message // See if we have a resource, in case not cancel with message
$link_resource = $this->connection->getConnectionResource(); $link_resource = $this->connection->getConnectionResource();
if(!is_resource($link_resource)) {
if(!$this->ldap->isResource($link_resource)) {
// Seems like we didn't find any resource. // Seems like we didn't find any resource.
// Return an empty array just like before. // Return an empty array just like before.
\OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG);

+ 5
- 4
apps/user_ldap/lib/connection.php View File

} }


public function __destruct() { public function __destruct() {
if(!$this->dontDestruct && is_resource($this->ldapConnectionRes)) {
if(!$this->dontDestruct &&
$this->ldap->isResource($this->ldapConnectionRes)) {
@$this->ldap->unbind($this->ldapConnectionRes); @$this->ldap->unbind($this->ldapConnectionRes);
}; };
} }
public function getConnectionResource() { public function getConnectionResource() {
if(!$this->ldapConnectionRes) { if(!$this->ldapConnectionRes) {
$this->init(); $this->init();
} else if(!is_resource($this->ldapConnectionRes)) {
} else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
$this->ldapConnectionRes = null; $this->ldapConnectionRes = null;
$this->establishConnection(); $this->establishConnection();
} }
if(!$this->config['ldapOverrideMainServer'] && !$this->getFromCache('overrideMainServer')) { if(!$this->config['ldapOverrideMainServer'] && !$this->getFromCache('overrideMainServer')) {
$this->doConnect($this->config['ldapHost'], $this->config['ldapPort']); $this->doConnect($this->config['ldapHost'], $this->config['ldapPort']);
$bindStatus = $this->bind(); $bindStatus = $this->bind();
$error = is_resource($this->ldapConnectionRes) ? ldap_errno($this->ldapConnectionRes) : -1;
$error = $this->ldap->isResource($this->ldapConnectionRes) ? ldap_errno($this->ldapConnectionRes) : -1;
} else { } else {
$bindStatus = false; $bindStatus = false;
$error = null; $error = null;
$getConnectionResourceAttempt = true; $getConnectionResourceAttempt = true;
$cr = $this->getConnectionResource(); $cr = $this->getConnectionResource();
$getConnectionResourceAttempt = false; $getConnectionResourceAttempt = false;
if(!is_resource($cr)) {
if(!$this->ldap->isResource($cr)) {
return false; return false;
} }
$ldapLogin = @$this->ldap->bind($cr, $this->config['ldapAgentName'], $this->config['ldapAgentPassword']); $ldapLogin = @$this->ldap->bind($cr, $this->config['ldapAgentName'], $this->config['ldapAgentPassword']);

+ 10
- 0
apps/user_ldap/lib/ldap.php View File

return $hasSupport; return $hasSupport;
} }


/**
* Checks whether the submitted parameter is a resource
*
* @param $resource the resource variable to check
* @return true if it is a resource, false otherwise
*/
public function isResource($resource) {
return is_resource($resource);
}

private function preFunctionCall($functionName, $args) { private function preFunctionCall($functionName, $args) {
$this->curFunc = $functionName; $this->curFunc = $functionName;
$this->curArgs = $args; $this->curArgs = $args;

Loading…
Cancel
Save