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 "hyprlock.hpp"
|
||||
#include "../helpers/Log.hpp"
|
||||
|
||||
#include <unistd.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::thread([this, result, pass]() {
|
||||
const pam_conv localConv = {conv, NULL};
|
||||
pam_handle_t* handle = NULL;
|
||||
auto auth = [&](std::string auth) -> bool {
|
||||
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) {
|
||||
result->success = false;
|
||||
result->failReason = "pam_start failed";
|
||||
result->realized = true;
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(1), passwordCheckTimerCallback, nullptr);
|
||||
return;
|
||||
}
|
||||
if (ret != PAM_SUCCESS) {
|
||||
result->success = false;
|
||||
result->failReason = "pam_start failed";
|
||||
Debug::log(ERR, "auth: pam_start failed for {}", auth);
|
||||
return false;
|
||||
}
|
||||
|
||||
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_retcode = 0;
|
||||
ret = pam_authenticate(handle, 0);
|
||||
reply->resp = strdup(pass.c_str());
|
||||
reply->resp_retcode = 0;
|
||||
ret = pam_authenticate(handle, 0);
|
||||
|
||||
if (ret != PAM_SUCCESS) {
|
||||
result->success = false;
|
||||
result->failReason = ret == PAM_AUTH_ERR ? "Authentication failed" : "pam_authenticate failed";
|
||||
result->realized = true;
|
||||
g_pHyprlock->addTimer(std::chrono::milliseconds(1), passwordCheckTimerCallback, nullptr);
|
||||
return;
|
||||
}
|
||||
if (ret != PAM_SUCCESS) {
|
||||
result->success = false;
|
||||
result->failReason = ret == PAM_AUTH_ERR ? "Authentication failed" : "pam_authenticate failed";
|
||||
Debug::log(ERR, "auth: {} for {}", result->failReason, auth);
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = pam_end(handle, ret);
|
||||
ret = pam_end(handle, ret);
|
||||
|
||||
result->success = true;
|
||||
result->failReason = "Successfully authenticated";
|
||||
result->realized = true;
|
||||
result->success = true;
|
||||
result->failReason = "Successfully authenticated";
|
||||
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);
|
||||
}).detach();
|
||||
|
||||
|
|
Loading…
Reference in a new issue