diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-10-27 15:26:20 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-10-27 15:26:20 +0100 |
commit | 3a3ff949670c61a4a8856e1391222e156eb1cd17 (patch) | |
tree | fd8023fefa4829ceea428ec424608ef9aace1d9a | |
parent | cba05046ce20eed4c429093296eb481bf95d7e07 (diff) | |
parent | c99a43968f6a04c7d5d3038b4e39d14c22aa6e89 (diff) |
Merge insp20
-rw-r--r-- | docs/conf/modules.conf.example | 5 | ||||
-rw-r--r-- | include/configreader.h | 5 | ||||
-rwxr-xr-x | make/unit-cc.pl | 16 | ||||
-rw-r--r-- | src/channels.cpp | 8 | ||||
-rw-r--r-- | src/configparser.cpp | 9 | ||||
-rw-r--r-- | src/configreader.cpp | 10 | ||||
-rw-r--r-- | src/coremods/core_info/cmd_motd.cpp | 2 | ||||
-rw-r--r-- | src/coremods/core_whois.cpp | 2 | ||||
-rw-r--r-- | src/listmode.cpp | 5 | ||||
-rw-r--r-- | src/modules/extra/m_sqlite3.cpp | 7 | ||||
-rw-r--r-- | src/modules/extra/m_ssl_gnutls.cpp | 4 | ||||
-rw-r--r-- | src/modules/extra/m_ssl_openssl.cpp | 155 | ||||
-rw-r--r-- | src/modules/m_banredirect.cpp | 11 | ||||
-rw-r--r-- | src/modules/m_delayjoin.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_delaymsg.cpp | 10 | ||||
-rw-r--r-- | src/modules/m_nationalchars.cpp | 31 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treesocket.h | 2 | ||||
-rw-r--r-- | src/modules/m_spanningtree/treesocket2.cpp | 6 | ||||
-rw-r--r-- | src/modules/m_watch.cpp | 3 | ||||
-rw-r--r-- | src/server.cpp | 11 | ||||
-rw-r--r-- | win/inspircd_win32wrapper.cpp | 8 |
21 files changed, 278 insertions, 36 deletions
diff --git a/docs/conf/modules.conf.example b/docs/conf/modules.conf.example index a5e9fde8f..1071f5039 100644 --- a/docs/conf/modules.conf.example +++ b/docs/conf/modules.conf.example @@ -681,6 +681,8 @@ # from talking in the channel unless they've been joined for X seconds. # Settable using /MODE #chan +d 30 #<module name="m_delaymsg.so"> +# Set allownotice to no to disallow NOTICEs too. Defaults to yes. +#<delaymsg allownotice="no"> #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# # Deny channels module: Deny channels from being used by users. @@ -1167,7 +1169,8 @@ # # file - filename of existing file in "locales" directory # casemapping - custom value for 005 numeric (if you want it to be -# different from the filename). +# different from the filename). Set this to the name of +# the locale if you are specifying an absolute path. #<nationalchars file="bynets/russian-w1251-charlink" casemapping="ru_RU.cp1251-charlink"> #-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-# diff --git a/include/configreader.h b/include/configreader.h index 3d9923536..342743991 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -242,6 +242,9 @@ class CoreExport ServerConfig ConfigTagList ConfTags(const std::string& tag); + /** An empty configuration tag. */ + ConfigTag* EmptyTag; + /** Error stream, contains error output from any failed configuration parsing. */ std::stringstream errstr; @@ -467,6 +470,8 @@ class CoreExport ServerConfig */ ServerConfig(); + ~ServerConfig(); + /** Get server ID as string with required leading zeroes */ const std::string& GetSID() const { return sid; } diff --git a/make/unit-cc.pl b/make/unit-cc.pl index 77f97a3f2..66e9b15dc 100755 --- a/make/unit-cc.pl +++ b/make/unit-cc.pl @@ -30,6 +30,22 @@ my $type = shift; my $out = shift; my $verbose = ($type =~ s/-v$//); +## BEGIN HACK: REMOVE IN 2.2! +sub read_config_cache { + my %cfg = (); + open(CACHE, '../.config.cache') or return %cfg; + while (my $line = <CACHE>) { + next if $line =~ /^\s*($|\#)/; + my ($key, $value) = ($line =~ /^(\S+)="(.*)"$/); + $cfg{$key} = $value; + } + close(CACHE); + return %cfg; +} + +our %config = read_config_cache(); +## END HACK + if ($type eq 'gen-ld') { do_static_find(@ARGV); } elsif ($type eq 'static-ld') { diff --git a/src/channels.cpp b/src/channels.cpp index 2ea8688cf..53a48c469 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -136,10 +136,18 @@ void Channel::SetDefaultModes() continue; if (mode->GetNumParams(true)) + { list.GetToken(parameter); + // If the parameter begins with a ':' then it's invalid + if (parameter.c_str()[0] == ':') + continue; + } else parameter.clear(); + if ((mode->GetNumParams(true)) && (parameter.empty())) + continue; + mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true); } } diff --git a/src/configparser.cpp b/src/configparser.cpp index 60770d16d..1c406f218 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -385,8 +385,17 @@ bool ParseStack::ParseFile(const std::string& path, int flags, const std::string bool ConfigTag::readString(const std::string& key, std::string& value, bool allow_lf) { +#ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wunknown-pragmas" +# pragma clang diagnostic ignored "-Wundefined-bool-conversion" +#endif + // TODO: this is undefined behaviour but changing the API is too risky for 2.0. if (!this) return false; +#ifdef __clang__ +# pragma clang diagnostic pop +#endif for(std::vector<KeyVal>::iterator j = items.begin(); j != items.end(); ++j) { if(j->first != key) diff --git a/src/configreader.cpp b/src/configreader.cpp index af8a15f43..54c32d846 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -41,6 +41,14 @@ ServerConfig::ServerConfig() OperMaxChans = 30; c_ipv4_range = 32; c_ipv6_range = 128; + + std::vector<KeyVal>* items; + EmptyTag = ConfigTag::create("empty", "<auto>", 0, items); +} + +ServerConfig::~ServerConfig() +{ + delete EmptyTag; } static void ValidHost(const std::string& p, const std::string& msg) @@ -707,7 +715,7 @@ ConfigTag* ServerConfig::ConfValue(const std::string &tag) { ConfigTagList found = config_data.equal_range(tag); if (found.first == found.second) - return NULL; + return EmptyTag; ConfigTag* rv = found.first->second; found.first++; if (found.first != found.second) diff --git a/src/coremods/core_info/cmd_motd.cpp b/src/coremods/core_info/cmd_motd.cpp index 4481e2d53..2d396858f 100644 --- a/src/coremods/core_info/cmd_motd.cpp +++ b/src/coremods/core_info/cmd_motd.cpp @@ -34,7 +34,7 @@ CmdResult CommandMotd::Handle (const std::vector<std::string>& parameters, User if (parameters.size() > 0 && parameters[0] != ServerInstance->Config->ServerName) return CMD_SUCCESS; - ConfigTag* tag = NULL; + ConfigTag* tag = ServerInstance->Config->EmptyTag; LocalUser* localuser = IS_LOCAL(user); if (localuser) tag = localuser->GetClass()->config; diff --git a/src/coremods/core_whois.cpp b/src/coremods/core_whois.cpp index 8fce7d339..966c4a790 100644 --- a/src/coremods/core_whois.cpp +++ b/src/coremods/core_whois.cpp @@ -224,7 +224,7 @@ CmdResult CommandWhois::HandleLocal(const std::vector<std::string>& parameters, LocalUser* localuser = IS_LOCAL(dest); if (localuser && (ServerInstance->Config->HideWhoisServer.empty() || parameters.size() > 1)) { - idle = abs((long)((localuser->idle_lastmsg)-ServerInstance->Time())); + idle = labs((long)((localuser->idle_lastmsg)-ServerInstance->Time())); signon = dest->signon; } diff --git a/src/listmode.cpp b/src/listmode.cpp index 9b2a0a90f..19f2d6061 100644 --- a/src/listmode.cpp +++ b/src/listmode.cpp @@ -74,8 +74,9 @@ void ListModeBase::DoRehash() chanlimits.push_back(limit); } - if (chanlimits.empty()) - chanlimits.push_back(ListLimit("*", 64)); + // Add the default entry. This is inserted last so if the user specifies a + // wildcard record in the config it will take precedence over this entry. + chanlimits.push_back(ListLimit("*", 64)); // Most of the time our settings are unchanged, so we can avoid iterating the chanlist if (oldlimits == chanlimits) diff --git a/src/modules/extra/m_sqlite3.cpp b/src/modules/extra/m_sqlite3.cpp index f86e08fb3..e5c8f600a 100644 --- a/src/modules/extra/m_sqlite3.cpp +++ b/src/modules/extra/m_sqlite3.cpp @@ -98,8 +98,11 @@ class SQLConn : public SQLProvider ~SQLConn() { - sqlite3_interrupt(conn); - sqlite3_close(conn); + if (conn) + { + sqlite3_interrupt(conn); + sqlite3_close(conn); + } } void Query(SQLQuery* query, const std::string& q) diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index e6efb9771..74b66d2de 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -159,6 +159,10 @@ namespace GnuTLS hash = GNUTLS_DIG_MD5; else if (hashname == "sha1") hash = GNUTLS_DIG_SHA1; +#ifdef INSPIRCD_GNUTLS_ENABLE_SHA256_FINGERPRINT + else if (hashname == "sha256") + hash = GNUTLS_DIG_SHA256; +#endif else throw Exception("Unknown hash type " + hashname); #endif diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp index b09539e50..3dd8a8544 100644 --- a/src/modules/extra/m_ssl_openssl.cpp +++ b/src/modules/extra/m_ssl_openssl.cpp @@ -53,6 +53,7 @@ char* get_error() } static int OnVerify(int preverify_ok, X509_STORE_CTX* ctx); +static void StaticSSLInfoCallback(const SSL* ssl, int where, int rc); namespace OpenSSL { @@ -95,6 +96,7 @@ namespace OpenSSL class Context { SSL_CTX* const ctx; + long ctx_options; public: Context(SSL_CTX* context) @@ -102,12 +104,20 @@ namespace OpenSSL { // Sane default options for OpenSSL see https://www.openssl.org/docs/ssl/SSL_CTX_set_options.html // and when choosing a cipher, use the server's preferences instead of the client preferences. - SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION | SSL_OP_CIPHER_SERVER_PREFERENCE); + long opts = SSL_OP_NO_SSLv2 | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION | SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_SINGLE_DH_USE; + // Only turn options on if they exist +#ifdef SSL_OP_SINGLE_ECDH_USE + opts |= SSL_OP_SINGLE_ECDH_USE; +#endif +#ifdef SSL_OP_NO_TICKET + opts |= SSL_OP_NO_TICKET; +#endif + + ctx_options = SSL_CTX_set_options(ctx, opts); SSL_CTX_set_mode(ctx, SSL_MODE_ENABLE_PARTIAL_WRITE | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE, OnVerify); - - const unsigned char session_id[] = "inspircd"; - SSL_CTX_set_session_id_context(ctx, session_id, sizeof(session_id) - 1); + SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF); + SSL_CTX_set_info_callback(ctx, StaticSSLInfoCallback); } ~Context() @@ -117,29 +127,68 @@ namespace OpenSSL bool SetDH(DHParams& dh) { + ERR_clear_error(); return (SSL_CTX_set_tmp_dh(ctx, dh.get()) >= 0); } +#ifdef INSPIRCD_OPENSSL_ENABLE_ECDH + void SetECDH(const std::string& curvename) + { + int nid = OBJ_sn2nid(curvename.c_str()); + if (nid == 0) + throw Exception("Unknown curve: " + curvename); + + EC_KEY* eckey = EC_KEY_new_by_curve_name(nid); + if (!eckey) + throw Exception("Unable to create EC key object"); + + ERR_clear_error(); + bool ret = (SSL_CTX_set_tmp_ecdh(ctx, eckey) >= 0); + EC_KEY_free(eckey); + if (!ret) + throw Exception("Couldn't set ECDH parameters"); + } +#endif + bool SetCiphers(const std::string& ciphers) { + ERR_clear_error(); return SSL_CTX_set_cipher_list(ctx, ciphers.c_str()); } bool SetCerts(const std::string& filename) { + ERR_clear_error(); return SSL_CTX_use_certificate_chain_file(ctx, filename.c_str()); } bool SetPrivateKey(const std::string& filename) { + ERR_clear_error(); return SSL_CTX_use_PrivateKey_file(ctx, filename.c_str(), SSL_FILETYPE_PEM); } bool SetCA(const std::string& filename) { + ERR_clear_error(); return SSL_CTX_load_verify_locations(ctx, filename.c_str(), 0); } + long GetDefaultContextOptions() const + { + return ctx_options; + } + + long SetRawContextOptions(long setoptions, long clearoptions) + { + // Clear everything + SSL_CTX_clear_options(ctx, SSL_CTX_get_options(ctx)); + + // Set the default options and what is in the conf + SSL_CTX_set_options(ctx, ctx_options | setoptions); + return SSL_CTX_clear_options(ctx, clearoptions); + } + SSL* CreateSession() { return SSL_new(ctx); @@ -169,6 +218,10 @@ namespace OpenSSL */ std::string lasterr; + /** True if renegotiations are allowed, false if not + */ + const bool allowrenego; + static int error_callback(const char* str, size_t len, void* u) { Profile* profile = reinterpret_cast<Profile*>(u); @@ -176,12 +229,39 @@ namespace OpenSSL return 0; } + /** Set raw OpenSSL context (SSL_CTX) options from a config tag + * @param ctxname Name of the context, client or server + * @param tag Config tag defining this profile + * @param context Context object to manipulate + */ + void SetContextOptions(const std::string& ctxname, ConfigTag* tag, Context& context) + { + long setoptions = tag->getInt(ctxname + "setoptions"); + long clearoptions = tag->getInt(ctxname + "clearoptions"); +#ifdef SSL_OP_NO_COMPRESSION + if (!tag->getBool("compression", true)) + setoptions |= SSL_OP_NO_COMPRESSION; +#endif + if (!tag->getBool("sslv3", true)) + setoptions |= SSL_OP_NO_SSLv3; + if (!tag->getBool("tlsv1", true)) + setoptions |= SSL_OP_NO_TLSv1; + + if (!setoptions && !clearoptions) + return; // Nothing to do + + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Setting %s %s context options, default: %ld set: %ld clear: %ld", name.c_str(), ctxname.c_str(), ctx.GetDefaultContextOptions(), setoptions, clearoptions); + long final = context.SetRawContextOptions(setoptions, clearoptions); + ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "%s %s context options: %ld", name.c_str(), ctxname.c_str(), final); + } + public: Profile(const std::string& profilename, ConfigTag* tag) : name(profilename) , dh(ServerInstance->Config->Paths.PrependConfig(tag->getString("dhfile", "dh.pem"))) , ctx(SSL_CTX_new(SSLv23_server_method())) , clictx(SSL_CTX_new(SSLv23_client_method())) + , allowrenego(tag->getBool("renegotiation", true)) { if ((!ctx.SetDH(dh)) || (!clictx.SetDH(dh))) throw Exception("Couldn't set DH parameters"); @@ -201,6 +281,15 @@ namespace OpenSSL } } +#ifdef INSPIRCD_OPENSSL_ENABLE_ECDH + std::string curvename = tag->getString("ecdhcurve", "prime256v1"); + if (!curvename.empty()) + ctx.SetECDH(curvename); +#endif + + SetContextOptions("server", tag, ctx); + SetContextOptions("client", tag, clictx); + /* Load our keys and certificates * NOTE: OpenSSL's error logging API sucks, don't blame us for this clusterfuck. */ @@ -231,6 +320,7 @@ namespace OpenSSL SSL* CreateServerSession() { return ctx.CreateSession(); } SSL* CreateClientSession() { return clictx.CreateSession(); } const EVP_MD* GetDigest() { return digest; } + bool AllowRenegotiation() const { return allowrenego; } }; } @@ -261,6 +351,7 @@ class OpenSSLIOHook : public SSLIOHook { int ret; + ERR_clear_error(); if (outbound) ret = SSL_connect(sess); else @@ -303,10 +394,8 @@ class OpenSSLIOHook : public SSLIOHook else if (ret == 0) { CloseSession(); - return true; } - - return true; + return false; } void CloseSession() @@ -319,7 +408,6 @@ class OpenSSLIOHook : public SSLIOHook sess = NULL; certificate = NULL; status = ISSL_NONE; - errno = EIO; } void VerifyCertificate() @@ -380,6 +468,36 @@ class OpenSSLIOHook : public SSLIOHook X509_free(cert); } +#ifdef INSPIRCD_OPENSSL_ENABLE_RENEGO_DETECTION + void SSLInfoCallback(int where, int rc) + { + if ((where & SSL_CB_HANDSHAKE_START) && (status == ISSL_OPEN)) + { + if (profile->AllowRenegotiation()) + return; + + // The other side is trying to renegotiate, kill the connection and change status + // to ISSL_NONE so CheckRenego() closes the session + status = ISSL_NONE; + SocketEngine::Shutdown(SSL_get_fd(sess), 2); + } + } + + bool CheckRenego(StreamSocket* sock) + { + if (status != ISSL_NONE) + return true; + + ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Session %p killed, attempted to renegotiate", (void*)sess); + CloseSession(); + sock->SetError("Renegotiation is not allowed"); + return false; + } +#endif + + // Calls our private SSLInfoCallback() + friend void StaticSSLInfoCallback(const SSL* ssl, int where, int rc); + public: OpenSSLIOHook(IOHookProvider* hookprov, StreamSocket* sock, bool is_outbound, SSL* session, const reference<OpenSSL::Profile>& sslprofile) : SSLIOHook(hookprov) @@ -428,10 +546,16 @@ class OpenSSLIOHook : public SSLIOHook if (status == ISSL_OPEN) { + ERR_clear_error(); char* buffer = ServerInstance->GetReadBuffer(); size_t bufsiz = ServerInstance->Config->NetBufferSize; int ret = SSL_read(sess, buffer, bufsiz); +#ifdef INSPIRCD_OPENSSL_ENABLE_RENEGO_DETECTION + if (!CheckRenego(user)) + return -1; +#endif + if (ret > 0) { recvq.append(buffer, ret); @@ -494,7 +618,14 @@ class OpenSSLIOHook : public SSLIOHook if (status == ISSL_OPEN) { + ERR_clear_error(); int ret = SSL_write(sess, buffer.data(), buffer.size()); + +#ifdef INSPIRCD_OPENSSL_ENABLE_RENEGO_DETECTION + if (!CheckRenego(user)) + return -1; +#endif + if (ret == (int)buffer.length()) { data_to_write = false; @@ -550,6 +681,14 @@ class OpenSSLIOHook : public SSLIOHook } }; +static void StaticSSLInfoCallback(const SSL* ssl, int where, int rc) +{ +#ifdef INSPIRCD_OPENSSL_ENABLE_RENEGO_DETECTION + OpenSSLIOHook* hook = static_cast<OpenSSLIOHook*>(SSL_get_ex_data(ssl, exdataindex)); + hook->SSLInfoCallback(where, rc); +#endif +} + class OpenSSLIOHookProvider : public refcountbase, public IOHookProvider { reference<OpenSSL::Profile> profile; diff --git a/src/modules/m_banredirect.cpp b/src/modules/m_banredirect.cpp index d82b8473c..9833c720d 100644 --- a/src/modules/m_banredirect.cpp +++ b/src/modules/m_banredirect.cpp @@ -74,6 +74,9 @@ class BanRedirect : public ModeWatcher if (param.length() >= 2 && param[1] == ':') return true; + if (param.find('#') == std::string::npos) + return true; + ListModeBase* banlm = static_cast<ListModeBase*>(*ban); unsigned int maxbans = banlm->GetLimit(channel); ListModeBase::ModeList* list = banlm->GetList(channel); @@ -123,6 +126,14 @@ class BanRedirect : public ModeWatcher mask[NICK].swap(mask[IDENT]); } + if (!mask[NICK].empty() && mask[IDENT].empty() && mask[HOST].empty()) + { + if (mask[NICK].find('.') != std::string::npos || mask[NICK].find(':') != std::string::npos) + { + mask[NICK].swap(mask[HOST]); + } + } + for(int i = 0; i < 3; i++) { if(mask[i].empty()) diff --git a/src/modules/m_delayjoin.cpp b/src/modules/m_delayjoin.cpp index 55ffd08d7..2474cd6ad 100644 --- a/src/modules/m_delayjoin.cpp +++ b/src/modules/m_delayjoin.cpp @@ -168,6 +168,10 @@ ModResult ModuleDelayJoin::OnRawMode(User* user, Channel* channel, ModeHandler* if (!user || !channel || param.empty()) return MOD_RES_PASSTHRU; + // If not a prefix mode then we got nothing to do here + if (!mh->IsPrefixMode()) + return MOD_RES_PASSTHRU; + User* dest; if (IS_LOCAL(user)) dest = ServerInstance->FindNickOnly(param); diff --git a/src/modules/m_delaymsg.cpp b/src/modules/m_delaymsg.cpp index 06a05db02..c906e2c30 100644 --- a/src/modules/m_delaymsg.cpp +++ b/src/modules/m_delaymsg.cpp @@ -47,6 +47,7 @@ class DelayMsgMode : public ParamMode<DelayMsgMode, LocalIntExt> class ModuleDelayMsg : public Module { DelayMsgMode djm; + bool allownotice; public: ModuleDelayMsg() : djm(this) { @@ -55,6 +56,7 @@ class ModuleDelayMsg : public Module Version GetVersion() CXX11_OVERRIDE; void OnUserJoin(Membership* memb, bool sync, bool created, CUList&) CXX11_OVERRIDE; ModResult OnUserPreMessage(User* user, void* dest, int target_type, std::string& text, char status, CUList& exempt_list, MessageType msgtype) CXX11_OVERRIDE; + void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE; }; ModeAction DelayMsgMode::OnSet(User* source, Channel* chan, std::string& parameter) @@ -97,7 +99,7 @@ ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_ty if ((!user) || (!IS_LOCAL(user))) return MOD_RES_PASSTHRU; - if ((target_type != TYPE_CHANNEL) || (msgtype != MSG_PRIVMSG)) + if ((target_type != TYPE_CHANNEL) || ((!allownotice) && (msgtype == MSG_NOTICE))) return MOD_RES_PASSTHRU; Channel* channel = (Channel*) dest; @@ -130,4 +132,10 @@ ModResult ModuleDelayMsg::OnUserPreMessage(User* user, void* dest, int target_ty return MOD_RES_PASSTHRU; } +void ModuleDelayMsg::ReadConfig(ConfigStatus& status) +{ + ConfigTag* tag = ServerInstance->Config->ConfValue("delaymsg"); + allownotice = tag->getBool("allownotice", true); +} + MODULE_INIT(ModuleDelayMsg) diff --git a/src/modules/m_nationalchars.cpp b/src/modules/m_nationalchars.cpp index 0650cb3d0..f77899ad4 100644 --- a/src/modules/m_nationalchars.cpp +++ b/src/modules/m_nationalchars.cpp @@ -223,11 +223,40 @@ class ModuleNationalChars : public Module caller1<bool, const std::string&> rememberer; bool forcequit; const unsigned char * lowermap_rememberer; + unsigned char prev_map[256]; + + template <typename T> + void RehashHashmap(T& hashmap) + { + T newhash(hashmap.bucket_count()); + for (typename T::const_iterator i = hashmap.begin(); i != hashmap.end(); ++i) + newhash.insert(std::make_pair(i->first, i->second)); + hashmap.swap(newhash); + } + + void CheckRehash() + { + // See if anything changed + if (!memcmp(prev_map, national_case_insensitive_map, sizeof(prev_map))) + return; + + memcpy(prev_map, national_case_insensitive_map, sizeof(prev_map)); + + RehashHashmap(ServerInstance->Users.clientlist); + RehashHashmap(ServerInstance->Users.uuidlist); + RehashHashmap(ServerInstance->chanlist); + + // The OnGarbageCollect() method in m_watch rebuilds the hashmap used by it + Module* mod = ServerInstance->Modules->Find("m_watch.so"); + if (mod) + mod->OnGarbageCollect(); + } public: ModuleNationalChars() : rememberer(ServerInstance->IsNick), lowermap_rememberer(national_case_insensitive_map) { + memcpy(prev_map, national_case_insensitive_map, sizeof(prev_map)); } void init() CXX11_OVERRIDE @@ -254,6 +283,7 @@ class ModuleNationalChars : public Module loadtables(charset, tables, 8, 5); forcequit = tag->getBool("forcequit"); CheckForceQuit("National character set changed"); + CheckRehash(); } void CheckForceQuit(const char * message) @@ -276,6 +306,7 @@ class ModuleNationalChars : public Module ServerInstance->IsNick = rememberer; national_case_insensitive_map = lowermap_rememberer; CheckForceQuit("National characters module unloaded"); + CheckRehash(); } Version GetVersion() CXX11_OVERRIDE diff --git a/src/modules/m_spanningtree/treesocket.h b/src/modules/m_spanningtree/treesocket.h index a775d7c24..6dc584537 100644 --- a/src/modules/m_spanningtree/treesocket.h +++ b/src/modules/m_spanningtree/treesocket.h @@ -95,8 +95,6 @@ class TreeSocket : public BufferedSocket ServerState LinkState; /* Link state */ CapabData* capab; /* Link setup data (held until burst is sent) */ TreeServer* MyRoot; /* The server we are talking to */ - time_t NextPing; /* Time when we are due to ping this server */ - bool LastPingWasGood; /* Responded to last ping we sent? */ int proto_version; /* Remote protocol version */ /** True if we've sent our burst. diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 7574be90a..25b8e3b71 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -152,13 +152,13 @@ void TreeSocket::ProcessLine(std::string &line) time_t delta = them - ServerInstance->Time(); if ((delta < -600) || (delta > 600)) { - ServerInstance->SNO->WriteGlobalSno('l',"\2ERROR\2: Your clocks are out by %d seconds (this is more than five minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",abs((long)delta)); - SendError("Your clocks are out by "+ConvToStr(abs((long)delta))+" seconds (this is more than five minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!"); + ServerInstance->SNO->WriteGlobalSno('l',"\2ERROR\2: Your clocks are out by %ld seconds (this is more than five minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",labs((long)delta)); + SendError("Your clocks are out by "+ConvToStr(labs((long)delta))+" seconds (this is more than five minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!"); return; } else if ((delta < -30) || (delta > 30)) { - ServerInstance->SNO->WriteGlobalSno('l',"\2WARNING\2: Your clocks are out by %d seconds. Please consider synching your clocks.", abs((long)delta)); + ServerInstance->SNO->WriteGlobalSno('l',"\2WARNING\2: Your clocks are out by %ld seconds. Please consider synching your clocks.", labs((long)delta)); } } diff --git a/src/modules/m_watch.cpp b/src/modules/m_watch.cpp index 68fe09d64..9cb31a6d8 100644 --- a/src/modules/m_watch.cpp +++ b/src/modules/m_watch.cpp @@ -156,9 +156,6 @@ class CommandWatch : public Command /* Yup, is on my list */ watchlist::iterator n = wl->find(nick); - if (!wl) - return CMD_FAILURE; - if (n != wl->end()) { if (!n->second.empty()) diff --git a/src/server.cpp b/src/server.cpp index 256ccfc4c..42dce1372 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -46,13 +46,10 @@ void InspIRCd::Exit(int status) #ifdef _WIN32 SetServiceStopped(status); #endif - if (this) - { - this->SendError("Exiting with status " + ConvToStr(status) + " (" + std::string(ExitCodes[status]) + ")"); - this->Cleanup(); - ServerInstance = NULL; - delete this; - } + this->SendError("Exiting with status " + ConvToStr(status) + " (" + std::string(ExitCodes[status]) + ")"); + this->Cleanup(); + ServerInstance = NULL; + delete this; exit (status); } diff --git a/win/inspircd_win32wrapper.cpp b/win/inspircd_win32wrapper.cpp index 3a3b5917a..3e0a264a5 100644 --- a/win/inspircd_win32wrapper.cpp +++ b/win/inspircd_win32wrapper.cpp @@ -39,8 +39,8 @@ CoreExport const char *insp_inet_ntop(int af, const void *src, char *dst, sockle memset(&in, 0, sizeof(in)); in.sin_family = AF_INET; memcpy(&in.sin_addr, src, sizeof(struct in_addr)); - getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST); - return dst; + if (getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST) == 0) + return dst; } else if (af == AF_INET6) { @@ -48,8 +48,8 @@ CoreExport const char *insp_inet_ntop(int af, const void *src, char *dst, sockle memset(&in, 0, sizeof(in)); in.sin6_family = AF_INET6; memcpy(&in.sin6_addr, src, sizeof(struct in_addr6)); - getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST); - return dst; + if (getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST) == 0) + return dst; } return NULL; } |