2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5 * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
6 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
8 * This file is part of InspIRCd. InspIRCd is free software: you can
9 * redistribute it and/or modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation, version 2.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "core_oper.h"
25 CommandOper::CommandOper(Module* parent)
26 : SplitCommand(parent, "OPER", 2, 2)
28 syntax = "<username> <password>";
31 CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
33 bool match_login = false;
34 bool match_pass = false;
35 bool match_hosts = false;
37 const std::string userHost = user->ident + "@" + user->host;
38 const std::string userIP = user->ident + "@" + user->GetIPString();
40 ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
41 if (i != ServerInstance->Config->oper_blocks.end())
43 OperInfo* ifo = i->second;
44 ConfigTag* tag = ifo->oper_block;
46 match_pass = ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
47 match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP);
49 if (match_pass && match_hosts)
51 /* found this oper's opertype */
59 fields.append("login ");
61 fields.append("password ");
63 fields.append("hosts");
65 // tell them they suck, and lag them up to help prevent brute-force attacks
66 user->WriteNumeric(ERR_NOOPERHOST, "Invalid oper credentials");
67 user->CommandFloodPenalty += 10000;
69 ServerInstance->SNO->WriteGlobalSno('o', "WARNING! Failed oper attempt by %s using login '%s': The following fields do not match: %s", user->GetFullRealHost().c_str(), parameters[0].c_str(), fields.c_str());
70 ServerInstance->Logs->Log("OPER", LOG_DEFAULT, "OPER: Failed oper attempt by %s using login '%s': The following fields did not match: %s", user->GetFullRealHost().c_str(), parameters[0].c_str(), fields.c_str());