@@ -183,6 +183,10 @@ public function getUser($user_id): false|array
183183
184184 $ search = ldap_search ($ connection , trim (LibrenmsConfig::get ('auth_ldap_suffix ' ), ', ' ), $ filter );
185185 $ entries = ldap_get_entries ($ connection , $ search );
186+ if (! $ entries ) {
187+ return false ;
188+ }
189+
186190 foreach ($ entries as $ entry ) {
187191 $ user = $ this ->ldapToUser ($ entry );
188192 if ($ user ['user_id ' ] != $ user_id ) {
@@ -262,7 +266,12 @@ protected function setAuthLdapSuffixOu($username): bool
262266 $ base_dn = preg_replace ('/,ou=[^,]+,/ ' , ', ' , LibrenmsConfig::get ('auth_ldap_suffix ' ));
263267 $ base_dn = trim ($ base_dn , ', ' );
264268 $ search = ldap_search ($ connection , $ base_dn , $ filter );
265- foreach (ldap_get_entries ($ connection , $ search ) as $ entry ) {
269+ $ results = ldap_get_entries ($ connection , $ search );
270+ if (! $ results ) {
271+ return false ;
272+ }
273+
274+ foreach ($ results as $ entry ) {
266275 if (isset ($ entry ['uid ' ][0 ]) && $ entry ['uid ' ][0 ] == $ username ) {
267276 preg_match ('~,ou=([^,]+),~ ' , $ entry ['dn ' ], $ matches );
268277 $ user_ou = $ matches [1 ] ?? '' ;
@@ -305,7 +314,7 @@ protected function getLdapConnection($skip_bind = false)
305314 * @param array $entry ldap entry array
306315 * @return array
307316 */
308- private function ldapToUser ($ entry ): array
317+ private function ldapToUser (array $ entry ): array
309318 {
310319 $ uid_attr = strtolower (LibrenmsConfig::get ('auth_ldap_uid_attribute ' , 'uidnumber ' ));
311320
0 commit comments