mirror of
https://github.com/hyprwm/hyprlock.git
synced 2024-11-16 23:05:58 +01:00
pam: fallback auth to su
This commit is contained in:
parent
ada7ce8e56
commit
f9fe60c7eb
1 changed files with 30 additions and 25 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include "Password.hpp"
|
#include "Password.hpp"
|
||||||
#include "hyprlock.hpp"
|
#include "hyprlock.hpp"
|
||||||
|
#include "../helpers/Log.hpp"
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <security/pam_appl.h>
|
#include <security/pam_appl.h>
|
||||||
|
@ -27,38 +28,42 @@ std::shared_ptr<CPassword::SVerificationResult> CPassword::verify(const std::str
|
||||||
std::shared_ptr<CPassword::SVerificationResult> result = std::make_shared<CPassword::SVerificationResult>(false);
|
std::shared_ptr<CPassword::SVerificationResult> result = std::make_shared<CPassword::SVerificationResult>(false);
|
||||||
|
|
||||||
std::thread([this, result, pass]() {
|
std::thread([this, result, pass]() {
|
||||||
const pam_conv localConv = {conv, NULL};
|
auto auth = [&](std::string auth) -> bool {
|
||||||
pam_handle_t* handle = NULL;
|
const pam_conv localConv = {conv, NULL};
|
||||||
|
pam_handle_t* handle = NULL;
|
||||||
|
|
||||||
int ret = pam_start("hyprlock", getlogin(), &localConv, &handle);
|
int ret = pam_start(auth.c_str(), getlogin(), &localConv, &handle);
|
||||||
|
|
||||||
if (ret != PAM_SUCCESS) {
|
if (ret != PAM_SUCCESS) {
|
||||||
result->success = false;
|
result->success = false;
|
||||||
result->failReason = "pam_start failed";
|
result->failReason = "pam_start failed";
|
||||||
result->realized = true;
|
Debug::log(ERR, "auth: pam_start failed for {}", auth);
|
||||||
g_pHyprlock->addTimer(std::chrono::milliseconds(1), passwordCheckTimerCallback, nullptr);
|
return false;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
reply = (struct pam_response*)malloc(sizeof(struct pam_response));
|
reply = (struct pam_response*)malloc(sizeof(struct pam_response));
|
||||||
|
|
||||||
reply->resp = strdup(pass.c_str());
|
reply->resp = strdup(pass.c_str());
|
||||||
reply->resp_retcode = 0;
|
reply->resp_retcode = 0;
|
||||||
ret = pam_authenticate(handle, 0);
|
ret = pam_authenticate(handle, 0);
|
||||||
|
|
||||||
if (ret != PAM_SUCCESS) {
|
if (ret != PAM_SUCCESS) {
|
||||||
result->success = false;
|
result->success = false;
|
||||||
result->failReason = ret == PAM_AUTH_ERR ? "Authentication failed" : "pam_authenticate failed";
|
result->failReason = ret == PAM_AUTH_ERR ? "Authentication failed" : "pam_authenticate failed";
|
||||||
result->realized = true;
|
Debug::log(ERR, "auth: {} for {}", result->failReason, auth);
|
||||||
g_pHyprlock->addTimer(std::chrono::milliseconds(1), passwordCheckTimerCallback, nullptr);
|
return false;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ret = pam_end(handle, ret);
|
ret = pam_end(handle, ret);
|
||||||
|
|
||||||
result->success = true;
|
result->success = true;
|
||||||
result->failReason = "Successfully authenticated";
|
result->failReason = "Successfully authenticated";
|
||||||
result->realized = true;
|
Debug::log(LOG, "auth: authenticated for {}", auth);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
result->realized = auth("hyprlock") || auth("su") || true;
|
||||||
g_pHyprlock->addTimer(std::chrono::milliseconds(1), passwordCheckTimerCallback, nullptr);
|
g_pHyprlock->addTimer(std::chrono::milliseconds(1), passwordCheckTimerCallback, nullptr);
|
||||||
}).detach();
|
}).detach();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue