]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cmd_oper.cpp
Remove references to inspircd_io from these, stop configure making all the modules...
[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 <string>
18 #include <sstream>
19 #include <vector>
20 #include "inspircd_config.h"
21 #include "configreader.h"
22 #include "typedefs.h"
23 #include "users.h"
24 #include "globals.h"
25 #include "modules.h"
26 #include "dynamic.h"
27 #include "wildcard.h"
28 #include "message.h"
29 #include "commands.h"
30 #include "mode.h"
31 #include "xline.h"
32 #include "inspstring.h"
33 #include "dnsqueue.h"
34 #include "helperfuncs.h"
35 #include "hashcomp.h"
36 #include "socketengine.h"
37
38 #include "command_parse.h"
39 #include "cmd_oper.h"
40
41 extern ServerConfig* Config;
42 extern int MODCOUNT;
43 extern ModuleList modules;
44 extern FactoryList factory;
45 extern time_t TIME;
46
47 bool OneOfMatches(const char* host, const char* hostlist)
48 {
49         std::stringstream hl(hostlist);
50         std::string xhost;
51         while (hl >> xhost)
52         {
53                 log(DEBUG,"Oper: Matching host %s",xhost.c_str());
54                 if (match(host,xhost.c_str()))
55                 {
56                         return true;
57                 }
58         }
59         return false;
60 }
61
62 void cmd_oper::Handle (char **parameters, int pcnt, userrec *user)
63 {
64         char LoginName[MAXBUF];
65         char Password[MAXBUF];
66         char OperType[MAXBUF];
67         char TypeName[MAXBUF];
68         char HostName[MAXBUF];
69         char TheHost[MAXBUF];
70         int j;
71         bool found = false;
72         bool fail2 = false;
73
74         snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
75
76         for (int i = 0; i < Config->ConfValueEnum(Config->config_data, "oper"); i++)
77         {
78                 Config->ConfValue(Config->config_data, "oper", "name", i, LoginName, MAXBUF);
79                 Config->ConfValue(Config->config_data, "oper", "password", i, Password, MAXBUF);
80                 Config->ConfValue(Config->config_data, "oper", "type", i, OperType, MAXBUF);
81                 Config->ConfValue(Config->config_data, "oper", "host", i, HostName, MAXBUF);
82
83                 if ((!strcmp(LoginName,parameters[0])) && (!operstrcmp(Password,parameters[1])) && (OneOfMatches(TheHost,HostName)))
84                 {
85                         fail2 = true;
86                         for (j =0; j < Config->ConfValueEnum(Config->config_data, "type"); j++)
87                         {
88                                 Config->ConfValue(Config->config_data, "type","name", j, TypeName, MAXBUF);
89
90                                 if (!strcmp(TypeName,OperType))
91                                 {
92                                         /* found this oper's opertype */
93                                         Config->ConfValue(Config->config_data, "type","host", j, HostName, MAXBUF);
94                                         if (*HostName)
95                                                 ChangeDisplayedHost(user,HostName);
96                                         if (!isnick(TypeName))
97                                         {
98                                                 WriteServ(user->fd,"491 %s :Invalid oper type (oper types must follow the same syntax as nicknames)",user->nick);
99                                                 WriteOpers("*** CONFIGURATION ERROR! Oper type invalid for OperType '%s'",OperType);
100                                                 log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type erroneous.",user->nick,user->ident,user->host);
101                                                 return;
102                                         }
103                                         strlcpy(user->oper,TypeName,NICKMAX-1);
104                                         found = true;
105                                         fail2 = false;
106                                         break;
107                                 }
108                         }
109                 }
110                 if (found)
111                         break;
112         }
113         if (found)
114         {
115                 /* correct oper credentials */
116                 WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
117                 WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType);
118                 if (!strchr(user->modes,'o'))
119                 {
120                         strcat(user->modes,"o");
121                         WriteServ(user->fd,"MODE %s :+o",user->nick);
122                         FOREACH_MOD(I_OnOper,OnOper(user,OperType));
123                         log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,OperType);
124                         AddOper(user);
125                         FOREACH_MOD(I_OnPostOper,OnPostOper(user,OperType));
126                 }
127         }
128         else
129         {
130                 if (!fail2)
131                 {
132                         WriteServ(user->fd,"491 %s :Invalid oper credentials",user->nick);
133                         WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
134                         log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.",user->nick,user->ident,user->host);
135                 }
136                 else
137                 {
138                         WriteServ(user->fd,"491 %s :Your oper block does not have a valid opertype associated with it",user->nick);
139                         WriteOpers("*** CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType);
140                         log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host);
141                 }
142         }
143         return;
144 }