]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/userprocess.cpp
'svn propset -R svn:eol-style CR *' Set to UNIX-style always. Binaries are auto skipp...
[user/henk/code/inspircd.git] / src / userprocess.cpp
index b27844fb6c654917a53fac8e407dae769cf3bb58..c2b2f0b83b521c1fd65173bbd7fa0e00791d9e19 100644 (file)
@@ -1,305 +1 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
- *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
- *
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
- *
- * ---------------------------------------------------
- */
-
-#include "inspircd.h"
-#include "configreader.h"
-#include "users.h"
-#include "modules.h"
-#include "wildcard.h"
-#include "xline.h"
-#include "socketengine.h"
-#include "command_parse.h"
-
-void InspIRCd::FloodQuitUser(userrec* current)
-{
-       this->Log(DEFAULT,"Excess flood from: %s@%s", current->ident, current->host);
-       this->SNO->WriteToSnoMask('f',"Excess flood from: %s%s%s@%s",
-                       current->registered == REG_ALL ? current->nick : "",
-                       current->registered == REG_ALL ? "!" : "", current->ident, current->host);
-       current->SetWriteError("Excess flood");
-       if (current->registered != REG_ALL)
-       {
-               XLines->add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString());
-               XLines->apply_lines(APPLY_ZLINES);
-       }
-}
-
-void InspIRCd::ProcessUser(userrec* cu)
-{
-       int result = EAGAIN;
-
-       if (cu->GetFd() == FD_MAGIC_NUMBER)
-               return;
-
-       if (this->Config->GetIOHook(cu->GetPort()))
-       {
-               int result2 = 0;
-               int MOD_RESULT = 0;
-
-               try
-               {
-                       MOD_RESULT = this->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->GetFd(),ReadBuffer,sizeof(ReadBuffer),result2);
-               }
-               catch (CoreException& modexcept)
-               {
-                       this->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
-               }
-
-               if (MOD_RESULT < 0)
-               {
-                       result = -EAGAIN;
-               }
-               else
-               {
-                       result = result2;
-               }
-       }
-       else
-       {
-               result = cu->ReadData(ReadBuffer, sizeof(ReadBuffer));
-       }
-
-       if ((result) && (result != -EAGAIN))
-       {
-               userrec *current;
-               int currfd;
-               int floodlines = 0;
-
-               this->stats->statsRecv += result;
-               /*
-                * perform a check on the raw buffer as an array (not a string!) to remove
-                * character 0 which is illegal in the RFC - replace them with spaces.
-                * XXX - no garauntee there's not \0's in the middle of the data,
-                *       and no reason for it to be terminated either. -- Om
-                */
-
-               for (int checker = 0; checker < result; checker++)
-               {
-                       if (ReadBuffer[checker] == 0)
-                               ReadBuffer[checker] = ' ';
-               }
-
-               if (result > 0)
-                       ReadBuffer[result] = '\0';
-
-               current = cu;
-               currfd = current->GetFd();
-
-               // add the data to the users buffer
-               if (result > 0)
-               {
-                       if (!current->AddBuffer(ReadBuffer))
-                       {
-                               // AddBuffer returned false, theres too much data in the user's buffer and theyre up to no good.
-                               if (current->registered == REG_ALL)
-                               {
-                                       // Make sure they arn't flooding long lines.
-                                       if (TIME > current->reset_due)
-                                       {
-                                               current->reset_due = TIME + current->threshold;
-                                               current->lines_in = 0;
-                                       }
-
-                                       current->lines_in++;
-
-                                       if (current->flood && current->lines_in > current->flood)
-                                               FloodQuitUser(current);
-                                       else
-                                       {
-                                               current->WriteServ("NOTICE %s :Your previous line was too long and was not delivered (Over %d chars) Please shorten it.", current->nick, MAXBUF-2);
-                                               current->recvq.clear();
-                                       }
-                               }
-                               else
-                                       FloodQuitUser(current);
-
-                               return;
-                       }
-
-                       // while there are complete lines to process...
-                       while (current->BufferIsReady())
-                       {
-                               if (TIME > current->reset_due)
-                               {
-                                       current->reset_due = TIME + current->threshold;
-                                       current->lines_in = 0;
-                               }
-
-                               if (++current->lines_in > current->flood && current->flood)
-                               {
-                                       FloodQuitUser(current);
-                                       return;
-                               }
-
-                               if ((++floodlines > current->flood) && (current->flood != 0))
-                               {
-                                       FloodQuitUser(current);
-                                       return;
-                               }
-
-                               // use GetBuffer to copy single lines into the sanitized string
-                               std::string single_line = current->GetBuffer();
-                               current->bytes_in += single_line.length();
-                               current->cmds_in++;
-                               if (single_line.length() > MAXBUF - 2)  /* MAXBUF is 514 to allow for neccessary line terminators */
-                                       single_line.resize(MAXBUF - 2); /* So to trim to 512 here, we use MAXBUF - 2 */
-
-                               EventHandler* old_comp = this->SE->GetRef(currfd);
-
-                               this->Parser->ProcessBuffer(single_line,current);
-                               /*
-                                * look for the user's record in case it's changed... if theyve quit,
-                                * we cant do anything more with their buffer, so bail.
-                                * there used to be an ugly, slow loop here. Now we have a reference
-                                * table, life is much easier (and FASTER)
-                                */
-                               EventHandler* new_comp = this->SE->GetRef(currfd);
-
-                               if (new_comp != old_comp)
-                                       return;
-                       }
-
-                       return;
-               }
-
-               if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))
-               {
-                       cu->SetWriteError(strerror(errno));
-                       return;
-               }
-       }
-
-       // result EAGAIN means nothing read
-       else if ((result == EAGAIN) || (result == -EAGAIN))
-       {
-               /* do nothing */
-       }
-       else if (result == 0)
-       {
-               cu->SetWriteError("Connection closed");
-               return;
-       }
-}
-
-/**
- * This function is called once a second from the mainloop.
- * It is intended to do background checking on all the user structs, e.g.
- * stuff like ping checks, registration timeouts, etc.
- */
-void InspIRCd::DoBackgroundUserStuff(time_t TIME)
-{
-       /* Is it time yet? */
-       if (TIME < next_call)
-               return;
-       else
-       {
-               /* Time we actually need to call this again */
-               const time_t DUMMY_VALUE = 32768;
-               next_call = TIME + DUMMY_VALUE;
-
-               /* XXX: IT IS NOT SAFE TO USE AN ITERATOR HERE. DON'T EVEN THINK ABOUT IT. */
-               for (unsigned long count2 = 0; count2 != this->local_users.size(); count2++)
-               {
-                       if (count2 >= this->local_users.size())
-                               break;
-
-                       userrec* curr = this->local_users[count2];
-
-                       if (curr)
-                       {
-                               /*
-                                * registration timeout -- didnt send USER/NICK/HOST
-                                * in the time specified in their connection class.
-                                */
-                               if ((TIME > curr->timeout) && (curr->registered != REG_ALL))
-                               {
-                                       curr->muted = true;
-                                       GlobalCulls.AddItem(curr,"Registration timeout");
-                                       continue;
-                               }
-                               else
-                               {
-                                       if ((curr->registered != REG_ALL) && (next_call > (time_t)curr->timeout))
-                                               next_call = curr->timeout;
-                               }
-
-                               /*
-                                * user has signed on with USER/NICK/PASS, and dns has completed, all the modules
-                                * say this user is ok to proceed, fully connect them.
-                                */
-                               bool ready = AllModulesReportReady(curr);
-                               if ((TIME > curr->signon) && (curr->registered == REG_NICKUSER) && (ready))
-                               {
-                                       if (!curr->dns_done)
-                                       {
-                                               curr->WriteServ("NOTICE Auth :*** Could not resolve your hostname: Request timed out; using your IP address (%s) instead.", curr->GetIPString());
-                                               curr->dns_done = true;
-                                       }
-                                       this->stats->statsDnsBad++;
-                                       curr->FullConnect();
-                                       continue;
-                               }
-                               else
-                               {
-                                       if ((curr->registered == REG_NICKUSER) && (ready) && (next_call > curr->signon))
-                                               next_call = curr->signon;
-                               }
-
-                               if ((curr->dns_done) && (curr->registered == REG_NICKUSER) && (ready))
-                               {
-                                       curr->FullConnect();
-                                       continue;
-                               }
-                               else
-                               {
-                                       if ((curr->registered == REG_NICKUSER) && (ready) && (next_call > curr->signon + this->Config->dns_timeout))
-                                               next_call = curr->signon + this->Config->dns_timeout;
-                               }
-
-                               // It's time to PING this user. Send them a ping.
-                               if ((TIME > curr->nping) && (curr->registered == REG_ALL))
-                               {
-                                       // This user didn't answer the last ping, remove them
-                                       if (!curr->lastping)
-                                       {
-                                               /* Everybody loves boobies. */
-                                               time_t time = this->Time(false) - (curr->nping - curr->pingmax);
-                                               char message[MAXBUF];
-                                               snprintf(message, MAXBUF, "Ping timeout: %ld second%s", time, time > 1 ? "s" : "");
-                                               curr->muted = true;
-                                               GlobalCulls.AddItem(curr, message);
-                                               curr->lastping = 1;
-                                               curr->nping = TIME+curr->pingmax;
-                                               continue;
-                                       }
-                                       curr->Write("PING :%s",this->Config->ServerName);
-                                       curr->lastping = 0;
-                                       curr->nping = TIME+curr->pingmax;
-                               }
-                               else
-                               {
-                                       if ((curr->registered == REG_ALL) && (next_call > curr->nping))
-                                               next_call = curr->nping;
-                               }
-                       }
-               }
-
-               /* If theres nothing to do, trigger in the next second, something might come up */
-               time_t delta = next_call - TIME;
-               if (delta == DUMMY_VALUE)
-               {
-                       next_call = TIME + 1;
-                       delta = 1;
-               }
-       }
-}
+/*       +------------------------------------+\r *       | Inspire Internet Relay Chat Daemon |\r *       +------------------------------------+\r *\r *  InspIRCd: (C) 2002-2007 InspIRCd Development Team\r * See: http://www.inspircd.org/wiki/index.php/Credits\r *\r * This program is free but copyrighted software; see\r *            the file COPYING for details.\r *\r * ---------------------------------------------------\r */\r\r#include "inspircd.h"\r#include "configreader.h"\r#include "users.h"\r#include "modules.h"\r#include "wildcard.h"\r#include "xline.h"\r#include "socketengine.h"\r#include "command_parse.h"\r\rvoid InspIRCd::FloodQuitUser(userrec* current)\r{\r   this->Log(DEFAULT,"Excess flood from: %s@%s", current->ident, current->host);\r  this->SNO->WriteToSnoMask('f',"Excess flood from: %s%s%s@%s",\r                  current->registered == REG_ALL ? current->nick : "",\r                   current->registered == REG_ALL ? "!" : "", current->ident, current->host);\r     current->SetWriteError("Excess flood");\r        if (current->registered != REG_ALL)\r    {\r              XLines->add_zline(120,this->Config->ServerName,"Flood from unregistered connection",current->GetIPString());\r           XLines->apply_lines(APPLY_ZLINES);\r     }\r}\r\rvoid InspIRCd::ProcessUser(userrec* cu)\r{\r int result = EAGAIN;\r\r  if (cu->GetFd() == FD_MAGIC_NUMBER)\r            return;\r\r       if (this->Config->GetIOHook(cu->GetPort()))\r    {\r              int result2 = 0;\r               int MOD_RESULT = 0;\r\r           try\r            {\r                      MOD_RESULT = this->Config->GetIOHook(cu->GetPort())->OnRawSocketRead(cu->GetFd(),ReadBuffer,sizeof(ReadBuffer),result2);\r               }\r              catch (CoreException& modexcept)\r               {\r                      this->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());\r           }\r\r             if (MOD_RESULT < 0)\r            {\r                      result = -EAGAIN;\r              }\r              else\r           {\r                      result = result2;\r              }\r      }\r      else\r   {\r              result = cu->ReadData(ReadBuffer, sizeof(ReadBuffer));\r }\r\r     if ((result) && (result != -EAGAIN))\r   {\r              userrec *current;\r              int currfd;\r            int floodlines = 0;\r\r           this->stats->statsRecv += result;\r              /*\r              * perform a check on the raw buffer as an array (not a string!) to remove\r              * character 0 which is illegal in the RFC - replace them with spaces.\r          * XXX - no garauntee there's not \0's in the middle of the data,\r               *       and no reason for it to be terminated either. -- Om\r            */\r\r           for (int checker = 0; checker < result; checker++)\r             {\r                      if (ReadBuffer[checker] == 0)\r                          ReadBuffer[checker] = ' ';\r             }\r\r             if (result > 0)\r                        ReadBuffer[result] = '\0';\r\r            current = cu;\r          currfd = current->GetFd();\r\r            // add the data to the users buffer\r            if (result > 0)\r                {\r                      if (!current->AddBuffer(ReadBuffer))\r                   {\r                              // AddBuffer returned false, theres too much data in the user's buffer and theyre up to no good.\r                               if (current->registered == REG_ALL)\r                            {\r                                      // Make sure they arn't flooding long lines.\r                                   if (TIME > current->reset_due)\r                                 {\r                                              current->reset_due = TIME + current->threshold;\r                                                current->lines_in = 0;\r                                 }\r\r                                     current->lines_in++;\r\r                                  if (current->flood && current->lines_in > current->flood)\r                                              FloodQuitUser(current);\r                                        else\r                                   {\r                                              current->WriteServ("NOTICE %s :Your previous line was too long and was not delivered (Over %d chars) Please shorten it.", current->nick, MAXBUF-2);\r                                            current->recvq.clear();\r                                        }\r                              }\r                              else\r                                   FloodQuitUser(current);\r\r                               return;\r                        }\r\r                     // while there are complete lines to process...\r                        while (current->BufferIsReady())\r                       {\r                              if (TIME > current->reset_due)\r                         {\r                                      current->reset_due = TIME + current->threshold;\r                                        current->lines_in = 0;\r                         }\r\r                             if (++current->lines_in > current->flood && current->flood)\r                            {\r                                      FloodQuitUser(current);\r                                        return;\r                                }\r\r                             if ((++floodlines > current->flood) && (current->flood != 0))\r                          {\r                                      FloodQuitUser(current);\r                                        return;\r                                }\r\r                             // use GetBuffer to copy single lines into the sanitized string\r                                std::string single_line = current->GetBuffer();\r                                current->bytes_in += single_line.length();\r                             current->cmds_in++;\r                            if (single_line.length() > MAXBUF - 2)  /* MAXBUF is 514 to allow for neccessary line terminators */\r                                   single_line.resize(MAXBUF - 2); /* So to trim to 512 here, we use MAXBUF - 2 */\r\r                               EventHandler* old_comp = this->SE->GetRef(currfd);\r\r                            this->Parser->ProcessBuffer(single_line,current);\r                              /*\r                              * look for the user's record in case it's changed... if theyve quit,\r                           * we cant do anything more with their buffer, so bail.\r                                 * there used to be an ugly, slow loop here. Now we have a reference\r                            * table, life is much easier (and FASTER)\r                              */\r                            EventHandler* new_comp = this->SE->GetRef(currfd);\r\r                            if (new_comp != old_comp)\r                                      return;\r                        }\r\r                     return;\r                }\r\r             if ((result == -1) && (errno != EAGAIN) && (errno != EINTR))\r           {\r                      cu->SetWriteError(strerror(errno));\r                    return;\r                }\r      }\r\r     // result EAGAIN means nothing read\r    else if ((result == EAGAIN) || (result == -EAGAIN))\r    {\r              /* do nothing */\r       }\r      else if (result == 0)\r  {\r              cu->SetWriteError("Connection closed");\r                return;\r        }\r}\r\r/**\r * This function is called once a second from the mainloop.\r * It is intended to do background checking on all the user structs, e.g.\r * stuff like ping checks, registration timeouts, etc.\r */\rvoid InspIRCd::DoBackgroundUserStuff(time_t TIME)\r{\r  /* Is it time yet? */\r  if (TIME < next_call)\r          return;\r        else\r   {\r              /* Time we actually need to call this again */\r         const time_t DUMMY_VALUE = 32768;\r              next_call = TIME + DUMMY_VALUE;\r\r               /* XXX: IT IS NOT SAFE TO USE AN ITERATOR HERE. DON'T EVEN THINK ABOUT IT. */\r          for (unsigned long count2 = 0; count2 != this->local_users.size(); count2++)\r           {\r                      if (count2 >= this->local_users.size())\r                                break;\r\r                        userrec* curr = this->local_users[count2];\r\r                    if (curr)\r                      {\r                              /*\r                              * registration timeout -- didnt send USER/NICK/HOST\r                            * in the time specified in their connection class.\r                             */\r                            if ((TIME > curr->timeout) && (curr->registered != REG_ALL))\r                           {\r                                      curr->muted = true;\r                                    GlobalCulls.AddItem(curr,"Registration timeout");\r                                      continue;\r                              }\r                              else\r                           {\r                                      if ((curr->registered != REG_ALL) && (next_call > (time_t)curr->timeout))\r                                              next_call = curr->timeout;\r                             }\r\r                             /*\r                              * user has signed on with USER/NICK/PASS, and dns has completed, all the modules\r                               * say this user is ok to proceed, fully connect them.\r                          */\r                            bool ready = AllModulesReportReady(curr);\r                              if ((TIME > curr->signon) && (curr->registered == REG_NICKUSER) && (ready))\r                            {\r                                      if (!curr->dns_done)\r                                   {\r                                              curr->WriteServ("NOTICE Auth :*** Could not resolve your hostname: Request timed out; using your IP address (%s) instead.", curr->GetIPString());\r                                              curr->dns_done = true;\r                                 }\r                                      this->stats->statsDnsBad++;\r                                    curr->FullConnect();\r                                   continue;\r                              }\r                              else\r                           {\r                                      if ((curr->registered == REG_NICKUSER) && (ready) && (next_call > curr->signon))\r                                               next_call = curr->signon;\r                              }\r\r                             if ((curr->dns_done) && (curr->registered == REG_NICKUSER) && (ready))\r                         {\r                                      curr->FullConnect();\r                                   continue;\r                              }\r                              else\r                           {\r                                      if ((curr->registered == REG_NICKUSER) && (ready) && (next_call > curr->signon + this->Config->dns_timeout))\r                                           next_call = curr->signon + this->Config->dns_timeout;\r                          }\r\r                             // It's time to PING this user. Send them a ping.\r                              if ((TIME > curr->nping) && (curr->registered == REG_ALL))\r                             {\r                                      // This user didn't answer the last ping, remove them\r                                  if (!curr->lastping)\r                                   {\r                                              /* Everybody loves boobies. */\r                                         time_t time = this->Time(false) - (curr->nping - curr->pingmax);\r                                               char message[MAXBUF];\r                                          snprintf(message, MAXBUF, "Ping timeout: %ld second%s", time, time > 1 ? "s" : "");\r                                            curr->muted = true;\r                                            GlobalCulls.AddItem(curr, message);\r                                            curr->lastping = 1;\r                                            curr->nping = TIME+curr->pingmax;\r                                              continue;\r                                      }\r                                      curr->Write("PING :%s",this->Config->ServerName);\r                                      curr->lastping = 0;\r                                    curr->nping = TIME+curr->pingmax;\r                              }\r                              else\r                           {\r                                      if ((curr->registered == REG_ALL) && (next_call > curr->nping))\r                                                next_call = curr->nping;\r                               }\r                      }\r              }\r\r             /* If theres nothing to do, trigger in the next second, something might come up */\r             time_t delta = next_call - TIME;\r               if (delta == DUMMY_VALUE)\r              {\r                      next_call = TIME + 1;\r                  delta = 1;\r             }\r      }\r}\r
\ No newline at end of file