From 3b9ef1ae8dcaf2d36f0e31e8b39fe5cfea304d74 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 18 Jan 2019 13:12:00 +0000 Subject: ident: Fix making idents longer than maxident when a lookup fails. --- src/modules/m_ident.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/modules/m_ident.cpp') diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index 803c19846..302db0d97 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -254,9 +254,29 @@ class IdentRequestSocket : public EventHandler class ModuleIdent : public Module { + private: int RequestTimeout; bool NoLookupPrefix; SimpleExtItem 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) @@ -320,8 +340,8 @@ class ModuleIdent : public Module IdentRequestSocket *isock = ext.get(user); if (!isock) { - if ((NoLookupPrefix) && (user->ident[0] != '~')) - user->ident.insert(user->ident.begin(), 1, '~'); + if (NoLookupPrefix) + PrefixIdent(user); return MOD_RES_PASSTHRU; } @@ -343,7 +363,7 @@ class ModuleIdent : public Module /* wooo, got a result (it will be good, or bad) */ 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 -- cgit v1.3.1-10-gc9f91 From f35490427c17229e81b1ff266c7dcaf67d1a35b5 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 1 Feb 2019 10:39:11 +0000 Subject: ident: Change idents with the ChangeIdent method. --- src/modules/m_ident.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/modules/m_ident.cpp') diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index 302db0d97..74f049b44 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -368,11 +368,10 @@ class ModuleIdent : public Module } 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; -- cgit v1.3.1-10-gc9f91 From d66757a43817966edc0fdbe62722415354b042aa Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 1 Feb 2019 10:43:51 +0000 Subject: ident: reduce the amount of messages sent when a lookup fails. --- src/modules/m_ident.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/modules/m_ident.cpp') diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index 74f049b44..7bd403fd8 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -352,7 +352,8 @@ class ModuleIdent : public Module 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()) { @@ -361,7 +362,7 @@ class ModuleIdent : public Module } /* wooo, got a result (it will be good, or bad) */ - if (isock->result.empty()) + else if (isock->result.empty()) { PrefixIdent(user); user->WriteNotice("*** Could not find your ident, using " + user->ident + " instead."); -- cgit v1.3.1-10-gc9f91 From 965c55881b6804caa2f6c37f547dba06039c1194 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 1 Feb 2019 10:46:49 +0000 Subject: ident: store the timeout as an unsigned value and limit to 60s. --- src/modules/m_ident.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/modules/m_ident.cpp') diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index 7bd403fd8..f47901123 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -255,7 +255,7 @@ class IdentRequestSocket : public EventHandler class ModuleIdent : public Module { private: - int RequestTimeout; + unsigned int timeout; bool NoLookupPrefix; SimpleExtItem ext; @@ -291,7 +291,7 @@ class ModuleIdent : public Module void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { ConfigTag* tag = ServerInstance->Config->ConfValue("ident"); - RequestTimeout = tag->getDuration("timeout", 5, 1); + timeout = tag->getDuration("timeout", 5, 1, 60); NoLookupPrefix = tag->getBool("nolookupprefix", false); } @@ -345,8 +345,7 @@ class ModuleIdent : public Module 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) -- cgit v1.3.1-10-gc9f91 From 09da1499d7bc3a380c2b828eed22e3639d6e5e27 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 1 Feb 2019 10:49:00 +0000 Subject: ident: rename nolookupprefix to prefixunqueried. --- docs/conf/modules.conf.example | 4 ++-- src/modules/m_ident.cpp | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/modules/m_ident.cpp') diff --git a/docs/conf/modules.conf.example b/docs/conf/modules.conf.example index c9b6e298c..27068cbdb 100644 --- a/docs/conf/modules.conf.example +++ b/docs/conf/modules.conf.example @@ -1063,12 +1063,12 @@ # the timeout for ident lookups here. If not defined, it will default # # to 5 seconds. This is a non-blocking timeout which holds the user # # in a 'connecting' state until the lookup is complete. # -# nolookupprefix: If on, the idents of users being in a connect class # +# prefixunqueried: If on, the idents of users being in a connect class# # with ident lookups disabled (i.e. ) will be # # prefixed with a "~". If off, the ident of those users will not be # # prefixed. Default is off. # # -# +# #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # Invite exception module: Adds support for channel invite exceptions diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index f47901123..f3f8e7dd7 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -256,7 +256,7 @@ class ModuleIdent : public Module { private: unsigned int timeout; - bool NoLookupPrefix; + bool prefixunqueried; SimpleExtItem ext; static void PrefixIdent(LocalUser* user) @@ -292,7 +292,7 @@ class ModuleIdent : public Module { ConfigTag* tag = ServerInstance->Config->ConfValue("ident"); timeout = tag->getDuration("timeout", 5, 1, 60); - NoLookupPrefix = tag->getBool("nolookupprefix", false); + prefixunqueried = tag->getBool("prefixunqueried"); } void OnSetUserIP(LocalUser* user) CXX11_OVERRIDE @@ -340,7 +340,7 @@ class ModuleIdent : public Module IdentRequestSocket *isock = ext.get(user); if (!isock) { - if (NoLookupPrefix) + if (prefixunqueried) PrefixIdent(user); return MOD_RES_PASSTHRU; } -- cgit v1.3.1-10-gc9f91 From 625e5435f51650f547f4411441c0b7b958c53d30 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 1 Feb 2019 10:51:08 +0000 Subject: ident: rename ext to socket. --- src/modules/m_ident.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/modules/m_ident.cpp') diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index f3f8e7dd7..81bdf29c5 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -257,7 +257,7 @@ class ModuleIdent : public Module private: unsigned int timeout; bool prefixunqueried; - SimpleExtItem ext; + SimpleExtItem socket; static void PrefixIdent(LocalUser* user) { @@ -279,7 +279,7 @@ class ModuleIdent : public Module public: ModuleIdent() - : ext("ident_socket", ExtensionItem::EXT_USER, this) + : socket("ident_socket", ExtensionItem::EXT_USER, this) { } @@ -297,12 +297,12 @@ class ModuleIdent : public Module void OnSetUserIP(LocalUser* user) CXX11_OVERRIDE { - IdentRequestSocket* isock = ext.get(user); + IdentRequestSocket* isock = socket.get(user); if (isock) { // If an ident lookup request was in progress then cancel it. isock->Close(); - ext.unset(user); + socket.unset(user); } // The ident protocol requires that clients are connecting over a protocol with ports. @@ -322,7 +322,7 @@ class ModuleIdent : public Module try { isock = new IdentRequestSocket(user); - ext.set(user, isock); + socket.set(user, isock); } catch (ModuleException &e) { @@ -337,7 +337,7 @@ class ModuleIdent : public Module ModResult OnCheckReady(LocalUser *user) CXX11_OVERRIDE { /* Does user have an ident socket attached at all? */ - IdentRequestSocket *isock = ext.get(user); + IdentRequestSocket* isock = socket.get(user); if (!isock) { if (prefixunqueried) @@ -373,7 +373,7 @@ class ModuleIdent : public Module } isock->Close(); - ext.unset(user); + socket.unset(user); return MOD_RES_PASSTHRU; } -- cgit v1.3.1-10-gc9f91 From 26095b12f6d0037cfbbe9b2383398f0522f8f077 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Mon, 4 Feb 2019 10:20:33 +0000 Subject: ident: fix erroneously prefixing an ident multiple times. --- src/modules/m_ident.cpp | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'src/modules/m_ident.cpp') diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp index 81bdf29c5..bc1bad383 100644 --- a/src/modules/m_ident.cpp +++ b/src/modules/m_ident.cpp @@ -24,6 +24,24 @@ #include "inspircd.h" +enum +{ + // Either the ident looup has not started yet or the user is registered. + IDENT_UNKNOWN = 0, + + // Ident lookups are not enabled and a user has been marked as being skipped. + IDENT_SKIPPED, + + // Ident looups are not enabled and a user has been an insecure ident prefix. + IDENT_PREFIXED, + + // An ident lookup was done and an ident was found. + IDENT_FOUND, + + // An ident lookup was done but no ident was found + IDENT_MISSING +}; + /* -------------------------------------------------------------- * Note that this is the third incarnation of m_ident. The first * two attempts were pretty crashy, mainly due to the fact we tried @@ -258,6 +276,7 @@ class ModuleIdent : public Module unsigned int timeout; bool prefixunqueried; SimpleExtItem socket; + LocalIntExt state; static void PrefixIdent(LocalUser* user) { @@ -280,6 +299,7 @@ class ModuleIdent : public Module public: ModuleIdent() : socket("ident_socket", ExtensionItem::EXT_USER, this) + , state("ident_state", ExtensionItem::EXT_USER, this) { } @@ -315,7 +335,10 @@ class ModuleIdent : public Module ConfigTag* tag = user->MyClass->config; if (!tag->getBool("useident", true)) + { + state.set(user, IDENT_SKIPPED); return; + } user->WriteNotice("*** Looking up your ident..."); @@ -340,8 +363,11 @@ class ModuleIdent : public Module IdentRequestSocket* isock = socket.get(user); if (!isock) { - if (prefixunqueried) + if (prefixunqueried && state.get(user) == IDENT_SKIPPED) + { PrefixIdent(user); + state.set(user, IDENT_PREFIXED); + } return MOD_RES_PASSTHRU; } @@ -351,6 +377,7 @@ class ModuleIdent : public Module if (ServerInstance->Time() >= compare) { /* Ident timeout */ + state.set(user, IDENT_MISSING); PrefixIdent(user); user->WriteNotice("*** Ident lookup timed out, using " + user->ident + " instead."); } @@ -363,11 +390,13 @@ class ModuleIdent : public Module /* wooo, got a result (it will be good, or bad) */ else if (isock->result.empty()) { + state.set(user, IDENT_MISSING); PrefixIdent(user); user->WriteNotice("*** Could not find your ident, using " + user->ident + " instead."); } else { + state.set(user, IDENT_FOUND); user->ChangeIdent(isock->result); user->WriteNotice("*** Found your ident, '" + user->ident + "'"); } @@ -379,10 +408,16 @@ class ModuleIdent : public Module ModResult OnSetConnectClass(LocalUser* user, ConnectClass* myclass) CXX11_OVERRIDE { - if (myclass->config->getBool("requireident") && user->ident[0] == '~') + if (myclass->config->getBool("requireident") && state.get(user) != IDENT_FOUND) return MOD_RES_DENY; return MOD_RES_PASSTHRU; } + + void OnUserConnect(LocalUser* user) CXX11_OVERRIDE + { + // Clear this as it is no longer necessary. + state.unset(user); + } }; MODULE_INIT(ModuleIdent) -- cgit v1.3.1-10-gc9f91