summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/users.h93
-rw-r--r--src/cmd_pass.cpp7
-rw-r--r--src/cmd_stats.cpp5
-rw-r--r--src/configreader.cpp36
-rw-r--r--src/users.cpp69
5 files changed, 121 insertions, 89 deletions
diff --git a/include/users.h b/include/users.h
index a2d094734..8a7fa1aeb 100644
--- a/include/users.h
+++ b/include/users.h
@@ -78,48 +78,113 @@ class UserResolver : public Resolver
*/
class ConnectClass : public classbase
{
- public:
+ private:
/** Type of line, either CC_ALLOW or CC_DENY
*/
char type;
/** Max time to register the connection in seconds
*/
- int registration_timeout;
+ unsigned int registration_timeout;
/** Number of lines in buffer before excess flood is triggered
*/
- int flood;
+ unsigned int flood;
/** Host mask for this line
*/
std::string host;
/** Number of seconds between pings for this line
*/
- int pingtime;
+ unsigned int pingtime;
/** (Optional) Password for this line
*/
std::string pass;
/** Threshold value for flood disconnect
*/
- int threshold;
+ unsigned int threshold;
/** Maximum size of sendq for users in this class (bytes)
*/
- long sendqmax;
+ unsigned long sendqmax;
/** Maximum size of recvq for users in this class (bytes)
*/
- long recvqmax;
+ unsigned long recvqmax;
/** Local max when connecting by this connection class
*/
- long maxlocal;
+ unsigned long maxlocal;
/** Global max when connecting by this connection class
*/
- long maxglobal;
-
- ConnectClass() : registration_timeout(0), flood(0), host(""), pingtime(0), pass(""), threshold(0), sendqmax(0), recvqmax(0)
+ unsigned long maxglobal;
+
+public:
+
+ ConnectClass() : type(CC_DENY), registration_timeout(0), flood(0), host(""), pingtime(0), pass(""),
+ threshold(0), sendqmax(0), recvqmax(0), maxlocal(0), maxglobal(0) { }
+
+ ConnectClass(unsigned int timeout, unsigned int fld, const std::string &hst, unsigned int ping,
+ const std::string &pas, unsigned int thres, unsigned long sendq, unsigned long recvq,
+ unsigned long maxl, unsigned long maxg) :
+ type(CC_ALLOW), registration_timeout(timeout), flood(fld), host(hst), pingtime(ping), pass(pas),
+ threshold(thres), sendqmax(sendq), recvqmax(recvq), maxlocal(maxl), maxglobal(maxg) { }
+
+ ConnectClass(const std::string &hst) : type(CC_DENY), registration_timeout(0), flood(0), host(hst), pingtime(0),
+ pass(""), threshold(0), sendqmax(0), recvqmax(0), maxlocal(0), maxglobal(0) { }
+
+ char GetType()
+ {
+ return (type == CC_ALLOW ? CC_ALLOW : CC_DENY);
+ }
+
+ unsigned int GetRegTimeout()
+ {
+ return (registration_timeout ? registration_timeout : 90);
+ }
+
+ unsigned int GetFlood()
+ {
+ return (threshold ? flood : 999);
+ }
+
+ const std::string& GetHost()
+ {
+ return host;
+ }
+
+ unsigned int GetPingTime()
+ {
+ return (pingtime ? pingtime : 120);
+ }
+
+ const std::string& GetPass()
+ {
+ return pass;
+ }
+
+ unsigned int GetThreshold()
+ {
+ return (threshold ? threshold : 1);
+ }
+
+ unsigned long GetSendqMax()
+ {
+ return (sendqmax ? sendqmax : 262114);
+ }
+
+ unsigned long GetRecvqMax()
+ {
+ return (recvqmax ? recvqmax : 4096);
+ }
+
+ unsigned long GetMaxLocal()
+ {
+ return (maxlocal ? maxlocal : 1);
+ }
+
+ unsigned long GetMaxGlobal()
{
+ return (maxglobal ? maxglobal : 1);
}
};
@@ -593,12 +658,12 @@ class userrec : public connection
/** Return the number of global clones of this user
* @return The global clone count of this user
*/
- long GlobalCloneCount();
+ unsigned long GlobalCloneCount();
/** Return the number of local clones of this user
* @return The local clone count of this user
*/
- long LocalCloneCount();
+ unsigned long LocalCloneCount();
/** Write text to this user, appending CR/LF.
* @param text A std::string to send to the user
@@ -745,7 +810,7 @@ class userrec : public connection
/** Get the connect class which matches this user's host or IP address
* @return A reference to this user's connect class
*/
- ConnectClass& GetClass();
+ ConnectClass* GetClass();
/** Show the message of the day to this user
*/
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,
* <connect allow="127.0.0.1"> 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()