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 InspIRCd* ServerInstance;
56 extern ModuleList modules;
57 extern FactoryList factory;
60 const long duration_m = 60;
61 const long duration_h = duration_m * 60;
62 const long duration_d = duration_h * 24;
63 const long duration_w = duration_d * 7;
64 const long duration_y = duration_w * 52;
66 extern user_hash clientlist;
67 extern chan_hash chanlist;
69 extern std::vector<userrec*> all_opers;
70 extern std::vector<userrec*> local_users;
72 // This table references users by file descriptor.
73 // its an array to make it VERY fast, as all lookups are referenced
74 // by an integer, meaning there is no need for a scan/search operation.
75 extern userrec* fd_ref_table[MAX_DESCRIPTORS];
78 void split_chlist(userrec* user, userrec* dest, const std::string &cl)
81 std::ostringstream prefix;
82 std::string::size_type start, pos, length;
84 prefix << ":" << ServerInstance->Config->ServerName << " 319 " << user->nick << " " << dest->nick << " :";
87 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
89 length = (pos == std::string::npos) ? cl.length() : pos;
91 if (line.length() + length - start > 510)
97 if(pos == std::string::npos)
99 line += cl.substr(start, length - start);
104 line += cl.substr(start, length - start + 1);
114 /* XXX - these really belong in helperfuncs perhaps -- w00t */
115 bool is_uline(const char* server)
122 return (find(ServerInstance->Config->ulines.begin(),ServerInstance->Config->ulines.end(),server) != ServerInstance->Config->ulines.end());
125 int operstrcmp(const char* data,const char* input)
128 FOREACH_RESULT(I_OnOperCompare,OnOperCompare(data,input))
129 log(DEBUG,"operstrcmp: %d",MOD_RESULT);
132 if (MOD_RESULT == -1)
134 log(DEBUG,"strcmp fallback: '%s' '%s' %d",data,input,strcmp(data,input));
135 return strcmp(data,input);
138 long duration(const char* str)
140 char n_field[MAXBUF];
144 if ((!strchr(str,'s')) && (!strchr(str,'m')) && (!strchr(str,'h')) && (!strchr(str,'d')) && (!strchr(str,'w')) && (!strchr(str,'y')))
148 return duration(n.c_str());
151 for (char* i = (char*)str; *i; i++)
153 // if we have digits, build up a string for the value in n_field,
154 // up to 10 digits in size.
155 if ((*i >= '0') && (*i <= '9'))
157 strlcat(n_field,i,10);
161 // we dont have a digit, check for numeric tokens
165 total += atoi(n_field);
169 total += (atoi(n_field)*duration_m);
173 total += (atoi(n_field)*duration_h);
177 total += (atoi(n_field)*duration_d);
181 total += (atoi(n_field)*duration_w);
185 total += (atoi(n_field)*duration_y);
191 // add trailing seconds
192 total += atoi(n_field);
197 /* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */
199 bool host_matches_everyone(const std::string &mask, userrec* user)
202 char itrigger[MAXBUF];
205 if (!ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "insane","trigger", 0, itrigger, MAXBUF))
206 strlcpy(itrigger,"95.5",MAXBUF);
208 if (ServerInstance->Config->ConfValueBool(ServerInstance->Config->config_data, "insane","hostmasks", 0))
211 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
213 strlcpy(buffer,u->second->ident,MAXBUF);
214 charlcat(buffer,'@',MAXBUF);
215 strlcat(buffer,u->second->host,MAXBUF);
216 if (match(buffer,mask.c_str()))
219 float percent = ((float)matches / (float)clientlist.size()) * 100;
220 if (percent > (float)atof(itrigger))
222 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);
228 bool ip_matches_everyone(const std::string &ip, userrec* user)
230 char itrigger[MAXBUF];
233 if (!ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
234 strlcpy(itrigger,"95.5",MAXBUF);
236 if (ServerInstance->Config->ConfValueBool(ServerInstance->Config->config_data, "insane","ipmasks",0))
239 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
241 if (match(u->second->GetIPString(),ip.c_str(),true))
245 float percent = ((float)matches / (float)clientlist.size()) * 100;
246 if (percent > (float)atof(itrigger))
248 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);
254 bool nick_matches_everyone(const std::string &nick, userrec* user)
256 char itrigger[MAXBUF];
259 if (!ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
260 strlcpy(itrigger,"95.5",MAXBUF);
262 if (ServerInstance->Config->ConfValueBool(ServerInstance->Config->config_data, "insane","nickmasks",0))
265 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
267 if (match(u->second->nick,nick.c_str()))
271 float percent = ((float)matches / (float)clientlist.size()) * 100;
272 if (percent > (float)atof(itrigger))
274 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);