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 | |
| 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')
| -rw-r--r-- | modules/commands/cs_list.cpp | 6 | ||||
| -rw-r--r-- | modules/commands/ns_list.cpp | 6 | ||||
| -rw-r--r-- | modules/commands/os_akill.cpp | 201 | ||||
| -rw-r--r-- | modules/commands/os_chankill.cpp | 2 | ||||
| -rw-r--r-- | modules/commands/os_forbid.cpp | 15 | ||||
| -rw-r--r-- | modules/commands/os_ignore.cpp | 6 | ||||
| -rw-r--r-- | modules/commands/os_list.cpp | 10 | ||||
| -rw-r--r-- | modules/commands/os_sxline.cpp | 334 | ||||
| -rw-r--r-- | modules/extra/m_regex_pcre.cpp | 55 | ||||
| -rw-r--r-- | modules/extra/m_regex_posix.cpp | 57 | ||||
| -rw-r--r-- | modules/extra/m_regex_tre.cpp | 58 | ||||
| -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 | ||||
| -rw-r--r-- | modules/pseudoclients/operserv.cpp | 99 |
20 files changed, 882 insertions, 298 deletions
diff --git a/modules/commands/cs_list.cpp b/modules/commands/cs_list.cpp index 57c14d157..77d7613fe 100644 --- a/modules/commands/cs_list.cpp +++ b/modules/commands/cs_list.cpp @@ -87,7 +87,7 @@ class CommandCSList : public Command else if (channoexpire && !ci->HasFlag(CI_NO_EXPIRE)) continue; - if (pattern.equals_ci(ci->name) || ci->name.equals_ci(spattern) || Anope::Match(ci->name, pattern) || Anope::Match(ci->name, spattern)) + if (pattern.equals_ci(ci->name) || ci->name.equals_ci(spattern) || Anope::Match(ci->name, pattern, false, true) || Anope::Match(ci->name, spattern, false, true)) { if (((count + 1 >= from && count + 1 <= to) || (!from && !to)) && ++nchans <= Config->CSListMax) { @@ -125,6 +125,10 @@ class CommandCSList : public Command "(Channels with the \002PRIVATE\002 option set are not listed.)\n" "Note that a preceding '#' specifies a range, channel names\n" "are to be written without '#'.")); + if (!Config->RegexEngine.empty()) + source.Reply(" \n" + "Regex matches are also supported using the %s engine.\n" + "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str()); return true; } }; diff --git a/modules/commands/ns_list.cpp b/modules/commands/ns_list.cpp index 491ed8733..de2852302 100644 --- a/modules/commands/ns_list.cpp +++ b/modules/commands/ns_list.cpp @@ -93,7 +93,7 @@ class CommandNSList : public Command * Instead we build a nice nick!user@host buffer to compare. * The output is then generated separately. -TheShadow */ Anope::string buf = Anope::printf("%s!%s", na->nick.c_str(), !na->last_usermask.empty() ? na->last_usermask.c_str() : "*@*"); - if (na->nick.equals_ci(pattern) || Anope::Match(buf, pattern)) + if (na->nick.equals_ci(pattern) || Anope::Match(buf, pattern, false, true)) { if (((count + 1 >= from && count + 1 <= to) || (!from && !to)) && ++nnicks <= Config->NSListMax) { @@ -156,6 +156,10 @@ class CommandNSList : public Command " \n" " \002LIST * NOEXPIRE\002\n" " Lists all registered nicks which have been set to not expire.\n")); + if (!Config->RegexEngine.empty()) + source.Reply(" \n" + "Regex matches are also supported using the %s engine.\n" + "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str()); return true; } diff --git a/modules/commands/os_akill.cpp b/modules/commands/os_akill.cpp index d886ce2b3..f59c26e1f 100644 --- a/modules/commands/os_akill.cpp +++ b/modules/commands/os_akill.cpp @@ -60,19 +60,24 @@ class CommandOSAKill : public Command void DoAdd(CommandSource &source, const std::vector<Anope::string> ¶ms) { User *u = source.u; - unsigned last_param = 2; Anope::string expiry, mask; - time_t expires; - mask = params.size() > 1 ? params[1] : ""; - if (!mask.empty() && mask[0] == '+') + if (params.size() < 2) + { + this->OnSyntaxError(source, "ADD"); + return; + } + + spacesepstream sep(params[1]); + sep.GetToken(mask); + + if (mask[0] == '+') { expiry = mask; - mask = params.size() > 2 ? params[2] : ""; - last_param = 3; + sep.GetToken(mask); } - expires = !expiry.empty() ? dotime(expiry) : Config->AutokillExpiry; + time_t expires = !expiry.empty() ? dotime(expiry) : Config->AutokillExpiry; /* If the expiry given does not contain a final letter, it's in days, * said the doc. Ah well. */ @@ -87,84 +92,108 @@ class CommandOSAKill : public Command else if (expires > 0) expires += Anope::CurTime; - if (params.size() <= last_param) + if (sep.StreamEnd()) { this->OnSyntaxError(source, "ADD"); return; } - Anope::string reason = params[last_param]; - if (last_param == 2 && params.size() > 3) - reason += " " + params[3]; - if (!mask.empty() && !reason.empty()) + Anope::string reason; + if (mask.find('#') != Anope::string::npos) { - User *targ = NULL; - std::pair<int, XLine *> canAdd = akills->CanAdd(mask, expires); - if (mask.find('!') != Anope::string::npos) - source.Reply(_("\002Reminder\002: AKILL masks cannot contain nicknames; make sure you have \002not\002 included a nick portion in your mask.")); - else if (mask.find('@') == Anope::string::npos && !(targ = finduser(mask))) - source.Reply(BAD_USERHOST_MASK); - else if (mask.find_first_not_of("~@.*?") == Anope::string::npos) - source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); - else if (canAdd.first == 1) - source.Reply(_("\002%s\002 already exists on the AKILL list."), canAdd.second->Mask.c_str()); - else if (canAdd.first == 2) - source.Reply(_("Expiry time of \002%s\002 changed."), canAdd.second->Mask.c_str()); - else if (canAdd.first == 3) - source.Reply(_("\002%s\002 is already covered by %s."), mask.c_str(), canAdd.second->Mask.c_str()); - else + Anope::string remaining = sep.GetRemaining(); + + size_t co = remaining[0] == ':' ? 0 : remaining.rfind(" :"); + if (co == Anope::string::npos) { - if (targ) - mask = "*@" + targ->host; - unsigned int affected = 0; - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (Anope::Match(it->second->GetIdent() + "@" + it->second->host, mask)) - ++affected; - float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; - - if (percent > 95) - { - source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); - Log(LOG_ADMIN, u, this) << "tried to akill " << percent << "% of the network (" << affected << " users)"; - return; - } + this->OnSyntaxError(source, "ADD"); + return; + } - if (Config->AddAkiller) - reason = "[" + u->nick + "] " + reason; + if (co != 0) + ++co; - Anope::string id; - if (Config->AkillIds) - { - id = XLineManager::GenerateUID(); - reason = reason + " (ID: " + id + ")"; - } + reason = remaining.substr(co + 1); + mask += " " + remaining.substr(0, co); + mask.trim(); + } + else + reason = sep.GetRemaining(); - XLine *x = new XLine(mask, u->nick, expires, reason, id); + if (mask[0] == '/' && mask[mask.length() - 1] == '/') + { + if (Config->RegexEngine.empty()) + { + source.Reply(_("Regex is enabled.")); + return; + } - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, akills)); - if (MOD_RESULT == EVENT_STOP) - { - delete x; - return; - } + service_reference<RegexProvider> provider("Regex", Config->RegexEngine); + if (!provider) + { + source.Reply(_("Unable to find regex engine %s"), Config->RegexEngine.c_str()); + return; + } - akills->AddXLine(x); - if (Config->AkillOnAdd) - akills->Send(NULL, x); + try + { + Anope::string stripped_mask = mask.substr(1, mask.length() - 2); + delete provider->Compile(stripped_mask); + } + catch (const RegexException &ex) + { + source.Reply("%s", ex.GetReason().c_str()); + return; + } + } - source.Reply(_("\002%s\002 added to the AKILL list."), mask.c_str()); + User *targ = finduser(mask); + if (targ) + mask = "*@" + targ->host; - Log(LOG_ADMIN, u, this) << "on " << mask << " (" << x->Reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]"; + if (!akills->CanAdd(source, mask, expires, reason)) + return; + else if (mask.find_first_not_of("/~@.*?") == Anope::string::npos) + { + source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); + return; + } - if (readonly) - source.Reply(READ_ONLY_MODE); - } + XLine *x = new XLine(mask, u->nick, expires, reason); + if (Config->AkillIds) + x->UID = XLineManager::GenerateUID(); + + unsigned int affected = 0; + for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (akills->Check(it->second, x)) + ++affected; + float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; + + if (percent > 95) + { + source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); + Log(LOG_ADMIN, u, this) << "tried to akill " << percent << "% of the network (" << affected << " users)"; + delete x; + return; } - else - this->OnSyntaxError(source, "ADD"); - return; + EventReturn MOD_RESULT; + FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, akills)); + if (MOD_RESULT == EVENT_STOP) + { + delete x; + return; + } + + akills->AddXLine(x); + if (Config->AkillOnAdd) + akills->Send(NULL, x); + + source.Reply(_("\002%s\002 added to the AKILL list."), mask.c_str()); + + Log(LOG_ADMIN, u, this) << "on " << mask << " (" << x->Reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]"; + if (readonly) + source.Reply(READ_ONLY_MODE); } void DoDel(CommandSource &source, const std::vector<Anope::string> ¶ms) @@ -199,10 +228,14 @@ class CommandOSAKill : public Command return; } - FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, x, akills)); + do + { + FOREACH_MOD(I_OnDelXLine, OnDelXLine(u, x, akills)); - source.Reply(_("\002%s\002 deleted from the AKILL list."), x->Mask.c_str()); - AkillDelCallback::DoDel(source, x); + source.Reply(_("\002%s\002 deleted from the AKILL list."), x->Mask.c_str()); + AkillDelCallback::DoDel(source, x); + } + while ((x = akills->HasEntry(mask))); } @@ -240,7 +273,7 @@ class CommandOSAKill : public Command entry["Number"] = stringify(number); entry["Mask"] = x->Mask; entry["Creator"] = x->By; - entry["Created"] = do_strftime(x->Created); + entry["Created"] = do_strftime(x->Created, NULL, true); entry["Expires"] = expire_left(NULL, x->Expires); entry["Reason"] = x->Reason; this->list.addEntry(entry); @@ -255,13 +288,13 @@ class CommandOSAKill : public Command { XLine *x = akills->GetEntry(i); - if (mask.empty() || mask.equals_ci(x->Mask) || mask == x->UID || Anope::Match(x->Mask, mask)) + if (mask.empty() || mask.equals_ci(x->Mask) || mask == x->UID || Anope::Match(x->Mask, mask, false, true)) { ListFormatter::ListEntry entry; entry["Number"] = stringify(i + 1); entry["Mask"] = x->Mask; entry["Creator"] = x->By; - entry["Created"] = do_strftime(x->Created); + entry["Created"] = do_strftime(x->Created, NULL, true); entry["Expires"] = expire_left(source.u->Account(), x->Expires); entry["Reason"] = x->Reason; list.addEntry(entry); @@ -327,7 +360,7 @@ class CommandOSAKill : public Command source.Reply(_("The AKILL list has been cleared.")); } public: - CommandOSAKill(Module *creator) : Command(creator, "operserv/akill", 1, 4) + CommandOSAKill(Module *creator) : Command(creator, "operserv/akill", 1, 2) { this->SetDesc(_("Manipulate the AKILL list")); this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037 \037reason\037")); @@ -367,11 +400,14 @@ class CommandOSAKill : public Command source.Reply(_("Allows Services operators to manipulate the AKILL list. If\n" "a user matching an AKILL mask attempts to connect, Services\n" "will issue a KILL for that user and, on supported server\n" - "types, will instruct all servers to add a ban (K-line) for\n" - "the mask which the user matched.\n" + "types, will instruct all servers to add a ban for the mask\n" + "which the user matched.\n" " \n" - "\002AKILL ADD\002 adds the given nick or user@host/ip mask to the AKILL\n" - "list for the given reason (which \002must\002 be given).\n" + "\002AKILL ADD\002 adds the given mask to the AKILL\n" + "list for the given reason, which \002must\002 be given.\n" + "Mask should be in the format of nick!user@host#real name,\n" + "though all that is required is user@host. If a real name is specified,\n" + "the reason must be prepended with a :.\n" "\037expiry\037 is specified as an integer followed by one of \037d\037 \n" "(days), \037h\037 (hours), or \037m\037 (minutes). Combinations (such as \n" "\0371h30m\037) are not permitted. If a unit specifier is not \n" @@ -380,7 +416,12 @@ class CommandOSAKill : public Command "usermask to be added starts with a \037+\037, an expiry time must\n" "be given, even if it is the same as the default. The\n" "current AKILL default expiry time can be found with the\n" - "\002STATS AKILL\002 command.\n" + "\002STATS AKILL\002 command.\n")); + if (!Config->RegexEngine.empty()) + source.Reply(" \n" + "Regex matches are also supported using the %s engine.\n" + "Enclose your mask in // if this desired.", Config->RegexEngine.c_str()); + source.Reply(_( " \n" "The \002AKILL DEL\002 command removes the given mask from the\n" "AKILL list if it is present. If a list of entry numbers is \n" diff --git a/modules/commands/os_chankill.cpp b/modules/commands/os_chankill.cpp index 8b56eb3c2..bbfb5121b 100644 --- a/modules/commands/os_chankill.cpp +++ b/modules/commands/os_chankill.cpp @@ -82,7 +82,7 @@ class CommandOSChanKill : public Command XLine *x = new XLine("*@" + uc->user->host, u->nick, expires, realreason, XLineManager::GenerateUID()); akills->AddXLine(x); - akills->Check(uc->user); + akills->OnMatch(uc->user, x); } Log(LOG_ADMIN, u, this) << "on " << c->name << " (" << realreason << ")"; diff --git a/modules/commands/os_forbid.cpp b/modules/commands/os_forbid.cpp index 908e2f2ca..d305de3c6 100644 --- a/modules/commands/os_forbid.cpp +++ b/modules/commands/os_forbid.cpp @@ -41,7 +41,7 @@ class MyForbidService : public ForbidService { ForbidData *d = this->forbidData[i - 1]; - if ((ftype == FT_NONE || ftype == d->type) && Anope::Match(mask, d->mask)) + if ((ftype == FT_NONE || ftype == d->type) && Anope::Match(mask, d->mask, false, true)) return d; } return NULL; @@ -217,6 +217,10 @@ class CommandOSForbid : public Command source.Reply(" "); source.Reply(_("Forbid allows you to forbid usage of certain nicknames, channels,\n" "and email addresses. Wildcards are accepted for all entries.")); + if (!Config->RegexEngine.empty()) + source.Reply(" \n" + "Regex matches are also supported using the %s engine.\n" + "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str()); return true; } }; @@ -273,8 +277,13 @@ class OSForbid : public Module BotInfo *bi = findbot(Config->OperServ); ForbidData *d = this->forbidService.FindForbid(c->name, FT_CHAN); if (bi != NULL && d != NULL) - { - if (!c->HasFlag(CH_INHABIT)) + { + if (ircd->chansqline) + { + XLine x(c->name, bi->nick, Anope::CurTime + Config->CSInhabit, d->reason); + ircdproto->SendSQLine(NULL, &x); + } + else if (!c->HasFlag(CH_INHABIT)) { /* Join ChanServ and set a timer for this channel to part ChanServ later */ c->Hold(); diff --git a/modules/commands/os_ignore.cpp b/modules/commands/os_ignore.cpp index f2012f212..3d84a4635 100644 --- a/modules/commands/os_ignore.cpp +++ b/modules/commands/os_ignore.cpp @@ -119,7 +119,7 @@ class OSIgnoreService : public IgnoreService tmp = mask + "!*@*"; for (; ign != ign_end; ++ign) - if (Anope::Match(tmp, ign->mask)) + if (Anope::Match(tmp, ign->mask, false, true)) break; } @@ -297,6 +297,10 @@ class CommandOSIgnore : public Command "Wildcards are permitted.\n" " \n" "Ignores will not be enforced on IRC Operators.")); + if (!Config->RegexEngine.empty()) + source.Reply(" \n" + "Regex matches are also supported using the %s engine.\n" + "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str()); return true; } }; diff --git a/modules/commands/os_list.cpp b/modules/commands/os_list.cpp index e9d67b52e..2850e0203 100644 --- a/modules/commands/os_list.cpp +++ b/modules/commands/os_list.cpp @@ -67,7 +67,7 @@ class CommandOSChanList : public Command { Channel *c = cit->second; - if (!pattern.empty() && !Anope::Match(c->name, pattern)) + if (!pattern.empty() && !Anope::Match(c->name, pattern, false, true)) continue; if (!Modes.empty()) for (std::list<ChannelModeName>::iterator it = Modes.begin(), it_end = Modes.end(); it != it_end; ++it) @@ -102,6 +102,10 @@ class CommandOSChanList : public Command "is given, lists only the channels the user using it is on. If SECRET is\n" "specified, lists only channels matching \002pattern\002 that have the +s or\n" "+p mode.")); + if (!Config->RegexEngine.empty()) + source.Reply(" \n" + "Regex matches are also supported using the %s engine.\n" + "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str()); return true; } }; @@ -194,6 +198,10 @@ class CommandOSUserList : public Command "the format nick!user@host). If \002channel\002 is given, lists only users\n" "that are on the given channel. If INVISIBLE is specified, only users\n" "with the +i flag will be listed.")); + if (!Config->RegexEngine.empty()) + source.Reply(" \n" + "Regex matches are also supported using the %s engine.\n" + "Enclose your pattern in // if this desired.", Config->RegexEngine.c_str()); return true; } }; diff --git a/modules/commands/os_sxline.cpp b/modules/commands/os_sxline.cpp index e65811571..d6c2ba094 100644 --- a/modules/commands/os_sxline.cpp +++ b/modules/commands/os_sxline.cpp @@ -141,7 +141,7 @@ class CommandOSSXLineBase : public Command entry["Number"] = stringify(Number); entry["Mask"] = x->Mask; entry["By"] = x->By; - entry["Created"] = do_strftime(x->Created); + entry["Created"] = do_strftime(x->Created, NULL, true); entry["Expires"] = expire_left(NULL, x->Expires); entry["Reason"] = x->Reason; list.addEntry(entry); @@ -156,13 +156,13 @@ class CommandOSSXLineBase : public Command { XLine *x = this->xlm()->GetEntry(i); - if (mask.empty() || mask.equals_ci(x->Mask) || mask == x->UID || Anope::Match(x->Mask, mask)) + if (mask.empty() || mask.equals_ci(x->Mask) || mask == x->UID || Anope::Match(x->Mask, mask, false, true)) { ListFormatter::ListEntry entry; entry["Number"] = stringify(i + 1); entry["Mask"] = x->Mask; entry["By"] = x->By; - entry["Created"] = do_strftime(x->Created); + entry["Created"] = do_strftime(x->Created, NULL, true); entry["Expires"] = expire_left(source.u->Account(), x->Expires); entry["Reason"] = x->Reason; list.addEntry(entry); @@ -307,85 +307,105 @@ class CommandOSSNLine : public CommandOSSXLineBase sep.GetToken(mask); Anope::string reason = sep.GetRemaining(); - if (!mask.empty() && !reason.empty()) + if (mask.empty() || reason.empty()) { - std::pair<int, XLine *> canAdd = this->xlm()->CanAdd(mask, expires); - if (mask.find_first_not_of("*?") == Anope::string::npos) - source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); - else if (canAdd.first == 1) - source.Reply(_("\002%s\002 already exists on the %s list."), canAdd.second->Mask.c_str(), source.command.c_str()); - else if (canAdd.first == 2) - source.Reply(_("Expiry time of \002%s\002 changed."), canAdd.second->Mask.c_str()); - else if (canAdd.first == 3) - source.Reply(_("\002%s\002 is already covered by %s."), mask.c_str(), canAdd.second->Mask.c_str()); - else + this->OnSyntaxError(source, "ADD"); + return; + } + + if (mask[0] == '/' && mask[mask.length() - 1] == '/') + { + if (Config->RegexEngine.empty()) { - /* Clean up the last character of the mask if it is a space - * See bug #761 - */ - unsigned masklen = mask.length(); - if (mask[masklen - 1] == ' ') - mask.erase(masklen - 1); - unsigned int affected = 0; - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (Anope::Match(it->second->realname, mask)) - ++affected; - float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; - - if (percent > 95) - { - source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); - Log(LOG_ADMIN, u, this) << "tried to " << source.command << " " << percent << "% of the network (" << affected << " users)"; - return; - } + source.Reply(_("Regex is enabled.")); + return; + } - if (Config->AddAkiller) - reason = "[" + u->nick + "] " + reason; + service_reference<RegexProvider> provider("Regex", Config->RegexEngine); + if (!provider) + { + source.Reply(_("Unable to find regex engine %s"), Config->RegexEngine.c_str()); + return; + } - Anope::string id; - if (Config->AkillIds) - { - id = XLineManager::GenerateUID(); - reason = reason + " (ID: " + id + ")"; - } + try + { + Anope::string stripped_mask = mask.substr(1, mask.length() - 2); + delete provider->Compile(stripped_mask); + } + catch (const RegexException &ex) + { + source.Reply("%s", ex.GetReason().c_str()); + return; + } + } - XLine *x = new XLine(mask, u->nick, expires, reason, id); + if (!this->xlm()->CanAdd(source, mask, expires, reason)) + return; + else if (mask.find_first_not_of("/.*?") == Anope::string::npos) + { + source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); + return; + } - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, this->xlm())); - if (MOD_RESULT == EVENT_STOP) - { - delete x; - return; - } + /* Clean up the last character of the mask if it is a space + * See bug #761 + */ + unsigned masklen = mask.length(); + if (mask[masklen - 1] == ' ') + mask.erase(masklen - 1); - this->xlm()->AddXLine(x); - if (Config->KillonSNline && !ircd->sglineenforce) - { - Anope::string rreason = "G-Lined: " + reason; + XLine *x = new XLine(mask, u->nick, expires, reason); + if (Config->AkillIds) + x->UID = XLineManager::GenerateUID(); - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();) - { - User *user = it->second; - ++it; + unsigned int affected = 0; + for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (this->xlm()->Check(it->second, x)) + ++affected; + float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; - if (!user->HasMode(UMODE_OPER) && user->server != Me && Anope::Match(user->realname, x->Mask)) - user->Kill(Config->ServerName, rreason); - } - } + if (percent > 95) + { + source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); + Log(LOG_ADMIN, u, this) << "tried to " << source.command << " " << percent << "% of the network (" << affected << " users)"; + delete x; + return; + } - source.Reply(_("\002%s\002 added to the %s list."), mask.c_str(), source.command.c_str()); - Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]"; + EventReturn MOD_RESULT; + FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, this->xlm())); + if (MOD_RESULT == EVENT_STOP) + { + delete x; + return; + } - if (readonly) - source.Reply(READ_ONLY_MODE); - } + this->xlm()->AddXLine(x); + if (Config->KillonSNline) + { + this->xlm()->Send(u, x); + + if (!ircd->sglineenforce) + { + Anope::string rreason = "G-Lined: " + reason; + + for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();) + { + User *user = it->second; + ++it; + + if (!user->HasMode(UMODE_OPER) && user->server != Me && Anope::Match(user->realname, x->Mask, false, true)) + user->Kill(Config->ServerName, rreason); + } + } } - else - this->OnSyntaxError(source, "ADD"); - return; + source.Reply(_("\002%s\002 added to the %s list."), mask.c_str(), source.command.c_str()); + Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]"; + if (readonly) + source.Reply(READ_ONLY_MODE); } service_reference<XLineManager> snlines; @@ -421,6 +441,10 @@ class CommandOSSNLine : public CommandOSSXLineBase "\002STATS AKILL\002 command.\n" "Note: because the realname mask may contain spaces, the\n" "separator between it and the reason is a colon.\n")); + if (!Config->RegexEngine.empty()) + source.Reply(" \n" + "Regex matches are also supported using the %s engine.\n" + "Enclose your mask in // if this desired.", Config->RegexEngine.c_str()); source.Reply(_(" \n" "The \002SNLINE DEL\002 command removes the given mask from the\n" "SNLINE list if it is present. If a list of entry numbers is \n" @@ -496,95 +520,118 @@ class CommandOSSQLine : public CommandOSSXLineBase Anope::string reason = params[last_param]; if (last_param == 2 && params.size() > 3) reason += " " + params[3]; - if (!mask.empty() && !reason.empty()) + + if (mask.empty() || reason.empty()) { - std::pair<int, XLine *> canAdd = this->sqlines->CanAdd(mask, expires); - if (mask.find_first_not_of("*") == Anope::string::npos) - source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); - else if (canAdd.first == 1) - source.Reply(_("\002%s\002 already exists on the SQLINE list."), canAdd.second->Mask.c_str()); - else if (canAdd.first == 2) - source.Reply(_("Expiry time of \002%s\002 changed."), canAdd.second->Mask.c_str()); - else if (canAdd.first == 3) - source.Reply(_("\002%s\002 is already covered by %s."), mask.c_str(), canAdd.second->Mask.c_str()); - else + this->OnSyntaxError(source, "ADD"); + return; + } + + if (mask[0] == '/' && mask[mask.length() - 1] == '/') + { + if (Config->RegexEngine.empty()) { - unsigned int affected = 0; - for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) - if (Anope::Match(it->second->nick, mask)) - ++affected; - float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; + source.Reply(_("Regex is enabled.")); + return; + } - if (percent > 95) - { - source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); - Log(LOG_ADMIN, u, this) << "tried to SQLine " << percent << "% of the network (" << affected << " users)"; - return; - } + service_reference<RegexProvider> provider("Regex", Config->RegexEngine); + if (!provider) + { + source.Reply(_("Unable to find regex engine %s"), Config->RegexEngine.c_str()); + return; + } - Anope::string id = XLineManager::GenerateUID(); - reason = reason + " (ID: " + id + ")"; + try + { + Anope::string stripped_mask = mask.substr(1, mask.length() - 2); + delete provider->Compile(stripped_mask); + } + catch (const RegexException &ex) + { + source.Reply("%s", ex.GetReason().c_str()); + return; + } + } - XLine *x = new XLine(mask, u->nick, expires, reason, id); + if (!this->sqlines->CanAdd(source, mask, expires, reason)) + return; + else if (mask.find_first_not_of("./?*") == Anope::string::npos) + { + source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); + return; + } - EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, this->xlm())); - if (MOD_RESULT == EVENT_STOP) - { - delete x; - return; - } + XLine *x = new XLine(mask, u->nick, expires, reason); + if (Config->AkillIds) + x->UID = XLineManager::GenerateUID(); + + unsigned int affected = 0; + for (Anope::insensitive_map<User *>::iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) + if (this->xlm()->Check(it->second, x)) + ++affected; + float percent = static_cast<float>(affected) / static_cast<float>(UserListByNick.size()) * 100.0; - this->xlm()->AddXLine(x); - if (Config->KillonSQline) + if (percent > 95) + { + source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str()); + Log(LOG_ADMIN, u, this) << "tried to SQLine " << percent << "% of the network (" << affected << " users)"; + delete x; + return; + } + + EventReturn MOD_RESULT; + FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, this->xlm())); + if (MOD_RESULT == EVENT_STOP) + { + delete x; + return; + } + + this->xlm()->AddXLine(x); + if (Config->KillonSQline) + { + Anope::string rreason = "Q-Lined: " + reason; + + if (mask[0] == '#') + { + for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit) { - Anope::string rreason = "Q-Lined: " + reason; + Channel *c = cit->second; - if (mask[0] == '#') + if (!Anope::Match(c->name, mask, false, true)) + continue; + for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) { - for (channel_map::const_iterator cit = ChannelList.begin(), cit_end = ChannelList.end(); cit != cit_end; ++cit) - { - Channel *c = cit->second; - - if (!Anope::Match(c->name, mask)) - continue; - for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) - { - UserContainer *uc = *it; - ++it; - - if (uc->user->HasMode(UMODE_OPER) || uc->user->server == Me) - continue; - c->Kick(NULL, uc->user, "%s", reason.c_str()); - } - } - } - else - { - for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();) - { - User *user = it->second; - ++it; - - if (!user->HasMode(UMODE_OPER) && user->server != Me && Anope::Match(user->nick, x->Mask)) - user->Kill(Config->ServerName, rreason); - } + UserContainer *uc = *it; + ++it; + + if (uc->user->HasMode(UMODE_OPER) || uc->user->server == Me) + continue; + c->Kick(NULL, uc->user, "%s", reason.c_str()); } } - this->xlm()->Send(NULL, x); - - source.Reply(_("\002%s\002 added to the SQLINE list."), mask.c_str()); - Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]"; + } + else + { + for (Anope::insensitive_map<User *>::const_iterator it = UserListByNick.begin(); it != UserListByNick.end();) + { + User *user = it->second; + ++it; - if (readonly) - source.Reply(READ_ONLY_MODE); + if (!user->HasMode(UMODE_OPER) && user->server != Me && Anope::Match(user->nick, x->Mask, false, true)) + user->Kill(Config->ServerName, rreason); + } } + this->xlm()->Send(u, x); } - else - this->OnSyntaxError(source, "ADD"); - return; + source.Reply(_("\002%s\002 added to the SQLINE list."), mask.c_str()); + Log(LOG_ADMIN, u, this) << "on " << mask << " (" << reason << ") expires in " << (expires ? duration(expires - Anope::CurTime) : "never") << " [affects " << affected << " user(s) (" << percent << "%)]"; + + if (readonly) + source.Reply(READ_ONLY_MODE); } service_reference<XLineManager> sqlines; @@ -607,8 +654,7 @@ class CommandOSSQLine : public CommandOSSXLineBase "connect, Services will not allow it to pursue his IRC\n" "session.\n" "If the first character of the mask is #, services will \n" - "prevent the use of matching channels (on IRCds that \n" - "support it).\n")); + "prevent the use of matching channels.")); source.Reply(_(" \n" "\002SQLINE ADD\002 adds the given (nick's) mask to the SQLINE\n" "list for the given reason (which \002must\002 be given).\n" @@ -621,6 +667,10 @@ class CommandOSSQLine : public CommandOSSXLineBase "must be given, even if it is the same as the default. The\n" "current SQLINE default expiry time can be found with the\n" "\002STATS AKILL\002 command.\n")); + if (!Config->RegexEngine.empty()) + source.Reply(" \n" + "Regex matches are also supported using the %s engine.\n" + "Enclose your mask in // if this desired.", Config->RegexEngine.c_str()); source.Reply(_(" \n" "The \002SQLINE DEL\002 command removes the given mask from the\n" "SQLINE list if it is present. If a list of entry numbers is \n" diff --git a/modules/extra/m_regex_pcre.cpp b/modules/extra/m_regex_pcre.cpp new file mode 100644 index 000000000..998a7692d --- /dev/null +++ b/modules/extra/m_regex_pcre.cpp @@ -0,0 +1,55 @@ +/* RequiredLibraries: pcre */ + +#include "module.h" +#include <pcre.h> + +class PCRERegex : public Regex +{ + pcre *regex; + + public: + PCRERegex(const Anope::string &expr) : Regex(expr) + { + const char *error; + int erroffset; + this->regex = pcre_compile(expr.c_str(), PCRE_CASELESS, &error, &erroffset, NULL); + if (!this->regex) + throw RegexException("Error in regex " + expr + " at offset " + stringify(erroffset) + ": " + error); + } + + ~PCRERegex() + { + pcre_free(this->regex); + } + + bool Matches(const Anope::string &str) + { + return pcre_exec(this->regex, NULL, str.c_str(), str.length(), 0, 0, NULL, 0) > -1; + } +}; + +class PCRERegexProvider : public RegexProvider +{ + public: + PCRERegexProvider(Module *creator) : RegexProvider(creator, "regex/pcre") { } + + Regex *Compile(const Anope::string &expression) anope_override + { + return new PCRERegex(expression); + } +}; + +class ModuleRegexPCRE : public Module +{ + PCRERegexProvider pcre_regex_provider; + + public: + ModuleRegexPCRE(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED), + pcre_regex_provider(this) + { + this->SetAuthor("Anope"); + this->SetPermanent(true); + } +}; + +MODULE_INIT(ModuleRegexPCRE) diff --git a/modules/extra/m_regex_posix.cpp b/modules/extra/m_regex_posix.cpp new file mode 100644 index 000000000..409a057ba --- /dev/null +++ b/modules/extra/m_regex_posix.cpp @@ -0,0 +1,57 @@ +#include "module.h" +#include <sys/types.h> +#include <regex.h> + +class POSIXRegex : public Regex +{ + regex_t regbuf; + + public: + POSIXRegex(const Anope::string &expr) : Regex(expr) + { + int err = regcomp(&this->regbuf, expr.c_str(), REG_EXTENDED | REG_NOSUB); + if (err) + { + char buf[BUFSIZE]; + regerror(err, &this->regbuf, buf, sizeof(buf)); + regfree(&this->regbuf); + throw RegexException("Error in regex " + expr + ": " + buf); + } + } + + ~POSIXRegex() + { + regfree(&this->regbuf); + } + + bool Matches(const Anope::string &str) + { + return regexec(&this->regbuf, str.c_str(), 0, NULL, 0) == 0; + } +}; + +class POSIXRegexProvider : public RegexProvider +{ + public: + POSIXRegexProvider(Module *creator) : RegexProvider(creator, "regex/posix") { } + + Regex *Compile(const Anope::string &expression) anope_override + { + return new POSIXRegex(expression); + } +}; + +class ModuleRegexPOSIX : public Module +{ + POSIXRegexProvider posix_regex_provider; + + public: + ModuleRegexPOSIX(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED), + posix_regex_provider(this) + { + this->SetAuthor("Anope"); + this->SetPermanent(true); + } +}; + +MODULE_INIT(ModuleRegexPOSIX) diff --git a/modules/extra/m_regex_tre.cpp b/modules/extra/m_regex_tre.cpp new file mode 100644 index 000000000..8cfbd3b18 --- /dev/null +++ b/modules/extra/m_regex_tre.cpp @@ -0,0 +1,58 @@ +/* RequiredLibraries: tre */ + +#include "module.h" +#include <tre/regex.h> + +class TRERegex : public Regex +{ + regex_t regbuf; + + public: + TRERegex(const Anope::string &expr) : Regex(expr) + { + int err = regcomp(&this->regbuf, expr.c_str(), REG_EXTENDED | REG_NOSUB); + if (err) + { + char buf[BUFSIZE]; + regerror(err, &this->regbuf, buf, sizeof(buf)); + regfree(&this->regbuf); + throw RegexException("Error in regex " + expr + ": " + buf); + } + } + + ~TRERegex() + { + regfree(&this->regbuf); + } + + bool Matches(const Anope::string &str) + { + return regexec(&this->regbuf, str.c_str(), 0, NULL, 0) == 0; + } +}; + +class TRERegexProvider : public RegexProvider +{ + public: + TRERegexProvider(Module *creator) : RegexProvider(creator, "regex/tre") { } + + Regex *Compile(const Anope::string &expression) anope_override + { + return new TRERegex(expression); + } +}; + +class ModuleRegexTRE : public Module +{ + TRERegexProvider tre_regex_provider; + + public: + ModuleRegexTRE(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, SUPPORTED), + tre_regex_provider(this) + { + this->SetAuthor("Anope"); + this->SetPermanent(true); + } +}; + +MODULE_INIT(ModuleRegexTRE) 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; } diff --git a/modules/pseudoclients/operserv.cpp b/modules/pseudoclients/operserv.cpp index aeaa7e3c7..0224547eb 100644 --- a/modules/pseudoclients/operserv.cpp +++ b/modules/pseudoclients/operserv.cpp @@ -22,9 +22,9 @@ class SGLineManager : public XLineManager void OnMatch(User *u, XLine *x) anope_override { + this->Send(u, x); if (u) u->Kill(Config->OperServ, x->Reason); - this->Send(u, x); } void OnExpire(XLine *x) anope_override @@ -34,6 +34,11 @@ class SGLineManager : public XLineManager void Send(User *u, XLine *x) anope_override { + ircdproto->SendAkill(u, x); + } + + void SendDel(XLine *x) anope_override + { try { if (!ircd->szline) @@ -41,29 +46,50 @@ class SGLineManager : public XLineManager else if (x->GetUser() != "*") throw SocketException("Can not ZLine a username"); sockaddrs(x->GetHost()); - ircdproto->SendSZLine(u, x); + ircdproto->SendSZLineDel(x); } catch (const SocketException &) { - ircdproto->SendAkill(u, x); + ircdproto->SendAkillDel(x); } } - void SendDel(XLine *x) anope_override + bool Check(User *u, XLine *x) anope_override { - try + if (x->regex) { - if (!ircd->szline) - throw SocketException("SZLine is not supported"); - else if (x->GetUser() != "*") - throw SocketException("Can not ZLine a username"); - sockaddrs(x->GetHost()); - ircdproto->SendSZLineDel(x); + Anope::string uh = u->GetIdent() + "@" + u->host, nuhr = u->nick + "!" + uh + "#" + u->realname; + if (x->regex->Matches(uh) || x->regex->Matches(nuhr)) + return true; + + return false; } - catch (const SocketException &) + + if (!x->GetNick().empty() && !Anope::Match(u->nick, x->GetNick())) + return false; + + if (!x->GetUser().empty() && !Anope::Match(u->GetIdent(), x->GetUser())) + return false; + + if (!x->GetReal().empty() && !Anope::Match(u->realname, x->GetReal())) + return false; + + if (!x->GetHost().empty()) { - ircdproto->SendAkillDel(x); + try + { + cidr cidr_ip(x->GetHost()); + sockaddrs ip(u->ip); + if (cidr_ip.match(ip)) + return true; + } + catch (const SocketException &) { } } + + if (x->GetHost().empty() || Anope::Match(u->host, x->GetHost())) + return true; + + return false; } }; @@ -74,13 +100,13 @@ class SQLineManager : public XLineManager void OnMatch(User *u, XLine *x) anope_override { + this->Send(u, x); + if (u) { Anope::string reason = "Q-Lined: " + x->Reason; u->Kill(Config->OperServ, reason); } - - this->Send(u, x); } void OnExpire(XLine *x) anope_override @@ -98,12 +124,18 @@ class SQLineManager : public XLineManager ircdproto->SendSQLineDel(x); } + bool Check(User *u, XLine *x) anope_override + { + if (x->regex) + return x->regex->Matches(u->nick); + return Anope::Match(u->nick, x->Mask); + } + bool CheckChannel(Channel *c) { - if (ircd->chansqline) - for (std::vector<XLine *>::const_iterator it = this->GetList().begin(), it_end = this->GetList().end(); it != it_end; ++it) - if (Anope::Match(c->name, (*it)->Mask)) - return true; + for (std::vector<XLine *>::const_iterator it = this->GetList().begin(), it_end = this->GetList().end(); it != it_end; ++it) + if (Anope::Match(c->name, (*it)->Mask, false, true)) + return true; return false; } }; @@ -115,12 +147,13 @@ class SNLineManager : public XLineManager void OnMatch(User *u, XLine *x) anope_override { + this->Send(u, x); + if (u) { Anope::string reason = "G-Lined: " + x->Reason; u->Kill(Config->OperServ, reason); } - this->Send(u, x); } void OnExpire(XLine *x) anope_override @@ -138,27 +171,11 @@ class SNLineManager : public XLineManager ircdproto->SendSGLineDel(x); } - XLine *Check(User *u) anope_override + bool Check(User *u, XLine *x) anope_override { - for (unsigned i = this->GetList().size(); i > 0; --i) - { - XLine *x = this->GetList()[i - 1]; - - if (x->Expires && x->Expires < Anope::CurTime) - { - this->OnExpire(x); - this->DelXLine(x); - continue; - } - - if (Anope::Match(u->realname, x->Mask)) - { - this->OnMatch(u, x); - return x; - } - } - - return NULL; + if (x->regex) + return x->regex->Matches(u->realname); + return Anope::Match(u->realname, x->Mask, false, true); } }; @@ -237,7 +254,7 @@ class OperServCore : public Module void OnUserNickChange(User *u, const Anope::string &oldnick) anope_override { if (ircd->sqline && !u->HasMode(UMODE_OPER)) - this->sqlines.Check(u); + this->sqlines.CheckAllXLines(u); } EventReturn OnCheckKick(User *u, ChannelInfo *ci, bool &kick) anope_override |
