@@ -309,9 +309,9 @@ public function login($username, $password, $domainKey = false, $fetchUserDN = f
309309 continue ;
310310 }
311311
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 ;
315315 $ this ->_curDomainHostname = $ domainData ['hostname ' ];
316316 $ this ->_curDomainKey = $ domainKey ;
317317
@@ -463,8 +463,8 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
463463
464464 Yii::debug ('Search-Filter: ' . $ searchFilter . " | BaseDN: " . $ baseDN , __METHOD__ );
465465
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 );
468468
469469 if (empty ($ this ->_singleValuedAttrs ) || !isset ($ this ->_singleValuedAttrs [$ domain ['hostname ' ]])) {
470470 $ this ->_singleValuedAttrs [$ domain ['hostname ' ]] = [];
@@ -486,7 +486,7 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
486486 if (stripos ($ definition , 'SINGLE-VALUE ' ) !== false ) {
487487 $ match = preg_match ("/NAME [' \"](.*?)[' \"]/ " , $ definition , $ matches );
488488 if ($ match && isset ($ matches [1 ])) {
489- $ this ->_singleValuedAttrs [$ domain ['hostname ' ]][] = $ matches [1 ];
489+ $ this ->_singleValuedAttrs [$ domain ['hostname ' ]][] = strtolower ( $ matches [1 ]) ;
490490 }
491491 }
492492 }
@@ -502,8 +502,6 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
502502 }
503503
504504
505-
506-
507505 $ cookie = '' ;
508506 $ requestControls = [];
509507 if (($ domain ['pagedResultsSize ' ] ?? 0 ) > 0 ) {
@@ -621,18 +619,31 @@ public function searchUser(?string $searchFor, ?array $attributes = [], ?string
621619
622620 /**
623621 * 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
626626 * @param bool $returnMembers Should the function fetch the group members?
627627 * @param int|null $domainKey
628628 * @param bool $onlyActiveAccounts
629629 * @param bool $allDomainsHaveToBeReachable
630630 * @return array|false
631631 * @throws ErrorException
632632 */
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 )
634634 {
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 );
636647
637648 if (!$ returnMembers ) {
638649 return $ groups ;
@@ -642,7 +653,7 @@ public function searchGroup(?string $searchFor, ?array $attributes = ['dn', 'mem
642653 if (!isset ($ group ['member ' ])) {
643654 continue ;
644655 }
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 ' ]);
646657 }
647658
648659 return $ groups ;
@@ -730,16 +741,13 @@ private function handleEntry($entry)
730741 {
731742 $ newEntry = [];
732743 foreach ($ entry as $ attr => $ value ) {
733- // Yii::debug('Processing attribute ' . $attr, __FUNCTION__);
734744
735745 if (is_int ($ attr ) || $ attr == 'objectsid ' || $ attr == 'sidhistory ' || !isset ($ value ['count ' ])) {
736- // Yii::debug('Skipping...', __FUNCTION__);
737746 continue ;
738747 }
739- $ count = $ value ['count ' ];
740- // Yii::debug('Count: ' . $count, __FUNCTION__);
748+ $ count = $ value ['count ' ];
741749
742- if ($ count > 1 || !in_array ($ attr , $ this ->_singleValuedAttrs [$ this ->_curDomainHostname ] ?? [])) {
750+ if ($ count > 1 || !in_array (strtolower ( $ attr) , $ this ->_singleValuedAttrs [$ this ->_curDomainHostname ] ?? [])) {
743751 unset($ value ['count ' ]);
744752 $ newEntry [$ attr ] = $ value ; // Return value as is, because it contains multiple entries
745753 } else {
0 commit comments