From 7a69e7a88f65d279ebe8174a635452dc7c72e4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Arenaza?= Date: Sun, 3 Nov 2013 23:45:19 +0100 Subject: [PATCH] MDL-42723: Hide and handle LDAP error when user not in context being checked MDL-41304 only fixed the case when 'Search subcontext' is enabled. We need to fix the case when it's not enabled too. While silencing errors with an @ should be avoided if possible, there's no other way to prevent the warnings in this case. --- lib/ldaplib.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/ldaplib.php b/lib/ldaplib.php index 54bb66121c865..31ef0e181a1cf 100644 --- a/lib/ldaplib.php +++ b/lib/ldaplib.php @@ -247,15 +247,17 @@ function ldap_find_userdn($ldapconnection, $username, $contexts, $objectclass, $ } if ($search_sub) { - if (!$ldap_result = @ldap_search($ldapconnection, $context, - '(&'.$objectclass.'('.$search_attrib.'='.ldap_filter_addslashes($username).'))', - array($search_attrib))) { - break; // Not found in this context. - } + $ldap_result = @ldap_search($ldapconnection, $context, + '(&'.$objectclass.'('.$search_attrib.'='.ldap_filter_addslashes($username).'))', + array($search_attrib)); } else { - $ldap_result = ldap_list($ldapconnection, $context, - '(&'.$objectclass.'('.$search_attrib.'='.ldap_filter_addslashes($username).'))', - array($search_attrib)); + $ldap_result = @ldap_list($ldapconnection, $context, + '(&'.$objectclass.'('.$search_attrib.'='.ldap_filter_addslashes($username).'))', + array($search_attrib)); + } + + if (!$ldap_result) { + continue; // Not found in this context. } $entry = ldap_first_entry($ldapconnection, $ldap_result);