diff options
author | alex-z <blackslayer4@gmail.com> | 2021-10-27 18:55:08 +0300 |
---|---|---|
committer | Matthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr> | 2021-11-24 13:04:22 +0300 |
commit | b03bf1c1f0f1b69a57613926cbfad32e986f4dc5 (patch) | |
tree | 86e2f0627c20fe0b1b77beec9170c35a2b2460f2 /src/common | |
parent | 9bebda057a2fc883ad9a3bd66b503178dab161f8 (diff) |
Pass username from Windows to login page.
Signed-off-by: alex-z <blackslayer4@gmail.com>
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/utility.h | 5 | ||||
-rw-r--r-- | src/common/utility_mac.cpp | 5 | ||||
-rw-r--r-- | src/common/utility_unix.cpp | 5 | ||||
-rw-r--r-- | src/common/utility_win.cpp | 12 |
4 files changed, 27 insertions, 0 deletions
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 <comdef.h> +#include <Lmcons.h> #include <shlguid.h> #include <shlobj.h> #include <string> @@ -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() { |