diff options
-rw-r--r-- | include/command_parse.h | 2 | ||||
-rw-r--r-- | src/command_parse.cpp | 9 | ||||
-rw-r--r-- | src/modules/extra/m_sqloper.cpp | 37 |
3 files changed, 41 insertions, 7 deletions
diff --git a/include/command_parse.h b/include/command_parse.h index 682489ad5..d7c0c4ac1 100644 --- a/include/command_parse.h +++ b/include/command_parse.h @@ -108,6 +108,8 @@ class CommandParser : public classbase */ CmdResult CallHandler(const std::string &commandname,const char** parameters, int pcnt, userrec *user); + command_t* GetHandler(const std::string &commandname); + /** This function returns true if a command is valid with the given number of parameters and user. * @param commandname The command name to check * @param pcnt The parameter count diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 50ed7439b..e413bc4ac 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -281,6 +281,15 @@ bool CommandParser::IsValidCommand(const std::string &commandname, int pcnt, use return false; } +command_t* CommandParser::GetHandler(const std::string &commandname) +{ + nspace::hash_map<std::string,command_t*>::iterator n = cmdlist.find(commandname); + if (n != cmdlist.end()) + return n->second; + + return NULL; +} + // calls a handler function for a command CmdResult CommandParser::CallHandler(const std::string &commandname,const char** parameters, int pcnt, userrec *user) diff --git a/src/modules/extra/m_sqloper.cpp b/src/modules/extra/m_sqloper.cpp index 0771ab30a..8def1e8d3 100644 --- a/src/modules/extra/m_sqloper.cpp +++ b/src/modules/extra/m_sqloper.cpp @@ -69,7 +69,19 @@ public: { if ((result == CMD_FAILURE) && (command == "OPER")) { +<<<<<<< .mine + if (LookupOper(user, parameters[0], parameters[1])) + { + /* Returning true here just means the query is in progress, or on it's way to being + * in progress. Nothing about the /oper actually being successful.. + * If the oper lookup fails later, we pass the command to the original handler + * for /oper by calling its Handle method directly. + */ + return 1; + } +======= LookupOper(user, parameters[0], parameters[1]); +>>>>>>> .r5635 } } @@ -165,9 +177,7 @@ public: * "insufficient awesomeness" (invalid credentials) error */ - user->WriteServ( "491 %s :Invalid oper credentials", user->nick); - Srv->SNO->WriteToSnoMask('o',"WARNING! Failed oper attempt by %s!%s@%s!", user->nick, user->ident, user->host); - ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.", user->nick, user->ident, user->host); + LoginFail(user, row["username"].d, row["password"].d); } } else @@ -178,9 +188,7 @@ public: */ ServerInstance->Log(DEBUG, "Query failed: %s", res->error.Str()); - user->WriteServ( "491 %s :Invalid oper credentials", user->nick); - Srv->SNO->WriteToSnoMask('o',"WARNING! Failed oper attempt by %s!%s@%s! (SQL query failed: %s)", user->nick, user->ident, user->host, res->error.Str()); - ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.", user->nick, user->ident, user->host); + LoginFail(user, row["username"].d, row["password"].d); } } else @@ -194,7 +202,22 @@ public: ServerInstance->Log(DEBUG, "Got unsupported API version string: %s", request->GetId()); return NULL; - } + } + + void LoginFail(userrec* user, const std::string &user, const std::string &pass) + { + command_t* oper_command = ServerInstance->Parser->GetCommand("OPER"); + + if (oper_command) + { + const char* params = { user.c_str(), pass.c_str() }; + oper_command->Handle(params, 2, user); + } + else + { + ServerInstance->Log(DEBUG, "WHAT?! Why do we have no OPER command?!"); + } + } bool OperUser(userrec* user, const std::string &username, const std::string &password, const std::string &pattern, const std::string &type) { |