class ModuleIdent : public Module
{
- int RequestTimeout;
- bool NoLookupPrefix;
+ private:
+ unsigned int timeout;
+ bool prefixunqueried;
SimpleExtItem<IdentRequestSocket, stdalgo::culldeleter> ext;
+
+ static void PrefixIdent(LocalUser* user)
+ {
+ // Check that they haven't been prefixed already.
+ if (user->ident[0] == '~')
+ return;
+
+ // All invalid usernames are prefixed with a tilde.
+ std::string newident(user->ident);
+ newident.insert(newident.begin(), '~');
+
+ // If the username is too long then truncate it.
+ if (newident.length() > ServerInstance->Config->Limits.IdentMax)
+ newident.erase(ServerInstance->Config->Limits.IdentMax);
+
+ // Apply the new username.
+ user->ChangeIdent(newident);
+ }
+
public:
ModuleIdent()
: ext("ident_socket", ExtensionItem::EXT_USER, this)
void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
{
ConfigTag* tag = ServerInstance->Config->ConfValue("ident");
- RequestTimeout = tag->getDuration("timeout", 5, 1);
- NoLookupPrefix = tag->getBool("nolookupprefix", false);
+ timeout = tag->getDuration("timeout", 5, 1, 60);
+ prefixunqueried = tag->getBool("prefixunqueried");
}
void OnSetUserIP(LocalUser* user) CXX11_OVERRIDE
IdentRequestSocket *isock = ext.get(user);
if (!isock)
{
- if ((NoLookupPrefix) && (user->ident[0] != '~'))
- user->ident.insert(user->ident.begin(), 1, '~');
+ if (prefixunqueried)
+ PrefixIdent(user);
return MOD_RES_PASSTHRU;
}
- time_t compare = isock->age;
- compare += RequestTimeout;
+ time_t compare = isock->age + timeout;
/* Check for timeout of the socket */
if (ServerInstance->Time() >= compare)
{
/* Ident timeout */
- user->WriteNotice("*** Ident request timed out.");
+ PrefixIdent(user);
+ user->WriteNotice("*** Ident lookup timed out, using " + user->ident + " instead.");
}
else if (!isock->HasResult())
{
}
/* wooo, got a result (it will be good, or bad) */
- if (isock->result.empty())
+ else if (isock->result.empty())
{
- user->ident.insert(user->ident.begin(), 1, '~');
+ PrefixIdent(user);
user->WriteNotice("*** Could not find your ident, using " + user->ident + " instead.");
}
else
{
- user->ident = isock->result;
+ user->ChangeIdent(isock->result);
user->WriteNotice("*** Found your ident, '" + user->ident + "'");
}
- user->InvalidateCache();
isock->Close();
ext.unset(user);
return MOD_RES_PASSTHRU;