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 whowas_hash whowas;
61 extern std::vector<userrec*> all_opers;
62 extern std::vector<userrec*> local_users;
63 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
65 void cmd_oper::Handle (char **parameters, int pcnt, userrec *user)
67 char LoginName[MAXBUF];
68 char Password[MAXBUF];
69 char OperType[MAXBUF];
70 char TypeName[MAXBUF];
71 char HostName[MAXBUF];
77 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
79 for (int i = 0; i < Config->ConfValueEnum("oper",&Config->config_f); i++)
81 Config->ConfValue("oper","name",i,LoginName,&Config->config_f);
82 Config->ConfValue("oper","password",i,Password,&Config->config_f);
83 Config->ConfValue("oper","type",i,OperType,&Config->config_f);
84 Config->ConfValue("oper","host",i,HostName,&Config->config_f);
85 if ((!strcmp(LoginName,parameters[0])) && (!operstrcmp(Password,parameters[1])) && (match(TheHost,HostName)))
88 for (j =0; j < Config->ConfValueEnum("type",&Config->config_f); j++)
90 Config->ConfValue("type","name",j,TypeName,&Config->config_f);
92 if (!strcmp(TypeName,OperType))
94 /* found this oper's opertype */
95 Config->ConfValue("type","host",j,HostName,&Config->config_f);
97 ChangeDisplayedHost(user,HostName);
98 strlcpy(user->oper,TypeName,NICKMAX);
110 /* correct oper credentials */
111 WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
112 WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType);
113 if (!strchr(user->modes,'o'))
115 strcat(user->modes,"o");
116 WriteServ(user->fd,"MODE %s :+o",user->nick);
117 FOREACH_MOD(I_OnOper,OnOper(user,OperType));
118 log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,OperType);
126 WriteServ(user->fd,"491 %s :Invalid oper credentials",user->nick);
127 WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
128 log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.",user->nick,user->ident,user->host);
132 WriteServ(user->fd,"491 %s :Your oper block does not have a valid opertype associated with it",user->nick);
133 WriteOpers("*** CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType);
134 log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host);