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 <unistd.h>
#include <pwd.h>
#include <security/pam_appl.h>
#if __has_include(<security/pam_misc.h>)
#include <security/pam_misc.h>
@ -38,10 +39,11 @@ std::shared_ptr<CPassword::SVerificationResult> 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;

View File

@ -4,6 +4,7 @@
#include "../../core/hyprlock.hpp"
#include <chrono>
#include <unistd.h>
#include <pwd.h>
#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);