From cd11aba4e6f3f32178c406350b163b8b336fd728 Mon Sep 17 00:00:00 2001 From: MusiKid Date: Sun, 23 Jan 2022 14:25:32 +0100 Subject: [PATCH] refactor: replace boost locale by gnu gettext --- src/pam/main.cc | 31 +++++++++++++++++++------------ src/pam/meson.build | 2 -- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/pam/main.cc b/src/pam/main.cc index d002e77..15ce574 100644 --- a/src/pam/main.cc +++ b/src/pam/main.cc @@ -1,10 +1,10 @@ -#include #include #include #include #include #include +#include #include #include #include @@ -33,8 +33,6 @@ #include -#include - #include #include #include @@ -42,10 +40,16 @@ #include "main.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 = std::chrono::duration(2500); -#define S(msg) boost::locale::dgettext("pam", msg) +#define S(msg) gettext (msg) /** * Inspect the status code returned by the compare process @@ -64,7 +68,7 @@ auto howdy_error(int status, switch (status) { // Status 10 means we couldn't find any face models 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"); break; // Status 11 means we exceded the maximum retry count @@ -77,14 +81,13 @@ auto howdy_error(int status, break; // Status 13 means the image was too dark 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"); break; // Otherwise, we can't describe what happened but it wasn't successful default: - conv_function( - PAM_ERROR_MSG, - S("Unknown error: ").append(std::to_string(status)).c_str()); + conv_function(PAM_ERROR_MSG, + std::string(S("Unknown error: ") + status).c_str()); syslog(LOG_ERR, "Failure, unknown error %d", status); } } 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); }; - // Error out if we could not ready the config file + // Error out if we could not read the config file if (reader.ParseError() < 0) { syslog(LOG_ERR, "Failed to parse the configuration file"); return PAM_SYSTEM_ERR; @@ -231,10 +234,14 @@ auto identify(pam_handle_t *pamh, int flags, int argc, const char **argv, 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 (reader.GetBoolean("core", "detection_notice", false)) { - if ((conv_function(PAM_TEXT_INFO, - S("Attempting facial authentication").c_str())) != + if ((conv_function(PAM_TEXT_INFO, S("Attempting facial authentication"))) != PAM_SUCCESS) { syslog(LOG_ERR, "Failed to send detection notice"); } diff --git a/src/pam/meson.build b/src/pam/meson.build index 465e543..f6660a9 100644 --- a/src/pam/meson.build +++ b/src/pam/meson.build @@ -1,6 +1,5 @@ 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']) libpam = meson.get_compiler('cpp').find_library('pam') threads = dependency('threads') @@ -12,7 +11,6 @@ shared_library( 'pam_howdy', 'main.cc', dependencies: [ - boost, libpam, inih_cpp, threads