LDAP: move is_resource check to ldap wrapper to make it mockable
This commit is contained in:
parent
d34fbf3a86
commit
52454e39b7
|
@ -54,14 +54,14 @@ abstract class Access extends BackendBase {
|
|||
return false;
|
||||
}
|
||||
$cr = $this->connection->getConnectionResource();
|
||||
if(!is_resource($cr)) {
|
||||
if(!$this->ldap->isResource($cr)) {
|
||||
//LDAP not available
|
||||
\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG);
|
||||
return false;
|
||||
}
|
||||
$dn = $this->DNasBaseParameter($dn);
|
||||
$rr = @$this->ldap->read($cr, $dn, $filter, array($attr));
|
||||
if(!is_resource($rr)) {
|
||||
if(!$this->ldap->isResource($rr)) {
|
||||
if(!empty($attr)) {
|
||||
//do not throw this message on userExists check, irritates
|
||||
\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN '.$dn, \OCP\Util::DEBUG);
|
||||
|
@ -74,7 +74,7 @@ abstract class Access extends BackendBase {
|
|||
return array();
|
||||
}
|
||||
$er = $this->ldap->first_entry($cr, $rr);
|
||||
if(!is_resource($er)) {
|
||||
if(!$this->ldap->isResource($er)) {
|
||||
//did not match the filter, return false
|
||||
return false;
|
||||
}
|
||||
|
@ -653,7 +653,7 @@ abstract class Access extends BackendBase {
|
|||
|
||||
// See if we have a resource, in case not cancel with message
|
||||
$link_resource = $this->connection->getConnectionResource();
|
||||
if(!is_resource($link_resource)) {
|
||||
if(!$this->ldap->isResource($link_resource)) {
|
||||
// Seems like we didn't find any resource.
|
||||
// Return an empty array just like before.
|
||||
\OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG);
|
||||
|
|
|
@ -92,7 +92,8 @@ class Connection extends BackendBase {
|
|||
}
|
||||
|
||||
public function __destruct() {
|
||||
if(!$this->dontDestruct && is_resource($this->ldapConnectionRes)) {
|
||||
if(!$this->dontDestruct &&
|
||||
$this->ldap->isResource($this->ldapConnectionRes)) {
|
||||
@$this->ldap->unbind($this->ldapConnectionRes);
|
||||
};
|
||||
}
|
||||
|
@ -149,7 +150,7 @@ class Connection extends BackendBase {
|
|||
public function getConnectionResource() {
|
||||
if(!$this->ldapConnectionRes) {
|
||||
$this->init();
|
||||
} else if(!is_resource($this->ldapConnectionRes)) {
|
||||
} else if(!$this->ldap->isResource($this->ldapConnectionRes)) {
|
||||
$this->ldapConnectionRes = null;
|
||||
$this->establishConnection();
|
||||
}
|
||||
|
@ -624,7 +625,7 @@ class Connection extends BackendBase {
|
|||
if(!$this->config['ldapOverrideMainServer'] && !$this->getFromCache('overrideMainServer')) {
|
||||
$this->doConnect($this->config['ldapHost'], $this->config['ldapPort']);
|
||||
$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 {
|
||||
$bindStatus = false;
|
||||
$error = null;
|
||||
|
@ -679,7 +680,7 @@ class Connection extends BackendBase {
|
|||
$getConnectionResourceAttempt = true;
|
||||
$cr = $this->getConnectionResource();
|
||||
$getConnectionResourceAttempt = false;
|
||||
if(!is_resource($cr)) {
|
||||
if(!$this->ldap->isResource($cr)) {
|
||||
return false;
|
||||
}
|
||||
$ldapLogin = @$this->ldap->bind($cr, $this->config['ldapAgentName'], $this->config['ldapAgentPassword']);
|
||||
|
|
|
@ -58,6 +58,16 @@ class LDAP {
|
|||
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) {
|
||||
$this->curFunc = $functionName;
|
||||
$this->curArgs = $args;
|
||||
|
|
Loading…
Reference in New Issue