]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/coremods/core_oper/cmd_oper.cpp
bd7a35060e8e82a7c10543c322d08cc9bc825ef2
[user/henk/code/inspircd.git] / src / coremods / core_oper / cmd_oper.cpp
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
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>
7  *
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.
11  *
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
15  * details.
16  *
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/>.
19  */
20
21
22 #include "inspircd.h"
23
24 /** Handle /OPER.
25  */
26 class CommandOper : public SplitCommand
27 {
28  public:
29         /** Constructor for oper.
30          */
31         CommandOper ( Module* parent) : SplitCommand(parent,"OPER",2,2) { syntax = "<username> <password>"; }
32         /** Handle command.
33          * @param parameters The parameters to the command
34          * @param user The user issuing the command
35          * @return A value from CmdResult to indicate command success or failure.
36          */
37         CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user);
38 };
39
40 CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
41 {
42         bool match_login = false;
43         bool match_pass = false;
44         bool match_hosts = false;
45
46         const std::string userHost = user->ident + "@" + user->host;
47         const std::string userIP = user->ident + "@" + user->GetIPString();
48
49         OperIndex::iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
50         if (i != ServerInstance->Config->oper_blocks.end())
51         {
52                 OperInfo* ifo = i->second;
53                 ConfigTag* tag = ifo->oper_block;
54                 match_login = true;
55                 match_pass = ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
56                 match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP);
57
58                 if (match_pass && match_hosts)
59                 {
60                         /* found this oper's opertype */
61                         user->Oper(ifo);
62                         return CMD_SUCCESS;
63                 }
64         }
65
66         std::string fields;
67         if (!match_login)
68                 fields.append("login ");
69         if (!match_pass)
70                 fields.append("password ");
71         if (!match_hosts)
72                 fields.append("hosts");
73
74         // tell them they suck, and lag them up to help prevent brute-force attacks
75         user->WriteNumeric(ERR_NOOPERHOST, ":Invalid oper credentials");
76         user->CommandFloodPenalty += 10000;
77
78         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());
79         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());
80         return CMD_FAILURE;
81 }
82
83 COMMAND_INIT(CommandOper)