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 "inspircd_config.h"
19 #include "configreader.h"
21 #include <sys/errno.h>
22 #include <sys/ioctl.h>
23 #include <sys/utsname.h>
29 #include <sys/types.h>
31 #include <sys/resource.h>
37 #define RUSAGE_CHILDREN -1
49 #include "inspstring.h"
51 #include "helperfuncs.h"
53 #include "socketengine.h"
55 #include "command_parse.h"
57 extern ServerConfig* Config;
58 extern InspIRCd* ServerInstance;
61 extern ModuleList modules;
62 extern FactoryList factory;
65 const long duration_m = 60;
66 const long duration_h = duration_m * 60;
67 const long duration_d = duration_h * 24;
68 const long duration_w = duration_d * 7;
69 const long duration_y = duration_w * 52;
71 extern user_hash clientlist;
72 extern chan_hash chanlist;
74 extern std::vector<userrec*> all_opers;
75 extern std::vector<userrec*> local_users;
77 // This table references users by file descriptor.
78 // its an array to make it VERY fast, as all lookups are referenced
79 // by an integer, meaning there is no need for a scan/search operation.
80 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
83 void split_chlist(userrec* user, userrec* dest, const std::string &cl)
86 std::ostringstream prefix;
87 std::string::size_type start, pos, length;
89 prefix << ":" << Config->ServerName << " 319 " << user->nick << " " << dest->nick << " :";
92 for (start = 0; pos = cl.find(' ', start); start = pos+1)
94 length = (pos == std::string::npos) ? cl.length() : pos;
96 if (line.length() + length - start > 510)
98 Write_NoFormat(user->fd, line.c_str());
102 if(pos == std::string::npos)
104 line += cl.substr(start, length - start);
109 line += cl.substr(start, length - start + 1);
115 Write_NoFormat(user->fd, line.c_str());
119 /* XXX - these really belong in helperfuncs perhaps -- w00t */
120 bool is_uline(const char* server)
127 return (find(Config->ulines.begin(),Config->ulines.end(),server) != Config->ulines.end());
130 int operstrcmp(const char* data,const char* input)
133 FOREACH_RESULT(I_OnOperCompare,OnOperCompare(data,input))
134 log(DEBUG,"operstrcmp: %d",MOD_RESULT);
137 if (MOD_RESULT == -1)
139 log(DEBUG,"strcmp fallback: '%s' '%s' %d",data,input,strcmp(data,input));
140 return strcmp(data,input);
143 long duration(const char* str)
145 char n_field[MAXBUF];
149 if ((!strchr(str,'s')) && (!strchr(str,'m')) && (!strchr(str,'h')) && (!strchr(str,'d')) && (!strchr(str,'w')) && (!strchr(str,'y')))
153 return duration(n.c_str());
156 for (char* i = (char*)str; *i; i++)
158 // if we have digits, build up a string for the value in n_field,
159 // up to 10 digits in size.
160 if ((*i >= '0') && (*i <= '9'))
162 strlcat(n_field,i,10);
166 // we dont have a digit, check for numeric tokens
170 total += atoi(n_field);
174 total += (atoi(n_field)*duration_m);
178 total += (atoi(n_field)*duration_h);
182 total += (atoi(n_field)*duration_d);
186 total += (atoi(n_field)*duration_w);
190 total += (atoi(n_field)*duration_y);
196 // add trailing seconds
197 total += atoi(n_field);
202 /* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */
204 bool host_matches_everyone(const std::string &mask, userrec* user)
207 char itrigger[MAXBUF];
210 if (!Config->ConfValue(Config->config_data, "insane","trigger", 0, itrigger, MAXBUF))
211 strlcpy(itrigger,"95.5",MAXBUF);
213 if (Config->ConfValueBool(Config->config_data, "insane","hostmasks", 0))
216 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
218 strlcpy(buffer,u->second->ident,MAXBUF);
219 charlcat(buffer,'@',MAXBUF);
220 strlcat(buffer,u->second->host,MAXBUF);
221 if (match(buffer,mask.c_str()))
224 float percent = ((float)matches / (float)clientlist.size()) * 100;
225 if (percent > (float)atof(itrigger))
227 WriteOpers("*** \2WARNING\2: %s tried to set a G/K/E line mask of %s, which covers %.2f%% of the network!",user->nick,mask.c_str(),percent);
233 bool ip_matches_everyone(const std::string &ip, userrec* user)
235 char itrigger[MAXBUF];
238 if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
239 strlcpy(itrigger,"95.5",MAXBUF);
241 if (Config->ConfValueBool(Config->config_data, "insane","ipmasks",0))
244 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
246 if (match((char*)inet_ntoa(u->second->ip4),ip.c_str()))
250 float percent = ((float)matches / (float)clientlist.size()) * 100;
251 if (percent > (float)atof(itrigger))
253 WriteOpers("*** \2WARNING\2: %s tried to set a Z line mask of %s, which covers %.2f%% of the network!",user->nick,ip.c_str(),percent);
259 bool nick_matches_everyone(const std::string &nick, userrec* user)
261 char itrigger[MAXBUF];
264 if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
265 strlcpy(itrigger,"95.5",MAXBUF);
267 if (Config->ConfValueBool(Config->config_data, "insane","nickmasks",0))
270 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
272 if (match(u->second->nick,nick.c_str()))
276 float percent = ((float)matches / (float)clientlist.size()) * 100;
277 if (percent > (float)atof(itrigger))
279 WriteOpers("*** \2WARNING\2: %s tried to set a Q line mask of %s, which covers %.2f%% of the network!",user->nick,nick.c_str(),percent);