2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2020 Matt Schatz <genius3000@g3k.solutions>
5 * Copyright (C) 2013-2014, 2017-2018 Sadie Powell <sadie@witchery.services>
6 * Copyright (C) 2012, 2014, 2016 Attila Molnar <attilamolnar@hush.com>
7 * Copyright (C) 2012 Robby <robby@chatbelgie.be>
8 * Copyright (C) 2009 Uli Schlachter <psychon@inspircd.org>
9 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
10 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
11 * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
12 * Copyright (C) 2006, 2008, 2010 Craig Edwards <brain@inspircd.org>
14 * This file is part of InspIRCd. InspIRCd is free software: you can
15 * redistribute it and/or modify it under the terms of the GNU General Public
16 * License as published by the Free Software Foundation, version 2.
18 * This program is distributed in the hope that it will be useful, but WITHOUT
19 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #include "core_oper.h"
31 CommandOper::CommandOper(Module* parent)
32 : SplitCommand(parent, "OPER", 2, 2)
34 syntax = "<username> <password>";
37 CmdResult CommandOper::HandleLocal(LocalUser* user, const Params& parameters)
39 bool match_login = false;
40 bool match_pass = false;
41 bool match_hosts = false;
43 const std::string userHost = user->ident + "@" + user->GetRealHost();
44 const std::string userIP = user->ident + "@" + user->GetIPString();
46 ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
47 if (i != ServerInstance->Config->oper_blocks.end())
49 OperInfo* ifo = i->second;
50 ConfigTag* tag = ifo->oper_block;
52 match_pass = ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
53 match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP);
55 if (match_pass && match_hosts)
64 fields.append("login ");
66 fields.append("password ");
68 fields.append("hosts ");
69 fields.erase(fields.length() - 1, 1);
71 // Tell them they failed (generically) 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());