]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_oper/cmd_oper.cpp
Update copyright headers.
[user/henk/code/inspircd.git] / src / coremods / core_oper / cmd_oper.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
13  *
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.
17  *
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
21  * details.
22  *
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/>.
25  */
26
27
28 #include "inspircd.h"
29 #include "core_oper.h"
30
31 CommandOper::CommandOper(Module* parent)
32         : SplitCommand(parent, "OPER", 2, 2)
33 {
34         syntax = "<username> <password>";
35 }
36
37 CmdResult CommandOper::HandleLocal(LocalUser* user, const Params& parameters)
38 {
39         bool match_login = false;
40         bool match_pass = false;
41         bool match_hosts = false;
42
43         const std::string userHost = user->ident + "@" + user->GetRealHost();
44         const std::string userIP = user->ident + "@" + user->GetIPString();
45
46         ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
47         if (i != ServerInstance->Config->oper_blocks.end())
48         {
49                 OperInfo* ifo = i->second;
50                 ConfigTag* tag = ifo->oper_block;
51                 match_login = true;
52                 match_pass = ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
53                 match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP);
54
55                 if (match_pass && match_hosts)
56                 {
57                         user->Oper(ifo);
58                         return CMD_SUCCESS;
59                 }
60         }
61
62         std::string fields;
63         if (!match_login)
64                 fields.append("login ");
65         if (!match_pass)
66                 fields.append("password ");
67         if (!match_hosts)
68                 fields.append("hosts ");
69         fields.erase(fields.length() - 1, 1);
70
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;
74
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());
76         return CMD_FAILURE;
77 }