X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Ftreesocket2.cpp;h=acb822fbfa169419b2021fca91b9c4d2c984b49e;hb=d494c188245e1c80c9556a6a7efafd6fe8f4f6de;hp=0a0c22e39cf1cc1d95c685b8d069564e886c7d05;hpb=9826eb515cd5097394a20ef66eba4e73448fbc08;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 0a0c22e39..acb822fbf 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -129,7 +129,7 @@ void TreeSocket::ProcessLine(std::string &line) } else { - this->SendError(std::string("Invalid command in negotiation phase: ") + command.c_str()); + this->SendError("Invalid command in negotiation phase: " + command); } break; case WAIT_AUTH_2: @@ -155,18 +155,30 @@ void TreeSocket::ProcessLine(std::string &line) time_t delta = them - ServerInstance->Time(); if ((delta < -600) || (delta > 600)) { - ServerInstance->SNO->WriteGlobalSno('l',"\2ERROR\2: Your clocks are out by %d seconds (this is more than five minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",abs((long)delta)); - SendError("Your clocks are out by "+ConvToStr(abs((long)delta))+" seconds (this is more than five minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!"); + ServerInstance->SNO->WriteGlobalSno('l',"\2ERROR\2: Your clocks are out by %ld seconds (this is more than five minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",labs((long)delta)); + SendError("Your clocks are out by "+ConvToStr(labs((long)delta))+" seconds (this is more than five minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!"); return; } else if ((delta < -30) || (delta > 30)) { - ServerInstance->SNO->WriteGlobalSno('l',"\2WARNING\2: Your clocks are out by %d seconds. Please consider synching your clocks.", abs((long)delta)); + ServerInstance->SNO->WriteGlobalSno('l',"\2WARNING\2: Your clocks are out by %ld seconds. Please consider synching your clocks.", labs((long)delta)); } } + + // Check for duplicate server name/sid again, it's possible that a new + // server was introduced while we were waiting for them to send BURST. + // (we do not reserve their server name/sid when they send SERVER, we do it now) + if (!CheckDuplicate(capab->name, capab->sid)) + return; + this->LinkState = CONNECTED; Utils->timeoutlist.erase(this); + linkID = capab->name; + + MyRoot = new TreeServer(Utils, capab->name, capab->description, capab->sid, Utils->TreeRoot, this, capab->hidden); + Utils->TreeRoot->AddChild(MyRoot); + MyRoot->bursting = true; this->DoBurst(MyRoot); @@ -244,9 +256,25 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, * 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 '%s' from unknown prefix '%s'! Dropping entire command.", - command.c_str(), prefix.c_str()); - return; + + if ((prefix.length() == UUID_LENGTH-1) && (isdigit(prefix[0])) && + ((command == "FMODE") || (command == "MODE") || (command == "KICK") || (command == "TOPIC") || (command == "KILL") || (command == "ADDLINE") || (command == "DELLINE"))) + { + /* Special case, we cannot drop these commands as they've been committed already on a + * part of the network by the time we receive them, so in this scenario pretend the + * command came from a server to avoid desync. + */ + + who = ServerInstance->FindUUID(prefix.substr(0, 3)); + if (!who) + who = this->MyRoot->ServerUser; + } + else + { + ServerInstance->Logs->Log("m_spanningtree", DEBUG, "Command '%s' from unknown prefix '%s'! Dropping entire command.", + command.c_str(), prefix.c_str()); + return; + } } } @@ -394,7 +422,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, { if (params.size() != 2) { - SendError("Protocol violation: NICK message without TS - :"+std::string(who->uuid)+" NICK "+params[0]); + SendError("Protocol violation: Wrong number of parameters for NICK message"); return; } @@ -404,6 +432,12 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, return; } + if ((isdigit(params[0][0])) && (params[0] != who->uuid)) + { + SendError("Protocol violation: User changing nick to an invalid UID - " + params[0]); + return; + } + /* Update timestamp on user when they change nicks */ who->age = atoi(params[1].c_str()); @@ -411,23 +445,23 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, * On nick messages, check that the nick doesnt already exist here. * If it does, perform collision logic. */ + bool callfnc = true; User* x = ServerInstance->FindNickOnly(params[0]); - if ((x) && (x != who)) + if ((x) && (x != who) && (x->registered == REG_ALL)) { int collideret = 0; /* x is local, who is remote */ collideret = this->DoCollision(x, who->age, who->ident, who->GetIPString(), who->uuid); if (collideret != 1) { - /* - * Remote client lost, or both lost, parsing or passing on this - * nickchange would be pointless, as the incoming client's server will - * soon recieve SVSNICK to change its nick to its UID. :) -- w00t - */ - return; + // Remote client lost, or both lost, rewrite this nick change as a change to uuid before + // forwarding and don't call ForceNickChange() because DoCollision() has done it already + params[0] = who->uuid; + callfnc = false; } } - who->ForceNickChange(params[0].c_str()); + if (callfnc) + who->ForceNickChange(params[0].c_str()); Utils->RouteCommand(route_back_again, command, params, who); } else @@ -452,6 +486,14 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, return; } + if ((!params.empty()) && (params.back().empty()) && (!cmd->allow_empty_last_param)) + { + // the last param is empty and the command handler doesn't allow that, check if there will be enough params if we drop the last + if (params.size()-1 < cmd->min_params) + return; + params.pop_back(); + } + CmdResult res = cmd->Handle(params, who); if (res == CMD_INVALID) @@ -491,6 +533,9 @@ void TreeSocket::Close() time_t server_uptime = ServerInstance->Time() - this->age; if (server_uptime) - ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' was established for %s", linkID.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str()); + { + std::string timestr = Utils->Creator->TimeToStr(server_uptime); + ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' was established for %s", linkID.c_str(), timestr.c_str()); + } } }