diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/usermanager.cpp | 6 | ||||
-rw-r--r-- | src/users.cpp | 42 |
2 files changed, 40 insertions, 8 deletions
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) |