+/* +------------------------------------+
+ * | 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"
return false;
}
+bool TreeSocket::Modules(const std::string &prefix, std::deque<std::string> ¶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<std::string> 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," <no flags>");
+ 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<std::string> ¶ms)
{
return true;
}
+bool TreeSocket::OperQuit(const std::string &prefix, std::deque<std::string> ¶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:
{
/* 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;
if (ServerSource)
{
ServerSource->SetPingFlag();
+ ServerSource->rtt = Instance->Time() - ServerSource->LastPing;
}
}
else
{
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
{
if ((params.size() == 2) && (params[1] == "FORCE"))
force = true;
- time_t rts = atoi(params[0].c_str());
- time_t us = Instance->Time(true);
-
- 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 them = atoi(params[0].c_str());
+ time_t us = Instance->Time(false);
- 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<std::string> 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;
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);
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<std::string> ¶ms)
{
if (params.size() < 4)
std::string description = params[3];
for (std::vector<Link>::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)
// 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);
std::string description = params[3];
for (std::vector<Link>::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)
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;
n.clear();
irc::tokenstream tokens(line);
std::string param;
- while ((param = tokens.GetToken()) != "")
+ while (tokens.GetToken(param))
n.push_back(param);
return;
}
{
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);
{
return this->Error(params);
}
+ else if (command == "CAPAB")
+ {
+ return this->Capab(params);
+ }
break;
case CONNECTED:
// This is the 'authenticated' state, when all passwords
/* 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);
}
{
return this->Motd(prefix, params);
}
+ else if (command == "MODULES")
+ {
+ return this->Modules(prefix, params);
+ }
else if (command == "ADMIN")
{
return this->Admin(prefix, params);
}
return this->ForceNick(prefix,params);
}
+ else if (command == "OPERQUIT")
+ {
+ return this->OperQuit(prefix,params);
+ }
else if (command == "RSQUIT")
{
return this->RemoteSquit(prefix, params);