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 * ---------------------------------------------------
19 #include "inspircd_config.h"
21 #include "inspircd_io.h"
25 #include <ext/hash_map>
43 #include "inspstring.h"
45 #include "helperfuncs.h"
47 #include "socketengine.h"
49 #include "command_parse.h"
52 extern ServerConfig* Config;
53 extern InspIRCd* ServerInstance;
55 extern std::vector<Module*> modules;
56 extern std::vector<ircd_module*> factory;
58 extern user_hash clientlist;
59 extern chan_hash chanlist;
60 extern std::vector<userrec*> all_opers;
61 extern std::vector<userrec*> local_users;
62 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
64 bool OneOfMatches(const char* host, const char* hostlist)
66 std::stringstream hl(hostlist);
70 log(DEBUG,"Oper: Matching host %s",xhost.c_str());
71 if (match(host,xhost.c_str()))
79 void cmd_oper::Handle (char **parameters, int pcnt, userrec *user)
81 char LoginName[MAXBUF];
82 char Password[MAXBUF];
83 char OperType[MAXBUF];
84 char TypeName[MAXBUF];
85 char HostName[MAXBUF];
89 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
91 for (int i = 0; i < Config->ConfValueEnum("oper",&Config->config_f); i++)
93 Config->ConfValue("oper","name",i,LoginName,&Config->config_f);
94 Config->ConfValue("oper","password",i,Password,&Config->config_f);
95 Config->ConfValue("oper","type",i,OperType,&Config->config_f);
96 Config->ConfValue("oper","host",i,HostName,&Config->config_f);
98 if (!strcmp(LoginName, parameters[0]))
100 /* login name matches */
101 if (!operstrcmp(Password, parameters[1]))
103 /* password matches */
104 if (OneOfMatches(TheHost, HostName))
106 for (j =0; j < Config->ConfValueEnum("type",&Config->config_f); j++)
108 Config->ConfValue("type","name",j,TypeName,&Config->config_f);
110 if (!strcmp(TypeName,OperType))
112 /* found this oper's opertype */
113 Config->ConfValue("type","host",j,HostName,&Config->config_f);
115 ChangeDisplayedHost(user,HostName);
116 if (!isnick(TypeName))
118 WriteServ(user->fd,"491 %s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick);
119 WriteOpers("*** CONFIGURATION ERROR! Oper type invalid for OperType '%s'",OperType);
120 log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type erroneous.",user->nick,user->ident,user->host);
124 /* correct oper credentials */
125 WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
126 WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType);
128 if (!strchr(user->modes,'o'))
130 strcat(user->modes,"o");
131 WriteServ(user->fd,"MODE %s :+o",user->nick);
132 FOREACH_MOD(I_OnOper,OnOper(user,OperType));
133 log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,OperType);
135 FOREACH_MOD(I_OnPostOper,OnPostOper(user,OperType));
138 strlcpy(user->oper,TypeName,NICKMAX-1);
143 /* if we get to here, we have NOT found their opertype. */
144 WriteServ(user->fd,"491 %s :Your oper block does not have a valid opertype associated with it",user->nick);
145 WriteOpers("*** CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType);
146 log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host);
151 /* no host matches */
152 WriteServ(user->fd, "491 %s :Invalid Credentials", user->nick);
153 WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s (incorrect hostname)!", user->nick, user->ident, user->host);
154 log(DEFAULT, "OPER: Failed oper attempt by %s!%s@%s: host did not match.", user->nick, user->ident, user->host);
161 WriteServ(user->fd, "491 %s :Invalid Credentials", user->nick);
162 WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s (incorrect password)!", user->nick, user->ident, user->host);
163 log(DEFAULT, "OPER: Failed oper attempt by %s!%s@%s: password did not match.", user->nick, user->ident, user->host);
169 /* if we get here, invalid oper login */
170 WriteServ(user->fd, "491 %s :Invalid Credentials", user->nick);
171 WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s (incorrect oper (%s))!", user->nick, user->ident, user->host, parameters[0]);
172 log(DEFAULT, "OPER: Failed oper attempt by %s!%s@%s: incorrect oper (%s)", user->nick, user->ident, user->host, parameters[0]);