]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_oper/cmd_oper.cpp
391c7f41f24d21fb4e70937f0e793a12245c1465
[user/henk/code/inspircd.git] / src / coremods / core_oper / cmd_oper.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
12  *
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.
16  *
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
20  * details.
21  *
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/>.
24  */
25
26
27 #include "inspircd.h"
28 #include "core_oper.h"
29
30 CommandOper::CommandOper(Module* parent)
31         : SplitCommand(parent, "OPER", 2, 2)
32 {
33         syntax = "<username> <password>";
34 }
35
36 CmdResult CommandOper::HandleLocal(LocalUser* user, const Params& parameters)
37 {
38         bool match_login = false;
39         bool match_pass = false;
40         bool match_hosts = false;
41
42         const std::string userHost = user->ident + "@" + user->GetRealHost();
43         const std::string userIP = user->ident + "@" + user->GetIPString();
44
45         ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
46         if (i != ServerInstance->Config->oper_blocks.end())
47         {
48                 OperInfo* ifo = i->second;
49                 ConfigTag* tag = ifo->oper_block;
50                 match_login = true;
51                 match_pass = ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
52                 match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP);
53
54                 if (match_pass && match_hosts)
55                 {
56                         /* found this oper's opertype */
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 suck, 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 }