From 074727e7a74f8dcef6c250faf6a757f0274d27db Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sat, 18 Jan 2014 04:53:52 +0000 Subject: Convert InspIRCd::PassCompare to return bool instead of int. The insane behaviour of this method was due to an implementation detail which has since become irrelevent. --- include/inspircd.h | 4 ++-- src/command_parse.cpp | 11 +++++------ src/commands/cmd_die.cpp | 2 +- src/commands/cmd_oper.cpp | 2 +- src/commands/cmd_restart.cpp | 2 +- src/modules/m_customtitle.cpp | 2 +- src/modules/m_vhost.cpp | 2 +- src/users.cpp | 2 +- 8 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/inspircd.h b/include/inspircd.h index 897ae9e18..6f9163ad8 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -610,9 +610,9 @@ class CoreExport InspIRCd * @param data The data from the config file * @param input The data input by the oper * @param hashtype The hash from the config file - * @return 0 if the strings match, 1 or -1 if they do not + * @return True if the strings match, false if they do not */ - int PassCompare(Extensible* ex, const std::string &data, const std::string &input, const std::string &hashtype); + bool PassCompare(Extensible* ex, const std::string& data, const std::string& input, const std::string& hashtype); /** Returns the full version string of this ircd * @return The version string diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 20977995b..66b8dcd67 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -23,25 +23,24 @@ #include "inspircd.h" -int InspIRCd::PassCompare(Extensible* ex, const std::string &data, const std::string &input, const std::string &hashtype) +bool InspIRCd::PassCompare(Extensible* ex, const std::string& data, const std::string& input, const std::string& hashtype) { ModResult res; FIRST_MOD_RESULT(OnPassCompare, res, (ex, data, input, hashtype)); /* Module matched */ if (res == MOD_RES_ALLOW) - return 0; + return true; /* Module explicitly didnt match */ if (res == MOD_RES_DENY) - return 1; + return false; /* We dont handle any hash types except for plaintext - Thanks tra26 */ if (!hashtype.empty() && hashtype != "plaintext") - /* See below. 1 because they dont match */ - return 1; + return false; - return (data != input); // this seems back to front, but returns 0 if they *match*, 1 else + return (data == input); } bool CommandParser::LoopCall(User* user, Command* handler, const std::vector& parameters, unsigned int splithere, int extra, bool usemax) diff --git a/src/commands/cmd_die.cpp b/src/commands/cmd_die.cpp index 3ccc037b4..105f40d46 100644 --- a/src/commands/cmd_die.cpp +++ b/src/commands/cmd_die.cpp @@ -46,7 +46,7 @@ class CommandDie : public Command */ CmdResult CommandDie::Handle (const std::vector& parameters, User *user) { - if (!ServerInstance->PassCompare(user, ServerInstance->Config->diepass, parameters[0].c_str(), ServerInstance->Config->powerhash)) + if (ServerInstance->PassCompare(user, ServerInstance->Config->diepass, parameters[0].c_str(), ServerInstance->Config->powerhash)) { { std::string diebuf = "*** DIE command from " + user->GetFullHost() + ". Terminating."; diff --git a/src/commands/cmd_oper.cpp b/src/commands/cmd_oper.cpp index 5094fae22..a70c93dd1 100644 --- a/src/commands/cmd_oper.cpp +++ b/src/commands/cmd_oper.cpp @@ -56,7 +56,7 @@ CmdResult CommandOper::HandleLocal(const std::vector& parameters, L OperInfo* ifo = i->second; ConfigTag* tag = ifo->oper_block; match_login = true; - match_pass = !ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash")); + match_pass = ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash")); match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP); if (match_pass && match_hosts) diff --git a/src/commands/cmd_restart.cpp b/src/commands/cmd_restart.cpp index 6711ada7d..be711e069 100644 --- a/src/commands/cmd_restart.cpp +++ b/src/commands/cmd_restart.cpp @@ -40,7 +40,7 @@ class CommandRestart : public Command CmdResult CommandRestart::Handle (const std::vector& parameters, User *user) { ServerInstance->Logs->Log("COMMAND", LOG_DEFAULT, "Restart: %s",user->nick.c_str()); - if (!ServerInstance->PassCompare(user, ServerInstance->Config->restartpass, parameters[0].c_str(), ServerInstance->Config->powerhash)) + if (ServerInstance->PassCompare(user, ServerInstance->Config->restartpass, parameters[0].c_str(), ServerInstance->Config->powerhash)) { ServerInstance->SNO->WriteGlobalSno('a', "RESTART command from %s, restarting server.", user->GetFullRealHost().c_str()); diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp index 015353086..b0c9fad21 100644 --- a/src/modules/m_customtitle.cpp +++ b/src/modules/m_customtitle.cpp @@ -48,7 +48,7 @@ class CommandTitle : public Command std::string title = i->second->getString("title"); std::string vhost = i->second->getString("vhost"); - if (Name == parameters[0] && !ServerInstance->PassCompare(user, pass, parameters[1], hash) && + if (Name == parameters[0] && ServerInstance->PassCompare(user, pass, parameters[1], hash) && InspIRCd::MatchMask(host, userHost, userIP) && !title.empty()) { ctitle.set(user, title); diff --git a/src/modules/m_vhost.cpp b/src/modules/m_vhost.cpp index 2e25849ae..227d9426e 100644 --- a/src/modules/m_vhost.cpp +++ b/src/modules/m_vhost.cpp @@ -43,7 +43,7 @@ class CommandVhost : public Command std::string pass = tag->getString("pass"); std::string hash = tag->getString("hash"); - if (parameters[0] == username && !ServerInstance->PassCompare(user, pass, parameters[1], hash)) + if (parameters[0] == username && ServerInstance->PassCompare(user, pass, parameters[1], hash)) { if (!mask.empty()) { diff --git a/src/users.cpp b/src/users.cpp index 2458e1565..4968c7a37 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -1239,7 +1239,7 @@ void LocalUser::SetClass(const std::string &explicit_name) if (regdone && !c->config->getString("password").empty()) { - if (ServerInstance->PassCompare(this, c->config->getString("password"), password, c->config->getString("hash"))) + if (!ServerInstance->PassCompare(this, c->config->getString("password"), password, c->config->getString("hash"))) { ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "Bad password, skipping"); continue; -- cgit v1.2.3