From c4e9c0bf8548da1bf4fe2cfe5e7f5ab101b35e52 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 22 Feb 2024 15:58:23 +0000 Subject: If the IRCd sends a field limit then use it over that of the config. --- src/config.cpp | 8 ++++---- src/protocol.cpp | 34 +++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/config.cpp b/src/config.cpp index c3e27d469..bcba9de38 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -178,10 +178,10 @@ Conf::Conf() : Block("") ValidateNotZero("options", "readtimeout", options->Get("readtimeout")); ValidateNotZero("options", "warningtimeout", options->Get("warningtimeout")); - ValidateNotZero("networkinfo", "nicklen", networkinfo->Get("nicklen")); - ValidateNotZero("networkinfo", "userlen", networkinfo->Get("userlen")); - ValidateNotZero("networkinfo", "hostlen", networkinfo->Get("hostlen")); - ValidateNotZero("networkinfo", "chanlen", networkinfo->Get("chanlen")); + ValidateNotZero("networkinfo", "nicklen", networkinfo->Get("nicklen", "1")); + ValidateNotZero("networkinfo", "userlen", networkinfo->Get("userlen", "1")); + ValidateNotZero("networkinfo", "hostlen", networkinfo->Get("hostlen", "1")); + ValidateNotZero("networkinfo", "chanlen", networkinfo->Get("chanlen", "1")); spacesepstream(options->Get("ulineservers")).GetTokens(this->Ulines); diff --git a/src/protocol.cpp b/src/protocol.cpp index bf7d1bc28..06b654123 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -343,7 +343,7 @@ bool IRCDProto::IsNickValid(const Anope::string &nick) bool IRCDProto::IsChannelValid(const Anope::string &chan) { - if (chan.empty() || chan[0] != '#' || chan.length() > Config->GetBlock("networkinfo")->Get("chanlen")) + if (chan.empty() || chan[0] != '#' || chan.length() > IRCD->GetMaxChannel()) return false; if (chan.find_first_of(" ,") != Anope::string::npos) @@ -354,7 +354,7 @@ bool IRCDProto::IsChannelValid(const Anope::string &chan) bool IRCDProto::IsIdentValid(const Anope::string &ident) { - if (ident.empty() || ident.length() > Config->GetBlock("networkinfo")->Get("userlen")) + if (ident.empty() || ident.length() > IRCD->GetMaxUser()) return false; for (auto c : ident) @@ -370,7 +370,7 @@ bool IRCDProto::IsIdentValid(const Anope::string &ident) bool IRCDProto::IsHostValid(const Anope::string &host) { - if (host.empty() || host.length() > Config->GetBlock("networkinfo")->Get("hostlen")) + if (host.empty() || host.length() > IRCD->GetMaxHost()) return false; const Anope::string &vhostdisablebe = Config->GetBlock("networkinfo")->Get("disallow_start_or_end"), @@ -416,6 +416,34 @@ Anope::string IRCDProto::NormalizeMask(const Anope::string &mask) return Entry("", mask).GetNUHMask(); } +size_t IRCDProto::GetMaxChannel() +{ + // We can cache this as its not allowed to change on rehash. + static size_t chanlen = Config->GetBlock("networkinfo")->Get("chanlen", "32"); + return chanlen; +} + +size_t IRCDProto::GetMaxHost() +{ + // We can cache this as its not allowed to change on rehash. + static size_t hostlen = Config->GetBlock("networkinfo")->Get("hostlen", "64"); + return hostlen; +} + +size_t IRCDProto::GetMaxNick() +{ + // We can cache this as its not allowed to change on rehash. + static size_t nicklen = Config->GetBlock("networkinfo")->Get("nicklen", "31"); + return nicklen; +} + +size_t IRCDProto::GetMaxUser() +{ + // We can cache this as its not allowed to change on rehash. + static size_t userlen = Config->GetBlock("networkinfo")->Get("userlen", "10"); + return userlen; +} + MessageSource::MessageSource(const Anope::string &src) : source(src) { /* no source for incoming message is our uplink */ -- cgit