mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 18:49:03 -04:00
m_spanningtree Create new TreeServers for incoming connections only when they've accepted our credentials, not when they send SERVER
This commit is contained in:
parent
ac705cd20e
commit
65072d44f2
@ -180,6 +180,33 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist ¶ms)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TreeSocket::CheckDuplicate(const std::string& sname, const std::string& sid)
|
||||
{
|
||||
/* Check for fully initialized instances of the server by name */
|
||||
TreeServer* CheckDupe = Utils->FindServer(sname);
|
||||
if (CheckDupe)
|
||||
{
|
||||
std::string pname = CheckDupe->GetParent() ? CheckDupe->GetParent()->GetName() : "<ourself>";
|
||||
SendError("Server "+sname+" already exists on server "+pname+"!");
|
||||
ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+pname);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check for fully initialized instances of the server by id */
|
||||
ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Looking for dupe SID %s", sid.c_str());
|
||||
CheckDupe = Utils->FindServerID(sid);
|
||||
|
||||
if (CheckDupe)
|
||||
{
|
||||
this->SendError("Server ID "+CheckDupe->GetID()+" already exists on server "+CheckDupe->GetName()+"! You may want to specify the server ID for the server manually with <server:id> so they do not conflict.");
|
||||
ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server ID '"+CheckDupe->GetID()+
|
||||
"' already exists on server "+CheckDupe->GetName());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Someone else is attempting to connect to us if this is called. Validate their credentials etc.
|
||||
* -- w
|
||||
@ -226,39 +253,24 @@ bool TreeSocket::Inbound_Server(parameterlist ¶ms)
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Now check for fully initialized ServerInstances of the server by name */
|
||||
TreeServer* CheckDupe = Utils->FindServer(sname);
|
||||
if (CheckDupe)
|
||||
{
|
||||
std::string pname = CheckDupe->GetParent() ? CheckDupe->GetParent()->GetName() : "<ourself>";
|
||||
SendError("Server "+sname+" already exists on server "+pname+"!");
|
||||
ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+pname);
|
||||
if (!CheckDuplicate(sname, sid))
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Check for fully initialized instances of the server by id */
|
||||
ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Looking for dupe SID %s", sid.c_str());
|
||||
CheckDupe = Utils->FindServerID(sid);
|
||||
|
||||
if (CheckDupe)
|
||||
{
|
||||
this->SendError("Server ID "+CheckDupe->GetID()+" already exists on server "+CheckDupe->GetName()+"! You may want to specify the server ID for the server manually with <server:id> so they do not conflict.");
|
||||
ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server ID '"+CheckDupe->GetID()+
|
||||
"' already exists on server "+CheckDupe->GetName());
|
||||
return false;
|
||||
}
|
||||
|
||||
ServerInstance->SNO->WriteToSnoMask('l',"Verified incoming server connection " + linkID + " ("+description+")");
|
||||
linkID = sname;
|
||||
|
||||
// this is good. Send our details: Our server name and description and hopcount of 0,
|
||||
// along with the sendpass from this block.
|
||||
this->SendCapabilities(2);
|
||||
this->WriteLine("SERVER "+ServerInstance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+ServerInstance->Config->GetSID()+" :"+ServerInstance->Config->ServerDesc);
|
||||
// move to the next state, we are now waiting for THEM.
|
||||
MyRoot = new TreeServer(Utils, sname, description, sid, Utils->TreeRoot, this, x->Hidden);
|
||||
Utils->TreeRoot->AddChild(MyRoot);
|
||||
|
||||
// Save these for later, so when they accept our credentials (indicated by BURST) we remember them
|
||||
this->capab->hidden = x->Hidden;
|
||||
this->capab->sid = sid;
|
||||
this->capab->description = description;
|
||||
this->capab->name = sname;
|
||||
|
||||
// Send our details: Our server name and description and hopcount of 0,
|
||||
// along with the sendpass from this block.
|
||||
this->WriteLine("SERVER "+ServerInstance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+ServerInstance->Config->GetSID()+" :"+ServerInstance->Config->ServerDesc);
|
||||
|
||||
// move to the next state, we are now waiting for THEM.
|
||||
this->LinkState = WAIT_AUTH_2;
|
||||
return true;
|
||||
}
|
||||
|
@ -78,6 +78,12 @@ struct CapabData
|
||||
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 */
|
||||
|
||||
// Data saved from incoming SERVER command, for later use when our credentials have been accepted by the other party
|
||||
std::string description;
|
||||
std::string sid;
|
||||
std::string name;
|
||||
bool hidden;
|
||||
};
|
||||
|
||||
/** Every SERVER connection inbound or outbound is represented by an object of
|
||||
@ -95,6 +101,11 @@ class TreeSocket : public BufferedSocket
|
||||
bool LastPingWasGood; /* Responded to last ping we sent? */
|
||||
int proto_version; /* Remote protocol version */
|
||||
bool ConnectionFailureShown; /* Set to true if a connection failure message was shown */
|
||||
|
||||
/** Checks if the given servername and sid are both free
|
||||
*/
|
||||
bool CheckDuplicate(const std::string& servername, const std::string& sid);
|
||||
|
||||
public:
|
||||
time_t age;
|
||||
|
||||
|
@ -164,9 +164,21 @@ void TreeSocket::ProcessLine(std::string &line)
|
||||
ServerInstance->SNO->WriteGlobalSno('l',"\2WARNING\2: Your clocks are out by %d seconds. Please consider synching your clocks.", abs((long)delta));
|
||||
}
|
||||
}
|
||||
|
||||
// Check for duplicate server name/sid again, it's possible that a new
|
||||
// server was introduced while we were waiting for them to send BURST.
|
||||
// (we do not reserve their server name/sid when they send SERVER, we do it now)
|
||||
if (!CheckDuplicate(capab->name, capab->sid))
|
||||
return;
|
||||
|
||||
this->LinkState = CONNECTED;
|
||||
Utils->timeoutlist.erase(this);
|
||||
|
||||
linkID = capab->name;
|
||||
|
||||
MyRoot = new TreeServer(Utils, capab->name, capab->description, capab->sid, Utils->TreeRoot, this, capab->hidden);
|
||||
Utils->TreeRoot->AddChild(MyRoot);
|
||||
|
||||
MyRoot->bursting = true;
|
||||
this->DoBurst(MyRoot);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user