]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Added CAPAB checking to prevent some obvious n00biness that may occur
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 21 Dec 2005 14:47:44 +0000 (14:47 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Wed, 21 Dec 2005 14:47:44 +0000 (14:47 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2598 e03df62e-2008-0410-955e-edbf42e46eb7

src/modules/m_spanningtree.cpp

index e6b9b2bb2b7ee897a4a4614bf3a0b321fcf3a5bc..fe316977b41e79e79585005f0a32b313ed1b8139 100644 (file)
@@ -569,6 +569,7 @@ class TreeSocket : public InspSocket
                : InspSocket(newfd, ip)
        {
                this->LinkState = WAIT_AUTH_1;
+               this->SendCapabilities();
        }
 
        void InitAES(std::string key,std::string SName)
@@ -621,6 +622,7 @@ class TreeSocket : public InspSocket
                                                        this->InitAES(x->EncryptionKey,x->Name);
                                                }
                                        }
+                                       this->SendCapabilities();
                                        /* found who we're supposed to be connecting to, send the neccessary gubbins. */
                                        this->WriteLine("SERVER "+Srv->GetServerName()+" "+x->SendPass+" 0 :"+Srv->GetServerDescription());
                                        return true;
@@ -677,6 +679,51 @@ class TreeSocket : public InspSocket
                }
        }
 
+       std::string MyCapabilities()
+       {
+               ServerConfig* Config = Srv->GetConfig();
+               std::vector<std::string> modlist;
+               std::string capabilities = "";
+
+                for (int i = 0; i <= MODCOUNT; i++)
+                {
+                       if ((modules[i]->GetVersion().Flags & VF_STATIC) || (modules[i]->GetVersion().Flags & VF_COMMON))
+                               modlist.push_back(Config->module_names[i]);
+                }
+               sort(modlist.begin(),modlist.end());
+               for (unsigned int i = 0; i < modlist.size(); i++)
+               {
+                       if (i)
+                               capabilities = capabilities + ",";
+                       capabilities = capabilities + modlist[i];
+               }
+               return capabilities;
+       }
+       
+       void SendCapabilities()
+       {
+               this->WriteLine("CAPAB "+MyCapabilities());
+       }
+
+       bool Capab(std::deque<std::string> params)
+       {
+               if (params.size() != 1)
+               {
+                       this->WriteLine("ERROR :Invalid number of parameters for CAPAB");
+                       return false;
+               }
+               if (params[0] != this->MyCapabilities())
+               {
+                       WriteOpers("*** \2ERROR\2: Server '%s' does not have the same set of modules loaded, cannot link!");
+                       WriteOpers("*** Our networked module set is: '%s'",this->MyCapabilities().c_str());
+                       WriteOpers("*** Other server's networked module set is: '%s'",params[0].c_str());
+                       WriteOpers("*** These lists must match exactly on both servers. Please correct these errors, and try again.");
+                       this->WriteLine("ERROR :CAPAB mismatch; My capabilities: '"+this->MyCapabilities()+"'");
+                       return false;
+               }
+               return true;
+       }
+
        /* This function forces this server to quit, removing this server
         * and any users on it (and servers and users below that, etc etc).
         * It's very slow and pretty clunky, but luckily unless your network
@@ -1774,6 +1821,10 @@ class TreeSocket : public InspSocket
                                        this->WriteLine("ERROR :Client connections to this port are prohibited.");
                                        return false;
                                }
+                               else if (command == "CAPAB")
+                               {
+                                       return this->Capab(params);
+                               }
                                else
                                {
                                        this->WriteLine("ERROR :Invalid command in negotiation phase.");
@@ -1807,6 +1858,10 @@ class TreeSocket : public InspSocket
                                {
                                        return this->Error(params);
                                }
+                               else if (command == "CAPAB")
+                               {
+                                       return this->Capab(params);
+                               }
                                
                        break;
                        case LISTENER: