From 49eabd1197dcd604950e6d6b6d838ba2e63188ab Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 22 Dec 2006 20:12:15 +0000 Subject: Refactor connect allow/deny lines git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6061 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/cmd_pass.cpp | 7 ++++-- src/cmd_stats.cpp | 5 ++-- src/configreader.cpp | 36 ++------------------------- src/users.cpp | 69 ++++++++++++++++++++++++---------------------------- 4 files changed, 42 insertions(+), 75 deletions(-) (limited to 'src') diff --git a/src/cmd_pass.cpp b/src/cmd_pass.cpp index 60930c5b5..05f9114e0 100644 --- a/src/cmd_pass.cpp +++ b/src/cmd_pass.cpp @@ -29,9 +29,12 @@ CmdResult cmd_pass::Handle (const char** parameters, int pcnt, userrec *user) user->WriteServ("462 %s :You may not reregister",user->nick); return CMD_FAILURE; } - ConnectClass a = user->GetClass(); + ConnectClass* a = user->GetClass(); + if (!a) + return CMD_FAILURE; + strlcpy(user->password,parameters[0],63); - if (!strcmp(parameters[0],a.pass.c_str())) + if (a->GetPass() == parameters[0]) { user->haspassed = true; } diff --git a/src/cmd_stats.cpp b/src/cmd_stats.cpp index 3cc04496e..f31248659 100644 --- a/src/cmd_stats.cpp +++ b/src/cmd_stats.cpp @@ -88,7 +88,7 @@ void DoStats(InspIRCd* ServerInstance, char statschar, userrec* user, string_lis int idx = 0; for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++) { - results.push_back(sn+" 215 "+user->nick+" I NOMATCH * "+i->host+" "+ConvToStr(MAXCLIENTS)+" "+ConvToStr(idx)+" "+ServerInstance->Config->ServerName+" *"); + results.push_back(sn+" 215 "+user->nick+" I NOMATCH * "+i->GetHost()+" "+ConvToStr(MAXCLIENTS)+" "+ConvToStr(idx)+" "+ServerInstance->Config->ServerName+" *"); idx++; } } @@ -99,7 +99,8 @@ void DoStats(InspIRCd* ServerInstance, char statschar, userrec* user, string_lis int idx = 0; for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++) { - results.push_back(sn+" 218 "+user->nick+" Y "+ConvToStr(idx)+" "+ConvToStr(i->pingtime)+" 0 "+ConvToStr(i->sendqmax)+" :"+ConvToStr(i->flood)+" "+ConvToStr(i->registration_timeout)); + results.push_back(sn+" 218 "+user->nick+" Y "+ConvToStr(idx)+" "+ConvToStr(i->GetPingTime())+" 0 "+ConvToStr(i->GetSendqMax())+" :"+ + ConvToStr(i->GetFlood())+" "+ConvToStr(i->GetRegTimeout())); idx++; } } diff --git a/src/configreader.cpp b/src/configreader.cpp index 79c2119c6..55321770b 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -416,45 +416,13 @@ bool DoConnect(ServerConfig* conf, const char* tag, char** entries, ValueList &v if (*allow) { - c.host = allow; - c.type = CC_ALLOW; - c.pass = password; - c.registration_timeout = timeout; - c.pingtime = pingfreq; - c.flood = flood; - c.threshold = threshold; - c.sendqmax = sendq; - c.recvqmax = recvq; - c.maxlocal = localmax; - c.maxglobal = globalmax; - - - if (c.maxlocal == 0) - c.maxlocal = 3; - if (c.maxglobal == 0) - c.maxglobal = 3; - if (c.threshold == 0) - { - c.threshold = 1; - c.flood = 999; - conf->GetInstance()->Log(DEFAULT,"Warning: Connect allow line '%s' has no flood/threshold settings. Setting this tag to 999 lines in 1 second.",c.host.c_str()); - } - if (c.sendqmax == 0) - c.sendqmax = 262114; - if (c.recvqmax == 0) - c.recvqmax = 4096; - if (c.registration_timeout == 0) - c.registration_timeout = 90; - if (c.pingtime == 0) - c.pingtime = 120; + ConnectClass c(timeout, flood, allow, pingfreq, password, threshold, sendq, recvq, localmax, globalmax); conf->Classes.push_back(c); } else { - c.host = deny; - c.type = CC_DENY; + ConnectClass c(deny); conf->Classes.push_back(c); - conf->GetInstance()->Log(DEBUG,"Read connect class type DENY, host=%s",deny); } return true; diff --git a/src/users.cpp b/src/users.cpp index 45071d231..71c88ee85 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -1023,33 +1023,23 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, Instance->AddLocalClone(New); Instance->AddGlobalClone(New); - // set the registration timeout for this user - unsigned long class_regtimeout = 90; - int class_flood = 0; - long class_threshold = 5; - long class_sqmax = 262144; // 256kb - long class_rqmax = 4096; // 4k + ConnectClass* i = New->GetClass(); - for (ClassVector::iterator i = Instance->Config->Classes.begin(); i != Instance->Config->Classes.end(); i++) + Instance->Log(DEBUG,"Class=%08x", i); + + if ((!i) || (i->GetType() == CC_DENY)) { - if ((i->type == CC_ALLOW) && (match(ipaddr,i->host.c_str(),true))) - { - class_regtimeout = (unsigned long)i->registration_timeout; - class_flood = i->flood; - New->pingmax = i->pingtime; - class_threshold = i->threshold; - class_sqmax = i->sendqmax; - class_rqmax = i->recvqmax; - break; - } + userrec::QuitUser(Instance, New,"Unauthorised connection"); + return; } - New->nping = Instance->Time() + New->pingmax + Instance->Config->dns_timeout; - New->timeout = Instance->Time() + class_regtimeout; - New->flood = class_flood; - New->threshold = class_threshold; - New->sendqmax = class_sqmax; - New->recvqmax = class_rqmax; + New->pingmax = i->GetPingTime(); + New->nping = Instance->Time() + i->GetPingTime() + Instance->Config->dns_timeout; + New->timeout = Instance->Time() + i->GetRegTimeout(); + New->flood = i->GetFlood(); + New->threshold = i->GetThreshold(); + New->sendqmax = i->GetSendqMax(); + New->recvqmax = i->GetRecvqMax(); Instance->local_users.push_back(New); @@ -1104,7 +1094,7 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, New->WriteServ("NOTICE Auth :*** Looking up your hostname..."); } -long userrec::GlobalCloneCount() +unsigned long userrec::GlobalCloneCount() { clonemap::iterator x = ServerInstance->global_clones.find(this->GetIPString()); if (x != ServerInstance->global_clones.end()) @@ -1113,7 +1103,7 @@ long userrec::GlobalCloneCount() return 0; } -long userrec::LocalCloneCount() +unsigned long userrec::LocalCloneCount() { clonemap::iterator x = ServerInstance->local_clones.find(this->GetIPString()); if (x != ServerInstance->local_clones.end()) @@ -1127,30 +1117,30 @@ void userrec::FullConnect(CullList* Goners) ServerInstance->stats->statsConnects++; this->idle_lastmsg = ServerInstance->Time(); - ConnectClass a = this->GetClass(); + ConnectClass* a = this->GetClass(); - if (a.type == CC_DENY) + if ((!a) || (a->GetType() == CC_DENY)) { Goners->AddItem(this,"Unauthorised connection"); return; } - - if ((*(a.pass.c_str())) && (!this->haspassed)) + + if ((!a->GetPass().empty()) && (!this->haspassed)) { Goners->AddItem(this,"Invalid password"); return; } - if (this->LocalCloneCount() > a.maxlocal) + if (this->LocalCloneCount() > a->GetMaxLocal()) { Goners->AddItem(this, "No more connections allowed from your host via this connect class (local)"); - ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a.maxlocal, this->GetIPString()); + ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a->GetMaxLocal(), this->GetIPString()); return; } - else if (this->GlobalCloneCount() > a.maxglobal) + else if (this->GlobalCloneCount() > a->GetMaxGlobal()) { Goners->AddItem(this, "No more connections allowed from your host via this connect class (global)"); - ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal, this->GetIPString()); + ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a->GetMaxGlobal(), this->GetIPString()); return; } @@ -1926,15 +1916,20 @@ void userrec::SplitChanList(userrec* dest, const std::string &cl) * then their ip will be taken as 'priority' anyway, so for example, * will match joe!bloggs@localhost */ -ConnectClass& userrec::GetClass() +ConnectClass* userrec::GetClass() { for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++) { - if ((match(this->GetIPString(),i->host.c_str(),true)) || (match(this->host,i->host.c_str()))) - return *i; + ServerInstance->Log(DEBUG, "IP=%s, HOST=%s, CLASS=%s", this->GetIPString(), this->host,i->GetHost().c_str()); + if ((match(this->GetIPString(),i->GetHost().c_str(),true)) || (match(this->host,i->GetHost().c_str()))) + { + ServerInstance->Log(DEBUG, "Matches!"); + return &(*i); + } } - return *(ServerInstance->Config->Classes.begin()); + ServerInstance->Log(DEBUG, "You get nowt!"); + return NULL; } void userrec::PurgeEmptyChannels() -- cgit v1.2.3