X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Ftreesocket2.cpp;h=6c0418a0bd9a9bb414c86bc2741be8f5d4049aa1;hb=7f00015727fab50e37de46aa90d218b31c852c87;hp=8bb404a457c404360049eaf694d85237d88c8b0e;hpb=38ca8be9a3881a3cb3cf6864e67b779ffbab6874;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 8bb404a45..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" @@ -38,6 +51,61 @@ bool TreeSocket::Error(std::deque ¶ms) return false; } +bool TreeSocket::Modules(const std::string &prefix, std::deque ¶ms) +{ + if (params.empty()) + return true; + + if (!this->Instance->MatchText(this->Instance->Config->ServerName, params[0])) + { + /* Pass it on, not for us */ + Utils->DoOneToOne(prefix, "MODULES", params, params[0]); + return true; + } + + char strbuf[MAXBUF]; + std::deque par; + par.push_back(prefix); + par.push_back(""); + + userrec* source = this->Instance->FindNick(prefix); + if (!source) + return true; + + for (unsigned int i = 0; i < Instance->Config->module_names.size(); i++) + { + Version V = Instance->modules[i]->GetVersion(); + char modulename[MAXBUF]; + char flagstate[MAXBUF]; + *flagstate = 0; + if (V.Flags & VF_STATIC) + strlcat(flagstate,", static",MAXBUF); + if (V.Flags & VF_VENDOR) + strlcat(flagstate,", vendor",MAXBUF); + if (V.Flags & VF_COMMON) + strlcat(flagstate,", common",MAXBUF); + if (V.Flags & VF_SERVICEPROVIDER) + strlcat(flagstate,", service provider",MAXBUF); + if (!flagstate[0]) + strcpy(flagstate," "); + strlcpy(modulename,Instance->Config->module_names[i].c_str(),256); + if (*source->oper) + { + snprintf(strbuf, MAXBUF, "::%s 900 %s :0x%08lx %d.%d.%d.%d %s (%s)",Instance->Config->ServerName,source->nick,(long unsigned int)Instance->modules[i],V.Major,V.Minor,V.Revision,V.Build,ServerConfig::CleanFilename(modulename),flagstate+2); + } + else + { + snprintf(strbuf, MAXBUF, "::%s 900 %s :%s",Instance->Config->ServerName,source->nick,ServerConfig::CleanFilename(modulename)); + } + par[1] = strbuf; + Utils->DoOneToOne(Instance->Config->ServerName, "PUSH", par, source->server); + } + snprintf(strbuf, MAXBUF, "::%s 901 %s :End of MODULES list", Instance->Config->ServerName, source->nick); + par[1] = strbuf; + Utils->DoOneToOne(Instance->Config->ServerName, "PUSH", par, source->server); + return true; +} + /** remote MOTD. leet, huh? */ bool TreeSocket::Motd(const std::string &prefix, std::deque ¶ms) { @@ -280,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; @@ -345,6 +413,7 @@ bool TreeSocket::LocalPong(const std::string &prefix, std::deque &p if (ServerSource) { ServerSource->SetPingFlag(); + ServerSource->rtt = Instance->Time() - ServerSource->LastPing; } } else @@ -487,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 { @@ -602,28 +672,17 @@ bool TreeSocket::HandleSetTime(const std::string &prefix, std::dequeTime(true); + time_t them = atoi(params[0].c_str()); + time_t us = Instance->Time(false); - if (rts == us) - { - Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix); - } - else if (force || (rts < us)) - { - int old = Instance->SetTimeDelta(rts - us); - Instance->Log(DEBUG, "%s TS (diff %d) from %s applied (old delta was %d)", (force) ? "Forced" : "Lower", rts - us, prefix.c_str(), old); + time_t diff = them - us; - Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix); - } - else - { - Instance->Log(DEBUG, "Higher TS (diff %d) from %s overridden", us - rts, prefix.c_str()); + Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix); - std::deque oparams; - oparams.push_back(ConvToStr(us)); - - Utils->DoOneToMany(prefix, "TIMESET", oparams); + if (force || (them != us)) + { + time_t old = Instance->SetTimeDelta(diff); + Instance->Log(DEBUG, "TS (diff %d) from %s applied (old delta was %d)", diff, prefix.c_str(), old); } return true; @@ -743,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); @@ -754,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) @@ -773,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) @@ -790,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); @@ -822,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) @@ -842,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; @@ -858,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; } @@ -947,34 +1025,30 @@ bool TreeSocket::ProcessLine(std::string &line) { if (params.size() && Utils->EnableTimeSync) { - /* If a time stamp is provided, apply synchronization */ - bool force = false; + bool we_have_delta = (Instance->Time(false) != Instance->Time(true)); time_t them = atoi(params[0].c_str()); - time_t us = Instance->Time(false); - int delta = them - us; - if ((params.size() == 2) && (params[1] == "FORCE")) - force = true; - if ((delta < -600) || (delta > 600)) + time_t delta = them - Instance->Time(false); + if ((delta < -300) || (delta > 300)) { - this->Instance->SNO->WriteToSnoMask('l',"\2ERROR\2: Your clocks are out by %d seconds (this is more than ten minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",abs(delta)); - this->WriteLine("ERROR :Your clocks are out by "+ConvToStr(abs(delta))+" seconds (this is more than ten minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!"); + Instance->SNO->WriteToSnoMask('l',"\2ERROR\2: Your clocks are out by %d seconds (this is more than five minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",abs(delta)); + 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; } + else if ((delta < -30) || (delta > 30)) + { + Instance->SNO->WriteToSnoMask('l',"\2WARNING\2: Your clocks are out by %d seconds. Please consider synching your clocks.", abs(delta)); + } - if (force || (us > them)) + if (!Utils->MasterTime && !we_have_delta) { - this->Instance->SetTimeDelta(them - us); + this->Instance->SetTimeDelta(delta); // Send this new timestamp to any other servers Utils->DoOneToMany(Utils->TreeRoot->GetName(), "TIMESET", params); } - else - { - // Override the timestamp - this->WriteLine(":" + Utils->TreeRoot->GetName() + " TIMESET " + ConvToStr(us)); - } } 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); @@ -1013,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 @@ -1070,6 +1148,10 @@ bool TreeSocket::ProcessLine(std::string &line) { return this->Motd(prefix, params); } + else if (command == "MODULES") + { + return this->Modules(prefix, params); + } else if (command == "ADMIN") { return this->Admin(prefix, params);