Skip to content

Commit f7cf6da

Browse files
author
robin.kluth
committed
fix(paging): Make Paging optional, disabled by default.
1 parent 7d781d3 commit f7cf6da

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/LdapAuth.php

+21-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class LdapAuth extends BaseObject
3131
'baseDn' => 'DC=Example,DC=tld',
3232
'publicSearchUser' => 'example@domain',
3333
'publicSearchUserPassword' => 'secret',
34+
'pagedResultsSize' => 0
3435
],
3536
];
3637

@@ -454,12 +455,25 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
454455

455456
Yii::debug('Search-Filter: ' . $searchFilter, __METHOD__);
456457

458+
$result = ldap_read($this->_l, '', '(objectClass=*)', ['supportedControl']);
459+
$supControls = ldap_get_entries($this->_l, $result);
460+
Yii::debug("Supported Controls here:", __METHOD__);
461+
Yii::debug($supControls, __METHOD__);
462+
463+
457464
$cookie = '';
465+
$requestControls = [];
466+
if (($domain['pagedResultsSize'] ?? 0) > 0) {
467+
if (!in_array(LDAP_CONTROL_PAGEDRESULTS, $supControls[0]['supportedcontrol'])) {
468+
Yii::error("This server does NOT support pagination!", __METHOD__);
469+
}
470+
$requestControls = [
471+
['oid' => LDAP_CONTROL_PAGEDRESULTS, 'value' => ['size' => $domain['pagedResultsSize'], 'cookie' => $cookie], 'iscritical' => false]
472+
];
473+
}
458474

459475
do {
460-
$result = @ldap_search($this->_l, $this->_ldapBaseDn, $searchFilter, $attributes, 0, 0, 0, LDAP_DEREF_NEVER, [
461-
['oid' => LDAP_CONTROL_PAGEDRESULTS, 'value' => ['size' => 500, 'cookie' => $cookie]]
462-
]);
476+
$result = ldap_search($this->_l, $this->_ldapBaseDn, $searchFilter, $attributes, 0, -1, -1, LDAP_DEREF_NEVER, $requestControls);
463477
if (!$result) {
464478
// Something is wrong with the search query
465479
if (is_null($this->_l)) {
@@ -474,7 +488,7 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
474488

475489
if ($result) {
476490
$entries = ldap_get_entries($this->_l, $result);
477-
Yii::debug('Found entries: ' . ($entries ? $entries["count"] : '0'), __FUNCTION__);
491+
Yii::debug('Found entries: ' . ($entries ? $entries["count"] : '0'), __METHOD__);
478492
foreach ($entries as $entry) {
479493
if (!is_array($entry) || empty($entry)) {
480494
continue;
@@ -517,10 +531,13 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
517531
}
518532

519533

534+
Yii::debug($controls, __METHOD__);
520535
if (isset($controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'])) {
536+
Yii::debug("Page cookie set!", __METHOD__);
521537
// You need to pass the cookie from the last call to the next one
522538
$cookie = $controls[LDAP_CONTROL_PAGEDRESULTS]['value']['cookie'];
523539
} else {
540+
Yii::debug("Page cookie NOT set!", __METHOD__);
524541
$cookie = '';
525542
}
526543
// Empty cookie means last page
@@ -612,9 +629,7 @@ public function updateAttributes($attributes, $dn = null)
612629
public static function SIDtoString($ADsid)
613630
{
614631
$results = [];
615-
Yii::debug('Converting SID...', __METHOD__);
616632
for ($cnt = 0; $cnt < $ADsid['count']; $cnt++) {
617-
Yii::debug('Run ' . $cnt, __METHOD__);
618633
$sid = "S-";
619634
//$ADguid = $info[0]['objectguid'][0];
620635
$sidinhex = str_split(bin2hex($ADsid[$cnt]), 2);

0 commit comments

Comments
 (0)