X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Ftreesocket2.cpp;h=6c0418a0bd9a9bb414c86bc2741be8f5d4049aa1;hb=7f00015727fab50e37de46aa90d218b31c852c87;hp=eefffe1f9805b91f663180eaa39303f406e720fb;hpb=a17174ec0aeeffc1236d0ddbcf6a63f56205acea;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index eefffe1f9..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" @@ -19,6 +32,8 @@ #include "m_spanningtree/resolvers.h" #include "m_spanningtree/handshaketimer.h" +/* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h */ + int TreeSocket::WriteLine(std::string line) { Instance->Log(DEBUG, "-> %s", line.c_str()); @@ -36,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) { @@ -205,6 +275,21 @@ bool TreeSocket::ForceNick(const std::string &prefix, std::deque &p return true; } +bool TreeSocket::OperQuit(const std::string &prefix, std::deque ¶ms) +{ + if (params.size() < 1) + return true; + + userrec* u = this->Instance->FindNick(prefix); + + if (u) + { + Utils->DoOneToAllButSender(prefix,"OPERQUIT",params,prefix); + u->SetOperQuit(params[0]); + } + return true; +} + /* * Remote SQUIT (RSQUIT). Routing works similar to SVSNICK: Route it to the server that the target is connected to locally, * then let that server do the dirty work (squit it!). Example: @@ -263,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; @@ -328,6 +413,7 @@ bool TreeSocket::LocalPong(const std::string &prefix, std::deque &p if (ServerSource) { ServerSource->SetPingFlag(); + ServerSource->rtt = Instance->Time() - ServerSource->LastPing; } } else @@ -359,8 +445,10 @@ bool TreeSocket::LocalPong(const std::string &prefix, std::deque &p bool TreeSocket::MetaData(const std::string &prefix, std::deque ¶ms) { - if (params.size() < 3) + if (params.size() < 2) return true; + else + params.push_back(""); TreeServer* ServerSource = Utils->FindServer(prefix); if (ServerSource) { @@ -468,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 { @@ -583,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); - - Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix); - } - else - { - Instance->Log(DEBUG, "Higher TS (diff %d) from %s overridden", us - rts, prefix.c_str()); + time_t diff = them - us; - std::deque oparams; - oparams.push_back(ConvToStr(us)); + Utils->DoOneToAllButSender(prefix, "TIMESET", params, prefix); - 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; @@ -687,6 +765,8 @@ bool TreeSocket::LocalPing(const std::string &prefix, std::deque &p } } +/** TODO: This creates a total mess of output and needs to really use irc::modestacker. + */ bool TreeSocket::RemoveStatus(const std::string &prefix, std::deque ¶ms) { if (params.size() < 1) @@ -694,41 +774,11 @@ bool TreeSocket::RemoveStatus(const std::string &prefix, std::deque chanrec* c = Instance->FindChan(params[0]); if (c) { - irc::modestacker modestack(false); - CUList *ulist = c->GetUsers(); - const char* y[127]; - std::deque stackresult; - std::string x; - for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) + for (char modeletter = 'A'; modeletter <= 'z'; modeletter++) { - std::string modesequence = Instance->Modes->ModeString(i->second, c); - if (modesequence.length()) - { - irc::spacesepstream sep(modesequence); - std::string modeletters = sep.GetToken(); - while (!modeletters.empty()) - { - char mletter = *(modeletters.begin()); - modestack.Push(mletter,sep.GetToken()); - modeletters.erase(modeletters.begin()); - } - } - } - - while (modestack.GetStackedLine(stackresult)) - { - stackresult.push_front(ConvToStr(c->age)); - stackresult.push_front(c->name); - Utils->DoOneToMany(Instance->Config->ServerName, "FMODE", stackresult); - stackresult.erase(stackresult.begin() + 1); - for (size_t z = 0; z < stackresult.size(); z++) - { - y[z] = stackresult[z].c_str(); - } - userrec* n = new userrec(Instance); - n->SetFd(FD_MAGIC_NUMBER); - Instance->SendMode(y, stackresult.size(), n); - delete n; + ModeHandler* mh = Instance->Modes->FindMode(modeletter, MODETYPE_CHANNEL); + if (mh) + mh->RemoveMode(c); } } return true; @@ -752,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); @@ -763,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) @@ -782,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) @@ -799,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); @@ -831,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) @@ -851,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; @@ -867,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; } @@ -956,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(true); - 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); @@ -1022,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 @@ -1063,7 +1132,7 @@ bool TreeSocket::ProcessLine(std::string &line) /* Yes, know, this is a mess. Its reasonably fast though as we're * working with std::string here. */ - if ((command == "NICK") && (params.size() > 1)) + if ((command == "NICK") && (params.size() >= 8)) { return this->IntroduceClient(prefix,params); } @@ -1079,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); @@ -1181,6 +1254,10 @@ bool TreeSocket::ProcessLine(std::string &line) } return this->ForceNick(prefix,params); } + else if (command == "OPERQUIT") + { + return this->OperQuit(prefix,params); + } else if (command == "RSQUIT") { return this->RemoteSquit(prefix, params);