1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
17 bool OneOfMatches(const char* host, const char* ip, const char* hostlist);
19 /** Handle /OPER. These command handlers can be reloaded by the core,
20 * and handle basic RFC1459 commands. Commands within modules work
21 * the same way, however, they can be fully unloaded, where these
24 class CommandOper : public SplitCommand
27 /** Constructor for oper.
29 CommandOper ( Module* parent) : SplitCommand(parent,"OPER",2,2) { syntax = "<username> <password>"; }
31 * @param parameters The parameters to the comamnd
32 * @param pcnt The number of parameters passed to teh command
33 * @param user The user issuing the command
34 * @return A value from CmdResult to indicate command success or failure.
36 CmdResult HandleLocal(const std::vector<std::string>& parameters, LocalUser *user);
39 bool OneOfMatches(const char* host, const char* ip, const std::string& hostlist)
41 std::stringstream hl(hostlist);
45 if (InspIRCd::Match(host, xhost, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(ip, xhost, ascii_case_insensitive_map))
53 CmdResult CommandOper::HandleLocal(const std::vector<std::string>& parameters, LocalUser *user)
57 bool match_login = false;
58 bool match_pass = false;
59 bool match_hosts = false;
61 snprintf(TheHost,MAXBUF,"%s@%s",user->ident.c_str(),user->host.c_str());
62 snprintf(TheIP, MAXBUF,"%s@%s",user->ident.c_str(),user->GetIPString());
64 OperIndex::iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]);
65 if (i != ServerInstance->Config->oper_blocks.end())
67 OperInfo* ifo = i->second;
68 ConfigTag* tag = ifo->oper_block;
70 match_pass = !ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));
71 match_hosts = OneOfMatches(TheHost,TheIP,tag->getString("host"));
73 if (match_pass && match_hosts)
75 /* found this oper's opertype */
80 char broadcast[MAXBUF];
84 fields.append("login ");
86 fields.append("password ");
88 fields.append("hosts");
90 // tell them they suck, and lag them up to help prevent brute-force attacks
91 user->WriteNumeric(491, "%s :Invalid oper credentials",user->nick.c_str());
92 user->CommandFloodPenalty += 10000;
94 snprintf(broadcast, MAXBUF, "WARNING! Failed oper attempt by %s!%s@%s using login '%s': The following fields do not match: %s", user->nick.c_str(), user->ident.c_str(), user->host.c_str(), parameters[0].c_str(), fields.c_str());
95 ServerInstance->SNO->WriteGlobalSno('o',std::string(broadcast));
97 ServerInstance->Logs->Log("OPER",DEFAULT,"OPER: Failed oper attempt by %s!%s@%s using login '%s': The following fields did not match: %s", user->nick.c_str(), user->ident.c_str(), user->host.c_str(), parameters[0].c_str(), fields.c_str());
101 COMMAND_INIT(CommandOper)