1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
20 #include "inspircd_config.h"
21 #include "configreader.h"
32 #include "inspstring.h"
33 #include "helperfuncs.h"
35 #include "socketengine.h"
37 #include "command_parse.h"
38 #include "commands/cmd_oper.h"
40 extern ServerConfig* Config;
42 extern ModuleList modules;
43 extern FactoryList factory;
46 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
48 std::stringstream hl(hostlist);
52 log(DEBUG,"Oper: Matching host %s",xhost.c_str());
53 if (match(host,xhost.c_str()) || match(ip,xhost.c_str(),true))
61 void cmd_oper::Handle (const char** parameters, int pcnt, userrec *user)
63 char LoginName[MAXBUF];
64 char Password[MAXBUF];
65 char OperType[MAXBUF];
66 char TypeName[MAXBUF];
67 char HostName[MAXBUF];
73 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
75 for (int i = 0; i < Config->ConfValueEnum(Config->config_data, "oper"); i++)
77 Config->ConfValue(Config->config_data, "oper", "name", i, LoginName, MAXBUF);
78 Config->ConfValue(Config->config_data, "oper", "password", i, Password, MAXBUF);
79 Config->ConfValue(Config->config_data, "oper", "type", i, OperType, MAXBUF);
80 Config->ConfValue(Config->config_data, "oper", "host", i, HostName, MAXBUF);
82 if ((!strcmp(LoginName,parameters[0])) && (!operstrcmp(Password,parameters[1])) && (OneOfMatches(TheHost,user->GetIPString(),HostName)))
85 for (j =0; j < Config->ConfValueEnum(Config->config_data, "type"); j++)
87 Config->ConfValue(Config->config_data, "type","name", j, TypeName, MAXBUF);
89 if (!strcmp(TypeName,OperType))
91 /* found this oper's opertype */
92 Config->ConfValue(Config->config_data, "type","host", j, HostName, MAXBUF);
94 ChangeDisplayedHost(user,HostName);
95 if (!isnick(TypeName))
97 WriteServ(user->fd,"491 %s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick);
98 WriteOpers("*** CONFIGURATION ERROR! Oper type invalid for OperType '%s'",OperType);
99 log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type erroneous.",user->nick,user->ident,user->host);
102 strlcpy(user->oper,TypeName,NICKMAX-1);
114 /* correct oper credentials */
115 WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
116 WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType);
117 if (!user->modes[UM_OPERATOR])
119 user->modes[UM_OPERATOR] = 1;
120 WriteServ(user->fd,"MODE %s :+o",user->nick);
121 FOREACH_MOD(I_OnOper,OnOper(user,OperType));
122 log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,OperType);
124 FOREACH_MOD(I_OnPostOper,OnPostOper(user,OperType));
131 WriteServ(user->fd,"491 %s :Invalid oper credentials",user->nick);
132 WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
133 log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.",user->nick,user->ident,user->host);
137 WriteServ(user->fd,"491 %s :Your oper block does not have a valid opertype associated with it",user->nick);
138 WriteOpers("*** CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType);
139 log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host);