From: alex-z Date: Wed, 27 Oct 2021 15:55:08 +0000 (+0300) Subject: Pass username from Windows to login page. X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~12^2~18^2~89^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b03bf1c1f0f1b69a57613926cbfad32e986f4dc5;p=nextcloud-desktop.git Pass username from Windows to login page. Signed-off-by: alex-z --- diff --git a/NEXTCLOUD.cmake b/NEXTCLOUD.cmake index d34e682af..576ca8156 100644 --- a/NEXTCLOUD.cmake +++ b/NEXTCLOUD.cmake @@ -13,6 +13,7 @@ set( APPLICATION_REV_DOMAIN "com.nextcloud.desktopclient" ) set( APPLICATION_VIRTUALFILE_SUFFIX "nextcloud" CACHE STRING "Virtual file suffix (not including the .)") set( APPLICATION_OCSP_STAPLING_ENABLED OFF ) set( APPLICATION_FORBID_BAD_SSL OFF ) +set( APPLICATION_LOGIN_WITH_SYSTEM_USERNAME OFF ) set( LINUX_PACKAGE_SHORTNAME "nextcloud" ) set( LINUX_APPLICATION_ID "${APPLICATION_REV_DOMAIN}.${LINUX_PACKAGE_SHORTNAME}") diff --git a/config.h.in b/config.h.in index e9eff6c92..2aebdb6b5 100644 --- a/config.h.in +++ b/config.h.in @@ -31,6 +31,7 @@ #cmakedefine APPLICATION_VIRTUALFILE_SUFFIX "@APPLICATION_VIRTUALFILE_SUFFIX@" #cmakedefine APPLICATION_OCSP_STAPLING_ENABLED "@APPLICATION_OCSP_STAPLING_ENABLED@" #cmakedefine APPLICATION_FORBID_BAD_SSL "@APPLICATION_FORBID_BAD_SSL@" +#cmakedefine APPLICATION_LOGIN_WITH_SYSTEM_USERNAME "@APPLICATION_LOGIN_WITH_SYSTEM_USERNAME@" #define APPLICATION_DOTVIRTUALFILE_SUFFIX "." APPLICATION_VIRTUALFILE_SUFFIX #cmakedefine01 ENFORCE_VIRTUAL_FILES_SYNC_FOLDER diff --git a/src/common/utility.h b/src/common/utility.h index 349791644..45df7f647 100644 --- a/src/common/utility.h +++ b/src/common/utility.h @@ -242,6 +242,11 @@ namespace Utility { */ OCSYNC_EXPORT bool isPathWindowsDrivePartitionRoot(const QString &path); + /** + * @brief Retrieves current logged-in user name from the OS + */ + OCSYNC_EXPORT QString getCurrentUserName(); + #ifdef Q_OS_WIN OCSYNC_EXPORT bool registryKeyExists(HKEY hRootKey, const QString &subKey); OCSYNC_EXPORT QVariant registryGetKeyValue(HKEY hRootKey, const QString &subKey, const QString &valueName); diff --git a/src/common/utility_mac.cpp b/src/common/utility_mac.cpp index f11cf0b8f..d3a3d480a 100644 --- a/src/common/utility_mac.cpp +++ b/src/common/utility_mac.cpp @@ -136,4 +136,9 @@ static bool hasDarkSystray_private() return returnValue; } +QString Utility::getCurrentUserName() +{ + return {}; +} + } // namespace OCC diff --git a/src/common/utility_unix.cpp b/src/common/utility_unix.cpp index d99475738..887213f09 100644 --- a/src/common/utility_unix.cpp +++ b/src/common/utility_unix.cpp @@ -108,4 +108,9 @@ static inline bool hasDarkSystray_private() return true; } +QString Utility::getCurrentUserName() +{ + return {}; +} + } // namespace OCC diff --git a/src/common/utility_win.cpp b/src/common/utility_win.cpp index 2c14ccb1f..5637a023e 100644 --- a/src/common/utility_win.cpp +++ b/src/common/utility_win.cpp @@ -20,6 +20,7 @@ #include "utility.h" #include +#include #include #include #include @@ -380,6 +381,17 @@ QString Utility::formatWinError(long errorCode) return QStringLiteral("WindowsError: %1: %2").arg(QString::number(errorCode, 16), QString::fromWCharArray(_com_error(errorCode).ErrorMessage())); } +QString Utility::getCurrentUserName() +{ + TCHAR username[UNLEN + 1] = {0}; + DWORD len = sizeof(username) / sizeof(TCHAR); + + if (!GetUserName(username, &len)) { + qCWarning(lcUtility) << "Could not retrieve Windows user name." << formatWinError(GetLastError()); + } + + return QString::fromWCharArray(username); +} Utility::NtfsPermissionLookupRAII::NtfsPermissionLookupRAII() { diff --git a/src/gui/creds/flow2auth.cpp b/src/gui/creds/flow2auth.cpp index 54b7b28a8..9873a2705 100644 --- a/src/gui/creds/flow2auth.cpp +++ b/src/gui/creds/flow2auth.cpp @@ -132,6 +132,16 @@ void Flow2Auth::fetchNewToken(const TokenAction action) _loginUrl = loginUrl; + + if (Theme::instance()->loginWithSystemUserName()) { + const auto userName = Utility::getCurrentUserName(); + if (!userName.isEmpty()) { + auto query = QUrlQuery(_loginUrl); + query.addQueryItem(QStringLiteral("user"), userName); + _loginUrl.setQuery(query); + } + } + _pollToken = pollToken; _pollEndpoint = pollEndpoint; diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp index ff7f58e60..330b12902 100644 --- a/src/libsync/theme.cpp +++ b/src/libsync/theme.cpp @@ -417,6 +417,15 @@ bool Theme::forbidBadSSL() const #endif } +bool Theme::loginWithSystemUserName() const +{ +#ifdef APPLICATION_LOGIN_WITH_SYSTEM_USERNAME + return true; +#else + return false; +#endif +} + QString Theme::forceConfigAuthType() const { return QString(); diff --git a/src/libsync/theme.h b/src/libsync/theme.h index 6b9aefb25..6ab8fb3f7 100644 --- a/src/libsync/theme.h +++ b/src/libsync/theme.h @@ -254,6 +254,13 @@ public: */ virtual bool forbidBadSSL() const; + /** + * Use current logged in username from the system + * + * When true, the Web login form will be pre-filled with system user name + */ + bool loginWithSystemUserName() const; + /** * This is only usefull when previous version had a different overrideServerUrl * with a different auth type in that case You should then specify "http" or "shibboleth".