Skip to content

Commit f32b6c0

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 "NC\", "NEXTCLOUD\" or "WORKGROUP\" to their username. The respective prefix is removed from the given username when trying to login if the login failed and also interpreting the given username as an email address failed. 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".
1 parent 4e39d1c commit f32b6c0

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

lib/private/User/Session.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,21 @@ public function logClientIn($user,
464464
// Failed, maybe the user used their email address
465465
$users = $this->manager->getByEmail($user);
466466
if (!(\count($users) === 1 && $this->login($users[0]->getUID(), $password))) {
467-
$this->logger->warning('Login failed: \'' . $user . '\' (Remote IP: \'' . \OC::$server->getRequest()->getRemoteAddress() . '\')', ['app' => 'core']);
468467

469-
$throttler->registerAttempt('login', $request->getRemoteAddress(), ['user' => $user]);
468+
// Failed, try username from DOMAIN\USERNAME syntax, if applicable
469+
$nonDomainUser = preg_replace("/^(?:NC|NEXTCLOUD|WORKGROUP)\\\(.*)/", "\${1}", $user);
470+
if ($nonDomainUser === $user || !$this->login($nonDomainUser, $password)) {
471+
$this->logger->warning('Login failed: \'' . $user . '\' (Remote IP: \'' . \OC::$server->getRequest()->getRemoteAddress() . '\')', ['app' => 'core']);
470472

471-
$this->dispatcher->dispatchTyped(new OC\Authentication\Events\LoginFailed($user));
473+
$throttler->registerAttempt('login', $request->getRemoteAddress(), ['user' => $user]);
472474

473-
if ($currentDelay === 0) {
474-
$throttler->sleepDelay($request->getRemoteAddress(), 'login');
475+
$this->dispatcher->dispatchTyped(new OC\Authentication\Events\LoginFailed($user));
476+
477+
if ($currentDelay === 0) {
478+
$throttler->sleepDelay($request->getRemoteAddress(), 'login');
479+
}
480+
return false;
475481
}
476-
return false;
477482
}
478483
}
479484

0 commit comments

Comments
 (0)