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 * ---------------------------------------------------
17 #include "configreader.h"
22 #include "commands/cmd_oper.h"
24 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
26 std::stringstream hl(hostlist);
30 if (match(host,xhost.c_str()) || match(ip,xhost.c_str(),true))
40 extern "C" command_t* init_command(InspIRCd* Instance)
42 return new cmd_oper(Instance);
45 CmdResult cmd_oper::Handle (const char** parameters, int pcnt, userrec *user)
47 char LoginName[MAXBUF];
48 char Password[MAXBUF];
49 char OperType[MAXBUF];
50 char TypeName[MAXBUF];
51 char HostName[MAXBUF];
58 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
59 snprintf(TheIP, MAXBUF,"%s@%s",user->ident,user->GetIPString());
61 for (int i = 0; i < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "oper"); i++)
63 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "name", i, LoginName, MAXBUF);
64 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "password", i, Password, MAXBUF);
65 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "type", i, OperType, MAXBUF);
66 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "host", i, HostName, MAXBUF);
68 if ((!strcmp(LoginName,parameters[0])) && (!ServerInstance->OperPassCompare(Password,parameters[1])) && (OneOfMatches(TheHost,TheIP,HostName)))
71 for (j =0; j < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "type"); j++)
73 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "type","name", j, TypeName, MAXBUF);
75 if (!strcmp(TypeName,OperType))
77 /* found this oper's opertype */
78 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "type","host", j, HostName, MAXBUF);
80 user->ChangeDisplayedHost(HostName);
81 if (!ServerInstance->IsNick(TypeName))
83 user->WriteServ("491 %s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick);
84 ServerInstance->SNO->WriteToSnoMask('o',"CONFIGURATION ERROR! Oper type invalid for OperType '%s'",OperType);
85 ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type erroneous.",user->nick,user->ident,user->host);
99 /* correct oper credentials */
100 ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
101 user->WriteServ("381 %s :You are now an IRC operator of type %s",user->nick,OperType);
102 if (!user->modes[UM_OPERATOR])
103 user->Oper(OperType);
109 user->WriteServ("491 %s :Invalid oper credentials",user->nick);
110 ServerInstance->SNO->WriteToSnoMask('o',"WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
111 ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.",user->nick,user->ident,user->host);
116 user->WriteServ("491 %s :Your oper block does not have a valid opertype associated with it",user->nick);
117 ServerInstance->SNO->WriteToSnoMask('o',"CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType);
118 ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host);