From 8a3d174d3f0535a44ef0aa79a948a74cde1366a1 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 18 Aug 2022 09:34:26 +0530 Subject: [PATCH 1/5] login with device fix --- patches/002-login-without-domain.patch | 31 +++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/patches/002-login-without-domain.patch b/patches/002-login-without-domain.patch index 847c5635..8f34f35c 100644 --- a/patches/002-login-without-domain.patch +++ b/patches/002-login-without-domain.patch @@ -12,7 +12,7 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll @@ -303,6 +303,27 @@ return $this->generateRedirect($redirect_url); } - + + $user = trim($user); + $user = mb_strtolower($user, 'UTF-8'); + $domain = $this->config->getSystemValue('mail_domain', ''); @@ -37,10 +37,18 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll $data = new LoginData( $this->request, trim($user), ---- ./core/Controller/WebAuthnController.php 2022-05-11 11:11:55.469731468 +0530 -+++ ./core/Controller/WebAuthnController-new.php 2022-05-30 19:34:53.540848852 +0530 -@@ -73,6 +73,26 @@ - +--- ./core/Controller/WebAuthnController.php 2022-08-18 09:19:54.820199100 +0530 ++++ ./core/Controller/WebAuthnController-new.php 2022-08-18 09:29:53.340199100 +0530 +@@ -37,6 +37,7 @@ + use OCP\ISession; + use OCP\Util; + use Webauthn\PublicKeyCredentialRequestOptions; ++use OCP\IUserManager; + + class WebAuthnController extends Controller { + private const WEBAUTHN_LOGIN = 'webauthn_login'; +@@ -73,6 +74,26 @@ + $this->logger->debug('Converting login name to UID'); $uid = $loginName; + $uid = trim($uid); @@ -59,13 +67,20 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll + $uid = str_replace($alt_domain_suffix, '', $uid); + } + -+ if(!$this->userManager->userExists($uid)) { ++ if(!\OC::$server->get(IUserManager::class)->userExists($uid)) { + $uid = $uid . $domain_suffix; + } + Util::emitHook( '\OCA\Files_Sharing\API\Server2Server', 'preLoginNameUsedAsUserName', +@@ -115,4 +136,4 @@ + + return new JSONResponse([]); + } +-} +\ No newline at end of file ++} --- ./lib/private/User/Session.php 2022-08-10 15:39:33.131890282 +0530 +++ ./lib/private/User/Session-new.php 2022-08-10 15:48:23.236165783 +0530 @@ -74,11 +89,11 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll OC\Security\Bruteforce\Throttler $throttler) { $currentDelay = $throttler->sleepDelay($request->getRemoteAddress(), 'login'); - -+ ++ + $altDomain = $this->config->getSystemValue('alt_mail_domain', ''); + $altDomainSuffix = !empty($altDomain) ? '@' . $altDomain : ''; + $user = str_replace($altDomainSuffix, '', $user); -+ ++ if ($this->manager instanceof PublicEmitter) { $this->manager->emit('\OC\User', 'preLogin', [$user, $password]); } -- GitLab From d86cd80b187c4691a03095b4d9cea96bfda0b069 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 18 Aug 2022 09:45:06 +0530 Subject: [PATCH 2/5] login with device fix --- patches/002-login-without-domain.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patches/002-login-without-domain.patch b/patches/002-login-without-domain.patch index 8f34f35c..f50a34c0 100644 --- a/patches/002-login-without-domain.patch +++ b/patches/002-login-without-domain.patch @@ -37,7 +37,7 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll $data = new LoginData( $this->request, trim($user), ---- ./core/Controller/WebAuthnController.php 2022-08-18 09:19:54.820199100 +0530 +--- ./core/Controller/WebAuthnController.php 2022-08-18 09:41:40.030199100 +0530 +++ ./core/Controller/WebAuthnController-new.php 2022-08-18 09:29:53.340199100 +0530 @@ -37,6 +37,7 @@ use OCP\ISession; -- GitLab From 1b97abd81aace0bcd3844743e8d8f2ac7e1d38dd Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 18 Aug 2022 09:57:28 +0530 Subject: [PATCH 3/5] login with device fix --- patches/002-login-without-domain.patch | 48 +++++++++----------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/patches/002-login-without-domain.patch b/patches/002-login-without-domain.patch index f50a34c0..363cefe9 100644 --- a/patches/002-login-without-domain.patch +++ b/patches/002-login-without-domain.patch @@ -37,7 +37,7 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll $data = new LoginData( $this->request, trim($user), ---- ./core/Controller/WebAuthnController.php 2022-08-18 09:41:40.030199100 +0530 +--- ./core/Controller/WebAuthnController.php 2022-08-18 09:54:41.180199100 +0530 +++ ./core/Controller/WebAuthnController-new.php 2022-08-18 09:29:53.340199100 +0530 @@ -37,6 +37,7 @@ use OCP\ISession; @@ -47,40 +47,26 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll class WebAuthnController extends Controller { private const WEBAUTHN_LOGIN = 'webauthn_login'; -@@ -73,6 +74,26 @@ - - $this->logger->debug('Converting login name to UID'); +@@ -75,9 +76,9 @@ $uid = $loginName; -+ $uid = trim($uid); -+ $uid = mb_strtolower($uid, 'UTF-8'); + $uid = trim($uid); + $uid = mb_strtolower($uid, 'UTF-8'); +- $domain = $this->config->getSystemValue('mail_domain', ''); + $domain = \OC::$server->getConfig()->getSystemValue('mail_domain', ''); -+ $domain_suffix = !empty($domain) ? '@' . $domain : ''; + $domain_suffix = !empty($domain) ? '@' . $domain : ''; +- $alt_domain = $this->config->getSystemValue('alt_mail_domain', ''); + $alt_domain = \OC::$server->getConfig()->getSystemValue('alt_mail_domain', ''); -+ $alt_domain_suffix = !empty($alt_domain) ? '@' . $alt_domain : ''; -+ $admin_username = $_ENV["NEXTCLOUD_ADMIN_USER"]; -+ $is_admin = strcmp($uid, $admin_username) === 0; -+ -+ if(!$is_admin && stristr($uid, $domain_suffix) !== FALSE) { -+ $uid = str_replace($domain_suffix, '', $uid); -+ } -+ if (!$is_admin && stristr($uid, $alt_domain_suffix) !== FALSE) { -+ $uid = str_replace($alt_domain_suffix, '', $uid); -+ } -+ -+ if(!\OC::$server->get(IUserManager::class)->userExists($uid)) { -+ $uid = $uid . $domain_suffix; -+ } -+ - Util::emitHook( - '\OCA\Files_Sharing\API\Server2Server', - 'preLoginNameUsedAsUserName', -@@ -115,4 +136,4 @@ + $alt_domain_suffix = !empty($alt_domain) ? '@' . $alt_domain : ''; + $admin_username = $_ENV["NEXTCLOUD_ADMIN_USER"]; + $is_admin = strcmp($uid, $admin_username) === 0; +@@ -89,7 +90,7 @@ + $uid = str_replace($alt_domain_suffix, '', $uid); + } - return new JSONResponse([]); - } --} -\ No newline at end of file -+} +- if(!$this->userManager->userExists($uid)) { ++ if(!\OC::$server->get(IUserManager::class)->userExists($uid)) { + $uid = $uid . $domain_suffix; + } --- ./lib/private/User/Session.php 2022-08-10 15:39:33.131890282 +0530 +++ ./lib/private/User/Session-new.php 2022-08-10 15:48:23.236165783 +0530 -- GitLab From 1876f09d84d1f28da7bea61dcd7d5298f757bf60 Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 18 Aug 2022 10:15:38 +0530 Subject: [PATCH 4/5] login with device fix --- patches/002-login-without-domain.patch | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/patches/002-login-without-domain.patch b/patches/002-login-without-domain.patch index 363cefe9..a97a737f 100644 --- a/patches/002-login-without-domain.patch +++ b/patches/002-login-without-domain.patch @@ -37,8 +37,8 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll $data = new LoginData( $this->request, trim($user), ---- ./core/Controller/WebAuthnController.php 2022-08-18 09:54:41.180199100 +0530 -+++ ./core/Controller/WebAuthnController-new.php 2022-08-18 09:29:53.340199100 +0530 +--- ./core/Controller/WebAuthnController.php 2022-08-18 10:14:10.940199100 +0530 ++++ ./core/Controller/WebAuthnController-new.php 2022-08-18 10:14:17.280199100 +0530 @@ -37,6 +37,7 @@ use OCP\ISession; use OCP\Util; @@ -68,6 +68,7 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll $uid = $uid . $domain_suffix; } + --- ./lib/private/User/Session.php 2022-08-10 15:39:33.131890282 +0530 +++ ./lib/private/User/Session-new.php 2022-08-10 15:48:23.236165783 +0530 @@ -438,7 +438,11 @@ -- GitLab From c69653fbc5cde980d9d36fcc21fc253a341e0bde Mon Sep 17 00:00:00 2001 From: Avinash Gusain Date: Thu, 18 Aug 2022 10:35:31 +0530 Subject: [PATCH 5/5] login with device fix --- patches/002-login-without-domain.patch | 42 +++++++++++++++----------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/patches/002-login-without-domain.patch b/patches/002-login-without-domain.patch index a97a737f..b8575978 100644 --- a/patches/002-login-without-domain.patch +++ b/patches/002-login-without-domain.patch @@ -37,8 +37,8 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll $data = new LoginData( $this->request, trim($user), ---- ./core/Controller/WebAuthnController.php 2022-08-18 10:14:10.940199100 +0530 -+++ ./core/Controller/WebAuthnController-new.php 2022-08-18 10:14:17.280199100 +0530 +--- ./core/Controller/WebAuthnController.php 2022-08-18 10:33:16.150199100 +0530 ++++ ./core/Controller/WebAuthnController-new.php 2022-08-18 10:34:31.880199100 +0530 @@ -37,6 +37,7 @@ use OCP\ISession; use OCP\Util; @@ -47,26 +47,32 @@ diff --git ./core/Controller/LoginController.php ./core/Controller/LoginControll class WebAuthnController extends Controller { private const WEBAUTHN_LOGIN = 'webauthn_login'; -@@ -75,9 +76,9 @@ +@@ -73,6 +74,25 @@ + + $this->logger->debug('Converting login name to UID'); $uid = $loginName; - $uid = trim($uid); - $uid = mb_strtolower($uid, 'UTF-8'); -- $domain = $this->config->getSystemValue('mail_domain', ''); ++ $uid = trim($uid); ++ $uid = mb_strtolower($uid, 'UTF-8'); + $domain = \OC::$server->getConfig()->getSystemValue('mail_domain', ''); - $domain_suffix = !empty($domain) ? '@' . $domain : ''; -- $alt_domain = $this->config->getSystemValue('alt_mail_domain', ''); ++ $domain_suffix = !empty($domain) ? '@' . $domain : ''; + $alt_domain = \OC::$server->getConfig()->getSystemValue('alt_mail_domain', ''); - $alt_domain_suffix = !empty($alt_domain) ? '@' . $alt_domain : ''; - $admin_username = $_ENV["NEXTCLOUD_ADMIN_USER"]; - $is_admin = strcmp($uid, $admin_username) === 0; -@@ -89,7 +90,7 @@ - $uid = str_replace($alt_domain_suffix, '', $uid); - } - -- if(!$this->userManager->userExists($uid)) { ++ $alt_domain_suffix = !empty($alt_domain) ? '@' . $alt_domain : ''; ++ $admin_username = $_ENV["NEXTCLOUD_ADMIN_USER"]; ++ $is_admin = strcmp($uid, $admin_username) === 0; ++ ++ if(!$is_admin && stristr($uid, $domain_suffix) !== FALSE) { ++ $uid = str_replace($domain_suffix, '', $uid); ++ } ++ if (!$is_admin && stristr($uid, $alt_domain_suffix) !== FALSE) { ++ $uid = str_replace($alt_domain_suffix, '', $uid); ++ } ++ + if(!\OC::$server->get(IUserManager::class)->userExists($uid)) { - $uid = $uid . $domain_suffix; - } ++ $uid = $uid . $domain_suffix; ++ } + Util::emitHook( + '\OCA\Files_Sharing\API\Server2Server', + 'preLoginNameUsedAsUserName', --- ./lib/private/User/Session.php 2022-08-10 15:39:33.131890282 +0530 -- GitLab