From 8eeb07be8cd397ea9b54f965ae72d8939ffdccc2 Mon Sep 17 00:00:00 2001 From: danieldg Date: Wed, 2 Sep 2009 00:48:02 +0000 Subject: [PATCH] Route whois notices using ENCAP WHOISNOTICE to properly fix remote user PrivPermission bug git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11625 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/usermanager.h | 8 ++--- src/modules/m_showwhois.cpp | 72 ++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/include/usermanager.h b/include/usermanager.h index 8b396eab0..56a545353 100644 --- a/include/usermanager.h +++ b/include/usermanager.h @@ -83,10 +83,10 @@ class CoreExport UserManager : public Extensible void AddUser(InspIRCd* Instance, int socket, bool iscached, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server); /** Disconnect a user gracefully - * @param user The user to remove - * @param r The quit reason to show to normal users - * @param oreason The quit reason to show to opers - * @return Although this function has no return type, on exit the user provided will no longer exist. + * @param user The user to remove + * @param r The quit reason to show to normal users + * @param oreason The quit reason to show to opers + * @return Although this function has no return type, on exit the user provided will no longer exist. */ void QuitUser(User *user, const std::string &quitreason, const char* operreason = ""); diff --git a/src/modules/m_showwhois.cpp b/src/modules/m_showwhois.cpp index 473fd6adc..7464a0d21 100644 --- a/src/modules/m_showwhois.cpp +++ b/src/modules/m_showwhois.cpp @@ -45,14 +45,41 @@ class SeeWhois : public ModeHandler } }; +class WhoisNoticeCmd : public Command +{ + public: + WhoisNoticeCmd(InspIRCd* Instance) : Command(Instance,"WHOISNOTICE", 0, 1) + { + this->source = "m_showwhois.cpp"; + } + + void HandleFast(User* dest, User* src) + { + dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you", + dest->nick.c_str(), src->nick.c_str(), src->ident.c_str(), + dest->HasPrivPermission("users/auspex") ? src->host.c_str() : src->dhost.c_str()); + } + + CmdResult Handle(const std::vector ¶meters, User *user) + { + User* dest = ServerInstance->FindNick(parameters[0]); + + if (IS_LOCAL(dest)) + HandleFast(dest, user); + + return CMD_SUCCESS; + } +}; + class ModuleShowwhois : public Module { bool ShowWhoisFromOpers; SeeWhois* sw; + WhoisNoticeCmd cmd; public: - ModuleShowwhois(InspIRCd* Me) : Module(Me) + ModuleShowwhois(InspIRCd* Me) : Module(Me), cmd(Me) { ConfigReader conf(ServerInstance); bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0); @@ -61,6 +88,7 @@ class ModuleShowwhois : public Module sw = new SeeWhois(ServerInstance, OpersOnly); if (!ServerInstance->Modes->AddMode(sw)) throw ModuleException("Could not add new modes!"); + ServerInstance->AddCommand(&cmd); Implementation eventlist[] = { I_OnWhois }; ServerInstance->Modules->Attach(eventlist, this, 1); } @@ -78,35 +106,23 @@ class ModuleShowwhois : public Module virtual void OnWhois(User* source, User* dest) { - if ((dest->IsModeSet('W')) && (source != dest)) - { - if (!ShowWhoisFromOpers && IS_OPER(source)) - return; + if (!dest->IsModeSet('W') || source == dest) + return; - std::string wmsg = "*** "; - wmsg += source->nick + " (" + source->ident + "@"; + if (!ShowWhoisFromOpers && (IS_OPER(source) != IS_OPER(dest))) + return; - /* XXX HasPrivPermission doesn't work correctly for remote users */ - if (IS_LOCAL(dest) && dest->HasPrivPermission("users/auspex")) - { - wmsg += source->host; - } - else - { - wmsg += source->dhost; - } - - wmsg += ") did a /whois on you"; - - if (IS_LOCAL(dest)) - { - dest->WriteServ("NOTICE %s :%s", dest->nick.c_str(), wmsg.c_str()); - } - else - { - std::string msg = std::string("::") + dest->server + " NOTICE " + dest->nick + " :" + wmsg; - ServerInstance->PI->PushToClient(dest, msg); - } + if (IS_LOCAL(dest)) + { + cmd.HandleFast(dest, source); + } + else + { + std::vector params; + params.push_back(dest->server); + params.push_back("WHOISNOTICE"); + params.push_back(dest->uuid); + ServerInstance->PI->SendEncapsulatedData(params); } } -- 2.39.5