1
0
mirror of https://github.com/anope/anope.git synced 2026-07-07 13:23:12 +02:00

Add sasl support to unreal, inspircd

This commit is contained in:
Adam
2012-10-26 10:46:19 -04:00
parent 8d27b25bf8
commit 8fd3fc7c13
3 changed files with 145 additions and 4 deletions
+8 -1
View File
@@ -579,9 +579,16 @@ struct IRCDMessageMetadata : IRCDMessage
{
u->Login(nc);
const BotInfo *bi = findbot(Config->NickServ);
const NickAlias *user_na = findnick(u->nick);
if (!Config->NoNicknameOwnership && nickserv && user_na && user_na->nc == nc && user_na->nc->HasFlag(NI_UNCONFIRMED) == false)
u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
u->SetMode(bi, UMODE_REGISTERED);
/* Sometimes a user connects, we send them the usual "this nickname is registered" mess (if
* their server isn't syncing) and then we receive this.. so tell them about it.
*/
if (bi)
u->SendMessage(bi, _("You have been logged in as \2%s\2."), nc->display.c_str());
}
}
+58 -2
View File
@@ -447,7 +447,9 @@ struct IRCDMessageCapab : IRCDMessage
struct IRCDMessageEncap : IRCDMessage
{
IRCDMessageEncap() : IRCDMessage("ENCAP", 4) { }
Module *me;
IRCDMessageEncap(Module *m) : IRCDMessage("ENCAP", 4), me(m) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); }
bool Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
{
@@ -481,6 +483,60 @@ struct IRCDMessageEncap : IRCDMessage
u->SetRealname(params[3]);
UplinkSocket::Message(u) << "FNAME " << params[3];
}
else if (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";
}
void OnFail() anope_override
{
UplinkSocket::Message(Me) << "ENCAP " << this->uid.substr(0, 3) << " SASL " << Me->GetSID() << " " << this->uid << " " << " D F";
}
};
/*
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")
UplinkSocket::Message(Me) << "ENCAP " << params[2].substr(0, 3) << " SASL " << Me->GetSID() << " " << params[2] << " C +";
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 true;
decoded = decoded.substr(p + 1);
p = decoded.find('\0');
if (p == Anope::string::npos)
return true;
Anope::string acc = decoded.substr(0, p),
pass = decoded.substr(p + 1);
if (acc.empty() || pass.empty())
return true;
IdentifyRequest *req = new InspIRCDSASLIdentifyRequest(me, params[2], acc, pass);
FOREACH_MOD(I_OnCheckAuthentication, OnCheckAuthentication(NULL, req));
req->Dispatch();
}
}
return true;
}
@@ -546,7 +602,7 @@ class ProtoInspIRCd : public Module
public:
ProtoInspIRCd(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL),
message_fhost("FHOST")
message_fhost("FHOST"), message_encap(this)
{
this->SetAuthor("Anope");
+79 -1
View File
@@ -851,6 +851,83 @@ struct IRCDMessagePong : IRCDMessage
}
};
struct IRCDMessageSASL : IRCDMessage
{
class UnrealSASLIdentifyRequest : public IdentifyRequest
{
Anope::string uid;
public:
UnrealSASLIdentifyRequest(Module *m, const Anope::string &id, const Anope::string &acc, const Anope::string &pass) : IdentifyRequest(m, acc, pass), uid(id) { }
void OnSuccess() anope_override
{
size_t p = this->uid.find('!');
if (p == Anope::string::npos)
return;
UplinkSocket::Message(Me) << "SVSLOGIN " << this->uid.substr(0, p) << " " << this->uid << " " << this->GetAccount();
UplinkSocket::Message(findbot(Config->NickServ)) << "SASL " << this->uid.substr(0, p) << " " << this->uid << " D S";
}
void OnFail() anope_override
{
size_t p = this->uid.find('!');
if (p == Anope::string::npos)
return;
UplinkSocket::Message(findbot(Config->NickServ)) << "SASL " << this->uid.substr(0, p) << " " << this->uid << " D F";
}
};
Module *me;
IRCDMessageSASL(Module *m) : IRCDMessage("SASL", 4), me(m) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
/* Received: :irc.foonet.com SASL services.localhost.net irc.foonet.com!1.57290 S PLAIN
* uid
*
* Received: :irc.foonet.com SASL services.localhost.net irc.foonet.com!3.56270 C QWRhbQBBZGFtAHF3ZXJ0eQ==
* uid base64(account\0account\0pass)
*/
bool Run(MessageSource &source, const std::vector<Anope::string> &params) anope_override
{
size_t p = params[1].find('!');
if (p == Anope::string::npos)
return true;
/* Unreal segfaults if we send from Me */
if (params[2] == "S")
UplinkSocket::Message(findbot(Config->NickServ)) << "SASL " << params[1].substr(0, p) << " " << params[1] << " C +";
else if (params[2] == "C")
{
Anope::string decoded;
Anope::B64Decode(params[3], decoded);
p = decoded.find('\0');
if (p == Anope::string::npos)
return true;
decoded = decoded.substr(p + 1);
p = decoded.find('\0');
if (p == Anope::string::npos)
return true;
Anope::string acc = decoded.substr(0, p),
pass = decoded.substr(p + 1);
if (acc.empty() || pass.empty())
return true;
IdentifyRequest *req = new UnrealSASLIdentifyRequest(me, params[1], acc, pass);
FOREACH_MOD(I_OnCheckAuthentication, OnCheckAuthentication(NULL, req));
req->Dispatch();
}
return true;
}
};
struct IRCDMessageSDesc : IRCDMessage
{
IRCDMessageSDesc() : IRCDMessage("SDESC", 1) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); }
@@ -1124,6 +1201,7 @@ class ProtoUnreal : public Module
IRCDMessageNetInfo message_netinfo;
IRCDMessageNick message_nick;
IRCDMessagePong message_pong;
IRCDMessageSASL message_sasl;
IRCDMessageSDesc message_sdesc;
IRCDMessageSetHost message_sethost;
IRCDMessageSetIdent message_setident;
@@ -1173,7 +1251,7 @@ class ProtoUnreal : public Module
public:
ProtoUnreal(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PROTOCOL),
message_mode("MODE"), message_svsmode("SVSMODE"), message_svs2mode("SVS2MODE")
message_mode("MODE"), message_svsmode("SVSMODE"), message_svs2mode("SVS2MODE"), message_sasl(this)
{
this->SetAuthor("Anope");