diff options
author | attilamolnar <attilamolnar@hush.com> | 2012-07-09 15:35:12 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2012-09-13 18:51:28 +0200 |
commit | 2115bd71dc5307cdcda1b7d7be3b9d9b0545531f (patch) | |
tree | 1fa41e05856843c1385aa47940549bf080c043bd | |
parent | 91abba488ad4b2c5bf59c720cde387b6390528d9 (diff) |
Call OnUserSetIP() whenever the IP of a local user changes, set ident,host,dhost in LocalUser constructor
-rw-r--r-- | include/users.h | 6 | ||||
-rw-r--r-- | src/usermanager.cpp | 6 | ||||
-rw-r--r-- | src/users.cpp | 42 |
3 files changed, 46 insertions, 8 deletions
diff --git a/include/users.h b/include/users.h index 57dea3fa5..5a8864cdd 100644 --- a/include/users.h +++ b/include/users.h @@ -395,6 +395,8 @@ class CoreExport User : public Extensible */ bool SetClientIP(const char* sip); + void SetClientIP(const irc::sockets::sockaddrs& sa); + /** Constructor * @throw CoreException if the UID allocated to the user already exists */ @@ -819,6 +821,10 @@ class CoreExport LocalUser : public User, public InviteBase */ void SetClass(const std::string &explicit_name = ""); + bool SetClientIP(const char* sip); + + void SetClientIP(const irc::sockets::sockaddrs& sa); + void SendText(const std::string& line); void Write(const std::string& text); void Write(const char*, ...) CUSTOM_PRINTF(2, 3); diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 785d23625..d65f47128 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -66,16 +66,10 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs New->nick.assign(New->uuid, 0, ServerInstance->Config->Limits.NickMax); (*(this->clientlist))[New->nick] = New; - New->ident.assign("unknown"); - New->registered = REG_NONE; New->signon = ServerInstance->Time() + ServerInstance->Config->dns_timeout; New->lastping = 1; - /* Smarter than your average bear^H^H^H^Hset of strlcpys. */ - New->dhost.assign(New->GetIPString(), 0, 64); - New->host.assign(New->GetIPString(), 0, 64); - ServerInstance->Users->AddLocalClone(New); ServerInstance->Users->AddGlobalClone(New); 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) |