Skip to content

Commit 51fa32d

Browse files
committed
allow login with prefix of "<domain>\" for selected domains
Some WebDAV clients force to use a domain name for authentication. That domain name is prepended to the username and separated from it using a backslash. This commit allows any user to login with a prefix of "WORKGROUP\", "NC\", or "NEXTCLOUD\" added to their username. The respective prefix is removed from the given username when trying to login, if the login failed using the original username. The same logic is applied when testing login tokens. In particular, this can help allowing access to Nextcloud for devices with an interface to SharePoint that forces to specify a domain name for authentication. As an example, HP LaserJet M428/M429 (and many others) can then "Scan to Nextcloud" by using the "Scan to SharePoint" feature (wich is essentially WebDav) and configuring a domain name of "NC", "NEXTCLOUD" or "WORKGROUP". Signed-off-by: Bernhard Kirchen <schlimmchen@posteo.net>
1 parent 41148ac commit 51fa32d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

lib/private/User/Session.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,15 @@ public function completeLogin(IUser $user, array $loginDetails, $regenerateSessi
408408
throw new LoginException($message);
409409
}
410410

411+
/**
412+
* Removes domain prefix from username, if any, for defined domain names
413+
* @param string $user
414+
* @return string
415+
*/
416+
private function stripDomainName($user) {
417+
return preg_replace("/^(?:(?:NC|NEXTCLOUD|WORKGROUP)\\\)?(.*)/", "\${1}", $user);
418+
}
419+
411420
/**
412421
* Tries to log in a client
413422
*
@@ -447,7 +456,7 @@ public function logClientIn($user,
447456
}
448457

449458
// Try to login with this username and password
450-
if (!$this->login($user, $password)) {
459+
if (!$this->login($user, $password) && !$this->login($this->stripDomainName($user), $password)) {
451460
// Failed, maybe the user used their email address
452461
if (!filter_var($user, FILTER_VALIDATE_EMAIL)) {
453462
return false;
@@ -779,7 +788,7 @@ private function validateToken($token, $user = null) {
779788
}
780789

781790
// Check if login names match
782-
if (!is_null($user) && $dbToken->getLoginName() !== $user) {
791+
if (!is_null($user) && $dbToken->getLoginName() !== $user && $dbToken->getLoginName() !== $this->stripDomainName($user)) {
783792
// TODO: this makes it impossible to use different login names on browser and client
784793
// e.g. login by e-mail 'user@example.com' on browser for generating the token will not
785794
// allow to use the client token with the login name 'user'.

0 commit comments

Comments
 (0)