From ffa21a16815329762096edbdbfddeb36b7e643cc Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 28 Aug 2021 13:11:59 +0100 Subject: Significantly upgrade the check module's ability to find users. - Check for users based on nick mask, ident mask, and real name mask as well as ip mask and host mask. - Include matching user's nick, ident and displayed host in the command output. - Specify in the output what was actually matched against. Closes #1909. --- src/modules/m_check.cpp | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index 798747541..8e961cadc 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -156,7 +156,10 @@ class CommandCheck : public Command , snomaskmode(parent, "snomask") { access_needed = CmdAccess::OPERATOR; - syntax = { "||| []" }; + syntax = { + "| []", + "|||| []", + }; } CmdResult Handle(User* user, const Params& parameters) override @@ -272,19 +275,37 @@ class CommandCheck : public Command /* /check on an IP address, or something that doesn't exist */ size_t x = 0; + std::vector matches; + matches.reserve(6); + /* hostname or other */ for (const auto& [_, u] : ServerInstance->Users.GetUsers()) { - if (InspIRCd::Match(u->GetRealHost(), parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(u->GetDisplayedHost(), parameters[0], ascii_case_insensitive_map)) - { - /* host or vhost matches mask */ - context.Write("match", ConvToStr(++x) + " " + u->GetFullRealHost() + " " + u->GetIPString() + " " + u->GetRealName()); - } - /* IP address */ - else if (InspIRCd::MatchCIDR(u->GetIPString(), parameters[0])) + if (InspIRCd::Match(u->nick, parameters[0], ascii_case_insensitive_map)) + matches.push_back("nick"); + + if (InspIRCd::Match(u->ident, parameters[0], ascii_case_insensitive_map)) + matches.push_back("ident"); + + if (InspIRCd::Match(u->GetRealHost(), parameters[0], ascii_case_insensitive_map)) + matches.push_back("rhost"); + + if (InspIRCd::Match(u->GetDisplayedHost(), parameters[0], ascii_case_insensitive_map)) + matches.push_back("dhost"); + + if (InspIRCd::MatchCIDR(u->GetIPString(), parameters[0])) + matches.push_back("ipaddr"); + + if (InspIRCd::MatchCIDR(u->GetRealName(), parameters[0])) + matches.push_back("realname"); + + if (!matches.empty()) { - /* same IP. */ - context.Write("match", ConvToStr(++x) + " " + u->GetFullRealHost() + " " + u->GetIPString() + " " + u->GetRealName()); + const std::string whatmatch = stdalgo::string::join(matches, ','); + context.Write("match", InspIRCd::Format("%ld %s %s %s %s %s %s :%s", ++x, whatmatch.c_str(), + u->nick.c_str(), u->ident.c_str(), u->GetRealHost().c_str(), u->GetDisplayedHost().c_str(), + u->GetIPString().c_str(), u->GetRealName().c_str())); + matches.clear(); } } -- cgit v1.3.1-10-gc9f91