diff options
Diffstat (limited to 'modules/protocol/inspircd20.cpp')
| -rw-r--r-- | modules/protocol/inspircd20.cpp | 1931 |
1 files changed, 1206 insertions, 725 deletions
diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index 859bc667f..e53a88eaa 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -1,105 +1,466 @@ -/* Inspircd 2.0 functions +/* + * Anope IRC Services * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2005-2016 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ +/* Dependencies: anope_protocol.rfc1459,anope_protocol.ts6 */ + #include "module.h" -#include "modules/cs_mode.h" +#include "modules/sasl.h" +#include "modules/chanserv/mode.h" +#include "modules/chanserv/set.h" +#include "modules/protocol/rfc1459.h" +#include "modules/protocol/inspircd20.h" +struct SASLUser +{ + Anope::string uid; + Anope::string acc; + time_t created; +}; + +static std::list<SASLUser> saslusers; +static Anope::string rsquit_server, rsquit_id; static unsigned int spanningtree_proto_ver = 0; -static ServiceReference<IRCDProto> insp12("IRCDProto", "inspircd12"); +void inspircd20::senders::Akill::Send(User* u, XLine* x) +{ + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) + timeleft = 172800; + + /* InspIRCd may support regex bans, if they do we can send this and forget about it */ + if (x->IsRegex() && Servers::Capab.count("RLINE")) + { + Anope::string mask = x->GetMask(); + size_t h = mask.find('#'); + if (h != Anope::string::npos) + mask = mask.replace(h, 1, ' '); + proto->SendAddLine("R", mask, timeleft, x->GetBy(), x->GetReason()); + return; + } + else if (x->IsRegex() || x->HasNickOrReal()) + { + if (!u) + { + /* No user (this akill was just added), and contains nick and/or realname. Find users that match and ban them */ + for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (x->GetManager()->Check(it->second, x)) + this->Send(it->second, x); + return; + } + + XLine *old = x; + + if (old->GetManager()->HasEntry("*@" + u->host)) + return; + + /* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */ + x = Serialize::New<XLine *>(); + x->SetMask("*@" + u->host); + x->SetBy(old->GetBy()); + x->SetExpires(old->GetExpires()); + x->SetReason(old->GetReason()); + old->GetManager()->AddXLine(x); -class InspIRCd20Proto : public IRCDProto + Anope::Logger.Bot("OperServ").Category("akill").Log(_("AKILL: Added an akill for {0} because {1}#{2} matches {3}"), + x->GetMask(), u->GetMask(), u->realname, old->GetMask()); + } + + /* ZLine if we can instead */ + if (x->GetUser() == "*") + { + cidr addr(x->GetHost()); + if (addr.valid()) + { + IRCD->Send<messages::SZLine>(u, x); + return; + } + } + + proto->SendAddLine("G", x->GetUser() + "@" + x->GetHost(), timeleft, x->GetBy(), x->GetReason()); +} + +void inspircd20::senders::AkillDel::Send(XLine* x) { - public: - InspIRCd20Proto(Module *creator) : IRCDProto(creator, "InspIRCd 2.0") + /* InspIRCd may support regex bans */ + if (x->IsRegex() && Servers::Capab.count("RLINE")) { - DefaultPseudoclientModes = "+I"; - CanSVSNick = true; - CanSVSJoin = true; - CanSetVHost = true; - CanSetVIdent = true; - CanSQLine = true; - CanSZLine = true; - CanSVSHold = true; - CanCertFP = true; - RequiresID = true; - MaxModes = 20; + Anope::string mask = x->GetMask(); + size_t h = mask.find('#'); + if (h != Anope::string::npos) + mask = mask.replace(h, 1, ' '); + proto->SendDelLine("R", mask); + return; } + else if (x->IsRegex() || x->HasNickOrReal()) + return; - void SendConnect() anope_override + /* ZLine if we can instead */ + if (x->GetUser() == "*") { - UplinkSocket::Message() << "CAPAB START 1202"; - UplinkSocket::Message() << "CAPAB CAPABILITIES :PROTOCOL=1202"; - UplinkSocket::Message() << "CAPAB END"; - insp12->SendConnect(); + cidr addr(x->GetHost()); + if (addr.valid()) + { + IRCD->Send<messages::SZLineDel>(x); + return; + } } - void SendSASLMechanisms(std::vector<Anope::string> &mechanisms) anope_override + proto->SendDelLine("G", x->GetUser() + "@" + x->GetHost()); +} + +void inspircd20::senders::MessageChannel::Send(Channel* c) +{ + Uplink::Send(Me, "FJOIN", c->name, c->creation_time, "+" + c->GetModes(true, true), ""); +} + +void inspircd20::senders::Join::Send(User* user, Channel* c, const ChannelStatus* status) +{ + Uplink::Send(Me, "FJOIN", c->name, c->creation_time, "+" + c->GetModes(true, true), "," + user->GetUID()); + + /* Note that we can send this with the FJOIN but choose not to + * because the mode stacker will handle this and probably will + * merge these modes with +nrt and other mlocked modes + */ + if (status) { - Anope::string mechlist; - for (unsigned i = 0; i < mechanisms.size(); ++i) - mechlist += "," + mechanisms[i]; + /* First save the channel status incase uc->Status == status */ + ChannelStatus cs = *status; + /* If the user is internally on the channel with flags, kill them so that + * the stacker will allow this. + */ + ChanUserContainer *uc = c->FindUser(user); + if (uc != NULL) + uc->status.Clear(); + + ServiceBot *setter = ServiceBot::Find(user->nick); + for (size_t i = 0; i < cs.Modes().length(); ++i) + c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); + + if (uc != NULL) + uc->status = cs; + } +} + +void inspircd20::senders::Login::Send(User *u, NickServ::Nick *na) +{ + /* InspIRCd uses an account to bypass chmode +R, not umode +r, so we can't send this here */ + if (na->GetAccount()->IsUnconfirmed()) + return; + + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", na->GetAccount()->GetDisplay()); +} + +void inspircd20::senders::Logout::Send(User *u) +{ + Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", ""); +} + +void inspircd20::senders::ModeChannel::Send(const MessageSource &source, Channel *channel, const Anope::string &modes) +{ + IRCMessage message(source, "FMODE", channel->name, channel->creation_time); + message.TokenizeAndPush(modes); + Uplink::SendMessage(message); +} - UplinkSocket::Message(Me) << "METADATA * saslmechlist :" << (mechanisms.empty() ? "" : mechlist.substr(1)); +void inspircd20::senders::NickIntroduction::Send(User *user) +{ + Anope::string modes = "+" + user->GetModes(); + Uplink::Send(Me, "UID", user->GetUID(), user->timestamp, user->nick, user->host, user->host, user->GetIdent(), "0.0.0.0", user->timestamp, modes, user->realname); + if (modes.find('o') != Anope::string::npos) + Uplink::Send(user, "OPERTYPE", "services"); +} + + +void inspircd20::senders::SASL::Send(const ::SASL::Message& message) +{ + if (!message.ext.empty()) + Uplink::Send(Me, "ENCAP", message.target.substr(0, 3), "SASL", + message.source, message.target, + message.type, message.data, message.ext); + else + Uplink::Send(Me, "ENCAP", message.target.substr(0, 3), "SASL", + message.source, message.target, + message.type, message.data); +} + +void inspircd20::senders::SASLMechanisms::Send(const std::vector<Anope::string>& mechanisms) +{ + Anope::string mechlist; + for (unsigned int i = 0; i < mechanisms.size(); ++i) + mechlist += "," + mechanisms[i]; + + Uplink::Send(Me, "METADATA", "*", "saslmechlist", mechlist.empty() ? "" : mechlist.substr(1)); +} + +void inspircd20::senders::MessageServer::Send(Server* server) +{ + /* if rsquit is set then we are waiting on a squit */ + if (rsquit_id.empty() && rsquit_server.empty()) + Uplink::Send("SERVER", server->GetName(), Config->Uplinks[Anope::CurrentUplink].password, server->GetHops(), server->GetSID(), server->GetDescription()); +} + +void inspircd20::senders::SQLine::Send(User*, XLine* x) +{ + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) + timeleft = 172800; + proto->SendAddLine("Q", x->GetMask(), timeleft, x->GetBy(), x->GetReason()); +} + +void inspircd20::senders::SQLineDel::Send(XLine* x) +{ + proto->SendDelLine("Q", x->GetMask()); +} + +void inspircd20::senders::SQuit::Send(Server *s, const Anope::string &message) +{ + if (s != Me) + { + rsquit_id = s->GetSID(); + rsquit_server = s->GetName(); + + Uplink::Send("RSQUIT", s->GetName(), message); } + else + { + Uplink::Send("SQUIT", s->GetName(), message); + } +} - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) anope_override { insp12->SendSVSKillInternal(source, user, buf); } - void SendGlobalNotice(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalNotice(bi, dest, msg); } - void SendGlobalPrivmsg(BotInfo *bi, const Server *dest, const Anope::string &msg) anope_override { insp12->SendGlobalPrivmsg(bi, dest, msg); } - void SendAkillDel(const XLine *x) anope_override { insp12->SendAkillDel(x); } - void SendTopic(const MessageSource &whosets, Channel *c) anope_override { insp12->SendTopic(whosets, c); }; - void SendVhostDel(User *u) anope_override { insp12->SendVhostDel(u); } - void SendAkill(User *u, XLine *x) anope_override { insp12->SendAkill(u, x); } - void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) anope_override { insp12->SendNumericInternal(numeric, dest, buf); } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) anope_override { insp12->SendModeInternal(source, dest, buf); } - void SendClientIntroduction(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); } - void SendVhost(User *u, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendVhost(u, vident, vhost); } - void SendSVSHold(const Anope::string &nick, time_t t) anope_override { insp12->SendSVSHold(nick, t); } - void SendSVSHoldDel(const Anope::string &nick) anope_override { insp12->SendSVSHoldDel(nick); } - void SendSZLineDel(const XLine *x) anope_override { insp12->SendSZLineDel(x); } - void SendSZLine(User *u, const XLine *x) anope_override { insp12->SendSZLine(u, x); } - void SendSVSJoin(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string &other) anope_override { insp12->SendSVSJoin(source, u, chan, other); } - void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) anope_override { insp12->SendSVSPart(source, u, chan, param); } - void SendSWhois(const MessageSource &bi, const Anope::string &who, const Anope::string &mask) anope_override { insp12->SendSWhois(bi, who, mask); } - void SendBOB() anope_override { insp12->SendBOB(); } - void SendEOB() anope_override { insp12->SendEOB(); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) { insp12->SendGlobopsInternal(source, buf); } - void SendLogin(User *u, NickAlias *na) anope_override { insp12->SendLogin(u, na); } - void SendLogout(User *u) anope_override { insp12->SendLogout(u); } - void SendChannel(Channel *c) anope_override { insp12->SendChannel(c); } - void SendSASLMessage(const SASL::Message &message) anope_override { insp12->SendSASLMessage(message); } - void SendSVSLogin(const Anope::string &uid, const Anope::string &acc, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendSVSLogin(uid, acc, vident, vhost); } - bool IsExtbanValid(const Anope::string &mask) anope_override { return insp12->IsExtbanValid(mask); } - bool IsIdentValid(const Anope::string &ident) anope_override { return insp12->IsIdentValid(ident); } -}; +void inspircd20::senders::SZLine::Send(User*, XLine* x) +{ + // Calculate the time left before this would expire, capping it at 2 days + time_t timeleft = x->GetExpires() - Anope::CurTime; + if (timeleft > 172800 || !x->GetExpires()) + timeleft = 172800; + proto->SendAddLine("Z", x->GetHost(), timeleft, x->GetBy(), x->GetReason()); +} -class InspIRCdAutoOpMode : public ChannelModeList +void inspircd20::senders::SZLineDel::Send(XLine* x) { - public: - InspIRCdAutoOpMode(char mode) : ChannelModeList("AUTOOP", mode) + proto->SendDelLine("Z", x->GetHost()); +} + +void inspircd20::senders::SVSHold::Send(const Anope::string& nick, time_t t) +{ + Uplink::Send(Config->GetClient("NickServ"), "SVSHOLD", nick, t, "Being held for registered user"); +} + +void inspircd20::senders::SVSHoldDel::Send(const Anope::string& nick) +{ + Uplink::Send(Config->GetClient("NickServ"), "SVSHOLD", nick); +} + +void inspircd20::senders::SVSJoin::Send(const MessageSource& source, User* u, const Anope::string& chan, const Anope::string& key) +{ + Uplink::Send(source, "SVSJOIN", u->GetUID(), chan); +} + +void inspircd20::senders::SVSLogin::Send(const Anope::string& uid, const Anope::string& acc, const Anope::string& vident, const Anope::string& vhost) +{ + Uplink::Send(Me, "METADATA", uid, "accountname", acc); + + SASLUser su; + su.uid = uid; + su.acc = acc; + 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 == uid) + it = saslusers.erase(it); + else + ++it; } - bool IsValid(Anope::string &mask) const anope_override + saslusers.push_back(su); +} + +void inspircd20::senders::SVSNick::Send(User* u, const Anope::string& newnick, time_t ts) +{ + Uplink::Send("SVSNICK", u->GetUID(), newnick, ts); +} + +void inspircd20::senders::SVSPart::Send(const MessageSource& source, User* u, const Anope::string& chan, const Anope::string& reason) +{ + if (!reason.empty()) + Uplink::Send(source, "SVSPART", u->GetUID(), chan, reason); + else + Uplink::Send(source, "SVSPART", u->GetUID(), chan); +} + +void inspircd20::senders::SWhois::Send(const MessageSource&, User *user, const Anope::string& swhois) +{ + Uplink::Send(Me, "METADATA", user->GetUID(), "swhois", swhois); +} + +void inspircd20::senders::Topic::Send(const MessageSource &source, Channel *channel, const Anope::string &topic, time_t topic_ts, const Anope::string &topic_setter) +{ + if (Servers::Capab.count("SVSTOPIC")) + { + Uplink::Send(source, "SVSTOPIC", channel->name, topic_ts, topic_setter, topic); + } + else + { + /* If the last time a topic was set is after the TS we want for this topic we must bump this topic's timestamp to now */ + time_t ts = topic_ts; + if (channel->topic_time > ts) + ts = Anope::CurTime; + /* But don't modify c->topic_ts, it should remain set to the real TS we want as ci->last_topic_time pulls from it */ + Uplink::Send(source, "FTOPIC", channel->name, ts, topic_setter, topic); + } +} + +void inspircd20::senders::VhostDel::Send(User* u) +{ + if (u->HasMode("CLOAK")) + proto->SendChgHostInternal(u->nick, u->chost); + else + proto->SendChgHostInternal(u->nick, u->host); + + if (Servers::Capab.count("CHGIDENT") && u->GetIdent() != u->GetVIdent()) + proto->SendChgIdentInternal(u->nick, u->GetIdent()); +} + +void inspircd20::senders::VhostSet::Send(User* u, const Anope::string& vident, const Anope::string& vhost) +{ + if (!vident.empty()) + proto->SendChgIdentInternal(u->nick, vident); + if (!vhost.empty()) + proto->SendChgHostInternal(u->nick, vhost); +} + +void inspircd20::senders::Wallops::Send(const MessageSource &source, const Anope::string &msg) +{ + if (Servers::Capab.count("GLOBOPS")) + Uplink::Send(source, "SNONOTICE", "g", msg); + else + Uplink::Send(source, "SNONOTICE", "A", msg); +} + +void inspircd20::Proto::SendChgIdentInternal(const Anope::string &nick, const Anope::string &vIdent) +{ + if (!Servers::Capab.count("CHGIDENT")) + Anope::Logger.Log("CHGIDENT not loaded!"); + else + Uplink::Send(Me, "CHGIDENT", nick, vIdent); +} + +void inspircd20::Proto::SendChgHostInternal(const Anope::string &nick, const Anope::string &vhost) +{ + if (!Servers::Capab.count("CHGHOST")) + Anope::Logger.Log("CHGHOST not loaded!"); + else + Uplink::Send(Me, "CHGHOST", nick, vhost); +} + +void inspircd20::Proto::SendAddLine(const Anope::string &xtype, const Anope::string &mask, time_t duration, const Anope::string &addedby, const Anope::string &reason) +{ + Uplink::Send(Me, "ADDLINE", xtype, mask, addedby, Anope::CurTime, duration, reason); +} + +void inspircd20::Proto::SendDelLine(const Anope::string &xtype, const Anope::string &mask) +{ + Uplink::Send(Me, "DELLINE", xtype, mask); +} + +inspircd20::Proto::Proto(Module *creator) : ts6::Proto(creator, "InspIRCd 2.0") +{ + DefaultPseudoclientModes = "+I"; + CanSVSNick = true; + CanSVSJoin = true; + CanSetVHost = true; + CanSetVIdent = true; + CanSQLine = true; + CanSZLine = true; + CanSVSHold = true; + CanCertFP = true; + RequiresID = true; + MaxModes = 20; +} + +void inspircd20::Proto::Handshake() +{ + Uplink::Send("CAPAB START 1202"); + Uplink::Send("CAPAB CAPABILITIES :PROTOCOL=1202"); + Uplink::Send("CAPAB END"); + IRCD->Send<messages::MessageServer>(Me); +} + +void inspircd20::Proto::SendNumeric(int numeric, User *dest, IRCMessage &message) +{ + std::vector<Anope::string> params = message.GetParameters(); + if (params.empty()) + return; + + /* First parameter is the UID, change it to nick because it is pushed */ + params[0] = dest->nick; + + IRCMessage m(message.GetSource(), message.GetCommand()); + for (const Anope::string &s : params) + m.Push(s); + + Uplink::Send("PUSH", dest->GetUID(), Format(m)); +} + +void inspircd20::Proto::SendBOB() +{ + Uplink::Send(Me, "BURST", Anope::CurTime); + Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); + Uplink::Send(Me, "VERSION", Anope::Format("Anope-{0} {1} {2} - {3} - Built: {4} - Flags: {5}", + Anope::Version(), Me->GetName(), IRCD->GetProtocolName(), enc ? enc->name : "(none)", Anope::VersionBuildTime(), Anope::VersionFlags())); +} + +void inspircd20::Proto::SendEOB() +{ + Uplink::Send(Me, "ENDBURST"); +} + +bool inspircd20::Proto::IsExtbanValid(const Anope::string &mask) +{ + return mask.length() >= 3 && mask[1] == ':'; +} + +bool inspircd20::Proto::IsIdentValid(const Anope::string &ident) +{ + if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get<unsigned int>("userlen")) + return false; + + for (unsigned i = 0; i < ident.length(); ++i) { - // We can not validate this because we don't know about the - // privileges of the setter so just reject attempts to set it. + const char &c = ident[i]; + + if (c >= 'A' && c <= '}') + continue; + + if ((c >= '0' && c <= '9') || c == '-' || c == '.') + continue; + return false; } -}; + + return true; +} class InspIRCdExtBan : public ChannelModeVirtual<ChannelModeList> { @@ -111,13 +472,13 @@ class InspIRCdExtBan : public ChannelModeVirtual<ChannelModeList> { } - ChannelMode *Wrap(Anope::string ¶m) anope_override + ChannelMode *Wrap(Anope::string ¶m) override { param = Anope::string(ext) + ":" + param; return ChannelModeVirtual<ChannelModeList>::Wrap(param); } - ChannelMode *Unwrap(ChannelMode *cm, Anope::string ¶m) anope_override + ChannelMode *Unwrap(ChannelMode *cm, Anope::string ¶m) override { if (cm->type != MODE_LIST || param.length() < 3 || param[0] != ext || param[1] != ':') return cm; @@ -136,7 +497,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(3); @@ -152,7 +513,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); @@ -188,12 +549,12 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); - return u->IsIdentified() && real_mask.equals_ci(u->Account()->display); + return u->IsIdentified() && real_mask.equals_ci(u->Account()->GetDisplay()); } }; @@ -204,7 +565,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -219,7 +580,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -227,14 +588,14 @@ namespace InspIRCdExtban } }; - class FinerprintMatcher : public InspIRCdExtBan + class FingerprintMatcher : public InspIRCdExtBan { public: - FinerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c) + FingerprintMatcher(const Anope::string &mname, const Anope::string &mbase, char c) : InspIRCdExtBan(mname, mbase, c) { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -249,7 +610,7 @@ namespace InspIRCdExtban { } - bool Matches(User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) override { const Anope::string &mask = e->GetMask(); Anope::string real_mask = mask.substr(2); @@ -258,783 +619,905 @@ namespace InspIRCdExtban }; } -class ColonDelimitedParamMode : public ChannelModeParam +void inspircd20::Capab::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - public: - ColonDelimitedParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { } - - bool IsValid(Anope::string &value) const anope_override + if (params[0].equals_cs("START")) { - return IsValid(value, false); - } + if (params.size() >= 2) + spanningtree_proto_ver = (Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0); - bool IsValid(const Anope::string &value, bool historymode) const - { - if (value.empty()) - return false; // empty param is never valid + if (spanningtree_proto_ver < 1202) + { + Uplink::Send("ERROR", "Protocol mismatch, no or invalid protocol version given in CAPAB START"); + Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; + Anope::Quitting = true; + return; + } - Anope::string::size_type pos = value.find(':'); - if ((pos == Anope::string::npos) || (pos == 0)) - return false; // no ':' or it's the first char, both are invalid + /* reset CAPAB */ + Servers::Capab.insert("SERVERS"); + Servers::Capab.insert("CHGHOST"); + Servers::Capab.insert("CHGIDENT"); + Servers::Capab.insert("TOPICLOCK"); + IRCD->CanSVSHold = false; + } + else if (params[0].equals_cs("CHANMODES") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string capab; - Anope::string rest; - try + while (ssep.GetToken(capab)) { - if (convertTo<int>(value, rest, false) <= 0) - return false; // negative numbers and zero are invalid + if (capab.find('=') == Anope::string::npos) + continue; - rest = rest.substr(1); - int n; - if (historymode) + Anope::string modename = capab.substr(0, capab.find('=')); + Anope::string modechar = capab.substr(capab.find('=') + 1); + char symbol = 0; + + if (modechar.empty()) + continue; + + if (modechar.length() == 2) { - // For the history mode, the part after the ':' is a duration and it - // can be in the user friendly "1d3h20m" format, make sure we accept that - n = Anope::DoTime(rest); + symbol = modechar[0]; + modechar = modechar.substr(1); } - else - n = convertTo<int>(rest); - if (n <= 0) - return false; + ChannelMode *cm = ModeManager::FindChannelModeByChar(modechar[0]); + if (cm == nullptr) + { + this->GetOwner()->logger.Log("Warning: Uplink has unknown channel mode {0}={1}", + modename, modechar); + continue; + } + + char modesymbol = cm->type == MODE_STATUS ? (anope_dynamic_static_cast<ChannelModeStatus *>(cm))->symbol : 0; + if (symbol != modesymbol) + { + this->GetOwner()->logger.Log("Warning: Channel mode {0} has a misconfigured status character", + modename); + continue; + } } - catch (const ConvertException &e) + } + if (params[0].equals_cs("USERMODES") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string capab; + + while (ssep.GetToken(capab)) { - // conversion error, invalid - return false; - } + if (capab.find('=') == Anope::string::npos) + continue; - return true; - } -}; + Anope::string modename = capab.substr(0, capab.find('=')); + Anope::string modechar = capab.substr(capab.find('=') + 1); -class SimpleNumberParamMode : public ChannelModeParam -{ - public: - SimpleNumberParamMode(const Anope::string &modename, char modeChar) : ChannelModeParam(modename, modeChar, true) { } + if (modechar.empty()) + continue; - bool IsValid(Anope::string &value) const anope_override + UserMode *um = ModeManager::FindUserModeByChar(modechar[0]); + if (um == nullptr) + { + this->GetOwner()->logger.Log("Warning: Uplink has unknown user mode {0}={1}", + modename, modechar); + continue; + } + } + } + else if (params[0].equals_cs("MODULES") && params.size() > 1) { - if (value.empty()) - return false; // empty param is never valid + spacesepstream ssep(params[1]); + Anope::string module; - try + while (ssep.GetToken(module)) { - if (convertTo<int>(value) <= 0) - return false; + if (module.equals_cs("m_svshold.so")) + IRCD->CanSVSHold = true; + else if (module.find("m_rline.so") == 0) + { + Servers::Capab.insert("RLINE"); + const Anope::string ®exengine = Config->GetBlock("options")->Get<Anope::string>("regexengine"); + if (!regexengine.empty() && module.length() > 11 && regexengine != module.substr(11)) + this->GetOwner()->logger.Log("Warning: InspIRCd is using regex engine {0}, but we have {1}. " + "This may cause inconsistencies.", + module.substr(11), regexengine); + } + else if (module.equals_cs("m_topiclock.so")) + Servers::Capab.insert("TOPICLOCK"); } - catch (const ConvertException &e) + } + else if (params[0].equals_cs("MODSUPPORT") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string module; + + while (ssep.GetToken(module)) { - // conversion error, invalid - return false; + if (module.equals_cs("m_services_account.so")) + Servers::Capab.insert("SERVICES"); + else if (module.equals_cs("m_chghost.so")) + Servers::Capab.insert("CHGHOST"); + else if (module.equals_cs("m_chgident.so")) + Servers::Capab.insert("CHGIDENT"); } - - return true; } -}; + else if (params[0].equals_cs("CAPABILITIES") && params.size() > 1) + { + spacesepstream ssep(params[1]); + Anope::string capab; + while (ssep.GetToken(capab)) + { + if (capab.find("MAXMODES=") != Anope::string::npos) + { + Anope::string maxmodes(capab.begin() + 9, capab.end()); + IRCD->MaxModes = maxmodes.is_pos_number_only() ? convertTo<unsigned>(maxmodes) : 3; + } + else if (capab == "GLOBOPS=1") + Servers::Capab.insert("GLOBOPS"); + } + } + else if (params[0].equals_cs("END")) + { + if (!Servers::Capab.count("SERVICES")) + { + Uplink::Send("ERROR", "m_services_account.so is not loaded. This is required by Anope"); + Anope::QuitReason = "ERROR: Remote server does not have the m_services_account module loaded, and this is required."; + Anope::Quitting = true; + return; + } + if (!ModeManager::FindUserModeByName("PRIV")) + { + Uplink::Send("ERROR", "m_hidechans.so is not loaded. This is required by Anope"); + Anope::QuitReason = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required."; + Anope::Quitting = true; + return; + } + if (!IRCD->CanSVSHold) + this->GetOwner()->logger.Log("SVSHOLD missing, Usage disabled until module is loaded."); + if (!Servers::Capab.count("CHGHOST")) + this->GetOwner()->logger.Log("CHGHOST missing, Usage disabled until module is loaded."); + if (!Servers::Capab.count("CHGIDENT")) + this->GetOwner()->logger.Log("CHGIDENT missing, Usage disabled until module is loaded."); + } -class ChannelModeFlood : public ColonDelimitedParamMode + rfc1459::Capab::Run(source, params); +} + +void inspircd20::ChgHost::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - public: - ChannelModeFlood(char modeChar) : ColonDelimitedParamMode("FLOOD", modeChar) { } + User *u = User::Find(params[0]); + if (!u || u->server != Me) + return; - bool IsValid(Anope::string &value) const anope_override - { - // The parameter of this mode is a bit different, it may begin with a '*', - // ignore it if that's the case - Anope::string v = value[0] == '*' ? value.substr(1) : value; - return ((!value.empty()) && (ColonDelimitedParamMode::IsValid(v))); - } -}; + u->SetDisplayedHost(params[1]); + Uplink::Send(u, "FHOST", params[1]); +} -class ChannelModeHistory : public ColonDelimitedParamMode +void inspircd20::ChgIdent::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - public: - ChannelModeHistory(char modeChar) : ColonDelimitedParamMode("HISTORY", modeChar) { } + User *u = User::Find(params[0]); + if (!u || u->server != Me) + return; + + u->SetIdent(params[1]); + Uplink::Send(u, "FIDENT", params[1]); +} + +void inspircd20::ChgName::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + User *u = User::Find(params[0]); + if (!u || u->server != Me) + return; + + u->SetRealname(params[1]); + Uplink::Send(u, "FNAME", params[1]); +} + +void inspircd20::Encap::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + if (Anope::Match(Me->GetSID(), params[0]) == false) + return; + + const Anope::string &command = params[1]; + std::vector<Anope::string> encap_params(params.begin() + 2, params.end()); + + Anope::ProcessCommand(source, command, encap_params); +} - bool IsValid(Anope::string &value) const anope_override +void inspircd20::Endburst::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + Server *s = source.GetServer(); + + s->logger.Debug("Processed ENDBURST for {0}", s->GetName()); + + s->Sync(true); +} + +void inspircd20::FHost::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + User *u = source.GetUser(); + if (u->HasMode("CLOAK")) + u->RemoveModeInternal(source, ModeManager::FindUserModeByName("CLOAK")); + u->SetDisplayedHost(params[0]); +} + +void inspircd20::FIdent::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + source.GetUser()->SetIdent(params[0]); +} + +void inspircd20::FJoin::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) +{ + Anope::string modes; + if (params.size() >= 3) { - return (ColonDelimitedParamMode::IsValid(value, true)); + for (unsigned i = 2; i < params.size() - 1; ++i) + modes += " " + params[i]; + if (!modes.empty()) + modes.erase(modes.begin()); } -}; -class ChannelModeRedirect : public ChannelModeParam -{ - public: - ChannelModeRedirect(char modeChar) : ChannelModeParam("REDIRECT", modeChar, true) { } + std::list<rfc1459::Join::SJoinUser> users; - bool IsValid(Anope::string &value) const anope_override + spacesepstream sep(params[params.size() - 1]); + Anope::string buf; + while (sep.GetToken(buf)) { - // The parameter of this mode is a channel, and channel names start with '#' - return ((!value.empty()) && (value[0] == '#')); + rfc1459::Join::SJoinUser sju; + + /* Loop through prefixes and find modes for them */ + for (char c; !buf.empty() && (c = buf[0]) != ',';) + { + buf.erase(buf.begin()); + sju.first.AddMode(c); + } + /* Erase the , */ + if (!buf.empty()) + buf.erase(buf.begin()); + + sju.second = User::Find(buf); + if (!sju.second) + { + this->GetOwner()->logger.Debug("FJOIN for non-existent user {0} on {1}", buf, params[0]); + continue; + } + + users.push_back(sju); } -}; -struct IRCDMessageCapab : Message::Capab + time_t ts = Anope::string(params[1]).is_pos_number_only() ? convertTo<time_t>(params[1]) : Anope::CurTime; + rfc1459::Join::SJoin(source, params[0], ts, modes, users); +} + +void inspircd20::FMode::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - std::map<char, Anope::string> chmodes, umodes; + /* :source FMODE #test 12345678 +nto foo */ - IRCDMessageCapab(Module *creator) : Message::Capab(creator, "CAPAB") { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Anope::string modes = params[2]; + for (unsigned n = 3; n < params.size(); ++n) + modes += " " + params[n]; - void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override + Channel *c = Channel::Find(params[0]); + time_t ts; + + try { - if (params[0].equals_cs("START")) - { - if (params.size() >= 2) - spanningtree_proto_ver = (Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0); + ts = convertTo<time_t>(params[1]); + } + catch (const ConvertException &) + { + ts = 0; + } - if (spanningtree_proto_ver < 1202) - { - UplinkSocket::Message() << "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START"; - Anope::QuitReason = "Protocol mismatch, no or invalid protocol version given in CAPAB START"; - Anope::Quitting = true; - return; - } + if (c) + c->SetModesInternal(source, modes, ts); +} - /* reset CAPAB */ |
