From 2115bd71dc5307cdcda1b7d7be3b9d9b0545531f Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Mon, 9 Jul 2012 15:35:12 +0200 Subject: Call OnUserSetIP() whenever the IP of a local user changes, set ident,host,dhost in LocalUser constructor --- src/users.cpp | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) (limited to 'src/users.cpp') diff --git a/src/users.cpp b/src/users.cpp index 6e282f7c0..f211f6b49 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -222,10 +222,22 @@ LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::so bytes_in(0), bytes_out(0), cmds_in(0), cmds_out(0), nping(0), CommandFloodPenalty(0), already_sent(0) { + ident = "unknown"; lastping = 0; eh.SetFd(myfd); - memcpy(&client_sa, client, sizeof(irc::sockets::sockaddrs)); memcpy(&server_sa, servaddr, sizeof(irc::sockets::sockaddrs)); + + /* + * Initialize host and dhost here to the user's IP. + * It is important to do this before calling SetClientIP() + * as that can pass execution to modules that expect these + * fields to be valid. + */ + + int port; + irc::sockets::satoap(*client, host, port); + dhost = host; + SetClientIP(*client); } User::~User() @@ -980,10 +992,36 @@ irc::sockets::cidr_mask User::GetCIDRMask() bool User::SetClientIP(const char* sip) { - this->cachedip = ""; + cachedip.clear(); return irc::sockets::aptosa(sip, 0, client_sa); } +void User::SetClientIP(const irc::sockets::sockaddrs& sa) +{ + cachedip.clear(); + memcpy(&client_sa, &sa, sizeof(irc::sockets::sockaddrs)); +} + +bool LocalUser::SetClientIP(const char* sip) +{ + irc::sockets::sockaddrs sa; + if (!irc::sockets::aptosa(sip, 0, sa)) + // Invalid + return false; + + LocalUser::SetClientIP(sa); + return true; +} + +void LocalUser::SetClientIP(const irc::sockets::sockaddrs& sa) +{ + if (sa != client_sa) + { + User::SetClientIP(sa); + FOREACH_MOD(I_OnSetUserIP,OnSetUserIP(this)); + } +} + static std::string wide_newline("\r\n"); void User::Write(const std::string& text) -- cgit v1.2.3