@@ -31,6 +31,7 @@ class LdapAuth extends BaseObject
31
31
'baseDn ' => 'DC=Example,DC=tld ' ,
32
32
'publicSearchUser ' => 'example@domain ' ,
33
33
'publicSearchUserPassword ' => 'secret ' ,
34
+ 'pagedResultsSize ' => 0
34
35
],
35
36
];
36
37
@@ -454,12 +455,25 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
454
455
455
456
Yii::debug ('Search-Filter: ' . $ searchFilter , __METHOD__ );
456
457
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
+
457
464
$ 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
+ }
458
474
459
475
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 );
463
477
if (!$ result ) {
464
478
// Something is wrong with the search query
465
479
if (is_null ($ this ->_l )) {
@@ -474,7 +488,7 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
474
488
475
489
if ($ result ) {
476
490
$ 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__ );
478
492
foreach ($ entries as $ entry ) {
479
493
if (!is_array ($ entry ) || empty ($ entry )) {
480
494
continue ;
@@ -517,10 +531,13 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
517
531
}
518
532
519
533
534
+ Yii::debug ($ controls , __METHOD__ );
520
535
if (isset ($ controls [LDAP_CONTROL_PAGEDRESULTS ]['value ' ]['cookie ' ])) {
536
+ Yii::debug ("Page cookie set! " , __METHOD__ );
521
537
// You need to pass the cookie from the last call to the next one
522
538
$ cookie = $ controls [LDAP_CONTROL_PAGEDRESULTS ]['value ' ]['cookie ' ];
523
539
} else {
540
+ Yii::debug ("Page cookie NOT set! " , __METHOD__ );
524
541
$ cookie = '' ;
525
542
}
526
543
// Empty cookie means last page
@@ -612,9 +629,7 @@ public function updateAttributes($attributes, $dn = null)
612
629
public static function SIDtoString ($ ADsid )
613
630
{
614
631
$ results = [];
615
- Yii::debug ('Converting SID... ' , __METHOD__ );
616
632
for ($ cnt = 0 ; $ cnt < $ ADsid ['count ' ]; $ cnt ++) {
617
- Yii::debug ('Run ' . $ cnt , __METHOD__ );
618
633
$ sid = "S- " ;
619
634
//$ADguid = $info[0]['objectguid'][0];
620
635
$ sidinhex = str_split (bin2hex ($ ADsid [$ cnt ]), 2 );
0 commit comments