auth: Use getpwuid(getuid()) instead of getlogin() (#204)

* Making changes

* Replacing struct with auto keyword

* Removing the extra semicolon

* ran clang-format
This commit is contained in:
kcirick 2024-03-19 11:50:23 -04:00 committed by GitHub
parent b50acfaf94
commit 54da0cae0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View file

@ -3,6 +3,7 @@
#include "../helpers/Log.hpp" #include "../helpers/Log.hpp"
#include <unistd.h> #include <unistd.h>
#include <pwd.h>
#include <security/pam_appl.h> #include <security/pam_appl.h>
#if __has_include(<security/pam_misc.h>) #if __has_include(<security/pam_misc.h>)
#include <security/pam_misc.h> #include <security/pam_misc.h>
@ -40,8 +41,9 @@ std::shared_ptr<CPassword::SVerificationResult> CPassword::verify(const std::str
auto auth = [&](std::string auth) -> bool { auto auth = [&](std::string auth) -> bool {
const pam_conv localConv = {conv, (void*)pass.c_str()}; const pam_conv localConv = {conv, (void*)pass.c_str()};
pam_handle_t* handle = NULL; 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) { if (ret != PAM_SUCCESS) {
result->success = false; result->success = false;

View file

@ -4,6 +4,7 @@
#include "../../core/hyprlock.hpp" #include "../../core/hyprlock.hpp"
#include <chrono> #include <chrono>
#include <unistd.h> #include <unistd.h>
#include <pwd.h>
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 190100 #if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION < 190100
#pragma comment(lib, "date-tz") #pragma comment(lib, "date-tz")
@ -82,7 +83,8 @@ static std::string getTime() {
IWidget::SFormatResult IWidget::formatString(std::string in) { IWidget::SFormatResult IWidget::formatString(std::string in) {
char* username = getlogin(); auto uidPassword = getpwuid(getuid());
char* username = uidPassword->pw_name;
if (!username) if (!username)
Debug::log(ERR, "Error in formatString, username null. Errno: ", errno); Debug::log(ERR, "Error in formatString, username null. Errno: ", errno);