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>
34 #define RUSAGE_CHILDREN -1
46 #include "inspstring.h"
47 #include "helperfuncs.h"
49 #include "socketengine.h"
51 #include "command_parse.h"
53 extern ServerConfig* Config;
54 extern InspIRCd* ServerInstance;
57 extern ModuleList modules;
58 extern FactoryList factory;
61 const long duration_m = 60;
62 const long duration_h = duration_m * 60;
63 const long duration_d = duration_h * 24;
64 const long duration_w = duration_d * 7;
65 const long duration_y = duration_w * 52;
67 extern user_hash clientlist;
68 extern chan_hash chanlist;
70 extern std::vector<userrec*> all_opers;
71 extern std::vector<userrec*> local_users;
73 // This table references users by file descriptor.
74 // its an array to make it VERY fast, as all lookups are referenced
75 // by an integer, meaning there is no need for a scan/search operation.
76 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
79 void split_chlist(userrec* user, userrec* dest, const std::string &cl)
82 std::ostringstream prefix;
83 std::string::size_type start, pos, length;
85 prefix << ":" << Config->ServerName << " 319 " << user->nick << " " << dest->nick << " :";
88 for (start = 0; pos = cl.find(' ', start); start = pos+1)
90 length = (pos == std::string::npos) ? cl.length() : pos;
92 if (line.length() + length - start > 510)
94 Write_NoFormat(user->fd, line.c_str());
98 if(pos == std::string::npos)
100 line += cl.substr(start, length - start);
105 line += cl.substr(start, length - start + 1);
111 Write_NoFormat(user->fd, line.c_str());
115 /* XXX - these really belong in helperfuncs perhaps -- w00t */
116 bool is_uline(const char* server)
123 return (find(Config->ulines.begin(),Config->ulines.end(),server) != Config->ulines.end());
126 int operstrcmp(const char* data,const char* input)
129 FOREACH_RESULT(I_OnOperCompare,OnOperCompare(data,input))
130 log(DEBUG,"operstrcmp: %d",MOD_RESULT);
133 if (MOD_RESULT == -1)
135 log(DEBUG,"strcmp fallback: '%s' '%s' %d",data,input,strcmp(data,input));
136 return strcmp(data,input);
139 long duration(const char* str)
141 char n_field[MAXBUF];
145 if ((!strchr(str,'s')) && (!strchr(str,'m')) && (!strchr(str,'h')) && (!strchr(str,'d')) && (!strchr(str,'w')) && (!strchr(str,'y')))
149 return duration(n.c_str());
152 for (char* i = (char*)str; *i; i++)
154 // if we have digits, build up a string for the value in n_field,
155 // up to 10 digits in size.
156 if ((*i >= '0') && (*i <= '9'))
158 strlcat(n_field,i,10);
162 // we dont have a digit, check for numeric tokens
166 total += atoi(n_field);
170 total += (atoi(n_field)*duration_m);
174 total += (atoi(n_field)*duration_h);
178 total += (atoi(n_field)*duration_d);
182 total += (atoi(n_field)*duration_w);
186 total += (atoi(n_field)*duration_y);
192 // add trailing seconds
193 total += atoi(n_field);
198 /* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */
200 bool host_matches_everyone(const std::string &mask, userrec* user)
203 char itrigger[MAXBUF];
206 if (!Config->ConfValue(Config->config_data, "insane","trigger", 0, itrigger, MAXBUF))
207 strlcpy(itrigger,"95.5",MAXBUF);
209 if (Config->ConfValueBool(Config->config_data, "insane","hostmasks", 0))
212 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
214 strlcpy(buffer,u->second->ident,MAXBUF);
215 charlcat(buffer,'@',MAXBUF);
216 strlcat(buffer,u->second->host,MAXBUF);
217 if (match(buffer,mask.c_str()))
220 float percent = ((float)matches / (float)clientlist.size()) * 100;
221 if (percent > (float)atof(itrigger))
223 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);
229 bool ip_matches_everyone(const std::string &ip, userrec* user)
231 char itrigger[MAXBUF];
234 if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
235 strlcpy(itrigger,"95.5",MAXBUF);
237 if (Config->ConfValueBool(Config->config_data, "insane","ipmasks",0))
240 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
242 if (match(insp_ntoa(u->second->ip4),ip.c_str()))
246 float percent = ((float)matches / (float)clientlist.size()) * 100;
247 if (percent > (float)atof(itrigger))
249 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);
255 bool nick_matches_everyone(const std::string &nick, userrec* user)
257 char itrigger[MAXBUF];
260 if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
261 strlcpy(itrigger,"95.5",MAXBUF);
263 if (Config->ConfValueBool(Config->config_data, "insane","nickmasks",0))
266 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
268 if (match(u->second->nick,nick.c_str()))
272 float percent = ((float)matches / (float)clientlist.size()) * 100;
273 if (percent > (float)atof(itrigger))
275 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);