]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree.cpp
Checks for timestamps, boot server off and abort if time delay > 10 mins (the safe...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree.cpp
index f927ac044185841290ffd9e07329043b5d39c189..b5584b5321b2f20575fb28451d583646db48bb45 100644 (file)
@@ -802,7 +802,7 @@ class TreeSocket : public InspSocket
         * is having a REAL bad hair day, this function shouldnt be called
         * too many times a month ;-)
         */
-       void SquitServer(TreeServer* Current, CullList* Goners)
+       void SquitServer(std::string &from, TreeServer* Current, CullList* Goners)
        {
                /* recursively squit the servers attached to 'Current'.
                 * We're going backwards so we don't remove users
@@ -811,7 +811,7 @@ class TreeSocket : public InspSocket
                for (unsigned int q = 0; q < Current->ChildCount(); q++)
                {
                        TreeServer* recursive_server = Current->GetChild(q);
-                       this->SquitServer(recursive_server,Goners);
+                       this->SquitServer(from,recursive_server,Goners);
                }
                /* Now we've whacked the kids, whack self */
                num_lost_servers++;
@@ -819,8 +819,7 @@ class TreeSocket : public InspSocket
                {
                        if (!strcasecmp(u->second->server,Current->GetName().c_str()))
                        {
-                               std::string qreason = Current->GetName()+" "+std::string(Srv->GetServerName());
-                               Goners->AddItem(u->second,qreason);
+                               Goners->AddItem(u->second,from);
                                num_lost_users++;
                        }
                }
@@ -849,7 +848,8 @@ class TreeSocket : public InspSocket
                        num_lost_servers = 0;
                        num_lost_users = 0;
                        CullList* Goners = new CullList();
-                       SquitServer(Current, Goners);
+                       std::string from = Current->GetParent()->GetName()+" "+Current->GetName();
+                       SquitServer(from, Current, Goners);
                        Goners->Apply();
                        Current->Tidy();
                        Current->GetParent()->DelChild(Current);
@@ -1094,8 +1094,8 @@ class TreeSocket : public InspSocket
                clientlist[tempnick] = new userrec();
                clientlist[tempnick]->fd = FD_MAGIC_NUMBER;
                strlcpy(clientlist[tempnick]->nick, tempnick,NICKMAX-1);
-               strlcpy(clientlist[tempnick]->host, params[2].c_str(),160);
-               strlcpy(clientlist[tempnick]->dhost, params[3].c_str(),160);
+               strlcpy(clientlist[tempnick]->host, params[2].c_str(),63);
+               strlcpy(clientlist[tempnick]->dhost, params[3].c_str(),63);
                clientlist[tempnick]->server = (char*)FindServerNamePtr(source.c_str());
                strlcpy(clientlist[tempnick]->ident, params[4].c_str(),IDENTMAX);
                strlcpy(clientlist[tempnick]->fullname, params[7].c_str(),MAXGECOS);
@@ -1107,13 +1107,10 @@ class TreeSocket : public InspSocket
                ucrec a;
                a.channel = NULL;
                a.uc_modes = 0;
-               for (int i = 0; i < MAXCHANS; i++)
-                       clientlist[tempnick]->chans.push_back(a);
+               clientlist[tempnick]->chans.resize(MAXCHANS);
+
+               WriteOpers("*** Client connecting at %s: %s!%s@%s [%s]",clientlist[tempnick]->server,clientlist[tempnick]->nick,clientlist[tempnick]->ident,clientlist[tempnick]->host,(char*)inet_ntoa(clientlist[tempnick]->ip4));
 
-               if (!this->bursting)
-               {
-                       WriteOpers("*** Client connecting at %s: %s!%s@%s [%s]",clientlist[tempnick]->server,clientlist[tempnick]->nick,clientlist[tempnick]->ident,clientlist[tempnick]->host,(char*)inet_ntoa(clientlist[tempnick]->ip4));
-               }
                params[7] = ":" + params[7];
                DoOneToAllButSender(source,"NICK",params,source);
 
@@ -1136,15 +1133,19 @@ class TreeSocket : public InspSocket
                log(DEBUG,"Sending FJOINs to other server for %s",c->name);
                char list[MAXBUF];
                std::string individual_halfops = ":"+Srv->GetServerName()+" FMODE "+c->name;
-               snprintf(list,MAXBUF,":%s FJOIN %s %lu",Srv->GetServerName().c_str(),c->name,(unsigned long)c->age);
+               size_t counter = snprintf(list,MAXBUF,":%s FJOIN %s %lu",Srv->GetServerName().c_str(),c->name,(unsigned long)c->age);
+               size_t initial = counter;
+
                std::map<char*,char*> *ulist = c->GetUsers();
                std::vector<userrec*> specific_halfop;
                std::vector<userrec*> specific_voice;
+
                for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
                {
                        char* o = i->second;
                        userrec* otheruser = (userrec*)o;
-                       strlcat(list," ",MAXBUF);
+                       charlcat(list,' ',MAXBUF);
+                       counter++;
                        int x = cflags(otheruser,c);
                        if ((x & UCMODE_HOP) && (x & UCMODE_OP))
                        {
@@ -1155,27 +1156,33 @@ class TreeSocket : public InspSocket
                                specific_voice.push_back(otheruser);
                        }
 
-                       char* n = "";
+                       char n = 0;
                        if (x & UCMODE_OP)
                        {
-                               n = "@";
+                               n = '@';
                        }
                        else if (x & UCMODE_HOP)
                        {
-                               n = "%";
+                               n = '%';
                        }
                        else if (x & UCMODE_VOICE)
                        {
-                               n = "+";
+                               n = '+';
+                       }
+
+                       if (n)
+                       {
+                               charlcat(list,n,MAXBUF);
+                               counter++;
                        }
 
-                       strlcat(list,n,MAXBUF);
-                       strlcat(list,otheruser->nick,MAXBUF);
-                       if (strlen(list)>(480-NICKMAX))
+                       counter += strlcat(list,otheruser->nick,MAXBUF);
+
+                       if (counter > (480-NICKMAX))
                        {
                                log(DEBUG,"FJOIN line wrapped");
                                this->WriteLine(list);
-                               snprintf(list,MAXBUF,":%s FJOIN %s %lu",Srv->GetServerName().c_str(),c->name,(unsigned long)c->age);
+                               counter = snprintf(list,MAXBUF,":%s FJOIN %s %lu",Srv->GetServerName().c_str(),c->name,(unsigned long)c->age);
                                for (unsigned int y = 0; y < specific_voice.size(); y++)
                                {
                                        this->WriteLine(":"+Srv->GetServerName()+" FMODE "+c->name+" +v "+specific_voice[y]->nick);
@@ -1186,7 +1193,7 @@ class TreeSocket : public InspSocket
                                }
                        }
                }
-               if (list[strlen(list)-1] != ':')
+               if (counter != initial)
                {
                        log(DEBUG,"Final FJOIN line");
                        this->WriteLine(list);
@@ -1358,7 +1365,7 @@ class TreeSocket : public InspSocket
                 * back to the core so that a large burst is split into at least 6 sections
                 * (possibly more)
                 */
-               std::string burst = "BURST";
+               std::string burst = "BURST "+ConvToStr(TIME);
                std::string endburst = "ENDBURST";
                Srv->SendOpers("*** Bursting to \2"+s->GetName()+"\2.");
                this->WriteLine(burst);
@@ -1742,11 +1749,20 @@ class TreeSocket : public InspSocket
                /* Send it on its way */
                if (propogate)
                {
+                       if (atoi(params[4].c_str()))
+                       {
+                               WriteOpers("*** %s Added %cLINE on %s to expire in %lu seconds (%s).",prefix.c_str(),*(params[0].c_str()),params[1].c_str(),atoi(params[4].c_str()),params[5].c_str());
+                       }
+                       else
+                       {
+                               WriteOpers("*** %s Added permenant %cLINE on %s (%s).",prefix.c_str(),*(params[0].c_str()),params[1].c_str(),params[5].c_str());
+                       }
                        params[5] = ":" + params[5];
                        DoOneToAllButSender(prefix,"ADDLINE",params,prefix);
                }
                if (!this->bursting)
                {
+                       log(DEBUG,"Applying lines...");
                        apply_lines(APPLY_ZLINES|APPLY_GLINES|APPLY_QLINES);
                }
                return true;
@@ -2072,13 +2088,21 @@ class TreeSocket : public InspSocket
 
        void Split(std::string line, bool stripcolon, std::deque<std::string> &n)
        {
+               // we don't do anything with a line > 2048
+               if (line.length() > 2048)
+               {
+                       log(DEBUG,"Line too long!");
+                       return;
+               }
                if (!strchr(line.c_str(),' '))
                {
                        n.push_back(line);
                        return;
                }
                std::stringstream s(line);
-               std::string param = "";
+               int count = 0;
+               char param[1024];
+               char* pptr = param;
 
                n.clear();
                int item = 0;
@@ -2088,51 +2112,64 @@ class TreeSocket : public InspSocket
                        s.get(c);
                        if (c == ' ')
                        {
-                               n.push_back(param);
-                               param = "";
+                               *pptr = 0;
+                               if (*param)
+                                       n.push_back(param);
+                               *param = count = 0;
+                               pptr = param;
                                item++;
                        }
                        else
                        {
                                if (!s.eof())
                                {
-                                       param = param + c;
+                                       *pptr++ = c;
+                                       count++;
                                }
-                               if ((param == ":") && (item > 0))
+                               if ((*param == ':') && (count == 1) && (item > 0))
                                {
-                                       param = "";
+                                       *param = count = 0;
+                                       pptr = param;
                                        while (!s.eof())
                                        {
                                                s.get(c);
                                                if (!s.eof())
                                                {
-                                                       param = param + c;
+                                                       *pptr++ = c;
+                                                       count++;
                                                }
                                        }
+                                       *pptr = 0;
                                        n.push_back(param);
-                                       param = "";
+                                       *param = count = 0;
+                                       pptr = param;
                                }
                        }
                }
-               if (param != "")
+               *pptr = 0;
+               if (*param)
                {
                        n.push_back(param);
                }
+
                return;
        }
 
        bool ProcessLine(std::string line)
        {
                char* l = (char*)line.c_str();
-               while ((strlen(l)) && (l[strlen(l)-1] == '\r') || (l[strlen(l)-1] == '\n'))
-                       l[strlen(l)-1] = '\0';
-               line = l;
-               if (line == "")
+               for (char* x = l; *x; x++)
+               {
+                       if ((*x == '\r') || (*x == '\n'))
+                               *x = 0;
+               }
+               if (!*l)
                        return true;
-               Srv->Log(DEBUG,"IN: "+line);
-               
+
+               log(DEBUG,"IN: %s",l);
+
                std::deque<std::string> params;
-               this->Split(line,true,params);
+               this->Split(l,true,params);
                irc::string command = "";
                std::string prefix = "";
                if (((params[0].c_str())[0] == ':') && (params.size() > 1))
@@ -2227,6 +2264,14 @@ class TreeSocket : public InspSocket
                                }
                                else if (command == "BURST")
                                {
+                                       time_t THEM = atoi(params[0].c_str());
+                                       long delta = THEM-TIME;
+                                       if ((delta < -600) || (delta > 600))
+                                       {
+                                               WriteOpers("*** \2ERROR\2: Your clocks are out by "+ConvToStr(abs(delta))+" seconds (this is more than ten minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2");
+                                               this->WriteLine("ERROR :Your clocks are out by "+ConvToStr(abs(delta))+" seconds (this is more than ten minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!");
+                                               return false;
+                                       }
                                        this->LinkState = CONNECTED;
                                        Node = new TreeServer(InboundServerName,InboundDescription,TreeRoot,this);
                                        TreeRoot->AddChild(Node);
@@ -2515,7 +2560,7 @@ class TreeSocket : public InspSocket
                                                }
                                                if (!Srv->CallCommandHandler(command.c_str(), strparams, params.size(), who))
                                                {
-                                                       this->WriteLine("ERROR :Unrecognised command -- possibly loaded mismatched modules");
+                                                       this->WriteLine("ERROR :Unrecognised command '"+std::string(command.c_str())+"' -- possibly loaded mismatched modules");
                                                        return false;
                                                }
                                        }