From fcbd72e3108dbac536e20788157b1de1dbb8384d Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Wed, 1 May 2024 00:27:31 +1200 Subject: [PATCH] Fix an exception if a LDAP group mentions a user that doesn't exist This tickles a bug as reported by Thorsten Marquardt in https://sourceforge.net/p/davical/mailman/message/58766531/ with this error message reported: Exception [0] ldap_get_attributes(): Argument #2 ($entry) must be of type LDAP\ResultEntry, false given At line 718 of /usr/share/davical-master/inc/drivers_ldap.php You need to look in 3da860e5d5e732c2dedb62a73c76608a2b7098a4 for that line number as I've just made some improvements to the code the last few commits. --- inc/drivers_ldap.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/inc/drivers_ldap.php b/inc/drivers_ldap.php index 017537ea..c3203fef 100644 --- a/inc/drivers_ldap.php +++ b/inc/drivers_ldap.php @@ -718,16 +718,21 @@ function sync_LDAP_groups(){ // in sync_LDAP and use more memory but not need // anymore trips to LDAP. - $entry = ldap_read($ldapDriver->connect, $member, $filter, + $entry = $query($ldapDriver->connect, $member, $filter, array($username_ldap_attribute)); $ldap_user_entry = ldap_first_entry($ldapDriver->connect, $entry); - $ldap_user_attributes - = ldap_get_attributes($ldapDriver->connect, - $ldap_user_entry); - $ldap_members_tmp[] - = $ldap_user_attributes[$username_ldap_attribute][0]; + if (! $ldap_user_entry) { + dbg_error_log( "ERROR", "%s not found in LDAP, not adding to group %s", $member, $group ); + } else { + $ldap_user_attributes + = ldap_get_attributes($ldapDriver->connect, + $ldap_user_entry); + + $ldap_members_tmp[] + = $ldap_user_attributes[$username_ldap_attribute][0]; + } } } else { // No need to rewrite.