From d865b434865907bfad0a187dd403d4ca8144e469 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Sun, 22 Oct 2017 21:53:24 +0100 Subject: Hide User#host and User#dhost and use accessors to modify them. This removes the need to invalidate the cache after changing a user's hostname. --- src/channels.cpp | 4 +-- src/command_parse.cpp | 2 +- src/coremods/core_hostname_lookup.cpp | 6 +--- src/coremods/core_oper/cmd_kill.cpp | 2 +- src/coremods/core_oper/cmd_oper.cpp | 2 +- src/coremods/core_stats.cpp | 10 +++---- src/coremods/core_userhost.cpp | 2 +- src/coremods/core_who.cpp | 6 ++-- src/coremods/core_whois.cpp | 4 +-- src/coremods/core_whowas.cpp | 4 +-- src/modules/m_alias.cpp | 4 +-- src/modules/m_callerid.cpp | 2 +- src/modules/m_cgiirc.cpp | 25 +++++++--------- src/modules/m_check.cpp | 4 +-- src/modules/m_chghost.cpp | 2 +- src/modules/m_clearchan.cpp | 2 +- src/modules/m_cloaking.cpp | 8 ++--- src/modules/m_customtitle.cpp | 2 +- src/modules/m_dccallow.cpp | 6 ++-- src/modules/m_hideoper.cpp | 2 +- src/modules/m_hostcycle.cpp | 2 +- src/modules/m_httpd_stats.cpp | 2 +- src/modules/m_ircv3_chghost.cpp | 2 +- src/modules/m_ldapoper.cpp | 2 +- src/modules/m_messageflood.cpp | 2 +- src/modules/m_repeat.cpp | 2 +- src/modules/m_rline.cpp | 2 +- src/modules/m_sasl.cpp | 2 +- src/modules/m_sethost.cpp | 2 +- src/modules/m_showwhois.cpp | 2 +- src/modules/m_spanningtree/opertype.cpp | 2 +- src/modules/m_spanningtree/uid.cpp | 8 ++--- src/modules/m_sqloper.cpp | 2 +- src/modules/m_watch.cpp | 8 ++--- src/usermanager.cpp | 2 +- src/users.cpp | 52 +++++++++++++++++++++++++++------ src/xline.cpp | 6 ++-- 37 files changed, 113 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/channels.cpp b/src/channels.cpp index bc23c680a..1edc57693 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -381,8 +381,8 @@ bool Channel::CheckBan(User* user, const std::string& mask) if (InspIRCd::Match(nickIdent, prefix, NULL)) { std::string suffix(mask, at + 1); - if (InspIRCd::Match(user->host, suffix, NULL) || - InspIRCd::Match(user->dhost, suffix, NULL) || + if (InspIRCd::Match(user->GetRealHost(), suffix, NULL) || + InspIRCd::Match(user->GetDisplayedHost(), suffix, NULL) || InspIRCd::MatchCIDR(user->GetIPString(), suffix, NULL)) return true; } diff --git a/src/command_parse.cpp b/src/command_parse.cpp index 9ffd20865..3b3329261 100644 --- a/src/command_parse.cpp +++ b/src/command_parse.cpp @@ -295,7 +295,7 @@ void CommandParser::ProcessCommand(LocalUser *user, std::string &cmd) } ServerInstance->SNO->WriteToSnoMask('a', "%s denied for %s (%s@%s)", - command.c_str(), user->nick.c_str(), user->ident.c_str(), user->host.c_str()); + command.c_str(), user->nick.c_str(), user->ident.c_str(), user->GetRealHost().c_str()); return; } diff --git a/src/coremods/core_hostname_lookup.cpp b/src/coremods/core_hostname_lookup.cpp index d150b8551..2a8426be9 100644 --- a/src/coremods/core_hostname_lookup.cpp +++ b/src/coremods/core_hostname_lookup.cpp @@ -145,11 +145,7 @@ class UserResolver : public DNS::Request hostname->insert(0, "0"); bound_user->WriteNotice("*** Found your hostname (" + *hostname + (r->cached ? ") -- cached" : ")")); - bound_user->host.assign(*hostname, 0, ServerInstance->Config->Limits.MaxHost); - bound_user->dhost = bound_user->host; - - /* Invalidate cache */ - bound_user->InvalidateCache(); + bound_user->ChangeRealHost(hostname->substr(ServerInstance->Config->Limits.MaxHost), true); } else { diff --git a/src/coremods/core_oper/cmd_kill.cpp b/src/coremods/core_oper/cmd_kill.cpp index 8e8c4fadc..8a453f7f1 100644 --- a/src/coremods/core_oper/cmd_kill.cpp +++ b/src/coremods/core_oper/cmd_kill.cpp @@ -102,7 +102,7 @@ CmdResult CommandKill::Handle (const std::vector& parameters, User ServerInstance->Logs->Log("KILL", LOG_DEFAULT, "%s KILL: %s :%s!%s!%s (%s)", IS_LOCAL(user) && IS_LOCAL(target) ? "LOCAL" : "REMOTE", target->nick.c_str(), - ServerInstance->Config->ServerName.c_str(), user->dhost.c_str(), user->nick.c_str(), + ServerInstance->Config->ServerName.c_str(), user->GetDisplayedHost().c_str(), user->nick.c_str(), parameters[1].c_str()); if (IS_LOCAL(target)) diff --git a/src/coremods/core_oper/cmd_oper.cpp b/src/coremods/core_oper/cmd_oper.cpp index 9c06583a8..0322a059a 100644 --- a/src/coremods/core_oper/cmd_oper.cpp +++ b/src/coremods/core_oper/cmd_oper.cpp @@ -34,7 +34,7 @@ CmdResult CommandOper::HandleLocal(const std::vector& parameters, L bool match_pass = false; bool match_hosts = false; - const std::string userHost = user->ident + "@" + user->host; + const std::string userHost = user->ident + "@" + user->GetRealHost(); const std::string userIP = user->ident + "@" + user->GetIPString(); ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]); diff --git a/src/coremods/core_stats.cpp b/src/coremods/core_stats.cpp index 9d1fdf3fe..7c3484917 100644 --- a/src/coremods/core_stats.cpp +++ b/src/coremods/core_stats.cpp @@ -58,7 +58,7 @@ static void GenerateStatsLl(Stats::Context& stats) for (UserManager::LocalList::const_iterator i = list.begin(); i != list.end(); ++i) { LocalUser* u = *i; - stats.AddRow(211, u->nick+"["+u->ident+"@"+(stats.GetSymbol() == 'l' ? u->dhost : u->GetIPString())+"] "+ConvToStr(u->eh.getSendQSize())+" "+ConvToStr(u->cmds_out)+" "+ConvToStr(u->bytes_out)+" "+ConvToStr(u->cmds_in)+" "+ConvToStr(u->bytes_in)+" "+ConvToStr(ServerInstance->Time() - u->signon)); + stats.AddRow(211, u->nick+"["+u->ident+"@"+(stats.GetSymbol() == 'l' ? u->GetDisplayedHost() : u->GetIPString())+"] "+ConvToStr(u->eh.getSendQSize())+" "+ConvToStr(u->cmds_out)+" "+ConvToStr(u->bytes_out)+" "+ConvToStr(u->cmds_in)+" "+ConvToStr(u->bytes_in)+" "+ConvToStr(ServerInstance->Time() - u->signon)); } } @@ -76,7 +76,7 @@ void CommandStats::DoStats(Stats::Context& stats) ServerInstance->SNO->WriteToSnoMask('t', "%s '%c' denied for %s (%s@%s)", (IS_LOCAL(user) ? "Stats" : "Remote stats"), - statschar, user->nick.c_str(), user->ident.c_str(), user->host.c_str()); + statschar, user->nick.c_str(), user->ident.c_str(), user->GetRealHost().c_str()); stats.AddRow(481, (std::string("Permission Denied - STATS ") + statschar + " requires the servers/auspex priv.")); return; } @@ -87,7 +87,7 @@ void CommandStats::DoStats(Stats::Context& stats) { stats.AddRow(219, statschar, "End of /STATS report"); ServerInstance->SNO->WriteToSnoMask('t',"%s '%c' requested by %s (%s@%s)", - (IS_LOCAL(user) ? "Stats" : "Remote stats"), statschar, user->nick.c_str(), user->ident.c_str(), user->host.c_str()); + (IS_LOCAL(user) ? "Stats" : "Remote stats"), statschar, user->nick.c_str(), user->ident.c_str(), user->GetRealHost().c_str()); return; } @@ -167,7 +167,7 @@ void CommandStats::DoStats(Stats::Context& stats) if (!oper->server->IsULine()) { LocalUser* lu = IS_LOCAL(oper); - stats.AddRow(249, oper->nick + " (" + oper->ident + "@" + oper->dhost + ") Idle: " + + stats.AddRow(249, oper->nick + " (" + oper->ident + "@" + oper->GetDisplayedHost() + ") Idle: " + (lu ? ConvToStr(ServerInstance->Time() - lu->idle_lastmsg) + " secs" : "unavailable")); idx++; } @@ -360,7 +360,7 @@ void CommandStats::DoStats(Stats::Context& stats) stats.AddRow(219, statschar, "End of /STATS report"); ServerInstance->SNO->WriteToSnoMask('t',"%s '%c' requested by %s (%s@%s)", - (IS_LOCAL(user) ? "Stats" : "Remote stats"), statschar, user->nick.c_str(), user->ident.c_str(), user->host.c_str()); + (IS_LOCAL(user) ? "Stats" : "Remote stats"), statschar, user->nick.c_str(), user->ident.c_str(), user->GetRealHost().c_str()); return; } diff --git a/src/coremods/core_userhost.cpp b/src/coremods/core_userhost.cpp index 3100995a8..7ee093cdb 100644 --- a/src/coremods/core_userhost.cpp +++ b/src/coremods/core_userhost.cpp @@ -72,7 +72,7 @@ CmdResult CommandUserhost::Handle (const std::vector& parameters, U retbuf += (u->IsAway() ? '-' : '+'); retbuf += u->ident; retbuf += '@'; - retbuf += (((u == user) || (has_privs)) ? u->host : u->dhost); + retbuf += u->GetHost(u == user || has_privs); retbuf += ' '; } } diff --git a/src/coremods/core_who.cpp b/src/coremods/core_who.cpp index 677a1eb6d..196bf0479 100644 --- a/src/coremods/core_who.cpp +++ b/src/coremods/core_who.cpp @@ -128,7 +128,7 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext) else if (opt_realname) match = InspIRCd::Match(user->fullname, matchtext); else if (opt_showrealhost) - match = InspIRCd::Match(user->host, matchtext, ascii_case_insensitive_map); + match = InspIRCd::Match(user->GetRealHost(), matchtext, ascii_case_insensitive_map); else if (opt_ident) match = InspIRCd::Match(user->ident, matchtext, ascii_case_insensitive_map); else if (opt_port) @@ -161,7 +161,7 @@ bool CommandWho::whomatch(User* cuser, User* user, const char* matchtext) * -- w00t */ if (!match) - match = InspIRCd::Match(user->dhost, matchtext, ascii_case_insensitive_map); + match = InspIRCd::Match(user->GetDisplayedHost(), matchtext, ascii_case_insensitive_map); if (!match) match = InspIRCd::Match(user->nick, matchtext); @@ -198,7 +198,7 @@ void CommandWho::SendWhoLine(User* user, const std::vector& parms, Numeric::Numeric wholine(RPL_WHOREPLY); wholine.push(memb ? memb->chan->name : "*").push(u->ident); - wholine.push(opt_showrealhost ? u->host : u->dhost); + wholine.push(u->GetHost(opt_showrealhost)); if (!ServerInstance->Config->HideWhoisServer.empty() && !user->HasPrivPermission("servers/auspex")) wholine.push(ServerInstance->Config->HideWhoisServer); else diff --git a/src/coremods/core_whois.cpp b/src/coremods/core_whois.cpp index 81e62c8e5..c2fac7577 100644 --- a/src/coremods/core_whois.cpp +++ b/src/coremods/core_whois.cpp @@ -177,10 +177,10 @@ void CommandWhois::DoWhois(LocalUser* user, User* dest, unsigned long signon, un { WhoisContextImpl whois(user, dest, lineevprov); - whois.SendLine(311, dest->ident, dest->dhost, '*', dest->fullname); + whois.SendLine(311, dest->ident, dest->GetDisplayedHost(), '*', dest->fullname); if (whois.IsSelfWhois() || user->HasPrivPermission("users/auspex")) { - whois.SendLine(378, InspIRCd::Format("is connecting from %s@%s %s", dest->ident.c_str(), dest->host.c_str(), dest->GetIPString().c_str())); + whois.SendLine(378, InspIRCd::Format("is connecting from %s@%s %s", dest->ident.c_str(), dest->GetRealHost().c_str(), dest->GetIPString().c_str())); } SendChanList(whois); diff --git a/src/coremods/core_whowas.cpp b/src/coremods/core_whowas.cpp index 0bb47b273..af1f99737 100644 --- a/src/coremods/core_whowas.cpp +++ b/src/coremods/core_whowas.cpp @@ -230,8 +230,8 @@ void WhoWas::Manager::PurgeNick(WhoWas::Nick* nick) } WhoWas::Entry::Entry(User* user) - : host(user->host) - , dhost(user->dhost) + : host(user->GetRealHost()) + , dhost(user->GetDisplayedHost()) , ident(user->ident) , server(user->server->GetName()) , gecos(user->fullname) diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 95667e7ed..bdb242938 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -296,7 +296,7 @@ class ModuleAlias : public Module } else if (!newline.compare(i, 5, "$host", 5)) { - result.append(user->host); + result.append(user->GetRealHost()); i += 4; } else if (!newline.compare(i, 5, "$chan", 5)) @@ -312,7 +312,7 @@ class ModuleAlias : public Module } else if (!newline.compare(i, 6, "$vhost", 6)) { - result.append(user->dhost); + result.append(user->GetDisplayedHost()); i += 5; } else if (!newline.compare(i, 12, "$requirement", 12)) diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index a00da6a6f..d191a9fc7 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -399,7 +399,7 @@ public: if (now > (dat->lastnotify + (time_t)notify_cooldown)) { user->WriteNumeric(RPL_TARGNOTIFY, dest->nick, "has been informed that you messaged them."); - dest->WriteRemoteNumeric(RPL_UMODEGMSG, user->nick, InspIRCd::Format("%s@%s", user->ident.c_str(), user->dhost.c_str()), InspIRCd::Format("is messaging you, and you have umode +g. Use /ACCEPT +%s to allow.", + dest->WriteRemoteNumeric(RPL_UMODEGMSG, user->nick, InspIRCd::Format("%s@%s", user->ident.c_str(), user->GetDisplayedHost().c_str()), InspIRCd::Format("is messaging you, and you have umode +g. Use /ACCEPT +%s to allow.", user->nick.c_str())); dat->lastnotify = now; } diff --git a/src/modules/m_cgiirc.cpp b/src/modules/m_cgiirc.cpp index 21098d7a7..2b80f6e5c 100644 --- a/src/modules/m_cgiirc.cpp +++ b/src/modules/m_cgiirc.cpp @@ -70,7 +70,7 @@ class WebIRCHost return false; // Does the user's hostname match our hostmask? - if (InspIRCd::Match(user->host, hostmask, ascii_case_insensitive_map)) + if (InspIRCd::Match(user->GetRealHost(), hostmask, ascii_case_insensitive_map)) return true; // Does the user's IP address match our hostmask? @@ -134,17 +134,16 @@ class CommandWebIRC : public SplitCommand // The user matched a WebIRC block! gateway.set(user, parameters[1]); - realhost.set(user, user->host); + realhost.set(user, user->GetRealHost()); realip.set(user, user->GetIPString()); if (notify) ServerInstance->SNO->WriteGlobalSno('w', "Connecting user %s is using a WebIRC gateway; changing their IP/host from %s/%s to %s/%s.", - user->nick.c_str(), user->GetIPString().c_str(), user->host.c_str(), parameters[3].c_str(), newhost.c_str()); + user->nick.c_str(), user->GetIPString().c_str(), user->GetRealHost().c_str(), parameters[3].c_str(), newhost.c_str()); // Set the IP address and hostname sent via WEBIRC. ChangeIP(user, parameters[3]); - user->host = user->dhost = newhost; - user->InvalidateCache(); + user->ChangeRealHost(newhost, true); return CMD_SUCCESS; } @@ -186,10 +185,9 @@ class CGIResolver : public DNS::Request return; if (notify) - ServerInstance->SNO->WriteGlobalSno('w', "Connecting user %s detected as using CGI:IRC (%s), changing real host to %s", them->nick.c_str(), them->host.c_str(), ans_record.rdata.c_str()); + ServerInstance->SNO->WriteGlobalSno('w', "Connecting user %s detected as using CGI:IRC (%s), changing real host to %s", them->nick.c_str(), them->GetRealHost().c_str(), ans_record.rdata.c_str()); - them->host = them->dhost = ans_record.rdata; - them->InvalidateCache(); + them->ChangeRealHost(ans_record.rdata, true); lu->CheckLines(true); } } @@ -202,7 +200,7 @@ class CGIResolver : public DNS::Request User* them = ServerInstance->FindUUID(theiruid); if ((them) && (!them->quitting)) { - ServerInstance->SNO->WriteToSnoMask('w', "Connecting user %s detected as using CGI:IRC (%s), but their host can't be resolved!", them->nick.c_str(), them->host.c_str()); + ServerInstance->SNO->WriteToSnoMask('w', "Connecting user %s detected as using CGI:IRC (%s), but their host can't be resolved!", them->nick.c_str(), them->GetRealHost().c_str()); } } @@ -233,11 +231,10 @@ class ModuleCgiIRC : public Module, public Whois::EventListener void HandleIdent(LocalUser* user, const std::string& newip) { - cmd.realhost.set(user, user->host); + cmd.realhost.set(user, user->GetRealHost()); cmd.realip.set(user, user->GetIPString()); ChangeIP(user, newip); - user->host = user->dhost = user->GetIPString(); - user->InvalidateCache(); + user->ChangeRealHost(user->GetIPString(), true); RecheckClass(user); // Don't create the resolver if the core couldn't put the user in a connect class or when dns is disabled @@ -257,7 +254,7 @@ class ModuleCgiIRC : public Module, public Whois::EventListener waiting.set(user, count - 1); delete r; if (cmd.notify) - ServerInstance->SNO->WriteToSnoMask('w', "Connecting user %s detected as using CGI:IRC (%s), but I could not resolve their hostname; %s", user->nick.c_str(), user->host.c_str(), ex.GetReason().c_str()); + ServerInstance->SNO->WriteToSnoMask('w', "Connecting user %s detected as using CGI:IRC (%s), but I could not resolve their hostname; %s", user->nick.c_str(), user->GetRealHost().c_str(), ex.GetReason().c_str()); } } @@ -364,7 +361,7 @@ public: { for (std::vector::const_iterator iter = hosts.begin(); iter != hosts.end(); ++iter) { - if (!InspIRCd::Match(user->host, *iter, ascii_case_insensitive_map) && !InspIRCd::MatchCIDR(user->GetIPString(), *iter, ascii_case_insensitive_map)) + if (!InspIRCd::Match(user->GetRealHost(), *iter, ascii_case_insensitive_map) && !InspIRCd::MatchCIDR(user->GetIPString(), *iter, ascii_case_insensitive_map)) continue; CheckIdent(user); // Nothing on failure. diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index 2cb45ad43..b442dea9c 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -265,7 +265,7 @@ class CommandCheck : public Command const UserManager::CloneCounts& clonecount = ServerInstance->Users->GetCloneCounts(i->first); context.Write("member", InspIRCd::Format("%-3u %s%s (%s@%s) %s ", clonecount.global, i->second->GetAllPrefixChars().c_str(), i->first->nick.c_str(), - i->first->ident.c_str(), i->first->dhost.c_str(), i->first->fullname.c_str())); + i->first->ident.c_str(), i->first->GetDisplayedHost().c_str(), i->first->fullname.c_str())); } const ModeParser::ListModeList& listmodes = ServerInstance->Modes->GetListModes(); @@ -283,7 +283,7 @@ class CommandCheck : public Command const user_hash& users = ServerInstance->Users->GetUsers(); for (user_hash::const_iterator a = users.begin(); a != users.end(); ++a) { - if (InspIRCd::Match(a->second->host, parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->dhost, parameters[0], ascii_case_insensitive_map)) + if (InspIRCd::Match(a->second->GetRealHost(), parameters[0], ascii_case_insensitive_map) || InspIRCd::Match(a->second->GetDisplayedHost(), parameters[0], ascii_case_insensitive_map)) { /* host or vhost matches mask */ context.Write("match", ConvToStr(++x) + " " + a->second->GetFullRealHost() + " " + a->second->GetIPString() + " " + a->second->fullname); diff --git a/src/modules/m_chghost.cpp b/src/modules/m_chghost.cpp index ad8353cbd..8b588b63d 100644 --- a/src/modules/m_chghost.cpp +++ b/src/modules/m_chghost.cpp @@ -66,7 +66,7 @@ class CommandChghost : public Command if ((dest->ChangeDisplayedHost(parameters[1])) && (!user->server->IsULine())) { // fix by brain - ulines set hosts silently - ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->dhost); + ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used CHGHOST to make the displayed host of "+dest->nick+" become "+dest->GetDisplayedHost()); } } diff --git a/src/modules/m_clearchan.cpp b/src/modules/m_clearchan.cpp index 1b4b8724a..08a7a88b5 100644 --- a/src/modules/m_clearchan.cpp +++ b/src/modules/m_clearchan.cpp @@ -116,7 +116,7 @@ class CommandClearChan : public Command XLine* xline; try { - mask = ((method[0] == 'Z') ? curr->GetIPString() : "*@" + curr->host); + mask = ((method[0] == 'Z') ? curr->GetIPString() : "*@" + curr->GetRealHost()); xline = xlf->Generate(ServerInstance->Time(), 60*60, user->nick, reason, mask); } catch (ModuleException&) diff --git a/src/modules/m_cloaking.cpp b/src/modules/m_cloaking.cpp index 7e9c78b31..f9a7fa380 100644 --- a/src/modules/m_cloaking.cpp +++ b/src/modules/m_cloaking.cpp @@ -90,7 +90,7 @@ class CloakUser : public ModeHandler if (adding) { // assume this is more correct - if (user->registered != REG_ALL && user->host != user->dhost) + if (user->registered != REG_ALL && user->GetRealHost() != user->GetDisplayedHost()) return MODEACTION_DENY; std::string* cloak = ext.get(user); @@ -116,7 +116,7 @@ class CloakUser : public ModeHandler * and make it match the displayed one. */ user->SetMode(this, false); - user->ChangeDisplayedHost(user->host.c_str()); + user->ChangeDisplayedHost(user->GetRealHost().c_str()); return MODEACTION_ALLOW; } } @@ -281,7 +281,7 @@ class ModuleCloaking : public Module OnUserConnect(lu); std::string* cloak = cu.ext.get(user); /* Check if they have a cloaked host, but are not using it */ - if (cloak && *cloak != user->dhost) + if (cloak && *cloak != user->GetDisplayedHost()) { const std::string cloakMask = user->nick + "!" + user->ident + "@" + *cloak; if (InspIRCd::Match(cloakMask, mask)) @@ -384,7 +384,7 @@ class ModuleCloaking : public Module if (cloak) return; - cu.ext.set(dest, GenCloak(dest->client_sa, dest->GetIPString(), dest->host)); + cu.ext.set(dest, GenCloak(dest->client_sa, dest->GetIPString(), dest->GetRealHost())); } }; diff --git a/src/modules/m_customtitle.cpp b/src/modules/m_customtitle.cpp index 30c0aa4f2..2a08592ea 100644 --- a/src/modules/m_customtitle.cpp +++ b/src/modules/m_customtitle.cpp @@ -35,7 +35,7 @@ class CommandTitle : public Command CmdResult Handle(const std::vector ¶meters, User* user) { - const std::string userHost = user->ident + "@" + user->host; + const std::string userHost = user->ident + "@" + user->GetRealHost(); const std::string userIP = user->ident + "@" + user->GetIPString(); ConfigTagList tags = ServerInstance->Config->ConfTags("title"); diff --git a/src/modules/m_dccallow.cpp b/src/modules/m_dccallow.cpp index edf9d012f..e687e1341 100644 --- a/src/modules/m_dccallow.cpp +++ b/src/modules/m_dccallow.cpp @@ -181,7 +181,7 @@ class CommandDccallow : public Command } } - std::string mask = target->nick+"!"+target->ident+"@"+target->dhost; + std::string mask = target->nick+"!"+target->ident+"@"+target->GetDisplayedHost(); std::string default_length = ServerInstance->Config->ConfValue("dccallow")->getString("length"); unsigned long length; @@ -382,14 +382,14 @@ class ModuleDCCAllow : public Module return MOD_RES_PASSTHRU; user->WriteNotice("The user " + u->nick + " is not accepting DCC SENDs from you. Your file " + filename + " was not sent."); - u->WriteNotice(user->nick + " (" + user->ident + "@" + user->dhost + ") attempted to send you a file named " + filename + ", which was blocked."); + u->WriteNotice(user->nick + " (" + user->ident + "@" + user->GetDisplayedHost() + ") attempted to send you a file named " + filename + ", which was blocked."); u->WriteNotice("If you trust " + user->nick + " and were expecting this, you can type /DCCALLOW HELP for information on the DCCALLOW system."); return MOD_RES_DENY; } else if ((blockchat) && (stdalgo::string::equalsci(type, "CHAT"))) { user->WriteNotice("The user " + u->nick + " is not accepting DCC CHAT requests from you."); - u->WriteNotice(user->nick + " (" + user->ident + "@" + user->dhost + ") attempted to initiate a DCC CHAT session, which was blocked."); + u->WriteNotice(user->nick + " (" + user->ident + "@" + user->GetDisplayedHost() + ") attempted to initiate a DCC CHAT session, which was blocked."); u->WriteNotice("If you trust " + user->nick + " and were expecting this, you can type /DCCALLOW HELP for information on the DCCALLOW system."); return MOD_RES_DENY; } diff --git a/src/modules/m_hideoper.cpp b/src/modules/m_hideoper.cpp index ff9e78ca2..6650b7f16 100644 --- a/src/modules/m_hideoper.cpp +++ b/src/modules/m_hideoper.cpp @@ -138,7 +138,7 @@ class ModuleHideOper : public Module, public Whois::LineEventListener if (!oper->server->IsULine() && (stats.GetSource()->IsOper() || !oper->IsModeSet(hm))) { LocalUser* lu = IS_LOCAL(oper); - stats.AddRow(249, oper->nick + " (" + oper->ident + "@" + oper->dhost + ") Idle: " + + stats.AddRow(249, oper->nick + " (" + oper->ident + "@" + oper->GetDisplayedHost() + ") Idle: " + (lu ? ConvToStr(ServerInstance->Time() - lu->idle_lastmsg) + " secs" : "unavailable")); count++; } diff --git a/src/modules/m_hostcycle.cpp b/src/modules/m_hostcycle.cpp index 621f06a27..0f7405dcc 100644 --- a/src/modules/m_hostcycle.cpp +++ b/src/modules/m_hostcycle.cpp @@ -109,7 +109,7 @@ class ModuleHostCycle : public Module void OnChangeIdent(User* user, const std::string& newident) CXX11_OVERRIDE { - DoHostCycle(user, newident, user->dhost, "Changing ident"); + DoHostCycle(user, newident, user->GetDisplayedHost(), "Changing ident"); } void OnChangeHost(User* user, const std::string& newhost) CXX11_OVERRIDE diff --git a/src/modules/m_httpd_stats.cpp b/src/modules/m_httpd_stats.cpp index de5a61e4d..00cab3197 100644 --- a/src/modules/m_httpd_stats.cpp +++ b/src/modules/m_httpd_stats.cpp @@ -183,7 +183,7 @@ class ModuleHttpStats : public Module, public HTTPRequestEventListener data << ""; data << "" << u->nick << "" << u->uuid << "" - << u->host << "" << u->dhost << "" + << u->GetRealHost() << "" << u->GetDisplayedHost() << "" << Sanitize(u->fullname) << "" << u->server->GetName() << ""; if (u->IsAway()) data << "" << Sanitize(u->awaymsg) << "" << u->awaytime << ""; diff --git a/src/modules/m_ircv3_chghost.cpp b/src/modules/m_ircv3_chghost.cpp index af3503108..0a9e055b4 100644 --- a/src/modules/m_ircv3_chghost.cpp +++ b/src/modules/m_ircv3_chghost.cpp @@ -40,7 +40,7 @@ class ModuleIRCv3ChgHost : public Module void OnChangeIdent(User* user, const std::string& newident) CXX11_OVERRIDE { - DoChgHost(user, newident, user->dhost); + DoChgHost(user, newident, user->GetDisplayedHost()); } void OnChangeHost(User* user, const std::string& newhost) CXX11_OVERRIDE diff --git a/src/modules/m_ldapoper.cpp b/src/modules/m_ldapoper.cpp index 9deb9a203..45e83333a 100644 --- a/src/modules/m_ldapoper.cpp +++ b/src/modules/m_ldapoper.cpp @@ -217,7 +217,7 @@ class ModuleLDAPAuth : public Module return MOD_RES_PASSTHRU; std::string acceptedhosts = tag->getString("host"); - std::string hostname = user->ident + "@" + user->host; + std::string hostname = user->ident + "@" + user->GetRealHost(); if (!InspIRCd::MatchMask(acceptedhosts, hostname, user->GetIPString())) return MOD_RES_PASSTHRU; diff --git a/src/modules/m_messageflood.cpp b/src/modules/m_messageflood.cpp index 404c9b861..fa929294c 100644 --- a/src/modules/m_messageflood.cpp +++ b/src/modules/m_messageflood.cpp @@ -138,7 +138,7 @@ class ModuleMsgFlood : public Module if (f->ban) { Modes::ChangeList changelist; - changelist.push_add(ServerInstance->Modes->FindMode('b', MODETYPE_CHANNEL), "*!*@" + user->dhost); + changelist.push_add(ServerInstance->Modes->FindMode('b', MODETYPE_CHANNEL), "*!*@" + user->GetDisplayedHost()); ServerInstance->Modes->Process(ServerInstance->FakeClient, dest, NULL, changelist); } diff --git a/src/modules/m_repeat.cpp b/src/modules/m_repeat.cpp index aa7dc762b..f1ebe18e5 100644 --- a/src/modules/m_repeat.cpp +++ b/src/modules/m_repeat.cpp @@ -384,7 +384,7 @@ class RepeatModule : public Module if (settings->Action == ChannelSettings::ACT_BAN) { Modes::ChangeList changelist; - changelist.push_add(ServerInstance->Modes->FindMode('b', MODETYPE_CHANNEL), "*!*@" + user->dhost); + changelist.push_add(ServerInstance->Modes->FindMode('b', MODETYPE_CHANNEL), "*!*@" + user->GetDisplayedHost()); ServerInstance->Modes->Process(ServerInstance->FakeClient, chan, NULL, changelist); } diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp index eb54e56b7..6fd7b832c 100644 --- a/src/modules/m_rline.cpp +++ b/src/modules/m_rline.cpp @@ -62,7 +62,7 @@ class RLine : public XLine if (lu && lu->exempt) return false; - const std::string host = u->nick + "!" + u->ident + "@" + u->host + " " + u->fullname; + const std::string host = u->nick + "!" + u->ident + "@" + u->GetRealHost() + " " + u->fullname; const std::string ip = u->nick + "!" + u->ident + "@" + u->GetIPString() + " " + u->fullname; return (regex->Matches(host) || regex->Matches(ip)); } diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index eedf968b4..e8a0e12a9 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -172,7 +172,7 @@ class SaslAuthenticator void SendHostIP() { parameterlist params; - params.push_back(user->host); + params.push_back(user->GetRealHost()); params.push_back(user->GetIPString()); params.push_back(SSLIOHook::IsSSL(&user->eh) ? "S" : "P"); diff --git a/src/modules/m_sethost.cpp b/src/modules/m_sethost.cpp index e2a5dc281..b37207b4f 100644 --- a/src/modules/m_sethost.cpp +++ b/src/modules/m_sethost.cpp @@ -53,7 +53,7 @@ class CommandSethost : public Command if (user->ChangeDisplayedHost(parameters[0])) { - ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used SETHOST to change their displayed host to "+user->dhost); + ServerInstance->SNO->WriteGlobalSno('a', user->nick+" used SETHOST to change their displayed host to "+user->GetDisplayedHost()); return CMD_SUCCESS; } diff --git a/src/modules/m_showwhois.cpp b/src/modules/m_showwhois.cpp index 3cb85f3fb..99774563d 100644 --- a/src/modules/m_showwhois.cpp +++ b/src/modules/m_showwhois.cpp @@ -50,7 +50,7 @@ class WhoisNoticeCmd : public Command void HandleFast(User* dest, User* src) { dest->WriteNotice("*** " + src->nick + " (" + src->ident + "@" + - (dest->HasPrivPermission("users/auspex") ? src->host : src->dhost) + + src->GetHost(dest->HasPrivPermission("users/auspex")) + ") did a /whois on you"); } diff --git a/src/modules/m_spanningtree/opertype.cpp b/src/modules/m_spanningtree/opertype.cpp index b1d0c327e..4b1dce23c 100644 --- a/src/modules/m_spanningtree/opertype.cpp +++ b/src/modules/m_spanningtree/opertype.cpp @@ -52,7 +52,7 @@ CmdResult CommandOpertype::HandleRemote(RemoteUser* u, std::vector& return CMD_SUCCESS; } - ServerInstance->SNO->WriteToSnoMask('O',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server->GetName().c_str(), u->nick.c_str(),u->ident.c_str(), u->host.c_str(), opertype.c_str()); + ServerInstance->SNO->WriteToSnoMask('O',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server->GetName().c_str(), u->nick.c_str(),u->ident.c_str(), u->GetRealHost().c_str(), opertype.c_str()); return CMD_SUCCESS; } diff --git a/src/modules/m_spanningtree/uid.cpp b/src/modules/m_spanningtree/uid.cpp index 2a17943e9..905061cc7 100644 --- a/src/modules/m_spanningtree/uid.cpp +++ b/src/modules/m_spanningtree/uid.cpp @@ -73,8 +73,8 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, std::vectorUsers->clientlist[params[2]] = _new; _new->nick = params[2]; - _new->host = params[3]; - _new->dhost = params[4]; + _new->ChangeRealHost(params[3], false); + _new->ChangeDisplayedHost(params[4]); _new->ident = params[5]; _new->fullname = params.back(); _new->registered = REG_ALL; @@ -157,8 +157,8 @@ CommandUID::Builder::Builder(User* user) push(user->uuid); push_int(user->age); push(user->nick); - push(user->host); - push(user->dhost); + push(user->GetRealHost()); + push(user->GetDisplayedHost()); push(user->ident); push(user->GetIPString()); push_int(user->signon); diff --git a/src/modules/m_sqloper.cpp b/src/modules/m_sqloper.cpp index b5f0d6c47..b6aa90f49 100644 --- a/src/modules/m_sqloper.cpp +++ b/src/modules/m_sqloper.cpp @@ -88,7 +88,7 @@ class OpMeQuery : public SQLQuery std::string hostname(user->ident); - hostname.append("@").append(user->host); + hostname.append("@").append(user->GetRealHost()); if (InspIRCd::MatchMask(pattern, hostname, user->GetIPString())) { diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp index 6e9a6f9ed..7fa8ad8f4 100644 --- a/src/modules/m_watch.cpp +++ b/src/modules/m_watch.cpp @@ -53,9 +53,9 @@ class CommandWatch : public SplitCommand { // The away state should only be sent if the client requests away notifications for a nick but 2.0 always sends them so we do that too if (target->IsAway()) - user->WriteNumeric(RPL_NOWISAWAY, target->nick, target->ident, target->dhost, (unsigned long)target->awaytime, "is away"); + user->WriteNumeric(RPL_NOWISAWAY, target->nick, target->ident, target->GetDisplayedHost(), (unsigned long)target->awaytime, "is away"); else - user->WriteNumeric(RPL_NOWON, target->nick, target->ident, target->dhost, (unsigned long)target->age, "is online"); + user->WriteNumeric(RPL_NOWON, target->nick, target->ident, target->GetDisplayedHost(), (unsigned long)target->age, "is online"); } else if (show_offline) user->WriteNumeric(RPL_NOWOFF, nick, "*", "*", "0", "is offline"); @@ -88,7 +88,7 @@ class CommandWatch : public SplitCommand User* target = IRCv3::Monitor::Manager::FindNick(nick); if (target) - user->WriteNumeric(RPL_WATCHOFF, target->nick, target->ident, target->dhost, (unsigned long)target->age, "stopped watching"); + user->WriteNumeric(RPL_WATCHOFF, target->nick, target->ident, target->GetDisplayedHost(), (unsigned long)target->age, "stopped watching"); else user->WriteNumeric(RPL_WATCHOFF, nick, "*", "*", "0", "stopped watching"); } @@ -190,7 +190,7 @@ class ModuleWatch : public Module return; Numeric::Numeric num(numeric); - num.push(nick).push(user->ident).push(user->dhost).push(ConvToStr(shownts)).push(numerictext); + num.push(nick).push(user->ident).push(user->GetDisplayedHost()).push(ConvToStr(shownts)).push(numerictext); for (IRCv3::Monitor::WatcherList::const_iterator i = list->begin(); i != list->end(); ++i) { LocalUser* curr = *i; diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 12ec36ec7..02c030a42 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -177,7 +177,7 @@ void UserManager::QuitUser(User* user, const std::string& quitreason, const std: user->quitting = true; ServerInstance->Logs->Log("USERS", LOG_DEBUG, "QuitUser: %s=%s '%s'", user->uuid.c_str(), user->nick.c_str(), quitreason.c_str()); - user->Write("ERROR :Closing link: (%s@%s) [%s]", user->ident.c_str(), user->host.c_str(), operreason ? operreason->c_str() : quitreason.c_str()); + user->Write("ERROR :Closing link: (%s@%s) [%s]", user->ident.c_str(), user->GetRealHost().c_str(), operreason ? operreason->c_str() : quitreason.c_str()); std::string reason; reason.assign(quitreason, 0, ServerInstance->Config->Limits.MaxQuit); diff --git a/src/users.cpp b/src/users.cpp index 9fef906d1..aa5031b2b 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -106,7 +106,7 @@ LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::so eh.SetFd(myfd); memcpy(&client_sa, client, sizeof(irc::sockets::sockaddrs)); memcpy(&server_sa, servaddr, sizeof(irc::sockets::sockaddrs)); - dhost = host = GetIPString(); + ChangeRealHost(GetIPString(), true); } User::~User() @@ -119,7 +119,7 @@ const std::string& User::MakeHost() return this->cached_makehost; // XXX: Is there really a need to cache this? - this->cached_makehost = ident + "@" + host; + this->cached_makehost = ident + "@" + GetRealHost(); return this->cached_makehost; } @@ -139,7 +139,7 @@ const std::string& User::GetFullHost() return this->cached_fullhost; // XXX: Is there really a need to cache this? - this->cached_fullhost = nick + "!" + ident + "@" + dhost; + this->cached_fullhost = nick + "!" + ident + "@" + GetDisplayedHost(); return this->cached_fullhost; } @@ -149,7 +149,7 @@ const std::string& User::GetFullRealHost() return this->cached_fullrealhost; // XXX: Is there really a need to cache this? - this->cached_fullrealhost = nick + "!" + ident + "@" + host; + this->cached_fullrealhost = nick + "!" + ident + "@" + GetRealHost(); return this->cached_fullrealhost; } @@ -360,7 +360,7 @@ void User::Oper(OperInfo* info) } ServerInstance->SNO->WriteToSnoMask('o',"%s (%s@%s) is now an IRC operator of type %s (using oper '%s')", - nick.c_str(), ident.c_str(), host.c_str(), oper->name.c_str(), opername.c_str()); + nick.c_str(), ident.c_str(), GetRealHost().c_str(), oper->name.c_str(), opername.c_str()); this->WriteNumeric(RPL_YOUAREOPER, InspIRCd::Format("You are now %s %s", strchr("aeiouAEIOU", oper->name[0]) ? "an" : "a", oper->name.c_str())); ServerInstance->Logs->Log("OPER", LOG_DEFAULT, "%s opered as type: %s", GetFullRealHost().c_str(), oper->name.c_str()); @@ -692,6 +692,21 @@ const std::string& User::GetIPString() return cachedip; } +const std::string& User::GetHost(bool uncloak) const +{ + return uncloak ? GetRealHost() : GetDisplayedHost(); +} + +const std::string& User::GetDisplayedHost() const +{ + return displayhost.empty() ? realhost : displayhost; +} + +const std::string& User::GetRealHost() const +{ + return realhost; +} + irc::sockets::cidr_mask User::GetCIDRMask() { int range = 0; @@ -997,7 +1012,7 @@ bool User::ChangeName(const std::string& gecos) bool User::ChangeDisplayedHost(const std::string& shost) { - if (dhost == shost) + if (GetDisplayedHost() == shost) return true; if (IS_LOCAL(this)) @@ -1010,15 +1025,34 @@ bool User::ChangeDisplayedHost(const std::string& shost) FOREACH_MOD(OnChangeHost, (this,shost)); - this->dhost.assign(shost, 0, ServerInstance->Config->Limits.MaxHost); + if (realhost == shost) + this->displayhost.clear(); + else + this->displayhost.assign(shost, 0, ServerInstance->Config->Limits.MaxHost); + this->InvalidateCache(); if (IS_LOCAL(this)) - this->WriteNumeric(RPL_YOURDISPLAYEDHOST, this->dhost, "is now your displayed host"); + this->WriteNumeric(RPL_YOURDISPLAYEDHOST, this->GetDisplayedHost(), "is now your displayed host"); return true; } +void User::ChangeRealHost(const std::string& host, bool resetdisplay) +{ + if (displayhost == host) + return; + + if (displayhost.empty() && !resetdisplay) + displayhost = realhost; + + else if (displayhost == host || resetdisplay) + displayhost.clear(); + + realhost = host; + this->InvalidateCache(); +} + bool User::ChangeIdent(const std::string& newident) { if (this->ident == newident) @@ -1085,7 +1119,7 @@ void LocalUser::SetClass(const std::string &explicit_name) /* check if host matches.. */ if (!InspIRCd::MatchCIDR(this->GetIPString(), c->GetHost(), NULL) && - !InspIRCd::MatchCIDR(this->host, c->GetHost(), NULL)) + !InspIRCd::MatchCIDR(this->GetRealHost(), c->GetHost(), NULL)) { ServerInstance->Logs->Log("CONNECTCLASS", LOG_DEBUG, "No host match (for %s)", c->GetHost().c_str()); continue; diff --git a/src/xline.cpp b/src/xline.cpp index 257af9ca7..f21b2b4fb 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -548,7 +548,7 @@ bool KLine::Matches(User *u) if (InspIRCd::Match(u->ident, this->identmask, ascii_case_insensitive_map)) { - if (InspIRCd::MatchCIDR(u->host, this->hostmask, ascii_case_insensitive_map) || + if (InspIRCd::MatchCIDR(u->GetRealHost(), this->hostmask, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, ascii_case_insensitive_map)) { return true; @@ -571,7 +571,7 @@ bool GLine::Matches(User *u) if (InspIRCd::Match(u->ident, this->identmask, ascii_case_insensitive_map)) { - if (InspIRCd::MatchCIDR(u->host, this->hostmask, ascii_case_insensitive_map) || + if (InspIRCd::MatchCIDR(u->GetRealHost(), this->hostmask, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, ascii_case_insensitive_map)) { return true; @@ -594,7 +594,7 @@ bool ELine::Matches(User *u) if (InspIRCd::Match(u->ident, this->identmask, ascii_case_insensitive_map)) { - if (InspIRCd::MatchCIDR(u->host, this->hostmask, ascii_case_insensitive_map) || + if (InspIRCd::MatchCIDR(u->GetRealHost(), this->hostmask, ascii_case_insensitive_map) || InspIRCd::MatchCIDR(u->GetIPString(), this->hostmask, ascii_case_insensitive_map)) { return true; -- cgit v1.2.3