]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/commands/cmd_oper.cpp
Replace hardcoded mode letters, part 3
[user/henk/code/inspircd.git] / src / commands / 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. These command handlers can be reloaded by the core,
25  * and handle basic RFC1459 commands. Commands within modules work
26  * the same way, however, they can be fully unloaded, where these
27  * may not.
28  */
29 class CommandOper : public SplitCommand
30 {
31  public:
32         /** Constructor for oper.
33          */
34         CommandOper ( Module* parent) : SplitCommand(parent,"OPER",2,2) { syntax = "<username> <password>"; }
35         /** Handle command.
36          * @param parameters The parameters to the comamnd
37          * @param pcnt The number of parameters passed to teh command
38          * @param user The user issuing the command
39          * @return A value from CmdResult to indicate command success or failure.
40          */
41         CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user);
42 };
43
44 CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
45 {
46         bool match_login = false;
47         bool match_pass = false;
48         bool match_hosts = false;
49
50         const std::string userHost = user->ident + "@" + user->host;
51         const std::string userIP = user->ident + "@" + user->GetIPString();
52
53         OperIndex::iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
54         if (i != ServerInstance->Config->oper_blocks.end())
55         {
56                 OperInfo* ifo = i->second;
57                 ConfigTag* tag = ifo->oper_block;
58                 match_login = true;
59                 match_pass = !ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
60                 match_hosts = InspIRCd::MatchMask(tag->getString("host"), userHost, userIP);
61
62                 if (match_pass && match_hosts)
63                 {
64                         /* found this oper's opertype */
65                         user->Oper(ifo);
66                         return CMD_SUCCESS;
67                 }
68         }
69
70         std::string fields;
71         if (!match_login)
72                 fields.append("login ");
73         if (!match_pass)
74                 fields.append("password ");
75         if (!match_hosts)
76                 fields.append("hosts");
77
78         // tell them they suck, and lag them up to help prevent brute-force attacks
79         user->WriteNumeric(491, "%s :Invalid oper credentials",user->nick.c_str());
80         user->CommandFloodPenalty += 10000;
81
82         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());
83         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());
84         return CMD_FAILURE;
85 }
86
87 COMMAND_INIT(CommandOper)