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"
31 #include "inspstring.h"
32 #include "helperfuncs.h"
34 #include "socketengine.h"
36 #include "command_parse.h"
37 #include "commands/cmd_oper.h"
39 extern InspIRCd* ServerInstance;
42 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
44 std::stringstream hl(hostlist);
48 log(DEBUG,"Oper: Matching host %s",xhost.c_str());
49 if (match(host,xhost.c_str()) || match(ip,xhost.c_str(),true))
57 void cmd_oper::Handle (const char** parameters, int pcnt, userrec *user)
59 char LoginName[MAXBUF];
60 char Password[MAXBUF];
61 char OperType[MAXBUF];
62 char TypeName[MAXBUF];
63 char HostName[MAXBUF];
70 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
71 snprintf(TheIP, MAXBUF,"%s@%s",user->ident,user->GetIPString());
73 for (int i = 0; i < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "oper"); i++)
75 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "name", i, LoginName, MAXBUF);
76 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "password", i, Password, MAXBUF);
77 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "type", i, OperType, MAXBUF);
78 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "host", i, HostName, MAXBUF);
80 if ((!strcmp(LoginName,parameters[0])) && (!operstrcmp(Password,parameters[1])) && (OneOfMatches(TheHost,TheIP,HostName)))
83 for (j =0; j < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "type"); j++)
85 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "type","name", j, TypeName, MAXBUF);
87 if (!strcmp(TypeName,OperType))
89 /* found this oper's opertype */
90 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "type","host", j, HostName, MAXBUF);
92 user->ChangeDisplayedHost(HostName);
93 if (!ServerInstance->IsNick(TypeName))
95 user->WriteServ("491 %s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick);
96 ServerInstance->WriteOpers("*** CONFIGURATION ERROR! Oper type invalid for OperType '%s'",OperType);
97 log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type erroneous.",user->nick,user->ident,user->host);
111 /* correct oper credentials */
112 ServerInstance->WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
113 user->WriteServ("381 %s :You are now an IRC operator of type %s",user->nick,OperType);
114 if (!user->modes[UM_OPERATOR])
115 user->Oper(OperType);
121 user->WriteServ("491 %s :Invalid oper credentials",user->nick);
122 ServerInstance->WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
123 log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.",user->nick,user->ident,user->host);
127 user->WriteServ("491 %s :Your oper block does not have a valid opertype associated with it",user->nick);
128 ServerInstance->WriteOpers("*** CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType);
129 log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host);