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
45 #include "inspstring.h"
48 #include "socketengine.h"
50 #include "command_parse.h"
52 /* XXX - these really belong in helperfuncs perhaps -- w00t */
53 bool InspIRCd::ULine(const char* server)
60 return (find(Config->ulines.begin(),Config->ulines.end(),server) != Config->ulines.end());
63 int InspIRCd::OperPassCompare(const char* data,const char* input)
66 FOREACH_RESULT_I(this,I_OnOperCompare,OnOperCompare(data,input))
67 Log(DEBUG,"OperPassCompare: %d",MOD_RESULT);
72 Log(DEBUG,"strcmp fallback: '%s' '%s' %d",data,input,strcmp(data,input));
73 return strcmp(data,input);
76 long InspIRCd::Duration(const char* str)
82 if ((!strchr(str,'s')) && (!strchr(str,'m')) && (!strchr(str,'h')) && (!strchr(str,'d')) && (!strchr(str,'w')) && (!strchr(str,'y')))
86 return Duration(n.c_str());
89 for (char* i = (char*)str; *i; i++)
91 // if we have digits, build up a string for the value in n_field,
92 // up to 10 digits in size.
93 if ((*i >= '0') && (*i <= '9'))
95 strlcat(n_field,i,10);
99 // we dont have a digit, check for numeric tokens
103 total += atoi(n_field);
107 total += (atoi(n_field)*duration_m);
111 total += (atoi(n_field)*duration_h);
115 total += (atoi(n_field)*duration_d);
119 total += (atoi(n_field)*duration_w);
123 total += (atoi(n_field)*duration_y);
129 // add trailing seconds
130 total += atoi(n_field);
135 /* All other ircds when doing this check usually just look for a string of *@* or *. We're smarter than that, though. */
137 bool InspIRCd::HostMatchesEveryone(const std::string &mask, userrec* user)
140 char itrigger[MAXBUF];
143 if (!Config->ConfValue(Config->config_data, "insane","trigger", 0, itrigger, MAXBUF))
144 strlcpy(itrigger,"95.5",MAXBUF);
146 if (Config->ConfValueBool(Config->config_data, "insane","hostmasks", 0))
149 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
151 strlcpy(buffer,u->second->ident,MAXBUF);
152 charlcat(buffer,'@',MAXBUF);
153 strlcat(buffer,u->second->host,MAXBUF);
154 if (match(buffer,mask.c_str()))
157 float percent = ((float)matches / (float)clientlist.size()) * 100;
158 if (percent > (float)atof(itrigger))
160 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);
166 bool InspIRCd::IPMatchesEveryone(const std::string &ip, userrec* user)
168 char itrigger[MAXBUF];
171 if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
172 strlcpy(itrigger,"95.5",MAXBUF);
174 if (Config->ConfValueBool(Config->config_data, "insane","ipmasks",0))
177 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
179 if (match(u->second->GetIPString(),ip.c_str(),true))
183 float percent = ((float)matches / (float)clientlist.size()) * 100;
184 if (percent > (float)atof(itrigger))
186 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);
192 bool InspIRCd::NickMatchesEveryone(const std::string &nick, userrec* user)
194 char itrigger[MAXBUF];
197 if (!Config->ConfValue(Config->config_data, "insane","trigger",0,itrigger,MAXBUF))
198 strlcpy(itrigger,"95.5",MAXBUF);
200 if (Config->ConfValueBool(Config->config_data, "insane","nickmasks",0))
203 for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
205 if (match(u->second->nick,nick.c_str()))
209 float percent = ((float)matches / (float)clientlist.size()) * 100;
210 if (percent > (float)atof(itrigger))
212 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);