diff options
| author | Adam <Adam@anope.org> | 2012-02-22 18:12:02 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2012-02-22 18:12:02 -0500 |
| commit | 3850b073ddf610415de54dced9ff134397779676 (patch) | |
| tree | c1a464fba432a7a79535fac4c05cc46f8f19901e /modules/protocol | |
| parent | 81e50dd1f404c9bad008fe1b569dad134df91125 (diff) | |
Added regex support for many commands, such as akill, sqline, snline,
all of the */list commands, etc.
Also extended the ability of akill to match a full nick!user@host and
real name of users.
Diffstat (limited to 'modules/protocol')
| -rw-r--r-- | modules/protocol/bahamut.cpp | 62 | ||||
| -rw-r--r-- | modules/protocol/inspircd-ts6.h | 65 | ||||
| -rw-r--r-- | modules/protocol/inspircd11.cpp | 58 | ||||
| -rw-r--r-- | modules/protocol/inspircd12.cpp | 3 | ||||
| -rw-r--r-- | modules/protocol/inspircd20.cpp | 9 | ||||
| -rw-r--r-- | modules/protocol/plexus.cpp | 37 | ||||
| -rw-r--r-- | modules/protocol/ratbox.cpp | 37 | ||||
| -rw-r--r-- | modules/protocol/unreal.cpp | 60 |
8 files changed, 304 insertions, 27 deletions
diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index 078e19a7d..a26669a9b 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -77,7 +77,7 @@ class BahamutIRCdProto : public IRCDProto /* SQLINE */ void SendSQLine(User *, const XLine *x) anope_override { - UplinkSocket::Message() << "SQLINE " << x->Mask << " :" << x->Reason; + UplinkSocket::Message() << "SQLINE " << x->Mask << " :" << x->GetReason(); } /* UNSLINE */ @@ -103,9 +103,9 @@ class BahamutIRCdProto : public IRCDProto if (timeleft > 172800 || !x->Expires) timeleft = 172800; /* this will likely fail so its only here for legacy */ - UplinkSocket::Message() << "SZLINE " << x->GetHost() << " :" << x->Reason; + UplinkSocket::Message() << "SZLINE " << x->GetHost() << " :" << x->GetReason(); /* this is how we are supposed to deal with it */ - UplinkSocket::Message() << "AKILL " << x->GetHost() << " * " << timeleft << " " << x->By << " " << Anope::CurTime << " :" << x->Reason; + UplinkSocket::Message() << "AKILL " << x->GetHost() << " * " << timeleft << " " << x->By << " " << Anope::CurTime << " :" << x->GetReason(); } /* SVSNOOP */ @@ -117,12 +117,27 @@ class BahamutIRCdProto : public IRCDProto /* SGLINE */ void SendSGLine(User *, const XLine *x) anope_override { - UplinkSocket::Message() << "SGLINE " << x->Mask.length() << " :" << x->Mask << ":" << x->Reason; + UplinkSocket::Message() << "SGLINE " << x->Mask.length() << " :" << x->Mask << ":" << x->GetReason(); } /* RAKILL */ void SendAkillDel(const XLine *x) anope_override { + if (x->IsRegex() || x->HasNickOrReal()) + return; + + /* ZLine if we can instead */ + try + { + if (x->GetUser() == "*") + { + sockaddrs(x->GetHost()); + ircdproto->SendSZLineDel(x); + return; + } + } + catch (const SocketException &) { } + UplinkSocket::Message() << "RAKILL " << x->GetHost() << " " << x->GetUser(); } @@ -160,13 +175,48 @@ class BahamutIRCdProto : public IRCDProto } } - void SendAkill(User *, const XLine *x) anope_override + void SendAkill(User *u, XLine *x) anope_override { + 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 (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (x->manager->Check(it->second, x)) + this->SendAkill(it->second, x); + return; + } + + XLine *old = x; + + if (old->manager->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 = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID); + old->manager->AddXLine(x); + + Log(findbot(Config->OperServ), "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; + } + + /* ZLine if we can instead */ + try + { + if (x->GetUser() == "*") + { + sockaddrs(x->GetHost()); + ircdproto->SendSZLine(u, x); + return; + } + } + catch (const SocketException &) { } + // Calculate the time left before this would expire, capping it at 2 days time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800) timeleft = 172800; - UplinkSocket::Message() << "AKILL " << x->GetHost() << " " << x->GetUser() << " " << timeleft << " " << x->By << " " << Anope::CurTime << " :" << x->Reason; + UplinkSocket::Message() << "AKILL " << x->GetHost() << " " << x->GetUser() << " " << timeleft << " " << x->By << " " << Anope::CurTime << " :" << x->GetReason(); } /* diff --git a/modules/protocol/inspircd-ts6.h b/modules/protocol/inspircd-ts6.h index 99b86d3ce..ec6246e49 100644 --- a/modules/protocol/inspircd-ts6.h +++ b/modules/protocol/inspircd-ts6.h @@ -51,7 +51,22 @@ class InspIRCdTS6Proto : public IRCDProto void SendAkillDel(const XLine *x) anope_override { - UplinkSocket::Message(findbot(Config->OperServ)) << "GLINE " << x->Mask; + BotInfo *bi = findbot(Config->OperServ); + + /* InspIRCd may support regex bans */ + if (x->IsRegex() && has_rlinemod) + { + Anope::string mask = x->Mask; + size_t h = x->Mask.find('#'); + if (h != Anope::string::npos) + mask = mask.replace(h, 1, ' '); + UplinkSocket::Message(bi) << "RLINE " << mask; + return; + } + else if (x->IsRegex() || x->HasNickOrReal()) + return; + + UplinkSocket::Message(bi) << "GLINE " << x->Mask; } void SendTopic(BotInfo *whosets, Channel *c) anope_override @@ -70,13 +85,59 @@ class InspIRCdTS6Proto : public IRCDProto this->SendChgIdentInternal(u->nick, u->GetIdent()); } - void SendAkill(User *, const XLine *x) anope_override + void SendAkill(User *u, XLine *x) anope_override { // Calculate the time left before this would expire, capping it at 2 days time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800 || !x->Expires) timeleft = 172800; + BotInfo *bi = findbot(Config->OperServ); + /* InspIRCd may support regex bans, if they do we can send this and forget about it */ + if (x->IsRegex() && has_rlinemod) + { + Anope::string mask = x->Mask; + size_t h = x->Mask.find('#'); + if (h != Anope::string::npos) + mask = mask.replace(h, 1, ' '); + UplinkSocket::Message(bi) << "RLINE " << mask << " " << timeleft << " :" << x->Reason; + 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 (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (x->manager->Check(it->second, x)) + this->SendAkill(it->second, x); + return; + } + + XLine *old = x; + + if (old->manager->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 = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID); + old->manager->AddXLine(x); + + Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; + } + + /* ZLine if we can instead */ + try + { + if (x->GetUser() == "*") + { + sockaddrs(x->GetHost()); + ircdproto->SendSZLine(u, x); + return; + } + } + catch (const SocketException &) { } + UplinkSocket::Message(bi) << "ADDLINE G " << x->GetUser() << "@" << x->GetHost() << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->Reason; } diff --git a/modules/protocol/inspircd11.cpp b/modules/protocol/inspircd11.cpp index d25fd5a86..f4c8c2202 100644 --- a/modules/protocol/inspircd11.cpp +++ b/modules/protocol/inspircd11.cpp @@ -81,6 +81,21 @@ class InspIRCdProto : public IRCDProto { void SendAkillDel(const XLine *x) anope_override { + if (x->IsRegex() || x->HasNickOrReal()) + return; + + /* ZLine if we can instead */ + try + { + if (x->GetUser() == "*") + { + sockaddrs(x->GetHost()); + ircdproto->SendSZLineDel(x); + return; + } + } + catch (const SocketException &) { } + UplinkSocket::Message(findbot(Config->OperServ)) << "GLINE " << x->Mask; } @@ -100,13 +115,48 @@ class InspIRCdProto : public IRCDProto inspircd_cmd_chgident(u->nick, u->GetIdent()); } - void SendAkill(User *, const XLine *x) anope_override + void SendAkill(User *u, XLine *x) anope_override { + 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 (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (x->manager->Check(it->second, x)) + this->SendAkill(it->second, x); + return; + } + + XLine *old = x; + + if (old->manager->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 = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID); + old->manager->AddXLine(x); + + Log(findbot(Config->OperServ), "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; + } + + /* ZLine if we can instead */ + try + { + if (x->GetUser() == "*") + { + sockaddrs(x->GetHost()); + ircdproto->SendSZLine(u, x); + return; + } + } + catch (const SocketException &) { } + // Calculate the time left before this would expire, capping it at 2 days time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800 || !x->Expires) timeleft = 172800; - UplinkSocket::Message(Me) << "ADDLINE G " << x->Mask << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->Reason; + UplinkSocket::Message(Me) << "ADDLINE G " << x->Mask << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason(); } void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) anope_override @@ -194,7 +244,7 @@ class InspIRCdProto : public IRCDProto time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800 || !x->Expires) timeleft = 172800; - UplinkSocket::Message(Me) << "ADDLINE Q " << x->Mask << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->Reason; + UplinkSocket::Message(Me) << "ADDLINE Q " << x->Mask << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason(); } /* Functions that use serval cmd functions */ @@ -254,7 +304,7 @@ class InspIRCdProto : public IRCDProto time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800 || !x->Expires) timeleft = 172800; - UplinkSocket::Message(Me) << "ADDLINE Z " << x->GetHost() << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->Reason; + UplinkSocket::Message(Me) << "ADDLINE Z " << x->GetHost() << " " << x->By << " " << Anope::CurTime << " " << timeleft << " :" << x->GetReason(); } void SendSVSJoin(const BotInfo *source, const Anope::string &nick, const Anope::string &chan, const Anope::string &) anope_override diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp index 68014c52b..b2985c08a 100644 --- a/modules/protocol/inspircd12.cpp +++ b/modules/protocol/inspircd12.cpp @@ -17,6 +17,7 @@ static bool has_globopsmod = false; static bool has_chghostmod = false; static bool has_chgidentmod = false; +static bool has_rlinemod = false; #include "inspircd-ts6.h" IRCDVar myIrcd = { @@ -369,6 +370,8 @@ class Inspircd12IRCdMessage : public InspircdIRCdMessage has_hidechansmod = true; if (params[1].find("m_servprotect.so") != Anope::string::npos) ircd->pseudoclient_mode = "+Ik"; + if (params[1].find("m_rline.so") != Anope::string::npos) + has_rlinemod = true; } else if (params[0].equals_cs("CAPABILITIES")) { diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index c5034e47e..f58f6e172 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -17,6 +17,7 @@ static bool has_chghostmod = false; static bool has_chgidentmod = false; static bool has_globopsmod = true; // Not a typo +static bool has_rlinemod = false; #include "inspircd-ts6.h" IRCDVar myIrcd = { @@ -556,8 +557,16 @@ class Inspircd20IRCdMessage : public InspircdIRCdMessage Anope::string module; while (ssep.GetToken(module)) + { if (module.equals_cs("m_svshold.so")) has_svsholdmod = true; + else if (module.find("m_rline.so") == 0) + { + has_rlinemod = true; + if (!Config->RegexEngine.empty() && Config->RegexEngine != module.substr(11)) + Log() << "Warning: InspIRCd is using regex engine " << module.substr(11) << ", but we have " << Config->RegexEngine << ". This may cause inconsistencies."; + } + } } else if (params[0].equals_cs("MODSUPPORT")) { diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index 3d28f9b7e..983e52630 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -47,7 +47,7 @@ class PlexusProto : public IRCDProto void SendSQLine(User *, const XLine *x) anope_override { - UplinkSocket::Message(Me) << "RESV * " << x->Mask << " :" << x->Reason; + UplinkSocket::Message(Me) << "RESV * " << x->Mask << " :" << x->GetReason(); } void SendSGLineDel(const XLine *x) anope_override @@ -59,11 +59,14 @@ class PlexusProto : public IRCDProto void SendSGLine(User *, const XLine *x) anope_override { BotInfo *bi = findbot(Config->OperServ); - UplinkSocket::Message(bi) << "XLINE * " << x->Mask << " 0 :" << x->Reason; + UplinkSocket::Message(bi) << "XLINE * " << x->Mask << " 0 :" << x->GetReason(); } void SendAkillDel(const XLine *x) anope_override { + if (x->IsRegex() || x->HasNickOrReal()) + return; + BotInfo *bi = findbot(Config->OperServ); UplinkSocket::Message(bi) << "UNKLINE * " << x->GetUser() << " " << x->GetHost(); } @@ -94,14 +97,38 @@ class PlexusProto : public IRCDProto } } - void SendAkill(User *, const XLine *x) anope_override + void SendAkill(User *u, XLine *x) anope_override { + BotInfo *bi = findbot(Config->OperServ); + + 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 (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (x->manager->Check(it->second, x)) + this->SendAkill(it->second, x); + return; + } + + XLine *old = x; + + if (old->manager->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 = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID); + old->manager->AddXLine(x); + + Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; + } + // Calculate the time left before this would expire, capping it at 2 days time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800 || !x->Expires) timeleft = 172800; - BotInfo *bi = findbot(Config->OperServ); - UplinkSocket::Message(bi) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->Reason; + UplinkSocket::Message(bi) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason(); } void SendServer(const Server *server) anope_override diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index eeb0a50ac..ed871480d 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -47,7 +47,7 @@ class RatboxProto : public IRCDProto void SendSQLine(User *, const XLine *x) anope_override { - UplinkSocket::Message(Me) << "RESV * " << x->Mask << " :" << x->Reason; + UplinkSocket::Message(Me) << "RESV * " << x->Mask << " :" << x->GetReason(); } void SendSGLineDel(const XLine *x) anope_override @@ -59,11 +59,14 @@ class RatboxProto : public IRCDProto void SendSGLine(User *, const XLine *x) anope_override { BotInfo *bi = findbot(Config->OperServ); - UplinkSocket::Message(bi) << "XLINE * " << x->Mask << " 0 :" << x->Reason; + UplinkSocket::Message(bi) << "XLINE * " << x->Mask << " 0 :" << x->GetReason(); } void SendAkillDel(const XLine *x) anope_override { + if (x->IsRegex() || x->HasNickOrReal()) + return; + BotInfo *bi = findbot(Config->OperServ); UplinkSocket::Message(bi) << "UNKLINE * " << x->GetUser() << " " << x->GetHost(); } @@ -89,14 +92,38 @@ class RatboxProto : public IRCDProto } } - void SendAkill(User *, const XLine *x) anope_override + void SendAkill(User *u, XLine *x) anope_override { + BotInfo *bi = findbot(Config->OperServ); + + 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 (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (x->manager->Check(it->second, x)) + this->SendAkill(it->second, x); + return; + } + + XLine *old = x; + + if (old->manager->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 = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID); + old->manager->AddXLine(x); + + Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; + } + // Calculate the time left before this would expire, capping it at 2 days time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800 || !x->Expires) timeleft = 172800; - BotInfo *bi = findbot(Config->OperServ); - UplinkSocket::Message(bi) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->Reason; + UplinkSocket::Message(bi) << "KLINE * " << timeleft << " " << x->GetUser() << " " << x->GetHost() << " :" << x->GetReason(); } /* SERVER name hop descript */ diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index 5a3a44bd7..f7c752095 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -48,6 +48,21 @@ class UnrealIRCdProto : public IRCDProto void SendAkillDel(const XLine *x) anope_override { + if (x->IsRegex() || x->HasNickOrReal()) + return; + + /* ZLine if we can instead */ + try + { + if (x->GetUser() == "*") + { + sockaddrs(x->GetHost()); + ircdproto->SendSZLineDel(x); + return; + } + } + catch (const SocketException &) { } + UplinkSocket::Message() << "BD - G " << x->GetUser() << " " << x->GetHost() << " " << Config->OperServ; } @@ -65,13 +80,48 @@ class UnrealIRCdProto : public IRCDProto u->SetMode(bi, UMODE_CLOAK); } - void SendAkill(User *, const XLine *x) anope_override + void SendAkill(User *u, XLine *x) anope_override { + 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 (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (x->manager->Check(it->second, x)) + this->SendAkill(it->second, x); + return; + } + + XLine *old = x; + + if (old->manager->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 = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID); + old->manager->AddXLine(x); + + Log(findbot(Config->OperServ), "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask; + } + + /* ZLine if we can instead */ + try + { + if (x->GetUser() == "*") + { + sockaddrs(x->GetHost()); + ircdproto->SendSZLine(u, x); + return; + } + } + catch (const SocketException &) { } + // Calculate the time left before this would expire, capping it at 2 days time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800 || !x->Expires) timeleft = 172800; - UplinkSocket::Message() << "BD + G " << x->GetUser() << " " << x->GetHost() << " " << x->By << " " << Anope::CurTime + timeleft << " " << x->Created << " :" << x->Reason; + UplinkSocket::Message() << "BD + G " << x->GetUser() << " " << x->GetHost() << " " << x->By << " " << Anope::CurTime + timeleft << " " << x->Created << " :" << x->GetReason(); } void SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) anope_override @@ -149,7 +199,7 @@ class UnrealIRCdProto : public IRCDProto */ void SendSQLine(User *, const XLine *x) anope_override { - UplinkSocket::Message() << "c " << x->Mask << " :" << x->Reason; + UplinkSocket::Message() << "c " << x->Mask << " :" << x->GetReason(); } /* @@ -237,7 +287,7 @@ class UnrealIRCdProto : public IRCDProto time_t timeleft = x->Expires - Anope::CurTime; if (timeleft > 172800 || !x->Expires) timeleft = 172800; - UplinkSocket::Message() << "BD + Z * " << x->GetHost() << " " << x->By << " " << Anope::CurTime + timeleft << " " << x->Created << " :" << x->Reason; + UplinkSocket::Message() << "BD + Z * " << x->GetHost() << " " << x->By << " " << Anope::CurTime + timeleft << " " << x->Created << " :" << x->GetReason(); } /* SGLINE */ @@ -246,7 +296,7 @@ class UnrealIRCdProto : public IRCDProto */ void SendSGLine(User *, const XLine *x) anope_override { - Anope::string edited_reason = x->Reason; + Anope::string edited_reason = x->GetReason(); edited_reason = edited_reason.replace_all_cs(" ", "_"); UplinkSocket::Message() << "BR + " << edited_reason << " :" << x->Mask; } |
