]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_oper.cpp
Fix for parameters which contain a colon (which is not the first char in the string)
[user/henk/code/inspircd.git] / src / cmd_oper.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include "configreader.h"
18 #include "typedefs.h"
19 #include "users.h"
20 #include "modules.h"
21 #include "wildcard.h"
22 #include "commands/cmd_oper.h"
23
24 bool OneOfMatches(const char* host, const char* ip, const char* hostlist)
25 {
26         std::stringstream hl(hostlist);
27         std::string xhost;
28         while (hl >> xhost)
29         {
30                 if (match(host,xhost.c_str()) || match(ip,xhost.c_str(),true))
31                 {
32                         return true;
33                 }
34         }
35         return false;
36 }
37
38 void cmd_oper::Handle (const char** parameters, int pcnt, userrec *user)
39 {
40         char LoginName[MAXBUF];
41         char Password[MAXBUF];
42         char OperType[MAXBUF];
43         char TypeName[MAXBUF];
44         char HostName[MAXBUF];
45         char TheHost[MAXBUF];
46         char TheIP[MAXBUF];
47         int j;
48         bool found = false;
49         bool fail2 = false;
50
51         snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
52         snprintf(TheIP, MAXBUF,"%s@%s",user->ident,user->GetIPString());
53
54         for (int i = 0; i < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "oper"); i++)
55         {
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);
60
61                 if ((!strcmp(LoginName,parameters[0])) && (!ServerInstance->OperPassCompare(Password,parameters[1])) && (OneOfMatches(TheHost,TheIP,HostName)))
62                 {
63                         fail2 = true;
64                         for (j =0; j < ServerInstance->Config->ConfValueEnum(ServerInstance->Config->config_data, "type"); j++)
65                         {
66                                 ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "type","name", j, TypeName, MAXBUF);
67
68                                 if (!strcmp(TypeName,OperType))
69                                 {
70                                         /* found this oper's opertype */
71                                         ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "type","host", j, HostName, MAXBUF);
72                                         if (*HostName)
73                                                 user->ChangeDisplayedHost(HostName);
74                                         if (!ServerInstance->IsNick(TypeName))
75                                         {
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);
79                                                 return;
80                                         }
81                                         found = true;
82                                         fail2 = false;
83                                         break;
84                                 }
85                         }
86                 }
87                 if (found)
88                         break;
89         }
90         if (found)
91         {
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])
96                         user->Oper(OperType);
97         }
98         else
99         {
100                 if (!fail2)
101                 {
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);
105                 }
106                 else
107                 {
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);
111                 }
112         }
113         return;
114 }
115