diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_spanningtree/capab.cpp | 26 | ||||
-rw-r--r-- | src/modules/m_spanningtree/compat.cpp | 56 | ||||
-rw-r--r-- | src/modules/m_spanningtree/handshaketimer.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_spanningtree/server.cpp | 8 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treesocket.h | 7 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treesocket1.cpp | 16 |
6 files changed, 77 insertions, 40 deletions
diff --git a/src/modules/m_spanningtree/capab.cpp b/src/modules/m_spanningtree/capab.cpp index 5b68ab4f9..66d448e55 100644 --- a/src/modules/m_spanningtree/capab.cpp +++ b/src/modules/m_spanningtree/capab.cpp @@ -21,10 +21,13 @@ /* $ModDep: m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/treesocket.h */ - std::string TreeSocket::MyModules(int filter) { std::vector<std::string> modlist = this->ServerInstance->Modules->GetAllModuleNames(filter); + + if (filter == VF_COMMON && proto_version != ProtocolVersion) + CompatAddModules(modlist); + std::string capabilities; sort(modlist.begin(),modlist.end()); for (unsigned int i = 0; i < modlist.size(); i++) @@ -36,16 +39,20 @@ std::string TreeSocket::MyModules(int filter) return capabilities; } -void TreeSocket::SendCapabilities() +void TreeSocket::SendCapabilities(int phase) { - if (sentcapab) + if (capab_phase >= phase) + return; + + if (capab_phase < 1 && phase >= 1) + WriteLine("CAPAB START " + ConvToStr(ProtocolVersion)); + + capab_phase = phase; + if (phase < 2) return; - sentcapab = true; irc::commasepstream modulelist(MyModules(VF_COMMON)); irc::commasepstream optmodulelist(MyModules(VF_OPTCOMMON)); - this->WriteLine("CAPAB START"); - /* Send module names, split at 509 length */ std::string item; std::string line = "CAPAB MODULES "; @@ -160,6 +167,9 @@ bool TreeSocket::Capab(const parameterlist ¶ms) ModuleList.clear(); OptModuleList.clear(); CapKeys.clear(); + if (params.size() > 1) + proto_version = atoi(params[1].c_str()); + SendCapabilities(2); } else if (params[0] == "END") { @@ -244,7 +254,7 @@ bool TreeSocket::Capab(const parameterlist ¶ms) this->SetTheirChallenge(n->second); if (!this->GetTheirChallenge().empty() && (this->LinkState == CONNECTING)) { - this->SendCapabilities(); + this->SendCapabilities(2); this->WriteLine(std::string("SERVER ")+this->ServerInstance->Config->ServerName+" "+this->MakePass(OutboundPass, this->GetTheirChallenge())+" 0 "+ ServerInstance->Config->GetSID()+" :"+this->ServerInstance->Config->ServerDesc); } @@ -254,7 +264,7 @@ bool TreeSocket::Capab(const parameterlist ¶ms) /* They didnt specify a challenge or we don't have m_sha256.so, we use plaintext */ if (this->LinkState == CONNECTING) { - this->SendCapabilities(); + this->SendCapabilities(2); this->WriteLine(std::string("SERVER ")+this->ServerInstance->Config->ServerName+" "+OutboundPass+" 0 "+ServerInstance->Config->GetSID()+" :"+this->ServerInstance->Config->ServerDesc); } } diff --git a/src/modules/m_spanningtree/compat.cpp b/src/modules/m_spanningtree/compat.cpp index 345215031..f278913c8 100644 --- a/src/modules/m_spanningtree/compat.cpp +++ b/src/modules/m_spanningtree/compat.cpp @@ -15,25 +15,53 @@ #include "main.h" #include "treesocket.h" -void TreeSocket::WriteLine(std::string line) +static const char* const forge_common_1201[] = { + "m_chghost.so", + "m_chgname.so", + "m_remove.so", + "m_sajoin.so", + "m_sakick.so", + "m_sanick.so", + "m_sapart.so", + "m_saquit.so", + "m_setident.so", +}; + +void TreeSocket::CompatAddModules(std::vector<std::string>& modlist) { - if (line[0] != ':' && LinkState == CONNECTED) + if (proto_version < 1202) { - ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!"); - line = ":" + ServerInstance->Config->GetSID() + " " + line; + // you MUST have chgident loaded in order to be able to translate FIDENT + modlist.push_back("m_chgident.so"); + for(int i=0; i * sizeof(char*) < sizeof(forge_common_1201); i++) + { + if (ServerInstance->Modules->Find(forge_common_1201[i])) + modlist.push_back(forge_common_1201[i]); + } } - if (proto_version != ProtocolVersion) +} + +void TreeSocket::WriteLine(std::string line) +{ + if (LinkState == CONNECTED) { - std::string::size_type a = line.find(' '); - std::string::size_type b = line.find(' ', a); - std::string command = line.substr(a,b); - // now try to find a translation entry - // TODO a more efficient lookup method will be needed later - if (proto_version < 1202 && command == "FIDENT") + if (line[0] != ':') + { + ServerInstance->Logs->Log("m_spanningtree", DEFAULT, "Sending line without server prefix!"); + line = ":" + ServerInstance->Config->GetSID() + " " + line; + } + if (proto_version != ProtocolVersion) { - // a more aggressive method would be to translate to CHGIDENT - ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Dropping FIDENT to 1201-protocol server"); - return; + std::string::size_type a = line.find(' ') + 1; + std::string::size_type b = line.find(' ', a); + std::string command = line.substr(a, b-a); + // now try to find a translation entry + // TODO a more efficient lookup method will be needed later + if (proto_version < 1202 && command == "FIDENT") + { + ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Rewriting FIDENT for 1201-protocol server"); + line = ":" + ServerInstance->Config->GetSID() + " CHGIDENT " + line.substr(1,a-2) + line.substr(b); + } } } diff --git a/src/modules/m_spanningtree/handshaketimer.cpp b/src/modules/m_spanningtree/handshaketimer.cpp index 1b3b1dd22..1ccd466ad 100644 --- a/src/modules/m_spanningtree/handshaketimer.cpp +++ b/src/modules/m_spanningtree/handshaketimer.cpp @@ -42,13 +42,13 @@ void HandshakeTimer::Tick(time_t TIME) if (!sock->GetHook()) { CancelRepeat(); - sock->SendCapabilities(); + sock->SendCapabilities(1); } else if (BufferedSocketHSCompleteRequest(sock, (Module*)Utils->Creator, sock->GetHook()).Send()) { CancelRepeat(); BufferedSocketAttachCertRequest(sock, (Module*)Utils->Creator, sock->GetHook()).Send(); - sock->SendCapabilities(); + sock->SendCapabilities(1); } // otherwise, try again later } diff --git a/src/modules/m_spanningtree/server.cpp b/src/modules/m_spanningtree/server.cpp index 24d1a66e7..6351c93b5 100644 --- a/src/modules/m_spanningtree/server.cpp +++ b/src/modules/m_spanningtree/server.cpp @@ -107,8 +107,7 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist ¶ms) this->InboundDescription = description; this->InboundSID = sid; - if (!sentcapab) - this->SendCapabilities(); + this->SendCapabilities(2); if (hops) { @@ -203,8 +202,7 @@ bool TreeSocket::Inbound_Server(parameterlist ¶ms) this->InboundDescription = description; this->InboundSID = sid; - if (!sentcapab) - this->SendCapabilities(); + this->SendCapabilities(2); if (hops) { @@ -261,7 +259,7 @@ bool TreeSocket::Inbound_Server(parameterlist ¶ms) // this is good. Send our details: Our server name and description and hopcount of 0, // along with the sendpass from this block. - this->SendCapabilities(); + this->SendCapabilities(2); this->WriteLine(std::string("SERVER ")+this->ServerInstance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+ServerInstance->Config->GetSID()+" :"+this->ServerInstance->Config->ServerDesc); // move to the next state, we are now waiting for THEM. this->LinkState = WAIT_AUTH_2; diff --git a/src/modules/m_spanningtree/treesocket.h b/src/modules/m_spanningtree/treesocket.h index 93016126b..e9830f9ad 100644 --- a/src/modules/m_spanningtree/treesocket.h +++ b/src/modules/m_spanningtree/treesocket.h @@ -89,7 +89,7 @@ class TreeSocket : public BufferedSocket std::string ourchallenge; /* Challenge sent for challenge/response */ std::string theirchallenge; /* Challenge recv for challenge/response */ std::string OutboundPass; /* Outbound password */ - bool sentcapab; /* Have sent CAPAB already */ + int capab_phase; /* Have sent CAPAB already */ bool auth_fingerprint; /* Did we auth using SSL fingerprint */ bool auth_challenge; /* Did we auth using challenge/response */ int proto_version; /* Remote protocol version */ @@ -194,7 +194,10 @@ class TreeSocket : public BufferedSocket /** Send my capabilities to the remote side */ - void SendCapabilities(); + void SendCapabilities(int phase); + + /** Add modules to VF_COMMON list for backwards compatability */ + void CompatAddModules(std::vector<std::string>& modlist); /* Check a comma seperated list for an item */ bool HasItem(const std::string &list, const std::string &item); diff --git a/src/modules/m_spanningtree/treesocket1.cpp b/src/modules/m_spanningtree/treesocket1.cpp index e77e6717e..f31685c01 100644 --- a/src/modules/m_spanningtree/treesocket1.cpp +++ b/src/modules/m_spanningtree/treesocket1.cpp @@ -41,9 +41,9 @@ TreeSocket::TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, std::string sh { age = SI->Time(); myhost = ServerName; - theirchallenge.clear(); - ourchallenge.clear(); - this->LinkState = CONNECTING; + capab_phase = 0; + proto_version = 0; + LinkState = CONNECTING; Utils->timeoutlist[this] = std::pair<std::string, int>(ServerName, maxtime); if (Hook) BufferedSocketHookRequest(this, (Module*)Utils->Creator, Hook).Send(); @@ -58,10 +58,9 @@ TreeSocket::TreeSocket(SpanningTreeUtilities* Util, InspIRCd* SI, int newfd, cha : BufferedSocket(SI, newfd, ip), Utils(Util), Hook(HookMod) { age = SI->Time(); - this->LinkState = WAIT_AUTH_1; - theirchallenge.clear(); - ourchallenge.clear(); - sentcapab = false; + LinkState = WAIT_AUTH_1; + capab_phase = 0; + proto_version = 0; /* If we have a transport module hooked to the parent, hook the same module to this * socket, and set a timer waiting for handshake before we send CAPAB etc. */ @@ -127,7 +126,6 @@ bool TreeSocket::OnConnected() x->Hook.c_str()); } this->OutboundPass = x->SendPass; - sentcapab = false; /* found who we're supposed to be connecting to, send the neccessary gubbins. */ if (this->GetHook()) @@ -136,7 +134,7 @@ bool TreeSocket::OnConnected() ServerInstance->Timers->AddTimer(hstimer); } else - this->SendCapabilities(); + this->SendCapabilities(1); return true; } |