Skip to content

Commit

Permalink
* [FIX] Wrong behaviour when retrieving LDAP results using pagination…
Browse files Browse the repository at this point in the history
…. Thanks to @jinyiwoo for the feedback. Closes nuxsmin#1149

Signed-off-by: nuxsmin <[email protected]>
  • Loading branch information
nuxsmin committed Dec 16, 2018
1 parent 3cf75fb commit ef5ef07
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/SP/Providers/Auth/Ldap/LdapActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
*/

/** @noinspection PhpComposerExtensionStubsInspection */

namespace SP\Providers\Auth\Ldap;

use SP\Core\Events\Event;
Expand Down Expand Up @@ -165,9 +167,19 @@ protected function getResults($filter, array $attributes = null)
$results = [];

do {
ldap_control_paged_result($this->ldapHandler, 1000, false, $cookie);
ldap_control_paged_result(
$this->ldapHandler,
LdapInterface::PAGE_SIZE,
false,
$cookie
);

$searchRes = @ldap_search($this->ldapHandler, $this->ldapParams->getSearchBase(), $filter, $attributes);
$searchRes = @ldap_search(
$this->ldapHandler,
$this->ldapParams->getSearchBase(),
$filter,
$attributes
);

if (!$searchRes) {
return false;
Expand All @@ -181,8 +193,12 @@ protected function getResults($filter, array $attributes = null)

$results = array_merge($results, $entries);

ldap_control_paged_result_response($this->ldapHandler, $searchRes, $cookie);
} while (!empty($cookie));
ldap_control_paged_result_response(
$this->ldapHandler,
$searchRes,
$cookie
);
} while ($cookie !== null && $cookie != '');

return $results;
}
Expand Down
2 changes: 2 additions & 0 deletions lib/SP/Providers/Auth/Ldap/LdapInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/
interface LdapInterface
{
const PAGE_SIZE = 500;

/**
* Obtener el filtro para buscar el usuario
*
Expand Down

0 comments on commit ef5ef07

Please sign in to comment.