]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treesocket2.cpp
Remove redundant PriorityState, enum Priority does the exact same thing.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
index 8b3fbf2fb68b786ed493742fbf325674560d50c0..c006344ba9bcc2b0c5bb88c717618395502b1426 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
@@ -173,10 +173,11 @@ bool TreeSocket::ProcessLine(std::string &line)
                                        }
                                }
                                this->LinkState = CONNECTED;
-                               Link* lnk = Utils->FindLink(InboundServerName);
 
                                Utils->timeoutlist.erase(this);
 
+                               Link* lnk = Utils->FindLink(InboundServerName);
+
                                Node = new TreeServer(this->Utils, this->ServerInstance, InboundServerName, InboundDescription, InboundSID, Utils->TreeRoot, this, lnk ? lnk->Hidden : false);
 
                                if (Node->DuplicateID())
@@ -247,14 +248,25 @@ bool TreeSocket::ProcessLine(std::string &line)
                                 * When would this be seen?
                                 * Well, hopefully never. It could be caused by race conditions, bugs, or
                                 * "miscreant" servers, though, so let's check anyway. -- w
+                                *
+                                * We also check here for totally invalid prefixes (prefixes that are neither
+                                * a valid SID or a valid UUID, so that invalid UUID or SID never makes it
+                                * to the higher level functions. -- B
                                 */
                                std::string direction = prefix;
 
                                User *t = this->ServerInstance->FindUUID(prefix);
                                if (t)
                                {
+                                       /* Find UID */
                                        direction = t->server;
                                }
+                               else if (!this->Utils->FindServer(direction))
+                               {
+                                       /* Find SID */
+                                       ServerInstance->Logs->Log("m_spanningtree",DEFAULT,"Protocol violation: Invalid prefix '%s' from connection '%s'", direction.c_str(), this->GetName().c_str());
+                                       return true;
+                               }
 
                                TreeServer* route_back_again = Utils->BestRouteTo(direction);
                                if ((!route_back_again) || (route_back_again->GetSocket() != this))
@@ -433,13 +445,24 @@ bool TreeSocket::ProcessLine(std::string &line)
                                if (params.size() == 3)
                                {
                                        TreeServer* pf = Utils->FindServer(prefix);
-                                       User* user = this->ServerInstance->FindNick(params[1]);
-                                       Channel* chan = this->ServerInstance->FindChan(params[0]);
-                                       if (pf && user && chan)
+                                       if (pf)
                                        {
-                                               if (!chan->ServerKickUser(user, params[2].c_str(), false, pf->GetName().c_str()))
-                                                       /* Yikes, the channels gone! */
-                                                       delete chan;
+                                               irc::commasepstream nicks(params[1]);
+                                               std::string nick;
+                                               Channel* chan = this->ServerInstance->FindChan(params[0]);
+                                               if (chan)
+                                               {
+                                                       while (nicks.GetToken(nick))
+                                                       {
+                                                               User* user = this->ServerInstance->FindNick(nick);
+                                                               if (user)
+                                                               {
+                                                                       if (!chan->ServerKickUser(user, params[2].c_str(), false, pf->GetName().c_str()))
+                                                                               /* Yikes, the channels gone! */
+                                                                               delete chan;
+                                                               }
+                                                       }
+                                               }
                                        }
                                }
 
@@ -474,7 +497,18 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                if (params.size() >= 2)
                                {
+                                       std::string oldprefix;
+                                       if (!ServerSource)
+                                       {
+                                               oldprefix = prefix;
+                                               User *u = ServerInstance->FindNick(prefix);
+                                               if (!u)
+                                                       return true;
+                                               prefix = u->nick;
+                                       }
+
                                        ServerInstance->SNO->WriteToSnoMask(*(params[0].c_str()), "From " + (ServerSource ? ServerSource->GetName().c_str() : prefix) + ": "+ params[1]);
+                                       prefix = oldprefix;
                                        return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
                                }
 
@@ -533,13 +567,17 @@ bool TreeSocket::ProcessLine(std::string &line)
                                 * Not a special s2s command. Emulate the user doing it.
                                 * This saves us having a huge ugly command parser again.
                                 */
-                               User *who = this->ServerInstance->FindUUID(prefix);
+                               Userwho = this->ServerInstance->FindUUID(prefix);
 
                                if (!who)
                                {
-                                       // this looks ugly because command is an irc::string
-                                       this->SendError("Command (" + std::string(command.c_str()) + ") from unknown prefix (" + prefix + ")! Dropping link.");
-                                       return false;
+                                       /* this looks ugly because command is an irc::string
+                                        * It is important that we dont close the link here, unknown prefix can occur
+                                        * due to various race conditions such as the KILL message for a user somehow
+                                        * crossing the users QUIT further upstream from the server. Thanks jilles!
+                                        */
+                                       ServerInstance->Logs->Log("m_spanningtree", DEBUG, "Command " + std::string(command.c_str()) + " from unknown prefix " + prefix + "! Dropping entire command.");
+                                       return true;
                                }
 
                                if (command == "NICK")
@@ -620,7 +658,7 @@ void TreeSocket::OnTimeout()
 {
        if (this->LinkState == CONNECTING)
        {
-               Utils->Creator->RemoteMessage(NULL, "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
+               this->ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
                Link* MyLink = Utils->FindLink(myhost);
                if (MyLink)
                        Utils->DoFailOver(MyLink);
@@ -649,11 +687,10 @@ void TreeSocket::OnClose()
 
        if (!quitserver.empty())
        {
-               Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' failed.",quitserver.c_str());
+               this->ServerInstance->SNO->WriteToSnoMask('l', "Connection to '\2%s\2' failed.",quitserver.c_str());
+
                time_t server_uptime = ServerInstance->Time() - this->age;
                if (server_uptime)
-                       Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
+                               this->ServerInstance->SNO->WriteToSnoMask('l', "Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
        }
 }
-
-