mirror of
https://github.com/boltgolt/howdy.git
synced 2024-09-12 09:41:18 +02:00
refactor: build workaround from string
This commit is contained in:
parent
c31acece3e
commit
e8e1624ea1
2 changed files with 11 additions and 25 deletions
|
@ -79,9 +79,9 @@ int howdy_error(int status, function<int(int, const char *)> 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) {
|
||||
|
|
|
@ -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_
|
||||
|
|
Loading…
Reference in a new issue