diff options
| author | Adam <Adam@anope.org> | 2012-10-26 10:46:19 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2012-10-26 10:46:19 -0400 |
| commit | 8fd3fc7c13650b9f34c78ed0590b3bd7a7cd10b1 (patch) | |
| tree | 7b6cf4ed7052edb35b30dbb99c8a2f81081884ff /modules/protocol/inspircd20.cpp | |
| parent | 8d27b25bf861072c35f534189b05a7a3811ee8f7 (diff) | |
Add sasl support to unreal, inspircd
Diffstat (limited to 'modules/protocol/inspircd20.cpp')
| -rw-r--r-- | modules/protocol/inspircd20.cpp | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index c547a11d6..2d3a3c4f2 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -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> ¶ms) 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"); |
