diff options
| author | 2022-01-07 17:12:42 +0000 | |
|---|---|---|
| committer | 2022-01-07 17:16:50 +0000 | |
| commit | 52cc8a418307ae7a551d23e6bd2d367b544e7bf9 (patch) | |
| tree | 9fff020964190f33174e78ff6201381be577d0b3 /src/modules/extra | |
| parent | Merge branch 'insp3' into master. (diff) | |
Refactor CoreException and ModuleException.
Diffstat (limited to 'src/modules/extra')
| -rw-r--r-- | src/modules/extra/m_argon2.cpp | 2 | ||||
| -rw-r--r-- | src/modules/extra/m_geo_maxmind.cpp | 2 | ||||
| -rw-r--r-- | src/modules/extra/m_mysql.cpp | 2 | ||||
| -rw-r--r-- | src/modules/extra/m_regex_pcre.cpp | 4 | ||||
| -rw-r--r-- | src/modules/extra/m_regex_posix.cpp | 4 | ||||
| -rw-r--r-- | src/modules/extra/m_regex_re2.cpp | 4 | ||||
| -rw-r--r-- | src/modules/extra/m_ssl_gnutls.cpp | 10 | ||||
| -rw-r--r-- | src/modules/extra/m_ssl_mbedtls.cpp | 15 | ||||
| -rw-r--r-- | src/modules/extra/m_ssl_openssl.cpp | 23 |
9 files changed, 39 insertions, 27 deletions
diff --git a/src/modules/extra/m_argon2.cpp b/src/modules/extra/m_argon2.cpp index 2a5341cd8..80289286e 100644 --- a/src/modules/extra/m_argon2.cpp +++ b/src/modules/extra/m_argon2.cpp @@ -144,7 +144,7 @@ class HashArgon2 final config.version); if (argonResult != ARGON2_OK) - throw ModuleException("Argon2 hashing failed!: " + std::string(argon2_error_message(argonResult))); + throw ModuleException(creator, "Argon2 hashing failed: " + std::string(argon2_error_message(argonResult))); // This isn't the raw version, but we don't have // the facilities to juggle around the extra state required diff --git a/src/modules/extra/m_geo_maxmind.cpp b/src/modules/extra/m_geo_maxmind.cpp index 56ccffef5..bff8c4b78 100644 --- a/src/modules/extra/m_geo_maxmind.cpp +++ b/src/modules/extra/m_geo_maxmind.cpp @@ -173,7 +173,7 @@ class ModuleGeoMaxMind final MMDB_s mmdb; int result = MMDB_open(file.c_str(), MMDB_MODE_MMAP, &mmdb); if (result != MMDB_SUCCESS) - throw ModuleException(InspIRCd::Format("Unable to load the MaxMind database (%s): %s", + throw ModuleException(this, InspIRCd::Format("Unable to load the MaxMind database (%s): %s", file.c_str(), MMDB_strerror(result))); // Swap the new database with the old database. diff --git a/src/modules/extra/m_mysql.cpp b/src/modules/extra/m_mysql.cpp index 05637a6a6..23bbdce3d 100644 --- a/src/modules/extra/m_mysql.cpp +++ b/src/modules/extra/m_mysql.cpp @@ -432,7 +432,7 @@ class SQLConnection final void ModuleSQL::init() { if (mysql_library_init(0, NULL, NULL)) - throw ModuleException("Unable to initialise the MySQL library!"); + throw ModuleException(this, "Unable to initialise the MySQL library!"); Dispatcher = new DispatcherThread(this); Dispatcher->Start(); diff --git a/src/modules/extra/m_regex_pcre.cpp b/src/modules/extra/m_regex_pcre.cpp index 368e3618d..681dd4021 100644 --- a/src/modules/extra/m_regex_pcre.cpp +++ b/src/modules/extra/m_regex_pcre.cpp @@ -43,7 +43,7 @@ class PCREPattern final pcre2_code* regex; public: - PCREPattern(const std::string& pattern, uint8_t options) + PCREPattern(const Module* mod, const std::string& pattern, uint8_t options) : Regex::Pattern(pattern, options) { int flags = 0; @@ -57,7 +57,7 @@ class PCREPattern final { PCRE2_UCHAR errorstr[128]; pcre2_get_error_message(errorcode, errorstr, sizeof errorstr); - throw Regex::Exception(pattern, reinterpret_cast<const char*>(errorstr), erroroffset); + throw Regex::Exception(mod, pattern, reinterpret_cast<const char*>(errorstr), erroroffset); } } diff --git a/src/modules/extra/m_regex_posix.cpp b/src/modules/extra/m_regex_posix.cpp index eaa5b37ee..bbde6ab35 100644 --- a/src/modules/extra/m_regex_posix.cpp +++ b/src/modules/extra/m_regex_posix.cpp @@ -35,7 +35,7 @@ class POSIXPattern final regex_t regex; public: - POSIXPattern(const std::string& pattern, uint8_t options) + POSIXPattern(const Module* mod, const std::string& pattern, uint8_t options) : Regex::Pattern(pattern, options) { int flags = REG_EXTENDED | REG_NOSUB; @@ -54,7 +54,7 @@ class POSIXPattern final regerror(error, ®ex, &errormsg[0], errormsg.size()); regfree(®ex); - throw Regex::Exception(pattern, std::string(&errormsg[0], errormsg.size())); + throw Regex::Exception(mod, pattern, std::string(&errormsg[0], errormsg.size())); } ~POSIXPattern() override diff --git a/src/modules/extra/m_regex_re2.cpp b/src/modules/extra/m_regex_re2.cpp index 78ccccd0a..a9f1843bb 100644 --- a/src/modules/extra/m_regex_re2.cpp +++ b/src/modules/extra/m_regex_re2.cpp @@ -46,12 +46,12 @@ class RE2Pattern final } public: - RE2Pattern(const std::string& pattern, uint8_t options) + RE2Pattern(const Module* mod, const std::string& pattern, uint8_t options) : Regex::Pattern(pattern, options) , regex(pattern, BuildOptions(options)) { if (!regex.ok()) - throw Regex::Exception(pattern, regex.error()); + throw Regex::Exception(mod, pattern, regex.error()); } bool IsMatch(const std::string& text) override diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index d5cd626a0..1db07d94a 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -81,8 +81,10 @@ namespace GnuTLS : public ModuleException { public: - Exception(const std::string& reason) - : ModuleException(reason) { } + Exception(const std::string& msg) + : ModuleException(thismod, msg) + { + } }; void ThrowOnError(int errcode, const char* msg) @@ -1108,7 +1110,7 @@ class ModuleSSLGnuTLS final auto tags = ServerInstance->Config->ConfTags("sslprofile"); if (tags.empty()) - throw ModuleException("You have not specified any <sslprofile> tags that are usable by this module!"); + throw ModuleException(this, "You have not specified any <sslprofile> tags that are usable by this module!"); for (const auto& [_, tag] : tags) { @@ -1133,7 +1135,7 @@ class ModuleSSLGnuTLS final } catch (CoreException& ex) { - throw ModuleException("Error while initializing TLS profile \"" + name + "\" at " + tag->source.str() + " - " + ex.GetReason()); + throw ModuleException(this, "Error while initializing TLS profile \"" + name + "\" at " + tag->source.str() + " - " + ex.GetReason()); } newprofiles.push_back(prov); diff --git a/src/modules/extra/m_ssl_mbedtls.cpp b/src/modules/extra/m_ssl_mbedtls.cpp index 8e1c382a9..f58f519db 100644 --- a/src/modules/extra/m_ssl_mbedtls.cpp +++ b/src/modules/extra/m_ssl_mbedtls.cpp @@ -51,14 +51,18 @@ #include <mbedtls/debug.h> #endif +static Module* thismod; + namespace mbedTLS { class Exception final : public ModuleException { public: - Exception(const std::string& reason) - : ModuleException(reason) { } + Exception(const std::string& msg) + : ModuleException(thismod, msg) + { + } }; std::string ErrorToString(int errcode) @@ -880,7 +884,7 @@ class ModuleSSLmbedTLS final auto tags = ServerInstance->Config->ConfTags("sslprofile"); if (tags.empty()) - throw ModuleException("You have not specified any <sslprofile> tags that are usable by this module!"); + throw ModuleException(this, "You have not specified any <sslprofile> tags that are usable by this module!"); for (const auto& [_, tag] : tags) { @@ -905,7 +909,7 @@ class ModuleSSLmbedTLS final } catch (CoreException& ex) { - throw ModuleException("Error while initializing TLS profile \"" + name + "\" at " + tag->source.str() + " - " + ex.GetReason()); + throw ModuleException(this, "Error while initializing TLS profile \"" + name + "\" at " + tag->source.str() + " - " + ex.GetReason()); } newprofiles.push_back(prov); @@ -923,6 +927,7 @@ class ModuleSSLmbedTLS final ModuleSSLmbedTLS() : Module(VF_VENDOR, "Allows TLS encrypted connections using the mbedTLS library.") { + thismod = this; } void init() override @@ -932,7 +937,7 @@ class ModuleSSLmbedTLS final ServerInstance->Logs.Log(MODNAME, LOG_DEFAULT, "mbedTLS lib version %s module was compiled for " MBEDTLS_VERSION_STRING, verbuf); if (!ctr_drbg.Seed(entropy)) - throw ModuleException("CTR DRBG seed failed"); + throw ModuleException(this, "CTR DRBG seed failed"); } void ReadConfig(ConfigStatus& status) override diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp index 98cb1527f..d4db4d180 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -54,6 +54,7 @@ static bool SelfSigned = false; static int exdataindex; +static Module* thismod; char* get_error() { @@ -69,8 +70,10 @@ namespace OpenSSL : public ModuleException { public: - Exception(const std::string& reason) - : ModuleException(reason) { } + Exception(const std::string& msg) + : ModuleException(thismod, msg) + { + } }; class DHParams final @@ -211,14 +214,14 @@ namespace OpenSSL } else if (!stdalgo::string::equalsci(crlmode, "leaf")) { - throw ModuleException("Unknown mode '" + crlmode + "'; expected either 'chain' (default) or 'leaf'"); + throw ModuleException(thismod, "Unknown mode '" + crlmode + "'; expected either 'chain' (default) or 'leaf'"); } /* Load CRL files */ X509_STORE* store = SSL_CTX_get_cert_store(ctx); if (!store) { - throw ModuleException("Unable to get X509_STORE from TLS context; this should never happen"); + throw ModuleException(thismod, "Unable to get X509_STORE from TLS context; this should never happen"); } ERR_clear_error(); if (!X509_STORE_load_locations(store, @@ -226,13 +229,13 @@ namespace OpenSSL crlpath.empty() ? NULL : crlpath.c_str())) { unsigned long err = ERR_get_error(); - throw ModuleException("Unable to load CRL file '" + crlfile + "' or CRL path '" + crlpath + "': '" + (err ? ERR_error_string(err, NULL) : "unknown") + "'"); + throw ModuleException(thismod, "Unable to load CRL file '" + crlfile + "' or CRL path '" + crlpath + "': '" + (err ? ERR_error_string(err, NULL) : "unknown") + "'"); } /* Set CRL mode */ if (X509_STORE_set_flags(store, crlflags) != 1) { - throw ModuleException("Unable to set X509 CRL flags"); + throw ModuleException(thismod, "Unable to set X509 CRL flags"); } } @@ -930,7 +933,7 @@ class ModuleSSLOpenSSL final ProfileList newprofiles; auto tags = ServerInstance->Config->ConfTags("sslprofile"); if (tags.empty()) - throw ModuleException("You have not specified any <sslprofile> tags that are usable by this module!"); + throw ModuleException(this, "You have not specified any <sslprofile> tags that are usable by this module!"); for (const auto& [_, tag] : tags) { @@ -954,7 +957,7 @@ class ModuleSSLOpenSSL final } catch (CoreException& ex) { - throw ModuleException("Error while initializing TLS profile \"" + name + "\" at " + tag->source.str() + " - " + ex.GetReason()); + throw ModuleException(this, "Error while initializing TLS profile \"" + name + "\" at " + tag->source.str() + " - " + ex.GetReason()); } newprofiles.push_back(prov); @@ -973,6 +976,8 @@ class ModuleSSLOpenSSL final // Initialize OpenSSL OPENSSL_init_ssl(0, NULL); biomethods = OpenSSL::BIOMethod::alloc(); + + thismod = this; } ~ModuleSSLOpenSSL() override @@ -988,7 +993,7 @@ class ModuleSSLOpenSSL final char exdatastr[] = "inspircd"; exdataindex = SSL_get_ex_new_index(0, exdatastr, NULL, NULL, NULL); if (exdataindex < 0) - throw ModuleException("Failed to register application specific data"); + throw ModuleException(this, "Failed to register application specific data"); } void ReadConfig(ConfigStatus& status) override |
