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))
38 void cmd_oper::Handle (const char** parameters, int pcnt, userrec *user)
40 char LoginName[MAXBUF];
41 char Password[MAXBUF];
42 char OperType[MAXBUF];
43 char TypeName[MAXBUF];
44 char HostName[MAXBUF];
51 snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
52 snprintf(TheIP, MAXBUF,"%s@%s",user->ident,user->GetIPString());
54 for (int i = 0; i < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "oper"); i++)
56 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "name", i, LoginName, MAXBUF);
57 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "password", i, Password, MAXBUF);
58 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "type", i, OperType, MAXBUF);
59 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "oper", "host", i, HostName, MAXBUF);
61 if ((!strcmp(LoginName,parameters[0])) && (!ServerInstance->OperPassCompare(Password,parameters[1])) && (OneOfMatches(TheHost,TheIP,HostName)))
64 for (j =0; j < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "type"); j++)
66 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "type","name", j, TypeName, MAXBUF);
68 if (!strcmp(TypeName,OperType))
70 /* found this oper's opertype */
71 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "type","host", j, HostName, MAXBUF);
73 user->ChangeDisplayedHost(HostName);
74 if (!ServerInstance->IsNick(TypeName))
76 user->WriteServ("491 %s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick);
77 ServerInstance->SNO->WriteToSnoMask('o',"CONFIGURATION ERROR! Oper type invalid for OperType '%s'",OperType);
78 ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type erroneous.",user->nick,user->ident,user->host);
92 /* correct oper credentials */
93 ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
94 user->WriteServ("381 %s :You are now an IRC operator of type %s",user->nick,OperType);
95 if (!user->modes[UM_OPERATOR])
102 user->WriteServ("491 %s :Invalid oper credentials",user->nick);
103 ServerInstance->SNO->WriteToSnoMask('o',"WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
104 ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.",user->nick,user->ident,user->host);
108 user->WriteServ("491 %s :Your oper block does not have a valid opertype associated with it",user->nick);
109 ServerInstance->SNO->WriteToSnoMask('o',"CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType);
110 ServerInstance->Log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host);