]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/uid.cpp
Some more safety checks to catch out invalid client introductions (e.g. from atheme...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / uid.cpp
index 7b7a477f28bfd454ae58981763bdc8c6531a2054..9ddc154c6c4e697f13ef0fe45d7a99e6445629c9 100644 (file)
  */
 
 #include "inspircd.h"
-#include "commands/cmd_whois.h"
-#include "commands/cmd_stats.h"
-#include "socket.h"
-#include "xline.h"
-#include "transport.h"
-#include "m_hash.h"
-#include "socketengine.h"
 
 #include "m_spanningtree/main.h"
 #include "m_spanningtree/utils.h"
@@ -55,13 +48,22 @@ bool TreeSocket::ParseUID(const std::string &source, std::deque<std::string> &pa
                this->WriteLine(std::string(":")+this->ServerInstance->Config->GetSID()+" KILL "+params[0]+" :Invalid client introduction (Unknown server "+source+")");
                return true;
        }
-
        /* Check parameters for validity before introducing the client, discovered by dmb */
-       if (!age_t)
+       else if (!age_t)
        {
                this->WriteLine(std::string(":")+this->ServerInstance->Config->GetSID()+" KILL "+params[0]+" :Invalid client introduction (Invalid TS?)");
                return true;
        }
+       else if (!signon)
+       {
+               this->WriteLine(std::string(":")+this->ServerInstance->Config->GetSID()+" KILL "+params[0]+" :Invalid client introduction (Invalid signon?)");
+               return true;
+       }
+       else if (params[8][0] != '+')
+       {
+               this->WriteLine(std::string(":")+this->ServerInstance->Config->GetSID()+" KILL "+params[0]+" :Invalid client introduction (Malformed MODE sequence?)");
+               return true;
+       }
 
        /* check for collision */
        user_hash::iterator iter = this->ServerInstance->Users->clientlist->find(params[2]);
@@ -124,10 +126,24 @@ bool TreeSocket::ParseUID(const std::string &source, std::deque<std::string> &pa
                {
                        if (mh->GetNumParams(true))
                        {
+                               /* IMPORTANT NOTE:
+                                * All modes are assumed to succeed here as they are being set by a remote server.
+                                * Modes CANNOT FAIL here. If they DO fail, then the failure is ignored. This is important
+                                * to note as all but one modules currently cannot ever fail in this situation, except for
+                                * m_servprotect which specifically works this way to prevent the mode being set ANYWHERE
+                                * but here, at client introduction. You may safely assume this behaviour is standard and
+                                * will not change in future versions if you want to make use of this protective behaviour
+                                * yourself.
+                                */
                                if (paramptr < params.size() - 1)
                                        mh->OnModeChange(_new, _new, NULL, params[paramptr++], true);
                                else
-                                       ServerInstance->Logs->Log("m_spanningtree", DEBUG, "Warning: Broken UID command, expected a parameter for user mode '%c' but there aren't enough parameters in the command!", *v);
+                               {
+                                       this->WriteLine(std::string(":")+this->ServerInstance->Config->GetSID()+" KILL "+params[0]+" :Broken UID command, expected a parameter for user mode '"+(*v)+"' but there aren't enough parameters in the command!");
+                                       this->ServerInstance->Users->clientlist->erase(params[0]);
+                                       delete _new;
+                                       return true;
+                               }
                        }
                        else
                                mh->OnModeChange(_new, _new, NULL, empty, true);
@@ -135,7 +151,12 @@ bool TreeSocket::ParseUID(const std::string &source, std::deque<std::string> &pa
                        mh->ChangeCount(1);
                }
                else
-                       ServerInstance->Logs->Log("m_spanningtree", DEBUG, "Warning: Broken UID command, unknown user mode '%c' in the mode string!", *v);
+               {
+                       this->WriteLine(std::string(":")+this->ServerInstance->Config->GetSID()+" KILL "+params[0]+" :Warning: Broken UID command, unknown user mode '"+(*v)+"' in the mode string!");
+                       this->ServerInstance->Users->clientlist->erase(params[0]);
+                       delete _new;
+                       return true;
+               }
        }
 
        //_new->ProcessNoticeMasks(params[7].c_str());