2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2013-2014, 2017-2018 Sadie Powell <sadie@witchery.services>
5 * Copyright (C) 2012, 2014, 2016 Attila Molnar <attilamolnar@hush.com>
6 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
7 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
8 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
9 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
10 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
11 * Copyright (C) 2006, 2008, 2010 Craig Edwards <brain@inspircd.org>
13 * This file is part of InspIRCd. InspIRCd is free software: you can
14 * redistribute it and/or modify it under the terms of the GNU General Public
15 * License as published by the Free Software Foundation, version 2.
17 * This program is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "core_oper.h"
30 CommandOper::CommandOper(Module* parent)
31 : SplitCommand(parent, "OPER", 2, 2)
33 syntax = "<username> <password>";
36 CmdResult CommandOper::HandleLocal(LocalUser* user, const Params& parameters)
38 bool match_login = false;
39 bool match_pass = false;
40 bool match_hosts = false;
42 const std::string userHost = user->ident + "@" + user->GetRealHost();
43 const std::string userIP = user->ident + "@" + user->GetIPString();
45 ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
46 if (i != ServerInstance->Config->oper_blocks.end())
48 OperInfo* ifo = i->second;
49 ConfigTag* tag = ifo->oper_block;
51 match_pass = ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
52 match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP);
54 if (match_pass && match_hosts)
56 /* found this oper's opertype */
64 fields.append("login ");
66 fields.append("password ");
68 fields.append("hosts ");
69 fields.erase(fields.length() - 1, 1);
71 // tell them they suck, and lag them up to help prevent brute-force attacks
72 user->WriteNumeric(ERR_NOOPERHOST, "Invalid oper credentials");
73 user->CommandFloodPenalty += 10000;
75 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());