refactor: improve structure
This commit is contained in:
parent
0f39bcc5fe
commit
6cddf402b7
3 changed files with 13 additions and 18 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef __ENTER_DEVICE_H_
|
#ifndef ENTER_DEVICE_H_
|
||||||
#define __ENTER_DEVICE_H_
|
#define ENTER_DEVICE_H_
|
||||||
|
|
||||||
#include <libevdev/libevdev-uinput.h>
|
#include <libevdev/libevdev-uinput.h>
|
||||||
#include <libevdev/libevdev.h>
|
#include <libevdev/libevdev.h>
|
||||||
|
|
@ -16,4 +16,4 @@ public:
|
||||||
~EnterDevice() = default;
|
~EnterDevice() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __ENTER_DEVICE_H
|
#endif // ENTER_DEVICE_H
|
||||||
|
|
|
||||||
|
|
@ -65,25 +65,20 @@ auto howdy_error(int status,
|
||||||
status = WEXITSTATUS(status);
|
status = WEXITSTATUS(status);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
// Status 10 means we couldn't find any face models
|
case CompareError::NO_FACE_MODEL:
|
||||||
case 10:
|
|
||||||
conv_function(PAM_ERROR_MSG, S("There is no face model known"));
|
conv_function(PAM_ERROR_MSG, S("There is no face model known"));
|
||||||
syslog(LOG_NOTICE, "Failure, no face model known");
|
syslog(LOG_NOTICE, "Failure, no face model known");
|
||||||
break;
|
break;
|
||||||
// Status 11 means we exceded the maximum retry count
|
case CompareError::TIMEOUT_REACHED:
|
||||||
case 11:
|
|
||||||
syslog(LOG_ERR, "Failure, timeout reached");
|
syslog(LOG_ERR, "Failure, timeout reached");
|
||||||
break;
|
break;
|
||||||
// Status 12 means we aborted
|
case CompareError::ABORT:
|
||||||
case 12:
|
|
||||||
syslog(LOG_ERR, "Failure, general abort");
|
syslog(LOG_ERR, "Failure, general abort");
|
||||||
break;
|
break;
|
||||||
// Status 13 means the image was too dark
|
case CompareError::TOO_DARK:
|
||||||
case 13:
|
|
||||||
conv_function(PAM_ERROR_MSG, S("Face detection image too dark"));
|
conv_function(PAM_ERROR_MSG, S("Face detection image too dark"));
|
||||||
syslog(LOG_ERR, "Failure, image too dark");
|
syslog(LOG_ERR, "Failure, image too dark");
|
||||||
break;
|
break;
|
||||||
// Otherwise, we can't describe what happened but it wasn't successful
|
|
||||||
default:
|
default:
|
||||||
conv_function(PAM_ERROR_MSG,
|
conv_function(PAM_ERROR_MSG,
|
||||||
std::string(S("Unknown error: ") + status).c_str());
|
std::string(S("Unknown error: ") + status).c_str());
|
||||||
|
|
@ -219,10 +214,6 @@ auto identify(pam_handle_t *pamh, int flags, int argc, const char **argv,
|
||||||
Workaround workaround =
|
Workaround workaround =
|
||||||
get_workaround(config.GetString("core", "workaround", "input"));
|
get_workaround(config.GetString("core", "workaround", "input"));
|
||||||
|
|
||||||
// We ask for the password if the function requires it and if a workaround is
|
|
||||||
// set
|
|
||||||
auth_tok = auth_tok && workaround != Workaround::Off;
|
|
||||||
|
|
||||||
// Will contain PAM conversation structure
|
// Will contain PAM conversation structure
|
||||||
struct pam_conv *conv = nullptr;
|
struct pam_conv *conv = nullptr;
|
||||||
const void **conv_ptr =
|
const void **conv_ptr =
|
||||||
|
|
@ -316,7 +307,9 @@ auto identify(pam_handle_t *pamh, int flags, int argc, const char **argv,
|
||||||
return std::tuple<int, char *>(pam_res, auth_tok_ptr);
|
return std::tuple<int, char *>(pam_res, auth_tok_ptr);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (auth_tok) {
|
// We ask for the password if the function requires it and if a workaround is
|
||||||
|
// set
|
||||||
|
if (auth_tok && workaround != Workaround::Off) {
|
||||||
pass_task.activate();
|
pass_task.activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,15 @@
|
||||||
#ifndef MAIN_H_
|
#ifndef MAIN_H_
|
||||||
#define MAIN_H_
|
#define MAIN_H_
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
enum class ConfirmationType { Unset, Howdy, Pam };
|
enum class ConfirmationType { Unset, Howdy, Pam };
|
||||||
|
|
||||||
enum class Workaround { Off, Input, Native };
|
enum class Workaround { Off, Input, Native };
|
||||||
|
|
||||||
|
// Exit status codes returned by the compare process
|
||||||
|
enum CompareError: int { NO_FACE_MODEL = 10, TIMEOUT_REACHED = 11, ABORT = 12, TOO_DARK = 13 };
|
||||||
|
|
||||||
inline auto get_workaround(const std::string &workaround) -> Workaround {
|
inline auto get_workaround(const std::string &workaround) -> Workaround {
|
||||||
if (workaround == "input") {
|
if (workaround == "input") {
|
||||||
return Workaround::Input;
|
return Workaround::Input;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue