Skip to content

Commit

Permalink
Merge pull request #14875 from owncloud/backport-14849-stable8
Browse files Browse the repository at this point in the history
[stable8] support paged results against 389ds.
  • Loading branch information
blizzz committed Mar 13, 2015
2 parents c6136de + a1c414c commit 92a024b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions apps/user_ldap/lib/access.php
Original file line number Diff line number Diff line change
Expand Up @@ -1372,7 +1372,8 @@ private function getPagedResultCookie($base, $filter, $limit, $offset) {
* @return void
*/
private function setPagedResultCookie($base, $filter, $limit, $offset, $cookie) {
if(!empty($cookie)) {
// allow '0' for 389ds
if(!empty($cookie) || $cookie === '0') {
$cacheKey = 'lc' . crc32($base) . '-' . crc32($filter) . '-' .intval($limit) . '-' . intval($offset);
$this->cookies[$cacheKey] = $cookie;
$this->lastCookie = $cookie;
Expand Down Expand Up @@ -1410,19 +1411,21 @@ private function initPagedSearch($filter, $bases, $attr, $limit, $offset) {
foreach($bases as $base) {

$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
if(empty($cookie) && ($offset > 0)) {
if(empty($cookie) && $cookie !== "0" && ($offset > 0)) {
// no cookie known, although the offset is not 0. Maybe cache run out. We need
// to start all over *sigh* (btw, Dear Reader, did you know LDAP paged
// searching was designed by MSFT?)
// Lukas: No, but thanks to reading that source I finally know!
// '0' is valid, because 389ds
$reOffset = ($offset - $limit) < 0 ? 0 : $offset - $limit;
//a bit recursive, $offset of 0 is the exit
\OCP\Util::writeLog('user_ldap', 'Looking for cookie L/O '.$limit.'/'.$reOffset, \OCP\Util::INFO);
$this->search($filter, array($base), $attr, $limit, $reOffset, true);
$cookie = $this->getPagedResultCookie($base, $filter, $limit, $offset);
//still no cookie? obviously, the server does not like us. Let's skip paging efforts.
//TODO: remember this, probably does not change in the next request...
if(empty($cookie)) {
if(empty($cookie) && $cookie !== '0') {
// '0' is valid, because 389ds
$cookie = null;
}
}
Expand Down

0 comments on commit 92a024b

Please sign in to comment.