only check ldap_errno if an ldap_* function actually fails

fix wizard errors
reset search paging right after the search, not before some of the possible next search operations
cookie contains binary characters, don't log it
  (avoids json_encode(): Invalid UTF-8 sequence in argument errors)
This commit is contained in:
root 2013-12-10 17:50:45 +01:00 committed by Alexander Bergolth
parent 7c3f3cc933
commit 8fcc29ee8b
3 changed files with 11 additions and 6 deletions

View File

@ -63,7 +63,6 @@ class Access extends LDAPUtility {
return false; return false;
} }
//all or nothing! otherwise we get in trouble with. //all or nothing! otherwise we get in trouble with.
$this->initPagedSearch($filter, array($dn), $attr, 99999, 0);
$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(!$this->ldap->isResource($rr)) { if(!$this->ldap->isResource($rr)) {
@ -707,6 +706,9 @@ class Access extends LDAPUtility {
$linkResources = array_pad(array(), count($base), $cr); $linkResources = array_pad(array(), count($base), $cr);
$sr = $this->ldap->search($linkResources, $base, $filter, $attr); $sr = $this->ldap->search($linkResources, $base, $filter, $attr);
$error = $this->ldap->errno($cr); $error = $this->ldap->errno($cr);
if ($pagedSearchOK) {
$this->ldap->controlPagedResult($cr, 0, false, "");
}
if(!is_array($sr) || $error !== 0) { if(!is_array($sr) || $error !== 0) {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'Error when searching: '.$this->ldap->error($cr). 'Error when searching: '.$this->ldap->error($cr).
@ -1236,9 +1238,9 @@ class Access extends LDAPUtility {
if($this->connection->hasPagedResultSupport && !is_null($limit)) { if($this->connection->hasPagedResultSupport && !is_null($limit)) {
$offset = intval($offset); //can be null $offset = intval($offset); //can be null
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'initializing paged search for Filter'.$filter.' base '.print_r($bases, true) 'initializing paged search for Filter '.$filter.' base '.print_r($bases, true)
.' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset,
\OCP\Util::INFO); \OCP\Util::DEBUG);
//get the cookie from the search for the previous search, required by LDAP //get the cookie from the search for the previous search, required by LDAP
foreach($bases as $base) { foreach($bases as $base) {
@ -1260,7 +1262,7 @@ class Access extends LDAPUtility {
} }
if(!is_null($cookie)) { if(!is_null($cookie)) {
if($offset > 0) { if($offset > 0) {
\OCP\Util::writeLog('user_ldap', 'Cookie '.$cookie, \OCP\Util::INFO); \OCP\Util::writeLog('user_ldap', 'Cookie '.CRC32($cookie), \OCP\Util::INFO);
} }
$pagedSearchOK = $this->ldap->controlPagedResult( $pagedSearchOK = $this->ldap->controlPagedResult(
$this->connection->getConnectionResource(), $limit, $this->connection->getConnectionResource(), $limit,

View File

@ -78,7 +78,7 @@ class LDAP implements ILDAPWrapper {
} }
public function nextEntry($link, $result) { public function nextEntry($link, $result) {
return $this->invokeLDAPMethod('next_entry', $link, $result); return ldap_next_entry($link, $result);
} }
public function read($link, $baseDN, $filter, $attr) { public function read($link, $baseDN, $filter, $attr) {
@ -139,7 +139,9 @@ class LDAP implements ILDAPWrapper {
if(function_exists($func)) { if(function_exists($func)) {
$this->preFunctionCall($func, $arguments); $this->preFunctionCall($func, $arguments);
$result = call_user_func_array($func, $arguments); $result = call_user_func_array($func, $arguments);
$this->postFunctionCall(); if ($result === FALSE) {
$this->postFunctionCall();
}
return $result; return $result;
} }
} }

View File

@ -799,6 +799,7 @@ class Wizard extends LDAPUtility {
\OCP\Util::writeLog('user_ldap', 'Wiz: Setting LDAP Options ', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Wiz: Setting LDAP Options ', \OCP\Util::DEBUG);
//set LDAP options //set LDAP options
$this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3); $this->ldap->setOption($cr, LDAP_OPT_PROTOCOL_VERSION, 3);
$this->ldap->setOption($cr, LDAP_OPT_REFERRALS, 0);
$this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT); $this->ldap->setOption($cr, LDAP_OPT_NETWORK_TIMEOUT, self::LDAP_NW_TIMEOUT);
if($tls) { if($tls) {
$isTlsWorking = @$this->ldap->startTls($cr); $isTlsWorking = @$this->ldap->startTls($cr);