@@ -309,9 +309,9 @@ public function login($username, $password, $domainKey = false, $fetchUserDN = f
309
309
continue ;
310
310
}
311
311
312
- $ this ->_l = $ l ;
313
- $ this ->_ldapBaseDn = $ domainData ['baseDn ' ];
314
- $ this ->_username = $ username ;
312
+ $ this ->_l = $ l ;
313
+ $ this ->_ldapBaseDn = $ domainData ['baseDn ' ];
314
+ $ this ->_username = $ username ;
315
315
$ this ->_curDomainHostname = $ domainData ['hostname ' ];
316
316
$ this ->_curDomainKey = $ domainKey ;
317
317
@@ -463,8 +463,8 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
463
463
464
464
Yii::debug ('Search-Filter: ' . $ searchFilter . " | BaseDN: " . $ baseDN , __METHOD__ );
465
465
466
- $ result = ldap_read ($ this ->_l , '' , '(objectClass=*) ' , ['supportedControl ' ]);
467
- $ supControls = ldap_get_entries ($ this ->_l , $ result );
466
+ $ result = ldap_read ($ this ->_l , '' , '(objectClass=*) ' , ['supportedControl ' ]);
467
+ $ supControls = ldap_get_entries ($ this ->_l , $ result );
468
468
469
469
if (empty ($ this ->_singleValuedAttrs ) || !isset ($ this ->_singleValuedAttrs [$ domain ['hostname ' ]])) {
470
470
$ this ->_singleValuedAttrs [$ domain ['hostname ' ]] = [];
@@ -486,7 +486,7 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
486
486
if (stripos ($ definition , 'SINGLE-VALUE ' ) !== false ) {
487
487
$ match = preg_match ("/NAME [' \"](.*?)[' \"]/ " , $ definition , $ matches );
488
488
if ($ match && isset ($ matches [1 ])) {
489
- $ this ->_singleValuedAttrs [$ domain ['hostname ' ]][] = $ matches [1 ];
489
+ $ this ->_singleValuedAttrs [$ domain ['hostname ' ]][] = strtolower ( $ matches [1 ]) ;
490
490
}
491
491
}
492
492
}
@@ -502,8 +502,6 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
502
502
}
503
503
504
504
505
-
506
-
507
505
$ cookie = '' ;
508
506
$ requestControls = [];
509
507
if (($ domain ['pagedResultsSize ' ] ?? 0 ) > 0 ) {
@@ -621,18 +619,31 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
621
619
622
620
/**
623
621
* Searches directly for groups and optionally return its members
624
- * @param string|null $searchFor The raw (!) LDAP-Filter. Like (&(objectCategory=group) (|(objectSid=%searchFor%)(cn=*%searchFor%*)))
625
- * @param array|null $attributes
622
+ * @param string|null $searchFor The search value (like in searchUser). Like (&(objectCategory=group) (|(objectSid=%searchFor%)(cn=*%searchFor%*)))
623
+ * @param array|null $userAttributes
624
+ * @param array $groupAttributes
625
+ * @param string|null $searchFilter The LDAP-Filter
626
626
* @param bool $returnMembers Should the function fetch the group members?
627
627
* @param int|null $domainKey
628
628
* @param bool $onlyActiveAccounts
629
629
* @param bool $allDomainsHaveToBeReachable
630
630
* @return array|false
631
631
* @throws ErrorException
632
632
*/
633
- public function searchGroup (?string $ searchFor , ? array $ attributes = ['dn ' , 'member ' ], bool $ returnMembers = false , ?int $ domainKey = null , bool $ onlyActiveAccounts = false , bool $ allDomainsHaveToBeReachable = false )
633
+ public function searchGroup (?string $ searchFor , array $ groupAttributes = ['dn ' , 'member ' ], ? array $ userAttributes = [ ' dn ' , ' samaccountname ' , ' mail ' ], bool $ returnMembers = false , ? string $ searchFilter = "" , ?int $ domainKey = null , bool $ onlyActiveAccounts = false , bool $ allDomainsHaveToBeReachable = false )
634
634
{
635
- $ groups = $ this ->searchUser (null , $ attributes , $ searchFor , $ domainKey , $ onlyActiveAccounts , $ allDomainsHaveToBeReachable );
635
+ if (!in_array ('dn ' , $ groupAttributes )) {
636
+ $ groupAttributes [] = 'dn ' ;
637
+ }
638
+ if (!in_array ('member ' , $ groupAttributes )) {
639
+ $ groupAttributes [] = 'member ' ;
640
+ }
641
+
642
+ if (empty ($ searchFilter )) {
643
+ $ searchFilter = "(&(objectCategory=group) (|(objectSid=%searchFor%)(cn=%searchFor%))) " ;
644
+ }
645
+
646
+ $ groups = $ this ->searchUser ($ searchFor , $ groupAttributes , $ searchFilter , $ domainKey , $ onlyActiveAccounts , $ allDomainsHaveToBeReachable );
636
647
637
648
if (!$ returnMembers ) {
638
649
return $ groups ;
@@ -642,7 +653,7 @@ public function searchGroup(?string $searchFor, ?array $attributes = ['dn', 'mem
642
653
if (!isset ($ group ['member ' ])) {
643
654
continue ;
644
655
}
645
- $ groups [$ gkey ]['users ' ] = $ this ->searchUser (null , [ ' dn ' ] , '(&(objectCategory=person)(memberof= ' . $ group ['dn ' ] . ')) ' , $ group ['domainKey ' ]);
656
+ $ groups [$ gkey ]['users ' ] = $ this ->searchUser (null , $ userAttributes , '(&(objectCategory=person)(memberof= ' . $ group ['dn ' ] . ')) ' , $ group ['domainKey ' ]);
646
657
}
647
658
648
659
return $ groups ;
@@ -730,16 +741,13 @@ private function handleEntry($entry)
730
741
{
731
742
$ newEntry = [];
732
743
foreach ($ entry as $ attr => $ value ) {
733
- // Yii::debug('Processing attribute ' . $attr, __FUNCTION__);
734
744
735
745
if (is_int ($ attr ) || $ attr == 'objectsid ' || $ attr == 'sidhistory ' || !isset ($ value ['count ' ])) {
736
- // Yii::debug('Skipping...', __FUNCTION__);
737
746
continue ;
738
747
}
739
- $ count = $ value ['count ' ];
740
- // Yii::debug('Count: ' . $count, __FUNCTION__);
748
+ $ count = $ value ['count ' ];
741
749
742
- if ($ count > 1 || !in_array ($ attr , $ this ->_singleValuedAttrs [$ this ->_curDomainHostname ] ?? [])) {
750
+ if ($ count > 1 || !in_array (strtolower ( $ attr) , $ this ->_singleValuedAttrs [$ this ->_curDomainHostname ] ?? [])) {
743
751
unset($ value ['count ' ]);
744
752
$ newEntry [$ attr ] = $ value ; // Return value as is, because it contains multiple entries
745
753
} else {
0 commit comments