]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Fix for bug #376 - FEATURE - (sorry w00t) - not backporting to stable.
[user/henk/code/inspircd.git] / src / users.cpp
index 97e2291be906a4a220e47ab72d20fd8f94573e8a..ccf506697142040fd0d4199e0796e12abe57bd5c 100644 (file)
@@ -164,8 +164,12 @@ UserResolver::UserResolver(InspIRCd* Instance, userrec* user, std::string to_res
        this->bound_fd = user->GetFd();
 }
 
-void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
+void UserResolver::OnLookupComplete(const std::string &result, unsigned int ttl, bool cached, int resultnum)
 {
+       /* We are only interested in the first matching result */
+       if (resultnum)
+               return;
+
        if ((!this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user))
        {
                this->bound_user->stored_host = result;
@@ -432,8 +436,8 @@ char* userrec::MakeHostIP()
 
 void userrec::CloseSocket()
 {
-       shutdown(this->fd,2);
-       close(this->fd);
+       ServerInstance->SE->Shutdown(this, 2);
+       ServerInstance->SE->Close(this);
 }
 
 char* userrec::GetFullHost()
@@ -723,11 +727,8 @@ void userrec::FlushWriteBuf()
                if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
                {
                        int old_sendq_length = sendq.length();
-#ifndef WIN32
-               int n_sent = write(this->fd, this->sendq.data(), this->sendq.length());
-#else
-               int n_sent = send(this->fd, (const char*)this->sendq.data(), this->sendq.length(), 0);
-#endif
+                       int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
+
                        if (n_sent == -1)
                        {
                                if (errno == EAGAIN)
@@ -923,16 +924,12 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached,
                return;
        }
 
+       /*
+        * Check connect class settings and initialise settings into userrec.
+        * This will be done again after DNS resolution. -- w00t
+        */
        New->CheckClass();
 
-       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);
 
        if ((Instance->local_users.size() > Instance->Config->SoftLimit) || (Instance->local_users.size() >= MAXCLIENTS))
@@ -1011,9 +1008,9 @@ unsigned long userrec::LocalCloneCount()
 /*
  * Check class restrictions
  */
-void userrec::CheckClass()
+void userrec::CheckClass(const std::string &explicit_class)
 {
-       ConnectClass* a = this->GetClass();
+       ConnectClass* a = this->GetClass(explicit_class);
 
        if ((!a) || (a->GetType() == CC_DENY))
        {
@@ -1032,11 +1029,19 @@ void userrec::CheckClass()
                ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s", a->GetMaxGlobal(), this->GetIPString());
                return;
        }
+
+       this->pingmax = a->GetPingTime();
+       this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
+       this->timeout = ServerInstance->Time() + a->GetRegTimeout();
+       this->flood = a->GetFlood();
+       this->threshold = a->GetThreshold();
+       this->sendqmax = a->GetSendqMax();
+       this->recvqmax = a->GetRecvqMax();
+       this->MaxChans = a->GetMaxChans();
 }
 
 void userrec::FullConnect()
 {
-       ServerInstance->Log(DEBUG,"FullConnect");
        ServerInstance->stats->statsConnects++;
        this->idle_lastmsg = ServerInstance->Time();
 
@@ -1117,8 +1122,6 @@ void userrec::FullConnect()
        FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
 
        ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s] [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString(), this->fullname);
-
-       ServerInstance->Log(DEBUG,"Exit FullConnect");
 }
 
 /** userrec::UpdateNick()
@@ -1848,27 +1851,42 @@ void userrec::SplitChanList(userrec* dest, const std::string &cl)
        }
 }
 
+unsigned int userrec::GetMaxChans()
+{
+       return this->MaxChans;
+}
 
 /* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
  * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
  * 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(const std::string &explicit_name)
 {
-       for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
+       if (!explicit_name.empty())
        {
-               if (((match(this->GetIPString(),i->GetHost().c_str(),true)) || (match(this->host,i->GetHost().c_str()))))
+               for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
                {
-                       if (i->GetPort())
+                       if (explicit_name == i->GetName())
+                               return &(*i);
+               }
+       }
+       else
+       {
+               for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
+               {
+                       if (((match(this->GetIPString(),i->GetHost().c_str(),true)) || (match(this->host,i->GetHost().c_str()))))
                        {
-                               if (this->GetPort() == i->GetPort())
-                                       return &(*i);
+                               if (i->GetPort())
+                               {
+                                       if (this->GetPort() == i->GetPort())
+                                               return &(*i);
+                                       else
+                                               continue;
+                               }
                                else
-                                       continue;
+                                       return &(*i);
                        }
-                       else
-                               return &(*i);
                }
        }
        return NULL;