From e73f2d73d41d5e3c41084e867e841f2375999a89 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Mon, 22 Jan 2024 02:15:43 +1300 Subject: [PATCH] Better handle when we can't talk to the server, log that --- inc/drivers_ldap.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/inc/drivers_ldap.php b/inc/drivers_ldap.php index ba8d549b..f087ac51 100644 --- a/inc/drivers_ldap.php +++ b/inc/drivers_ldap.php @@ -140,22 +140,38 @@ class ldapDriver $ret = array(); foreach($this->baseDNUsers as $baseDNUsers) { - $entry = $query($this->connect,$baseDNUsers,$this->filterUsers,$attributes); + $entry = $query($this->connect, $baseDNUsers, $this->filterUsers, $attributes); - if (!ldap_first_entry($this->connect,$entry)) { + if (! $entry) { + $c->messages[] = sprintf(translate('Error NoUserFound with filter >%s<, attributes >%s< , dn >%s<'), + $this->filterUsers, + join(', ', $attributes), + $baseDNUsers); + dbg_error_log('LDAP', 'Error NoUserFound with filter >%s<, attributes >%s< , dn >%s<', + $this->filterUsers, + join(', ', $attributes), + $baseDNUsers); + return $ret; + } + + if (! ldap_first_entry($this->connect, $entry)) { $c->messages[] = sprintf(translate('Error NoUserFound with filter >%s<, attributes >%s< , dn >%s<'), $this->filterUsers, join(', ', $attributes), $baseDNUsers); + return $ret; } + $row = array(); - for($i = ldap_first_entry($this->connect,$entry); - $i && $arr = ldap_get_attributes($this->connect,$i); - $i = ldap_next_entry($this->connect,$i) ) { + for ($i = ldap_first_entry($this->connect,$entry); + $i && $arr = ldap_get_attributes($this->connect,$i); + $i = ldap_next_entry($this->connect,$i) ) { $row = array(); + for ($j=0; $j < $arr['count']; $j++) { $row[$arr[$j]] = $arr[$arr[$j]][0]; } + $ret[]=$row; } }