mirror of
https://github.com/boltgolt/howdy.git
synced 2024-09-19 09:51:19 +02:00
refactor: replace boost locale by gnu gettext
This commit is contained in:
parent
9d61c0bc20
commit
cd11aba4e6
2 changed files with 19 additions and 14 deletions
|
@ -1,10 +1,10 @@
|
||||||
#include <boost/locale/message.hpp>
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
#include <glob.h>
|
#include <glob.h>
|
||||||
|
#include <libintl.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
#include <sys/signalfd.h>
|
#include <sys/signalfd.h>
|
||||||
|
@ -33,8 +33,6 @@
|
||||||
|
|
||||||
#include <INIReader.h>
|
#include <INIReader.h>
|
||||||
|
|
||||||
#include <boost/locale.hpp>
|
|
||||||
|
|
||||||
#include <security/pam_appl.h>
|
#include <security/pam_appl.h>
|
||||||
#include <security/pam_ext.h>
|
#include <security/pam_ext.h>
|
||||||
#include <security/pam_modules.h>
|
#include <security/pam_modules.h>
|
||||||
|
@ -42,10 +40,16 @@
|
||||||
#include "main.hh"
|
#include "main.hh"
|
||||||
#include "optional_task.hh"
|
#include "optional_task.hh"
|
||||||
|
|
||||||
|
// Should be defined by the build system
|
||||||
|
#ifndef GETTEXT_PACKAGE
|
||||||
|
#define GETTEXT_PACKAGE "pam_howdy"
|
||||||
|
#define LOCALEDIR "/usr/local/share/locales"
|
||||||
|
#endif
|
||||||
|
|
||||||
const auto DEFAULT_TIMEOUT =
|
const auto DEFAULT_TIMEOUT =
|
||||||
std::chrono::duration<int, std::chrono::milliseconds::period>(2500);
|
std::chrono::duration<int, std::chrono::milliseconds::period>(2500);
|
||||||
|
|
||||||
#define S(msg) boost::locale::dgettext("pam", msg)
|
#define S(msg) gettext (msg)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inspect the status code returned by the compare process
|
* Inspect the status code returned by the compare process
|
||||||
|
@ -64,7 +68,7 @@ auto howdy_error(int status,
|
||||||
switch (status) {
|
switch (status) {
|
||||||
// Status 10 means we couldn't find any face models
|
// Status 10 means we couldn't find any face models
|
||||||
case 10:
|
case 10:
|
||||||
conv_function(PAM_ERROR_MSG, S("There is no face model known").c_str());
|
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
|
// Status 11 means we exceded the maximum retry count
|
||||||
|
@ -77,14 +81,13 @@ auto howdy_error(int status,
|
||||||
break;
|
break;
|
||||||
// Status 13 means the image was too dark
|
// Status 13 means the image was too dark
|
||||||
case 13:
|
case 13:
|
||||||
conv_function(PAM_ERROR_MSG, S("Face detection image too dark").c_str());
|
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
|
// Otherwise, we can't describe what happened but it wasn't successful
|
||||||
default:
|
default:
|
||||||
conv_function(
|
conv_function(PAM_ERROR_MSG,
|
||||||
PAM_ERROR_MSG,
|
std::string(S("Unknown error: ") + status).c_str());
|
||||||
S("Unknown error: ").append(std::to_string(status)).c_str());
|
|
||||||
syslog(LOG_ERR, "Failure, unknown error %d", status);
|
syslog(LOG_ERR, "Failure, unknown error %d", status);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -178,7 +181,7 @@ auto identify(pam_handle_t *pamh, int flags, int argc, const char **argv,
|
||||||
return conv->conv(1, &msgp, &resp, conv->appdata_ptr);
|
return conv->conv(1, &msgp, &resp, conv->appdata_ptr);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Error out if we could not ready the config file
|
// Error out if we could not read the config file
|
||||||
if (reader.ParseError() < 0) {
|
if (reader.ParseError() < 0) {
|
||||||
syslog(LOG_ERR, "Failed to parse the configuration file");
|
syslog(LOG_ERR, "Failed to parse the configuration file");
|
||||||
return PAM_SYSTEM_ERR;
|
return PAM_SYSTEM_ERR;
|
||||||
|
@ -231,10 +234,14 @@ auto identify(pam_handle_t *pamh, int flags, int argc, const char **argv,
|
||||||
globfree(&glob_result);
|
globfree(&glob_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initialize gettext
|
||||||
|
setlocale(LC_ALL, "");
|
||||||
|
bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR);
|
||||||
|
textdomain(GETTEXT_PACKAGE);
|
||||||
|
|
||||||
// If enabled, send a notice to the user that facial login is being attempted
|
// If enabled, send a notice to the user that facial login is being attempted
|
||||||
if (reader.GetBoolean("core", "detection_notice", false)) {
|
if (reader.GetBoolean("core", "detection_notice", false)) {
|
||||||
if ((conv_function(PAM_TEXT_INFO,
|
if ((conv_function(PAM_TEXT_INFO, S("Attempting facial authentication"))) !=
|
||||||
S("Attempting facial authentication").c_str())) !=
|
|
||||||
PAM_SUCCESS) {
|
PAM_SUCCESS) {
|
||||||
syslog(LOG_ERR, "Failed to send detection notice");
|
syslog(LOG_ERR, "Failed to send detection notice");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
project('pam_howdy', 'cpp', version: '0.1.0', default_options: ['cpp_std=c++14'])
|
project('pam_howdy', 'cpp', version: '0.1.0', default_options: ['cpp_std=c++14'])
|
||||||
|
|
||||||
boost = dependency('boost', modules: ['locale'])
|
|
||||||
inih_cpp = dependency('INIReader', fallback: ['inih', 'INIReader_dep'])
|
inih_cpp = dependency('INIReader', fallback: ['inih', 'INIReader_dep'])
|
||||||
libpam = meson.get_compiler('cpp').find_library('pam')
|
libpam = meson.get_compiler('cpp').find_library('pam')
|
||||||
threads = dependency('threads')
|
threads = dependency('threads')
|
||||||
|
@ -12,7 +11,6 @@ shared_library(
|
||||||
'pam_howdy',
|
'pam_howdy',
|
||||||
'main.cc',
|
'main.cc',
|
||||||
dependencies: [
|
dependencies: [
|
||||||
boost,
|
|
||||||
libpam,
|
libpam,
|
||||||
inih_cpp,
|
inih_cpp,
|
||||||
threads
|
threads
|
||||||
|
|
Loading…
Reference in a new issue