aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorGravatar Sadie Powell2023-01-08 16:12:43 +0000
committerGravatar Sadie Powell2023-01-08 16:28:40 +0000
commit8831595e1a5306f4204fedc6ecbc4a3c9299fb35 (patch)
treef9f27322d35d199240dfeca82415ec94724f2ff9 /src/modules
parentSwitch sqloper to use a local user lookup instead of IS_LOCAL. (diff)
Rework how users are assigned to connect classes.
- Move core connect class checks and <performance:clonesonconnect> to the core_user module. - Add pre-change and post-change events for when a connect class changes. - Split explicit class changing out into its own method. - Remove the need to almost always call CheckClass after SetClass. - Add use counting to the connect class instead of relying on the shared_ptr use count.
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/m_account.cpp10
-rw-r--r--src/modules/m_dnsbl.cpp14
-rw-r--r--src/modules/m_gateway.cpp12
-rw-r--r--src/modules/m_geoclass.cpp8
-rw-r--r--src/modules/m_ident.cpp8
-rw-r--r--src/modules/m_sslinfo.cpp10
6 files changed, 31 insertions, 31 deletions
diff --git a/src/modules/m_account.cpp b/src/modules/m_account.cpp
index 3e1795ed5..369ca9efb 100644
--- a/src/modules/m_account.cpp
+++ b/src/modules/m_account.cpp
@@ -324,15 +324,15 @@ public:
return MOD_RES_DENY; // Account required but it does not match.
}
- ModResult OnSetConnectClass(LocalUser* user, const ConnectClass::Ptr& myclass) override
+ ModResult OnPreChangeConnectClass(LocalUser* user, const std::shared_ptr<ConnectClass>& klass) override
{
const char* error = nullptr;
- if (stdalgo::string::equalsci(myclass->config->getString("requireaccount"), "nick"))
+ if (stdalgo::string::equalsci(klass->config->getString("requireaccount"), "nick"))
{
if (!accountapi.GetAccountName(user) && !accountapi.IsIdentifiedToNick(user))
error = "an account matching their current nickname";
}
- else if (myclass->config->getBool("requireaccount"))
+ else if (klass->config->getBool("requireaccount"))
{
if (!accountapi.GetAccountName(user))
error = "an account";
@@ -340,8 +340,8 @@ public:
if (error)
{
- ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as it requires the user to be logged into %s",
- myclass->GetName().c_str(), error);
+ ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as it requires the user to be logged into %s.",
+ klass->GetName().c_str(), error);
return MOD_RES_DENY;
}
return MOD_RES_PASSTHRU;
diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp
index 25154d5a2..e0d2d276d 100644
--- a/src/modules/m_dnsbl.cpp
+++ b/src/modules/m_dnsbl.cpp
@@ -504,17 +504,17 @@ public:
}
}
- ModResult OnSetConnectClass(LocalUser* user, const ConnectClass::Ptr& myclass) override
+ ModResult OnPreChangeConnectClass(LocalUser* user, const std::shared_ptr<ConnectClass>& klass) override
{
- std::string dnsbl;
- if (!myclass->config->readString("dnsbl", dnsbl))
+ const std::string dnsbl = klass->config->getString("dnsbl");
+ if (!dnsbl.empty())
return MOD_RES_PASSTHRU;
MarkExtItem::List* match = data.markext.Get(user);
if (!match)
{
- ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as it requires a DNSBL mark",
- myclass->GetName().c_str());
+ ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as it requires a DNSBL mark.",
+ klass->GetName().c_str());
return MOD_RES_DENY;
}
@@ -525,8 +525,8 @@ public:
}
const std::string marks = stdalgo::string::join(dnsbl);
- ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as the DNSBL marks (%s) do not match %s",
- myclass->GetName().c_str(), marks.c_str(), dnsbl.c_str());
+ ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as the DNSBL marks (%s) do not match %s.",
+ klass->GetName().c_str(), marks.c_str(), dnsbl.c_str());
return MOD_RES_DENY;
}
diff --git a/src/modules/m_gateway.cpp b/src/modules/m_gateway.cpp
index 138894afd..c73c74924 100644
--- a/src/modules/m_gateway.cpp
+++ b/src/modules/m_gateway.cpp
@@ -408,10 +408,10 @@ public:
cmdwebirc.hosts.swap(webirchosts);
}
- ModResult OnSetConnectClass(LocalUser* user, const ConnectClass::Ptr& myclass) override
+ ModResult OnPreChangeConnectClass(LocalUser* user, const std::shared_ptr<ConnectClass>& klass) override
{
// If <connect:webirc> is not set then we have nothing to do.
- const std::string webirc = myclass->config->getString("webirc");
+ const std::string webirc = klass->config->getString("webirc");
if (webirc.empty())
return MOD_RES_PASSTHRU;
@@ -420,8 +420,8 @@ public:
const std::string* gateway = cmdwebirc.extban.gateway.Get(user);
if (!gateway)
{
- ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as it requires a connection via a WebIRC gateway",
- myclass->GetName().c_str());
+ ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as it requires a connection via a WebIRC gateway.",
+ klass->GetName().c_str());
return MOD_RES_DENY;
}
@@ -429,8 +429,8 @@ public:
// allow the check to continue. Otherwise, reject it.
if (!InspIRCd::Match(*gateway, webirc))
{
- ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as the WebIRC gateway name (%s) does not match %s",
- myclass->GetName().c_str(), gateway->c_str(), webirc.c_str());
+ ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as the WebIRC gateway name (%s) does not match %s.",
+ klass->GetName().c_str(), gateway->c_str(), webirc.c_str());
return MOD_RES_DENY;
}
diff --git a/src/modules/m_geoclass.cpp b/src/modules/m_geoclass.cpp
index 9f190b1c9..c57073cc5 100644
--- a/src/modules/m_geoclass.cpp
+++ b/src/modules/m_geoclass.cpp
@@ -36,9 +36,9 @@ public:
{
}
- ModResult OnSetConnectClass(LocalUser* user, const ConnectClass::Ptr& myclass) override
+ ModResult OnPreChangeConnectClass(LocalUser* user, const std::shared_ptr<ConnectClass>& klass) override
{
- const std::string country = myclass->config->getString("country");
+ const std::string country = klass->config->getString("country");
if (country.empty())
return MOD_RES_PASSTHRU;
@@ -58,8 +58,8 @@ public:
// A list of country codes were specified but the user didn't match
// any of them.
- ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as the origin country (%s) is not any of %s",
- myclass->GetName().c_str(), code.c_str(), country.c_str());
+ ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as the origin country (%s) is not any of %s.",
+ klass->GetName().c_str(), code.c_str(), country.c_str());
return MOD_RES_DENY;
}
diff --git a/src/modules/m_ident.cpp b/src/modules/m_ident.cpp
index 72db6d399..d6c96e3e6 100644
--- a/src/modules/m_ident.cpp
+++ b/src/modules/m_ident.cpp
@@ -404,12 +404,12 @@ public:
return MOD_RES_PASSTHRU;
}
- ModResult OnSetConnectClass(LocalUser* user, const ConnectClass::Ptr& myclass) override
+ ModResult OnPreChangeConnectClass(LocalUser* user, const std::shared_ptr<ConnectClass>& klass) override
{
- if (myclass->config->getBool("requireident") && state.Get(user) != IDENT_FOUND)
+ if (klass->config->getBool("requireident") && state.Get(user) != IDENT_FOUND)
{
- ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as it requires an identd response",
- myclass->GetName().c_str());
+ ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as it requires an identd response.",
+ klass->GetName().c_str());
return MOD_RES_DENY;
}
return MOD_RES_PASSTHRU;
diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp
index 2d2db02f6..812962e83 100644
--- a/src/modules/m_sslinfo.cpp
+++ b/src/modules/m_sslinfo.cpp
@@ -384,17 +384,17 @@ public:
user->WriteNotice(text);
}
- ModResult OnSetConnectClass(LocalUser* user, const ConnectClass::Ptr& myclass) override
+ ModResult OnPreChangeConnectClass(LocalUser* user, const std::shared_ptr<ConnectClass>& klass) override
{
ssl_cert* cert = cmd.sslapi.GetCertificate(user);
const char* error = nullptr;
- const std::string requiressl = myclass->config->getString("requiressl");
+ const std::string requiressl = klass->config->getString("requiressl");
if (stdalgo::string::equalsci(requiressl, "trusted"))
{
if (!cert || !cert->IsCAVerified())
error = "a trusted TLS client certificate";
}
- else if (myclass->config->getBool("requiressl"))
+ else if (klass->config->getBool("requiressl"))
{
if (!cert)
error = "a TLS connection";
@@ -402,8 +402,8 @@ public:
if (error)
{
- ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as it requires %s",
- myclass->GetName().c_str(), error);
+ ServerInstance->Logs.Debug("CONNECTCLASS", "The %s connect class is not suitable as it requires %s.",
+ klass->GetName().c_str(), error);
return MOD_RES_DENY;
}