using namespace std;
+#include "inspircd_config.h"
#include "inspircd.h"
#include "inspircd_io.h"
#include "inspircd_util.h"
-#include "inspircd_config.h"
#include <unistd.h>
#include <fcntl.h>
#include <sys/errno.h>
time_t startup_time = time(NULL);
int NetBufferSize = 10240; // NetBufferSize used as the buffer size for all read() ops
int MaxConn = SOMAXCONN; // size of accept() backlog (128 by default on *BSD)
+unsigned int SoftLimit = MAXCLIENTS;
extern int MaxWhoResults;
time_t nb_start = 0;
int dns_timeout = 5;
int ep, lep, sep;
#endif
+bool has_been_netsplit = false;
+extern std::vector<std::string> include_stack;
+
typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, irc::StrHashComp> user_hash;
typedef nspace::hash_map<std::string, chanrec*, nspace::hash<string>, irc::StrHashComp> chan_hash;
typedef nspace::hash_map<in_addr,string*, nspace::hash<in_addr>, irc::InAddr_HashComp> address_cache;
typedef nspace::hash_map<std::string, WhoWasUser*, nspace::hash<string>, irc::StrHashComp> whowas_hash;
typedef std::deque<command_t> command_table;
typedef std::map<std::string,time_t> autoconnects;
+typedef std::vector<std::string> servernamelist;
// This table references users by file descriptor.
// its an array to make it VERY fast, as all lookups are referenced
address_cache IP;
ClassVector Classes;
+servernamelist servernames;
struct linger linger = { 0 };
char MyExecutable[1024];
all_opers.push_back(user);
}
+void AddServerName(std::string servername)
+{
+ log(DEBUG,"Adding server name: %s",servername.c_str());
+ for (servernamelist::iterator a = servernames.begin(); a < servernames.end(); a++)
+ {
+ if (*a == servername)
+ return;
+ }
+ servernames.push_back(servername);
+}
+
+const char* FindServerNamePtr(std::string servername)
+{
+ for (servernamelist::iterator a = servernames.begin(); a < servernames.end(); a++)
+ {
+ if (*a == servername)
+ return a->c_str();
+ }
+ return "";
+}
+
void DeleteOper(userrec* user)
{
for (std::vector<userrec*>::iterator a = all_opers.begin(); a < all_opers.end(); a++)
void ReadConfig(bool bail, userrec* user)
{
char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF],MCON[MAXBUF];
- char AH[MAXBUF],AP[MAXBUF],AF[MAXBUF],DNT[MAXBUF],pfreq[MAXBUF],thold[MAXBUF],sqmax[MAXBUF],rqmax[MAXBUF];
+ char AH[MAXBUF],AP[MAXBUF],AF[MAXBUF],DNT[MAXBUF],pfreq[MAXBUF],thold[MAXBUF],sqmax[MAXBUF],rqmax[MAXBUF],SLIMT[MAXBUF];
ConnectClass c;
std::stringstream errstr;
+ include_stack.clear();
if (!LoadConf(CONFIG_FILE,&config_f,&errstr))
{
errstr.seekg(0);
+ log(DEFAULT,"There were errors in your configuration:\n%s",errstr.str().c_str());
if (bail)
{
printf("There were errors in your configuration:\n%s",errstr.str().c_str());
ConfValue("options","moduledir",0,ModPath,&config_f);
ConfValue("disabled","commands",0,DisabledCommands,&config_f);
ConfValue("options","somaxconn",0,MCON,&config_f);
+ ConfValue("options","softlimit",0,SLIMT,&config_f);
+ SoftLimit = atoi(SLIMT);
+ if ((SoftLimit < 1) || (SoftLimit > MAXCLIENTS))
+ {
+ log(DEFAULT,"WARNING: <options:softlimit> value is greater than %d or less than 0, set to %d.",MAXCLIENTS,MAXCLIENTS);
+ SoftLimit = MAXCLIENTS;
+ }
MaxConn = atoi(MCON);
if (MaxConn > SOMAXCONN)
log(DEFAULT,"WARNING: <options:somaxconn> value may be higher than the system-defined SOMAXCONN value!");
log(DEFAULT,"Applying K lines, Q lines and Z lines...");
apply_lines();
+ autoconns.clear();
for (int i = 0; i < ConfValueEnum("link",&config_f); i++)
{
char Link_ServerName[MAXBUF],Link_AConn[MAXBUF];
// we MUST declare this wherever we use FOREACH_RESULT
int MOD_RESULT = 0;
- if (strlen(cname) > CHANMAX-1)
+ if (strlen(cname) > CHANMAX)
{
- cname[CHANMAX-1] = '\0';
+ cname[CHANMAX] = '\0';
}
log(DEBUG,"add_channel: %s %s",user->nick,cname);
chanlist.erase(iter);
}
}
+
+ return NULL;
}
// if they were an oper with +s.
if (user->registered == 7) {
purge_empty_chans(user);
- WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason);
+ // fix by brain: only show local quits because we only show local connects (it just makes SENSE)
+ if (!strcmp(user->server,ServerName))
+ WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason);
AddWhoWas(user);
}
strlcpy(MyExecutable,argv[0],MAXBUF);
// initialize the lowercase mapping table
- for (int cn = 0; cn < 256; cn++)
+ for (unsigned int cn = 0; cn < 256; cn++)
lowermap[cn] = cn;
// lowercase the uppercase chars
- for (int cn = 65; cn < 91; cn++)
+ for (unsigned int cn = 65; cn < 91; cn++)
lowermap[cn] = tolower(cn);
// now replace the specific chars for scandanavian comparison
- lowermap['['] = '{';
- lowermap[']'] = '}';
- lowermap['\\'] = '|';
+ lowermap[(unsigned)'['] = '{';
+ lowermap[(unsigned)']'] = '}';
+ lowermap[(unsigned)'\\'] = '|';
if (InspIRCd(argv,argc) == ERROR)
{
whowas_hash::iterator iter = whowas.find(u->nick);
WhoWasUser *a = new WhoWasUser();
strlcpy(a->nick,u->nick,NICKMAX);
- strlcpy(a->ident,u->ident,15);
+ strlcpy(a->ident,u->ident,IDENTMAX);
strlcpy(a->dhost,u->dhost,160);
strlcpy(a->host,u->host,160);
- strlcpy(a->fullname,u->fullname,128);
+ strlcpy(a->fullname,u->fullname,MAXGECOS);
strlcpy(a->server,u->server,256);
a->signon = u->signon;
if (iter == whowas.end())
{
- if (whowas.size() >= WHOWAS_MAX)
+ if (whowas.size() >= (unsigned)WHOWAS_MAX)
{
for (whowas_hash::iterator i = whowas.begin(); i != whowas.end(); i++)
{
log(DEBUG,"AddClient: %lu %s %d %s",(unsigned long)socket,host,port,ip);
clientlist[tempnick]->fd = socket;
- strncpy(clientlist[tempnick]->nick, tn2,NICKMAX);
- strncpy(clientlist[tempnick]->host, host,160);
- strncpy(clientlist[tempnick]->dhost, host,160);
- strncpy(clientlist[tempnick]->server, ServerName,256);
- strncpy(clientlist[tempnick]->ident, "unknown",15);
+ strlcpy(clientlist[tempnick]->nick, tn2,NICKMAX);
+ strlcpy(clientlist[tempnick]->host, host,160);
+ strlcpy(clientlist[tempnick]->dhost, host,160);
+ clientlist[tempnick]->server = (char*)FindServerNamePtr(ServerName);
+ strlcpy(clientlist[tempnick]->ident, "unknown",IDENTMAX);
clientlist[tempnick]->registered = 0;
clientlist[tempnick]->signon = TIME+dns_timeout;
clientlist[tempnick]->lastping = 1;
clientlist[tempnick]->port = port;
- strncpy(clientlist[tempnick]->ip,ip,16);
+ strlcpy(clientlist[tempnick]->ip,ip,16);
// set the registration timeout for this user
unsigned long class_regtimeout = 90;
clientlist[tempnick]->chans[i].uc_modes = 0;
}
- if (clientlist.size() == MAXCLIENTS)
+ if (clientlist.size() > SoftLimit)
+ {
+ kill_link(clientlist[tempnick],"No more connections allowed");
+ return;
+ }
+
+ if (clientlist.size() >= MAXCLIENTS)
{
- kill_link(clientlist[tempnick],"No more connections allowed in this class");
+ kill_link(clientlist[tempnick],"No more connections allowed");
return;
}
// irc server at once (or the irc server otherwise initiating this many connections, files etc)
// which for the time being is a physical impossibility (even the largest networks dont have more
// than about 10,000 users on ONE server!)
- if (socket > 65534)
+ if ((unsigned)socket > 65534)
{
kill_link(clientlist[tempnick],"Server is full");
return;
std::stringstream v;
v << "MESHED WALLCHOPS MODES=13 CHANTYPES=# PREFIX=(ohv)@%+ MAP SAFELIST MAXCHANNELS=" << MAXCHANS;
v << " MAXBANS=60 NICKLEN=" << NICKMAX;
- v << " TOPICLEN=307 KICKLEN=307 MAXTARGETS=20 AWAYLEN=307 CHANMODES=ohvb,k,l,psmnti NETWORK=";
+ v << " TOPICLEN=" << MAXTOPIC << " KICKLEN=" << MAXKICK << " MAXTARGETS=20 AWAYLEN=" << MAXAWAY << " CHANMODES=ohvb,k,l,psmnti NETWORK=";
v << Network;
std::string data005 = v.str();
FOREACH_MOD On005Numeric(data005);
// fix by brain: these should be AFTER the N token, so other servers know what the HELL we're on about... :)
FOREACH_MOD OnUserConnect(user);
+ FOREACH_MOD OnGlobalConnect(user);
WriteOpers("*** Client connecting on port %lu: %s!%s@%s [%s]",(unsigned long)user->port,user->nick,user->ident,user->host,user->ip);
}
{
if (me[j] != NULL)
{
- for (int x = 0; x < me[j]->connectors.size(); x++)
+ for (unsigned int x = 0; x < me[j]->connectors.size(); x++)
{
WriteServ(user->fd,"351 %s :Server %d:%d (%s): %s",user->nick,j,x,me[j]->connectors[x].GetServerName().c_str(),me[j]->connectors[x].GetVersionString().c_str());
}
{
if (me[j] != NULL)
{
- for (int x = 0; x < me[j]->connectors.size(); x++)
+ for (unsigned int x = 0; x < me[j]->connectors.size(); x++)
{
if (match(me[j]->connectors[x].GetServerName().c_str(),parameters[0]))
{
void call_handler(const char* commandname,char **parameters, int pcnt, userrec *user)
{
- for (int i = 0; i < cmdlist.size(); i++)
+ for (unsigned int i = 0; i < cmdlist.size(); i++)
{
if (!strcasecmp(cmdlist[i].command,commandname))
{
}
}
}
+ has_been_netsplit = true;
}
int total_params = 0;
if (strlen(cmd)>2)
{
- for (int q = 0; q < strlen(cmd)-1; q++)
+ for (unsigned int q = 0; q < strlen(cmd)-1; q++)
{
if ((cmd[q] == ' ') && (cmd[q+1] == ':'))
{
items = 0;
command_p[0] = NULL;
parameters = NULL;
- for (int i = 0; i <= strlen(cmd); i++)
+ for (unsigned int i = 0; i <= strlen(cmd); i++)
{
cmd[i] = toupper(cmd[i]);
}
strcpy(cmd,"");
j = 0;
/* strip out extraneous linefeeds through mirc's crappy pasting (thanks Craig) */
- for (int i = 0; i < strlen(temp); i++)
+ for (unsigned int i = 0; i < strlen(temp); i++)
{
if ((temp[i] != 10) && (temp[i] != 13) && (temp[i] != 0) && (temp[i] != 7))
{
command = cmd;
if (strchr(cmd,' '))
{
- for (int i = 0; i <= strlen(cmd); i++)
+ for (unsigned int i = 0; i <= strlen(cmd); i++)
{
/* capitalise the command ONLY, leave params intact */
cmd[i] = toupper(cmd[i]);
}
else
{
- for (int i = 0; i <= strlen(cmd); i++)
+ for (unsigned int i = 0; i <= strlen(cmd); i++)
{
cmd[i] = toupper(cmd[i]);
}
return;
}
- for (int x = 0; x < strlen(command); x++)
+ for (unsigned int x = 0; x < strlen(command); x++)
{
if (((command[x] < 'A') || (command[x] > 'Z')) && (command[x] != '.'))
{
}
}
- for (int i = 0; i != cmdlist.size(); i++)
+ for (unsigned int i = 0; i != cmdlist.size(); i++)
{
if (cmdlist[i].command[0])
{
}
if ((user->registered == 7) && (!strchr(user->modes,'o')))
{
- char* mycmd;
- char* savept2;
- mycmd = strtok_r(DisabledCommands," ",&savept2);
- while (mycmd)
+ std::stringstream dcmds(DisabledCommands);
+ while (!dcmds.eof())
{
- if (!strcasecmp(mycmd,command))
+ std::string thiscmd;
+ dcmds >> thiscmd;
+ if (!strcasecmp(thiscmd.c_str(),command))
{
// command is disabled!
WriteServ(user->fd,"421 %s %s :This command has been disabled.",user->nick,command);
return;
}
- mycmd = strtok_r(NULL," ",&savept2);
}
-
-
}
if ((user->registered == 7) || (!strncmp(command,"USER",4)) || (!strncmp(command,"NICK",4)) || (!strncmp(command,"PASS",4)))
{
{
if (me[j] != NULL)
{
- for (int k = 0; k < me[j]->connectors.size(); k++)
+ for (unsigned int k = 0; k < me[j]->connectors.size(); k++)
{
if (is_uline(me[j]->connectors[k].GetServerName().c_str()))
{
for (int i = 0; i <= MODCOUNT; i++)
{
string_list l = modules[i]->OnUserSync(u->second);
- for (int j = 0; j < l.size(); j++)
+ for (unsigned int j = 0; j < l.size(); j++)
{
snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str());
serv->SendPacket(data,tcp_host);
for (int i = 0; i <= MODCOUNT; i++)
{
string_list l = modules[i]->OnChannelSync(c->second);
- for (int j = 0; j < l.size(); j++)
+ for (unsigned int j = 0; j < l.size(); j++)
{
snprintf(data,MAXBUF,"%s %s",CreateSum().c_str(),l[j].c_str());
serv->SendPacket(data,tcp_host);
{
if (me[i] != NULL)
{
- for (int j = 0; j < me[i]->connectors.size(); j++)
+ for (unsigned int j = 0; j < me[i]->connectors.size(); j++)
{
if ((me[i]->connectors[j].GetState() != STATE_DISCONNECTED) || (is_uline(me[i]->connectors[j].GetServerName().c_str())))
{
}
}
}
+ has_been_netsplit = true;
}
// removes a server. Will NOT remove its users!
bool UnloadModule(const char* filename)
{
std::string filename_str = filename;
- for (int j = 0; j != module_names.size(); j++)
+ for (unsigned int j = 0; j != module_names.size(); j++)
{
if (module_names[j] == filename_str)
{
snprintf(MODERR,MAXBUF,"Module not unloadable (marked static)");
return false;
}
+ FOREACH_MOD OnUnloadModule(modules[j],module_names[j]);
// found the module
log(DEBUG,"Deleting module...");
erase_module(j);
if (FileExists(modfile))
{
#endif
- for (int j = 0; j < module_names.size(); j++)
+ for (unsigned int j = 0; j < module_names.size(); j++)
{
if (module_names[j] == filename_str)
{
{
Module* m = factory[MODCOUNT+1]->factory->CreateModule();
modules[MODCOUNT+1] = m;
+ FOREACH_MOD OnLoadModule(m,filename_str);
/* save the module and the module's classfactory, if
* this isnt done, random crashes can occur :/ */
module_names.push_back(filename);
{
if (me[j] != NULL)
{
- for (int k = 0; k < me[j]->connectors.size(); k++)
+ for (unsigned int k = 0; k < me[j]->connectors.size(); k++)
{
if (name == me[j]->connectors[k].GetServerName())
{
int incomingSockfd, result = TRUE;
socklen_t length;
int count = 0;
+#ifdef USE_SELECT
int selectResult = 0, selectResult2 = 0;
- char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
fd_set selectFds;
+#endif
+ char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
timeval tv;
std::string logpath = GetFullProgDir(argv,argc) + "/ircd.log";
}
log(DEBUG,"InspIRCd: startup: read config");
+ AddServerName(ServerName);
+
int clientportcount = 0, serverportcount = 0;
for (count = 0; count < ConfValueEnum("bind",&config_f); count++)
WritePID(PID);
/* setup select call */
-#ifndef USE_KQUEUE
+#ifdef USE_SELECT
FD_ZERO(&selectFds);
#endif
log(DEBUG,"InspIRCd: startup: zero selects");
#ifdef USE_EPOLL
struct epoll_event event[33];
#endif
+#ifdef USE_SELECT
fd_set serverfds;
+ fd_set sfd;
+#endif
timeval tvs;
tvs.tv_usec = 10000L;
tvs.tv_sec = 0;
tv.tv_usec = 10000L;
char data[65536];
timeval tval;
- fd_set sfd;
tval.tv_usec = 10000L;
tval.tv_sec = 0;
int total_in_this_set = 0;
log(DEBUG,"epoll: Listening server socket event, i=%d, event.data.fd=%d",i,event[0].data.fd);
for (int x = 0; x != SERVERportCount; x++)
{
- if ((me[x]) && (event[0].data.fd == me[x]->fd))
+ if ((me[x]) && ((unsigned)event[0].data.fd == (unsigned)me[x]->fd))
{
#endif
#ifdef USE_KQUEUE
log(DEBUG,"kqueue: Listening server socket event, i=%d, ke.ident=%d",i,ke.ident);
for (int x = 0; x != SERVERportCount; x++)
{
- if ((me[x]) && (ke.ident == me[x]->fd))
+ if ((me[x]) && ((unsigned)ke.ident == (unsigned)me[x]->fd))
{
#endif
msgs.clear();
while ((me[x]) && (me[x]->RecvPacket(msgs, tcp_host, sums))) // returns 0 or more lines (can be multiple lines!)
{
- for (int ctr = 0; ctr < msgs.size(); ctr++)
+ has_been_netsplit = false;
+ for (unsigned int ctr = 0; ctr < msgs.size(); ctr++)
{
strlcpy(tcp_msg,msgs[ctr].c_str(),MAXBUF);
- strlcpy(tcp_sum,msgs[ctr].c_str(),MAXBUF);
+ strlcpy(tcp_sum,sums[ctr].c_str(),MAXBUF);
log(DEBUG,"Processing: %s",tcp_msg);
if (!tcp_msg[0])
{
goto label;
}
}
- sums.clear(); // we're done, clear the list for the next operation
- msgs.clear();
+ goto label;
}
}
// registration timeout -- didnt send USER/NICK/HOST in the time specified in
// their connection class.
- if ((TIME > curr->timeout) && (curr->registered != 7))
+ if (((unsigned)TIME > (unsigned)curr->timeout) && (curr->registered != 7))
{
log(DEBUG,"InspIRCd: registration timeout: %s",curr->nick);
kill_link(curr,"Registration timeout");
}
goto label;
}
- if (current->recvq.length() > NetBufferSize)
+ if (current->recvq.length() > (unsigned)NetBufferSize)
{
if (current->registered == 7)
{
// compared to the number of clients (possibly over 2000)
for (count = 0; count < boundPortCount; count++)
{
- if (ke_list[j].ident == openSockfd[count])
+ if ((unsigned)ke_list[j].ident == (unsigned)openSockfd[count])
{
#endif
#ifdef USE_EPOLL
log(DEBUG,"epoll: Listening socket event, i=%d,events[j].data.fd=%d",i,event[j].data.fd);
for (count = 0; count < boundPortCount; count++)
{
- if (event[j].data.fd == openSockfd[count])
+ if ((unsigned)event[j].data.fd == (unsigned)openSockfd[count])
{
#endif
char target[MAXBUF], resolved[MAXBUF];
}
/* not reached */
close (incomingSockfd);
+return 0;
}