]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_ident.cpp
Remove calls to ListModeBase::OnCleanup (deprecated, empty function)
[user/henk/code/inspircd.git] / src / modules / m_ident.cpp
index 314bd9b2700efa1a8f1ea10d97515a0bef3d7664..35084fd453a23be754804706cef5b8606edf649c 100644 (file)
@@ -1,16 +1,27 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2007, 2009 John Brooks <john.brooks@dereferenced.net>
+ *   Copyright (C) 2006-2008 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2005-2008 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
  *
- * This program is free but copyrighted software; see
- *         the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include "inspircd.h"
 
 /* $ModDesc: Provides support for RFC1413 ident lookups */
@@ -205,60 +216,50 @@ class IdentRequestSocket : public EventHandler
                char ibuf[MAXBUF];
                int recvresult = ServerInstance->SE->Recv(this, ibuf, MAXBUF-1, 0);
 
+               /* Close (but don't delete from memory) our socket
+                * and flag as done since the ident lookup has finished
+                */
+               Close();
+               done = true;
+
                /* Cant possibly be a valid response shorter than 3 chars,
                 * because the shortest possible response would look like: '1,1'
                 */
                if (recvresult < 3)
-               {
-                       Close();
-                       done = true;
                        return;
-               }
 
                ServerInstance->Logs->Log("m_ident",DEBUG,"ReadResponse()");
 
-               irc::sepstream sep(ibuf, ':');
-               std::string token;
-               for (int i = 0; sep.GetToken(token); i++)
+               /* Truncate at the first null character, but first make sure
+                * there is at least one null char (at the end of the buffer).
+                */
+               ibuf[recvresult] = '\0';
+               std::string buf(ibuf);
+               std::string::size_type lastcolon = buf.rfind(':');
+               if (lastcolon == std::string::npos)
+                       return;
+
+               /* Truncate the ident at any characters we don't like, skip leading spaces */
+               for (std::string::const_iterator i = buf.begin()+lastcolon+1; i != buf.end(); ++i)
                {
-                       /* We only really care about the 4th portion */
-                       if (i < 3)
-                               continue;
+                       if (result.size()+1 == ServerInstance->Config->Limits.IdentMax)
+                               /* Ident is getting too long */
+                               break;
 
-                       std::string ident;
+                       if (*i == ' ')
+                               continue;
 
-                       /* Truncate the ident at any characters we don't like, skip leading spaces */
-                       size_t k = 0;
-                       for (const char *j = token.c_str(); *j && (k < ServerInstance->Config->Limits.IdentMax + 1); j++)
+                       /* Add the next char to the result and see if it's still a valid ident,
+                        * according to IsIdent(). If it isn't, then erase what we just added and
+                        * we're done.
+                        */
+                       result += *i;
+                       if (!ServerInstance->IsIdent(result.c_str()))
                        {
-                               if (*j == ' ')
-                                       continue;
-
-                               /* Rules taken from InspIRCd::IsIdent */
-                               if (((*j >= 'A') && (*j <= '}')) || ((*j >= '0') && (*j <= '9')) || (*j == '-') || (*j == '.'))
-                               {
-                                       ident += *j;
-                                       continue;
-                               }
-
+                               result.erase(result.end()-1);
                                break;
                        }
-
-                       /* Re-check with IsIdent, in case that changes and this doesn't (paranoia!) */
-                       if (!ident.empty() && ServerInstance->IsIdent(ident.c_str()))
-                       {
-                               result = ident;
-                       }
-
-                       break;
                }
-
-               /* Close (but dont delete from memory) our socket
-                * and flag as done
-                */
-               Close();
-               done = true;
-               return;
        }
 };
 
@@ -288,9 +289,7 @@ class ModuleIdent : public Module
 
        virtual void OnRehash(User *user)
        {
-               ConfigReader Conf;
-
-               RequestTimeout = Conf.ReadInteger("ident", "timeout", 0, true);
+               RequestTimeout = ServerInstance->Config->ConfValue("ident")->getInt("timeout", 5);
                if (!RequestTimeout)
                        RequestTimeout = 5;
        }
@@ -377,7 +376,11 @@ class ModuleIdent : public Module
        {
                /* Module unloading, tidy up users */
                if (target_type == TYPE_USER)
-                       OnUserDisconnect((LocalUser*)item);
+               {
+                       LocalUser* user = IS_LOCAL((User*) item);
+                       if (user)
+                               OnUserDisconnect(user);
+               }
        }
 
        virtual void OnUserDisconnect(LocalUser *user)