1
0
mirror of https://github.com/anope/anope.git synced 2026-06-28 22:46:38 +02:00

Rethink jupe/squit thing somewhat. Workaround for the inspircd rsquit/squit mess

This commit is contained in:
Adam
2013-07-26 21:40:16 -04:00
parent f0f43cf426
commit fde83f6564
11 changed files with 182 additions and 157 deletions
+1 -2
View File
@@ -58,8 +58,7 @@ class CoreExport BotInfo : public User, public Serializable
void Serialize(Serialize::Data &data) const;
static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
void Up();
void Down();
void GenerateUID();
/** Change the nickname for the bot.
* @param newnick The nick to change to
+1 -1
View File
@@ -686,7 +686,7 @@ class ModuleDNS : public Module
void OnNewServer(Server *s) anope_override
{
if (Me == NULL || s == Me || s->IsJuped())
if (s == Me || s->IsJuped())
return;
if (!Me->IsSynced() || this->readd_connected_servers)
{
+3
View File
@@ -36,7 +36,10 @@ class CommandOSJupe : public Command
/* Generate the new sid before quitting the old server, so they can't collide */
Anope::string sid = Servers::TS6_SID_Retrieve();
if (server)
{
IRCD->SendSquit(server, rbuf);
server->Delete(rbuf);
}
Server *juped_server = new Server(Me, jserver, 1, rbuf, sid, true);
IRCD->SendServer(juped_server);
+129 -96
View File
@@ -220,7 +220,16 @@ class InspIRCd12Proto : public IRCDProto
/* SERVER services-dev.chatspike.net password 0 :Description here */
void SendServer(const Server *server) anope_override
{
UplinkSocket::Message() << "SERVER " << server->GetName() << " " << Config->Uplinks[Anope::CurrentUplink].password << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription();
if (!server->IsJuped())
UplinkSocket::Message() << "SERVER " << server->GetName() << " " << Config->Uplinks[Anope::CurrentUplink].password << " " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription();
}
void SendSquit(Server *s, const Anope::string &message) anope_override
{
if (s != Me)
UplinkSocket::Message() << "RSQUIT " << s->GetName() << " :" << message;
else
UplinkSocket::Message() << "SQUIT " << s->GetName() << " :" << message;
}
/* JOIN */
@@ -788,6 +797,96 @@ struct IRCDMessageChgName : IRCDMessage
}
};
struct IRCDMessageEncap : IRCDMessage
{
IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
{
if (Anope::Match(Me->GetSID(), params[0]) == false)
return;
if (sasl && params[1] == "SASL" && params.size() == 6)
{
class InspIRCDSASLIdentifyRequest : public IdentifyRequest
{
Anope::string uid;
public:
InspIRCDSASLIdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), uid(id) { }
void OnSuccess() anope_override
{
UplinkSocket::Message(Me) << "METADATA " << this->uid << " accountname :" << this->GetAccount();
UplinkSocket::Message(Me) << "ENCAP " << this->uid.substr(0, 3) << " SASL " << Me->GetSID() << " " << this->uid << " D S";
SASLUser su;
su.uid = this->uid;
su.acc = this->GetAccount();
su.created = Anope::CurTime;
for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();)
{
SASLUser &u = *it;
if (u.created + 30 < Anope::CurTime || u.uid == this->uid)
it = saslusers.erase(it);
else
++it;
}
saslusers.push_back(su);
}
void OnFail() anope_override
{
UplinkSocket::Message(Me) << "ENCAP " << this->uid.substr(0, 3) << " SASL " << Me->GetSID() << " " << this->uid << " " << " D F";
Log(Config->GetClient("NickServ")) << "A user failed to identify for account " << this->GetAccount() << " using SASL";
}
};
/*
Received: :869 ENCAP * SASL 869AAAAAH * S PLAIN
Sent: :00B ENCAP 869 SASL 00B 869AAAAAH C +
Received: :869 ENCAP * SASL 869AAAAAH 00B C QWRhbQBBZGFtAG1vbw==
base64(account\0account\0pass)
*/
if (params[4] == "S")
{
if (params[5] == "PLAIN")
UplinkSocket::Message(Me) << "ENCAP " << params[2].substr(0, 3) << " SASL " << Me->GetSID() << " " << params[2] << " C +";
else
UplinkSocket::Message(Me) << "ENCAP " << params[2].substr(0, 3) << " SASL " << Me->GetSID() << " " << params[2] << " D F";
}
else if (params[4] == "C")
{
Anope::string decoded;
Anope::B64Decode(params[5], decoded);
size_t p = decoded.find('\0');
if (p == Anope::string::npos)
return;
decoded = decoded.substr(p + 1);
p = decoded.find('\0');
if (p == Anope::string::npos)
return;
Anope::string acc = decoded.substr(0, p),
pass = decoded.substr(p + 1);
if (acc.empty() || pass.empty())
return;
IdentifyRequest *req = new InspIRCDSASLIdentifyRequest(this->owner, params[2], acc, pass);
FOREACH_MOD(OnCheckAuthentication, (NULL, req));
req->Dispatch();
}
}
}
};
struct IRCDMessageEndburst : IRCDMessage
{
IRCDMessageEndburst(Module *creator) : IRCDMessage(creator, "ENDBURST", 0) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
@@ -1122,6 +1221,29 @@ struct IRCDMessageServer : IRCDMessage
}
};
struct IRCDMessageSQuit : Message::SQuit
{
IRCDMessageSQuit(Module *creator) : Message::SQuit(creator) { }
void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
{
Server *server = Server::Find(params[0]);
if (server && server->IsJuped())
{
/* It is not possible to recieve a SQUIT for a server we have juped
* unless we have recently sent a RSQUIT. So, this SQUIT is a response
* to the server we just SQUIT off and is not meant for our juped server.
*
* Send the juped server now.
*/
UplinkSocket::Message() << "SERVER " << server->GetName() << " jupe " << server->GetHops() << " " << server->GetSID() << " :" << server->GetDescription();
}
else
Message::SQuit::Run(source, params);
}
};
struct IRCDMessageTime : IRCDMessage
{
IRCDMessageTime(Module *creator) : IRCDMessage(creator, "TIME", 2) { }
@@ -1178,96 +1300,6 @@ struct IRCDMessageUID : IRCDMessage
}
};
struct IRCDMessageEncap : IRCDMessage
{
IRCDMessageEncap(Module *creator) : IRCDMessage(creator, "ENCAP", 4) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
void Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
{
if (Anope::Match(Me->GetSID(), params[0]) == false)
return;
if (sasl && params[1] == "SASL" && params.size() == 6)
{
class InspIRCDSASLIdentifyRequest : public IdentifyRequest
{
Anope::string uid;
public:
InspIRCDSASLIdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), uid(id) { }
void OnSuccess() anope_override
{
UplinkSocket::Message(Me) << "METADATA " << this->uid << " accountname :" << this->GetAccount();
UplinkSocket::Message(Me) << "ENCAP " << this->uid.substr(0, 3) << " SASL " << Me->GetSID() << " " << this->uid << " D S";
SASLUser su;
su.uid = this->uid;
su.acc = this->GetAccount();
su.created = Anope::CurTime;
for (std::list<SASLUser>::iterator it = saslusers.begin(); it != saslusers.end();)
{
SASLUser &u = *it;
if (u.created + 30 < Anope::CurTime || u.uid == this->uid)
it = saslusers.erase(it);
else
++it;
}
saslusers.push_back(su);
}
void OnFail() anope_override
{
UplinkSocket::Message(Me) << "ENCAP " << this->uid.substr(0, 3) << " SASL " << Me->GetSID() << " " << this->uid << " " << " D F";
Log(Config->GetClient("NickServ")) << "A user failed to identify for account " << this->GetAccount() << " using SASL";
}
};
/*
Received: :869 ENCAP * SASL 869AAAAAH * S PLAIN
Sent: :00B ENCAP 869 SASL 00B 869AAAAAH C +
Received: :869 ENCAP * SASL 869AAAAAH 00B C QWRhbQBBZGFtAG1vbw==
base64(account\0account\0pass)
*/
if (params[4] == "S")
{
if (params[5] == "PLAIN")
UplinkSocket::Message(Me) << "ENCAP " << params[2].substr(0, 3) << " SASL " << Me->GetSID() << " " << params[2] << " C +";
else
UplinkSocket::Message(Me) << "ENCAP " << params[2].substr(0, 3) << " SASL " << Me->GetSID() << " " << params[2] << " D F";
}
else if (params[4] == "C")
{
Anope::string decoded;
Anope::B64Decode(params[5], decoded);
size_t p = decoded.find('\0');
if (p == Anope::string::npos)
return;
decoded = decoded.substr(p + 1);
p = decoded.find('\0');
if (p == Anope::string::npos)
return;
Anope::string acc = decoded.substr(0, p),
pass = decoded.substr(p + 1);
if (acc.empty() || pass.empty())
return;
IdentifyRequest *req = new InspIRCDSASLIdentifyRequest(this->owner, params[2], acc, pass);
FOREACH_MOD(OnCheckAuthentication, (NULL, req));
req->Dispatch();
}
}
}
};
class ProtoInspIRCd : public Module
{
InspIRCd12Proto ircd_proto;
@@ -1286,7 +1318,6 @@ class ProtoInspIRCd : public Module
Message::Ping message_ping;
Message::Privmsg message_privmsg;
Message::Quit message_quit;
Message::SQuit message_squit;
Message::Stats message_stats;
Message::Topic message_topic;
@@ -1294,6 +1325,7 @@ class ProtoInspIRCd : public Module
IRCDMessageChgIdent message_chgident;
IRCDMessageChgName message_setname, message_chgname;
IRCDMessageCapab message_capab;
IRCDMessageEncap message_encap;
IRCDMessageEndburst message_endburst;
IRCDMessageFHost message_fhost, message_sethost;
IRCDMessageFJoin message_fjoin;
@@ -1307,21 +1339,22 @@ class ProtoInspIRCd : public Module
IRCDMessageRSQuit message_rsquit;
IRCDMessageSetIdent message_setident;
IRCDMessageServer message_server;
IRCDMessageSQuit message_squit;
IRCDMessageTime message_time;
IRCDMessageUID message_uid;
IRCDMessageEncap message_encap;
public:
ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL | VENDOR),
ircd_proto(this), ssl(this, "ssl"),
message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this), message_kill(this),
message_motd(this), message_notice(this), message_part(this), message_ping(this), message_privmsg(this), message_quit(this),
message_squit(this), message_stats(this), message_topic(this),
message_stats(this), message_topic(this),
message_chgident(this), message_setname(this, "SETNAME"), message_chgname(this, "FNAME"), message_capab(this), message_endburst(this),
message_chgident(this), message_setname(this, "SETNAME"), message_chgname(this, "FNAME"), message_capab(this), message_encap(this),
message_endburst(this),
message_fhost(this, "FHOST"), message_sethost(this, "SETHOST"), message_fjoin(this), message_fmode(this), message_ftopic(this),
message_idle(this), message_metadata(this), message_mode(this), message_nick(this), message_opertype(this), message_rsquit(this),
message_setident(this), message_server(this), message_time(this), message_uid(this), message_encap(this)
message_setident(this), message_server(this), message_squit(this), message_time(this), message_uid(this)
{
Servers::Capab.insert("NOQUIT");
}
+4 -3
View File
@@ -53,6 +53,7 @@ class InspIRCd20Proto : public IRCDProto
void SendModeInternal(const BotInfo *source, const Channel *dest, const Anope::string &buf) anope_override { insp12->SendModeInternal(source, dest, buf); }
void SendClientIntroduction(const User *u) anope_override { insp12->SendClientIntroduction(u); }
void SendServer(const Server *server) anope_override { insp12->SendServer(server); }
void SendSquit(Server *s, const Anope::string &message) anope_override { insp12->SendSquit(s, message); }
void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { insp12->SendJoin(user, c, status); }
void SendSQLineDel(const XLine *x) anope_override { insp12->SendSQLineDel(x); }
void SendSQLine(User *u, const XLine *x) anope_override { insp12->SendSQLine(u, x); }
@@ -679,7 +680,6 @@ class ProtoInspIRCd : public Module
Message::Ping message_ping;
Message::Privmsg message_privmsg;
Message::Quit message_quit;
Message::SQuit message_squit;
Message::Stats message_stats;
Message::Topic message_topic;
@@ -687,7 +687,7 @@ class ProtoInspIRCd : public Module
ServiceAlias message_endburst, message_fhost, message_fjoin, message_fmode,
message_ftopic, message_idle, message_metadata, message_mode,
message_nick, message_opertype, message_rsquit, message_server,
message_time, message_uid;
message_squit, message_time, message_uid;
/* Our message handlers */
IRCDMessageCapab message_capab;
@@ -706,7 +706,7 @@ class ProtoInspIRCd : public Module
ircd_proto(this),
message_away(this), message_error(this), message_invite(this), message_join(this), message_kick(this),
message_kill(this), message_motd(this), message_notice(this), message_part(this), message_ping(this),
message_privmsg(this), message_quit(this), message_squit(this), message_stats(this), message_topic(this),
message_privmsg(this), message_quit(this), message_stats(this), message_topic(this),
message_endburst("IRCDMessage", "inspircd20/endburst", "inspircd12/endburst"),
message_fhost("IRCDMessage", "inspircd20/fhost", "inspircd12/fhost"),
@@ -720,6 +720,7 @@ class ProtoInspIRCd : public Module
message_opertype("IRCDMessage", "inspircd20/opertype", "inspircd12/opertype"),
message_rsquit("IRCDMessage", "inspircd20/rsquit", "inspircd12/rsquit"),
message_server("IRCDMessage", "inspircd20/server", "inspircd12/server"),
message_squit("IRCDMessage", "inspircd20/squit", "inspircd12/squit"),
message_time("IRCDMessage", "inspircd20/time", "inspircd12/time"),
message_uid("IRCDMessage", "inspircd20/uid", "inspircd12/uid"),
+1 -1
View File
@@ -79,7 +79,7 @@ class GlobalCore : public Module, public GlobalService
void OnNewServer(Server *s) anope_override
{
const Anope::string &gl = Config->GetModule(this)->Get<const Anope::string>("globaloncycleup");
if (!gl.empty() && Me && !Me->IsSynced())
if (!gl.empty() && !Me->IsSynced())
s->Notice(Global, gl);
}
+1 -12
View File
@@ -106,7 +106,7 @@ Serializable* BotInfo::Unserialize(Serializable *obj, Serialize::Data &data)
return bi;
}
void BotInfo::Up()
void BotInfo::GenerateUID()
{
if (!this->uid.empty())
throw CoreException("Bot already has a uid?");
@@ -114,17 +114,6 @@ void BotInfo::Up()
this->uid = Servers::TS6_UID_Retrieve();
(*BotListByUID)[this->uid] = this;
UserListByUID[this->uid] = this;
this->server = Me;
++this->server->users;
}
void BotInfo::Down()
{
BotListByUID->erase(this->uid);
UserListByUID.erase(this->uid);
--this->server->users;
this->server = NULL;
this->uid = "";
}
void BotInfo::SetNewNick(const Anope::string &newnick)
+1
View File
@@ -149,6 +149,7 @@ Conf::Conf() : Block("")
{"serverinfo", "name"},
{"serverinfo", "description"},
{"serverinfo", "localhost"},
{"serverinfo", "id"},
{"serverinfo", "pid"},
{"networkinfo", "nicklen"},
{"networkinfo", "userlen"},
+20 -1
View File
@@ -428,6 +428,15 @@ void Anope::Init(int ac, char **av)
/* Write our PID to the PID file. */
write_pidfile();
/* Create me */
Configuration::Block *block = Config->GetBlock("serverinfo");
Me = new Server(NULL, block->Get<const Anope::string>("name"), 0, block->Get<const Anope::string>("description"), block->Get<const Anope::string>("id"));
for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
{
it->second->server = Me;
++Me->users;
}
/* Announce ourselves to the logfile. */
Log() << "Anope " << Anope::Version() << " starting up" << (Anope::Debug || Anope::ReadOnly ? " (options:" : "") << (Anope::Debug ? " debug" : "") << (Anope::ReadOnly ? " readonly" : "") << (Anope::Debug || Anope::ReadOnly ? ")" : "");
@@ -437,7 +446,7 @@ void Anope::Init(int ac, char **av)
Language::InitLanguages();
/* Initialize random number generator */
Configuration::Block *block = Config->GetBlock("options");
block = Config->GetBlock("options");
srand(block->Get<unsigned>("seed"));
/* load modules */
@@ -451,6 +460,16 @@ void Anope::Init(int ac, char **av)
Log() << "Using IRCd protocol " << protocol->name;
/* Auto assign sid if applicable */
if (IRCD->RequiresID)
{
Anope::string sid = Servers::TS6_SID_Retrieve();
if (Me->GetSID() == Me->GetName())
Me->SetSID(sid);
for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
it->second->GenerateUID();
}
/* Load up databases */
Log() << "Loading databases...";
EventReturn MOD_RESULT;
-1
View File
@@ -264,7 +264,6 @@ void IRCDProto::SendGlobops(const BotInfo *source, const char *fmt, ...)
void IRCDProto::SendSquit(Server *s, const Anope::string &message)
{
UplinkSocket::Message() << "SQUIT " << s->GetSID() << " :" << message;
s->Delete(message);
}
void IRCDProto::SendNickChange(const User *u, const Anope::string &newnick)
+21 -40
View File
@@ -61,56 +61,42 @@ void Uplink::Connect()
UplinkSocket::UplinkSocket() : Socket(-1, Config->Uplinks[Anope::CurrentUplink].ipv6), ConnectionSocket(), BufferedSocket()
{
/* Create me */
Configuration::Block *block = Config->GetBlock("serverinfo");
Anope::string id = block->Get<const Anope::string>("id");
if (id.empty())
/* Defalt to a valid ts6 sid if this ircd is ts6 */
id = Servers::TS6_SID_Retrieve();
Me = new Server(NULL, block->Get<const Anope::string>("name"), 0, block->Get<const Anope::string>("description"), id);
for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
{
BotInfo *bi = it->second;
bi->Up();
}
UplinkSock = this;
}
UplinkSocket::~UplinkSocket()
{
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
if (IRCD && Servers::GetUplink() && Servers::GetUplink()->IsSynced())
{
User *u = it->second;
FOREACH_MOD(OnServerDisconnect, ());
if (u->server == Me)
for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it)
{
/* Don't use quitmsg here, it may contain information you don't want people to see */
IRCD->SendQuit(u, "Shutting down");
BotInfo* bi = BotInfo::Find(u->nick);
if (bi != NULL)
User *u = it->second;
if (u->server == Me)
{
bi->introduced = false;
bi->Down();
/* Don't use quitmsg here, it may contain information you don't want people to see */
IRCD->SendQuit(u, "Shutting down");
BotInfo* bi = BotInfo::Find(u->nick);
if (bi != NULL)
bi->introduced = false;
}
else
/* Enforcer client or some other non-service bot */
u->Quit("Shutting down");
}
IRCD->SendSquit(Me, Anope::QuitReason);
this->ProcessWrite(); // Write out the last bit
}
User::QuitUsers();
FOREACH_MOD(OnServerDisconnect, ());
IRCD->SendSquit(Me, Anope::QuitReason);
Me = NULL;
this->ProcessWrite(); // Write out the last bit
for (unsigned i = Me->GetLinks().size(); i > 0; --i)
if (!Me->GetLinks()[i - 1]->IsJuped())
Me->GetLinks()[i - 1]->Delete(Me->GetName() + " " + Me->GetLinks()[i - 1]->GetName());
UplinkSock = NULL;
Me->Unsync();
if (Anope::AtTerm())
{
if (static_cast<unsigned>(Anope::CurrentUplink + 1) == Config->Uplinks.size())
@@ -186,12 +172,7 @@ UplinkSocket::Message::~Message()
}
else if (this->user != NULL)
{
if (this->user->server == NULL)
{
Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << this->user->nick << " who has no server (I'm not introduced?)";
return;
}
else if (this->user->server != Me && !this->user->server->IsJuped())
if (this->user->server != Me && !this->user->server->IsJuped())
{
Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << this->user->nick << " who is not from me?";
return;