X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Ftreesocket2.cpp;h=6c0418a0bd9a9bb414c86bc2741be8f5d4049aa1;hb=7f00015727fab50e37de46aa90d218b31c852c87;hp=e4d53c8ef499308ba370d7cba28fa857c2d07925;hpb=3699bdaee53896b491256d3aa694ef20cbdb0743;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index e4d53c8ef..6c0418a0b 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -1,3 +1,16 @@ +/* +------------------------------------+ + * | Inspire Internet Relay Chat Daemon | + * +------------------------------------+ + * + * InspIRCd: (C) 2002-2007 InspIRCd Development Team + * See: http://www.inspircd.org/wiki/index.php/Credits + * + * This program is free but copyrighted software; see + * the file COPYING for details. + * + * --------------------------------------------------- + */ + #include "configreader.h" #include "users.h" #include "channels.h" @@ -335,7 +348,7 @@ bool TreeSocket::ServiceJoin(const std::string &prefix, std::deque { /* only join if it's local, otherwise just pass it on! */ if (IS_LOCAL(u)) - chanrec::JoinUser(this->Instance, u, params[1].c_str(), false); + chanrec::JoinUser(this->Instance, u, params[1].c_str(), false, "", Instance->Time()); Utils->DoOneToAllButSender(prefix,"SVSJOIN",params,prefix); } return true; @@ -400,6 +413,7 @@ bool TreeSocket::LocalPong(const std::string &prefix, std::deque &p if (ServerSource) { ServerSource->SetPingFlag(); + ServerSource->rtt = Instance->Time() - ServerSource->LastPing; } } else @@ -542,7 +556,8 @@ bool TreeSocket::AddLine(const std::string &prefix, std::deque &par { if (atoi(params[4].c_str())) { - this->Instance->SNO->WriteToSnoMask('x',"%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()); + time_t c_requires_crap = ConvToInt(params[4]) + Instance->Time(); + this->Instance->SNO->WriteToSnoMask('x',"%s Added %cLINE on %s to expire on %s (%s).",prefix.c_str(),*(params[0].c_str()),params[1].c_str(),Instance->TimeString(c_requires_crap).c_str(),params[5].c_str()); } else { @@ -787,10 +802,11 @@ bool TreeSocket::RemoteServer(const std::string &prefix, std::deque if (CheckDupe) { this->WriteLine("ERROR :Server "+servername+" already exists!"); - this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+servername+"\2 denied, already exists"); + this->Instance->SNO->WriteToSnoMask('l',"Server \2"+servername+"\2 being introduced from \2" + prefix + "\2 denied, already exists. Closing link with " + prefix); return false; } - TreeServer* Node = new TreeServer(this->Utils,this->Instance,servername,description,ParentOfThis,NULL); + Link* lnk = Utils->FindLink(servername); + TreeServer* Node = new TreeServer(this->Utils,this->Instance,servername,description,ParentOfThis,NULL, lnk ? lnk->Hidden : false); ParentOfThis->AddChild(Node); params[3] = ":" + params[3]; Utils->DoOneToAllButSender(prefix,"SERVER",params,prefix); @@ -798,6 +814,24 @@ bool TreeSocket::RemoteServer(const std::string &prefix, std::deque return true; } +bool TreeSocket::ComparePass(const std::string &ours, const std::string &theirs) +{ + if ((!strncmp(ours.c_str(), "HMAC-SHA256:", 12)) || (!strncmp(theirs.c_str(), "HMAC-SHA256:", 12))) + { + /* One or both of us specified hmac sha256, but we don't have sha256 module loaded! + * We can't allow this password as valid. + */ + if (!Instance->FindModule("m_sha256.so") || !Utils->ChallengeResponse) + return false; + else + /* Straight string compare of hashes */ + return ours == theirs; + } + else + /* Straight string compare of plaintext */ + return ours == theirs; +} + bool TreeSocket::Outbound_Reply_Server(std::deque ¶ms) { if (params.size() < 4) @@ -817,7 +851,7 @@ bool TreeSocket::Outbound_Reply_Server(std::deque ¶ms) std::string description = params[3]; for (std::vector::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++) { - if ((x->Name == servername) && (x->RecvPass == password)) + if ((x->Name == servername) && (ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password))) { TreeServer* CheckDupe = Utils->FindServer(sname); if (CheckDupe) @@ -834,7 +868,7 @@ bool TreeSocket::Outbound_Reply_Server(std::deque ¶ms) // we should add the details of this server now // to the servers tree, as a child of the root // node. - TreeServer* Node = new TreeServer(this->Utils,this->Instance,sname,description,Utils->TreeRoot,this); + TreeServer* Node = new TreeServer(this->Utils,this->Instance,sname,description,Utils->TreeRoot,this,x->Hidden); Utils->TreeRoot->AddChild(Node); params[3] = ":" + params[3]; Utils->DoOneToAllButSender(Utils->TreeRoot->GetName(),"SERVER",params,sname); @@ -866,7 +900,7 @@ bool TreeSocket::Inbound_Server(std::deque ¶ms) std::string description = params[3]; for (std::vector::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++) { - if ((x->Name == servername) && (x->RecvPass == password)) + if ((x->Name == servername) && (ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password))) { TreeServer* CheckDupe = Utils->FindServer(sname); if (CheckDupe) @@ -886,7 +920,7 @@ bool TreeSocket::Inbound_Server(std::deque ¶ms) this->InboundDescription = description; // this is good. Send our details: Our server name and description and hopcount of 0, // along with the sendpass from this block. - this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+x->SendPass+" 0 :"+this->Instance->Config->ServerDesc); + this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 :"+this->Instance->Config->ServerDesc); // move to the next state, we are now waiting for THEM. this->LinkState = WAIT_AUTH_2; return true; @@ -902,7 +936,7 @@ void TreeSocket::Split(const std::string &line, std::deque &n) n.clear(); irc::tokenstream tokens(line); std::string param; - while ((param = tokens.GetToken()) != "") + while (tokens.GetToken(param)) n.push_back(param); return; } @@ -1013,7 +1047,8 @@ bool TreeSocket::ProcessLine(std::string &line) } } this->LinkState = CONNECTED; - Node = new TreeServer(this->Utils,this->Instance,InboundServerName,InboundDescription,Utils->TreeRoot,this); + Link* lnk = Utils->FindLink(InboundServerName); + Node = new TreeServer(this->Utils,this->Instance, InboundServerName, InboundDescription, Utils->TreeRoot, this, lnk ? lnk->Hidden : false); Utils->TreeRoot->AddChild(Node); params.clear(); params.push_back(InboundServerName); @@ -1052,6 +1087,10 @@ bool TreeSocket::ProcessLine(std::string &line) { return this->Error(params); } + else if (command == "CAPAB") + { + return this->Capab(params); + } break; case CONNECTED: // This is the 'authenticated' state, when all passwords