From e8e1624ea162cdff0c81ac828ea8a691342c8010 Mon Sep 17 00:00:00 2001 From: MusiKid Date: Fri, 21 Jan 2022 12:18:25 +0100 Subject: [PATCH] refactor: build workaround from string --- src/pam/main.cc | 9 +++++---- src/pam/main.hh | 27 ++++++--------------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/src/pam/main.cc b/src/pam/main.cc index 0008eac..7bdd718 100644 --- a/src/pam/main.cc +++ b/src/pam/main.cc @@ -79,9 +79,9 @@ int howdy_error(int status, function conv_function) { break; // Otherwise, we can't describe what happened but it wasn't successful default: - conv_function(PAM_ERROR_MSG, string(dgettext("pam", "Unknown error:") + - to_string(status)) - .c_str()); + conv_function( + PAM_ERROR_MSG, + string(dgettext("pam", "Unknown error: ") + status).c_str()); syslog(LOG_INFO, "Failure, unknown error %d", status); } } @@ -153,7 +153,8 @@ int identify(pam_handle_t *pamh, int flags, int argc, const char **argv, // Open the system log so we can write to it openlog("pam_howdy", 0, LOG_AUTHPRIV); - string workaround = reader.GetString("core", "workaround", "input"); + Workaround workaround = + get_workaround(reader.GetString("core", "workaround", "input")); // In this case, we are not asking for the password if (workaround == Workaround::Off && auth_tok) { diff --git a/src/pam/main.hh b/src/pam/main.hh index cecadd5..df05f9a 100644 --- a/src/pam/main.hh +++ b/src/pam/main.hh @@ -8,29 +8,14 @@ enum class Type { Unset, Howdy, Pam }; enum class Workaround { Off, Input, Native }; -inline bool operator==(const std::string &l, const Workaround &r) { - switch (r) { - case Workaround::Off: - return (l == "off"); - case Workaround::Input: - return (l == "input"); - case Workaround::Native: - return (l == "native"); - default: - return false; - } -} +inline Workaround get_workaround(std::string workaround) { + if (workaround == "input") + return Workaround::Input; -inline bool operator==(const Workaround &l, const std::string &r) { - return operator==(r, l); -} + if (workaround == "native") + return Workaround::Native; -inline bool operator!=(const std::string &l, const Workaround &r) { - return !operator==(l, r); -} - -inline bool operator!=(const Workaround &l, const std::string &r) { - return operator!=(r, l); + return Workaround::Off; } #endif // MAIN_H_