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 std::vector<userrec*> all_opers;
68 void split_chlist(userrec* user, userrec* dest, const std::string &cl)
71 std::ostringstream prefix;
72 std::string::size_type start, pos, length;
74 prefix << ":" << ServerInstance->Config->ServerName << " 319 " << user->nick << " " << dest->nick << " :";
77 for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
79 length = (pos == std::string::npos) ? cl.length() : pos;
81 if (line.length() + length - start > 510)
87 if(pos == std::string::npos)
89 line += cl.substr(start, length - start);
94 line += cl.substr(start, length - start + 1);
104 /* XXX - these really belong in helperfuncs perhaps -- w00t */
105 bool is_uline(const char* server)
112 return (find(ServerInstance->Config->ulines.begin(),ServerInstance->Config->ulines.end(),server) != ServerInstance->Config->ulines.end());
115 int operstrcmp(const char* data,const char* input)
118 FOREACH_RESULT(I_OnOperCompare,OnOperCompare(data,input))
119 log(DEBUG,"operstrcmp: %d",MOD_RESULT);
122 if (MOD_RESULT == -1)
124 log(DEBUG,"strcmp fallback: '%s' '%s' %d",data,input,strcmp(data,input));
125 return strcmp(data,input);
128 long duration(const char* str)
130 char n_field[MAXBUF];
134 if ((!strchr(str,'s')) && (!strchr(str,'m')) && (!strchr(str,'h')) && (!strchr(str,'d')) && (!strchr(str,'w')) && (!strchr(str,'y')))
138 return duration(n.c_str());
141 for (char* i = (char*)str; *i; i++)
143 // if we have digits, build up a string for the value in n_field,
144 // up to 10 digits in size.
145 if ((*i >= '0') && (*i <= '9'))
147 strlcat(n_field,i,10);
151 // we dont have a digit, check for numeric tokens
155 total += atoi(n_field);
159 total += (atoi(n_field)*duration_m);
163 total += (atoi(n_field)*duration_h);
167 total += (atoi(n_field)*duration_d);
171 total += (atoi(n_field)*duration_w);
175 total += (atoi(n_field)*duration_y);
181 // add trailing seconds
182 total += atoi(n_field);
187 /* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */
189 bool host_matches_everyone(const std::string &mask, userrec* user)
192 char itrigger[MAXBUF];
195 if (!ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "insane","trigger", 0, itrigger, MAXBUF))
196 strlcpy(itrigger,"95.5",MAXBUF);
198 if (ServerInstance->Config->ConfValueBool(ServerInstance->Config->config_data, "insane","hostmasks", 0))
201 for (user_hash::iterator u = ServerInstance->clientlist.begin(); u != ServerInstance->clientlist.end(); u++)
203 strlcpy(buffer,u->second->ident,MAXBUF);
204 charlcat(buffer,'@',MAXBUF);
205 strlcat(buffer,u->second->host,MAXBUF);
206 if (match(buffer,mask.c_str()))
209 float percent = ((float)matches / (float)ServerInstance->clientlist.size()) * 100;
210 if (percent > (float)atof(itrigger))
212 ServerInstance->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);
218 bool ip_matches_everyone(const std::string &ip, userrec* user)
220 char itrigger[MAXBUF];
223 if (!ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
224 strlcpy(itrigger,"95.5",MAXBUF);
226 if (ServerInstance->Config->ConfValueBool(ServerInstance->Config->config_data, "insane","ipmasks",0))
229 for (user_hash::iterator u = ServerInstance->clientlist.begin(); u != ServerInstance->clientlist.end(); u++)
231 if (match(u->second->GetIPString(),ip.c_str(),true))
235 float percent = ((float)matches / (float)ServerInstance->clientlist.size()) * 100;
236 if (percent > (float)atof(itrigger))
238 ServerInstance->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);
244 bool nick_matches_everyone(const std::string &nick, userrec* user)
246 char itrigger[MAXBUF];
249 if (!ServerInstance->Config->ConfValue(ServerInstance->Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
250 strlcpy(itrigger,"95.5",MAXBUF);
252 if (ServerInstance->Config->ConfValueBool(ServerInstance->Config->config_data, "insane","nickmasks",0))
255 for (user_hash::iterator u = ServerInstance->clientlist.begin(); u != ServerInstance->clientlist.end(); u++)
257 if (match(u->second->nick,nick.c_str()))
261 float percent = ((float)matches / (float)ServerInstance->clientlist.size()) * 100;
262 if (percent > (float)atof(itrigger))
264 ServerInstance->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);