diff --git a/include/configreader.h b/include/configreader.h index c395e9886..d04aeea4d 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -193,7 +193,7 @@ struct CommandLineConf char** argv; }; -class CoreExport OperInfo : public refcountbase +class CoreExport OperInfo { public: TokenList AllowedOperCommands; @@ -281,7 +281,7 @@ class CoreExport ServerConfig /** Index of valid oper blocks and types */ - typedef insp::flat_map > OperIndex; + typedef insp::flat_map> OperIndex; /** Get a configuration tag by name. If one or more tags are present then the first is returned. * @param tag The name of the tag to get. diff --git a/include/inspircd.h b/include/inspircd.h index 7ee938c71..0fc86fa6e 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -167,7 +168,7 @@ class serverstats /** Cpu usage at last sample */ timeval LastCPU; - + /** Time last sample was read */ timespec LastSampled; diff --git a/include/users.h b/include/users.h index d336478fc..31ad66f1a 100644 --- a/include/users.h +++ b/include/users.h @@ -351,7 +351,7 @@ class CoreExport User : public Extensible /** The oper type they logged in as, if they are an oper. */ - reference oper; + std::shared_ptr oper; /** Used by User to indicate the registration status of the connection * It is a bitfield of the REG_NICK, REG_USER and REG_ALL bits to indicate @@ -434,7 +434,7 @@ class CoreExport User : public Extensible * oper information can be obtained from User::oper * @return True if the user is an oper, false otherwise */ - bool IsOper() const { return oper; } + bool IsOper() const { return !!oper; } /** Returns true if a notice mask is set * @param sm A notice mask character to check @@ -511,7 +511,7 @@ class CoreExport User : public Extensible /** Oper up the user using the given opertype. * This will also give the +o usermode. */ - void Oper(OperInfo* info); + void Oper(std::shared_ptr info); /** Oper down. * This will clear the +o usermode and unset the user's oper type diff --git a/src/configreader.cpp b/src/configreader.cpp index cbc5f21c7..f7704e665 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -131,7 +131,7 @@ void ServerConfig::CrossCheckOperClassType() if (OperTypes.find(name) != OperTypes.end()) throw CoreException("Duplicate type block with name " + name + " at " + tag->getTagLocation()); - OperInfo* ifo = new OperInfo(name); + auto ifo = std::make_shared(name); OperTypes[name] = ifo; ifo->type_block = tag; @@ -162,7 +162,7 @@ void ServerConfig::CrossCheckOperClassType() if (oper_blocks.find(name) != oper_blocks.end()) throw CoreException("Duplicate oper block with name " + name + " at " + tag->getTagLocation()); - OperInfo* ifo = new OperInfo(type); + auto ifo = std::make_shared(type); ifo->oper_block = tag; ifo->type_block = tblk->second->type_block; ifo->class_blocks.assign(tblk->second->class_blocks.begin(), tblk->second->class_blocks.end()); diff --git a/src/coremods/core_oper/cmd_oper.cpp b/src/coremods/core_oper/cmd_oper.cpp index ff0bd89a9..dc88d094b 100644 --- a/src/coremods/core_oper/cmd_oper.cpp +++ b/src/coremods/core_oper/cmd_oper.cpp @@ -46,7 +46,7 @@ CmdResult CommandOper::HandleLocal(LocalUser* user, const Params& parameters) ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]); if (i != ServerInstance->Config->oper_blocks.end()) { - OperInfo* ifo = i->second; + std::shared_ptr ifo = i->second; ConfigTag* tag = ifo->oper_block; match_login = true; match_pass = ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash")); diff --git a/src/coremods/core_stats.cpp b/src/coremods/core_stats.cpp index 4807132fd..0b25bf78a 100644 --- a/src/coremods/core_stats.cpp +++ b/src/coremods/core_stats.cpp @@ -327,9 +327,8 @@ void CommandStats::DoStats(Stats::Context& stats) /* stats o */ case 'o': { - for (ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->oper_blocks.begin(); i != ServerInstance->Config->oper_blocks.end(); ++i) + for (auto& [_, ifo] : ServerInstance->Config->oper_blocks) { - OperInfo* ifo = i->second; ConfigTag* tag = ifo->oper_block; stats.AddRow(243, 'O', tag->getString("host"), '*', tag->getString("name"), tag->getString("type"), '0'); } @@ -337,9 +336,8 @@ void CommandStats::DoStats(Stats::Context& stats) break; case 'O': { - for (ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->OperTypes.begin(); i != ServerInstance->Config->OperTypes.end(); ++i) + for (auto& [_, tag] : ServerInstance->Config->OperTypes) { - OperInfo* tag = i->second; tag->init(); std::string umodes; std::string cmodes; diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp index e5e43f8b5..3b273c671 100644 --- a/src/modules/extra/m_ssl_gnutls.cpp +++ b/src/modules/extra/m_ssl_gnutls.cpp @@ -41,7 +41,6 @@ #include "inspircd.h" #include "modules/ssl.h" -#include #include #include diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index 459bbfecf..28cbc3d3b 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -201,15 +201,14 @@ class CommandCheck : public Command if (targuser->IsOper()) { - OperInfo* oper = targuser->oper; /* user is an oper of type ____ */ - context.Write("opertype", oper->name); + context.Write("opertype", targuser->oper->name); if (loctarg) { context.Write("chanmodeperms", GetAllowedOperOnlyModes(loctarg, MODETYPE_CHANNEL)); context.Write("usermodeperms", GetAllowedOperOnlyModes(loctarg, MODETYPE_USER)); - context.Write("commandperms", oper->AllowedOperCommands.ToString()); - context.Write("permissions", oper->AllowedPrivs.ToString()); + context.Write("commandperms", targuser->oper->AllowedOperCommands.ToString()); + context.Write("permissions", targuser->oper->AllowedPrivs.ToString()); } } diff --git a/src/modules/m_ldapoper.cpp b/src/modules/m_ldapoper.cpp index 1a6a70528..3e3195d8e 100644 --- a/src/modules/m_ldapoper.cpp +++ b/src/modules/m_ldapoper.cpp @@ -91,8 +91,7 @@ class BindInterface : public LDAPOperBase return; } - OperInfo* ifo = iter->second; - user->Oper(ifo); + user->Oper(iter->second); delete this; } }; diff --git a/src/modules/m_spanningtree/opertype.cpp b/src/modules/m_spanningtree/opertype.cpp index b00829e99..986d35dc7 100644 --- a/src/modules/m_spanningtree/opertype.cpp +++ b/src/modules/m_spanningtree/opertype.cpp @@ -44,7 +44,7 @@ CmdResult CommandOpertype::HandleRemote(RemoteUser* u, CommandBase::Params& para if (iter != ServerInstance->Config->OperTypes.end()) u->oper = iter->second; else - u->oper = new OperInfo(opertype); + u->oper = std::make_shared(opertype); if (Utils->quiet_bursts) { diff --git a/src/modules/m_sqloper.cpp b/src/modules/m_sqloper.cpp index d33227b22..fe37f1fb2 100644 --- a/src/modules/m_sqloper.cpp +++ b/src/modules/m_sqloper.cpp @@ -96,7 +96,7 @@ class OperQuery : public SQL::Query continue; } - OperInfo* ifo = new OperInfo(type); + auto ifo = std::make_shared(type); ifo->type_block = tblk->second->type_block; ifo->oper_block = tag; diff --git a/src/modules/m_sslinfo.cpp b/src/modules/m_sslinfo.cpp index ff06347ce..5d3d04a24 100644 --- a/src/modules/m_sslinfo.cpp +++ b/src/modules/m_sslinfo.cpp @@ -250,7 +250,7 @@ class ModuleSSLInfo ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->oper_blocks.find(parameters[0]); if (i != ServerInstance->Config->oper_blocks.end()) { - OperInfo* ifo = i->second; + std::shared_ptr ifo = i->second; ssl_cert* cert = cmd.sslapi.GetCertificate(user); if (ifo->oper_block->getBool("sslonly") && !cert) @@ -302,9 +302,8 @@ class ModuleSSLInfo return; // Find an auto-oper block for this user - for (ServerConfig::OperIndex::const_iterator i = ServerInstance->Config->oper_blocks.begin(); i != ServerInstance->Config->oper_blocks.end(); ++i) + for (auto& [_, ifo] : ServerInstance->Config->oper_blocks) { - OperInfo* ifo = i->second; std::string fp = ifo->oper_block->getString("fingerprint"); if (MatchFP(cert, fp) && ifo->oper_block->getBool("autologin")) user->Oper(ifo); diff --git a/src/serializable.cpp b/src/serializable.cpp index cec44b008..92c483607 100644 --- a/src/serializable.cpp +++ b/src/serializable.cpp @@ -161,7 +161,7 @@ bool User::Deserialize(Serializable::Data& data) if (iter != ServerInstance->Config->OperTypes.end()) oper = iter->second; else - oper = new OperInfo(user_oper); + oper = std::make_shared(user_oper); irc::sockets::sockaddrs sa; if (irc::sockets::aptosa(client_addr, client_port, sa) || irc::sockets::untosa(client_addr, sa)) diff --git a/src/users.cpp b/src/users.cpp index 418b43ea4..5063da124 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -380,7 +380,7 @@ CullResult FakeUser::cull() return User::cull(); } -void User::Oper(OperInfo* info) +void User::Oper(std::shared_ptr info) { ModeHandler* opermh = ServerInstance->Modes.FindMode('o', MODETYPE_USER); if (opermh)