From 69483900d1c663394b665c218c4409b77d85fa1e Mon Sep 17 00:00:00 2001 From: Bjoern Kahl Date: Thu, 18 May 2023 16:49:47 +0000 Subject: [PATCH] Distinguish wrong credentials from other problems (IMAP) Verifying login data can fail for a number of reasons like temporary connection failure to the IMAP server, Internal problems of the IMAP server, or actually wrong username / password combination. This change logs the reason for login failures, helping server admins to diagnose login problems and better support their users. Ideally, we would have an option to pass the reason upwards, so the NextCloud login system can show appropriate errors to users attempting to login. Signed-off-by: Bjoern Kahl --- lib/IMAP.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/IMAP.php b/lib/IMAP.php index cd5e8ec..39469ff 100644 --- a/lib/IMAP.php +++ b/lib/IMAP.php @@ -106,9 +106,29 @@ public function checkPassword($uid, $password) { $uid = mb_strtolower($uid); $this->storeUser($uid, $groups); return $uid; + } elseif ($errorcode === CURLE_COULDNT_CONNECT || + $errorcode === CURLE_SSL_CONNECT_ERROR || + $errorcode === 28) { + # This is not defined in PHP-8.x + # 28: CURLE_OPERATION_TIMEDOUT + \OC::$server->getLogger()->error( + 'ERROR: Could not connect to imap server via curl: ' . curl_strerror($errorcode), + ['app' => 'user_external'] + ); + } elseif ($errorcode === 9 || + $errorcode === 67 || + $errorcode === 94) { + # These are not defined in PHP-8.x + # 9: CURLE_REMOTE_ACCESS_DENIED + # 67: CURLE_LOGIN_DENIED + # 94: CURLE_AUTH_ERROR) + \OC::$server->getLogger()->error( + 'ERROR: IMAP Login failed via curl: ' . curl_strerror($errorcode), + ['app' => 'user_external'] + ); } else { \OC::$server->getLogger()->error( - 'ERROR: Could not connect to imap server via curl: '.curl_error($ch), + 'ERROR: IMAP server returned an error: ' . $errorcode . ' / ' . curl_strerror($errorcode), ['app' => 'user_external'] ); }