From 54da0cae0f197f07c17c672ebdc22de244859494 Mon Sep 17 00:00:00 2001 From: kcirick Date: Tue, 19 Mar 2024 11:50:23 -0400 Subject: [PATCH] auth: Use getpwuid(getuid()) instead of getlogin() (#204) * Making changes * Replacing struct with auto keyword * Removing the extra semicolon * ran clang-format --- src/core/Password.cpp | 8 +++++--- src/renderer/widgets/IWidget.cpp | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/Password.cpp b/src/core/Password.cpp index bea5038..f1c3653 100644 --- a/src/core/Password.cpp +++ b/src/core/Password.cpp @@ -3,6 +3,7 @@ #include "../helpers/Log.hpp" #include +#include #include #if __has_include() #include @@ -38,10 +39,11 @@ std::shared_ptr CPassword::verify(const std::str std::thread([this, result, pass]() { auto auth = [&](std::string auth) -> bool { - const pam_conv localConv = {conv, (void*)pass.c_str()}; - pam_handle_t* handle = NULL; + const pam_conv localConv = {conv, (void*)pass.c_str()}; + pam_handle_t* handle = NULL; + auto uidPassword = getpwuid(getuid()); - int ret = pam_start(auth.c_str(), getlogin(), &localConv, &handle); + int ret = pam_start(auth.c_str(), uidPassword->pw_name, &localConv, &handle); if (ret != PAM_SUCCESS) { result->success = false; diff --git a/src/renderer/widgets/IWidget.cpp b/src/renderer/widgets/IWidget.cpp index 9483839..d9519de 100644 --- a/src/renderer/widgets/IWidget.cpp +++ b/src/renderer/widgets/IWidget.cpp @@ -4,6 +4,7 @@ #include "../../core/hyprlock.hpp" #include #include +#include #if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 190100 #pragma comment(lib, "date-tz") @@ -82,7 +83,8 @@ static std::string getTime() { IWidget::SFormatResult IWidget::formatString(std::string in) { - char* username = getlogin(); + auto uidPassword = getpwuid(getuid()); + char* username = uidPassword->pw_name; if (!username) Debug::log(ERR, "Error in formatString, username null. Errno: ", errno);