Convert OperInfo from reference<> to std::shared_ptr<>.

This commit is contained in:
Sadie Powell 2020-10-31 16:55:18 +00:00
parent 5a88a78f99
commit 4176261edf
14 changed files with 22 additions and 27 deletions

View File

@ -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<std::string, reference<OperInfo> > OperIndex;
typedef insp::flat_map<std::string, std::shared_ptr<OperInfo>> 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.

View File

@ -48,6 +48,7 @@
#include <deque>
#include <functional>
#include <list>
#include <memory>
#include <map>
#include <set>
#include <sstream>
@ -167,7 +168,7 @@ class serverstats
/** Cpu usage at last sample
*/
timeval LastCPU;
/** Time last sample was read
*/
timespec LastSampled;

View File

@ -351,7 +351,7 @@ class CoreExport User : public Extensible
/** The oper type they logged in as, if they are an oper.
*/
reference<OperInfo> oper;
std::shared_ptr<OperInfo> 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<OperInfo> info);
/** Oper down.
* This will clear the +o usermode and unset the user's oper type

View File

@ -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<OperInfo>(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<OperInfo>(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());

View File

@ -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<OperInfo> ifo = i->second;
ConfigTag* tag = ifo->oper_block;
match_login = true;
match_pass = ServerInstance->PassCompare(user, tag->getString("password"), parameters[1], tag->getString("hash"));

View File

@ -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;

View File

@ -41,7 +41,6 @@
#include "inspircd.h"
#include "modules/ssl.h"
#include <memory>
#include <gnutls/gnutls.h>
#include <gnutls/crypto.h>

View File

@ -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());
}
}

View File

@ -91,8 +91,7 @@ class BindInterface : public LDAPOperBase
return;
}
OperInfo* ifo = iter->second;
user->Oper(ifo);
user->Oper(iter->second);
delete this;
}
};

View File

@ -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<OperInfo>(opertype);
if (Utils->quiet_bursts)
{

View File

@ -96,7 +96,7 @@ class OperQuery : public SQL::Query
continue;
}
OperInfo* ifo = new OperInfo(type);
auto ifo = std::make_shared<OperInfo>(type);
ifo->type_block = tblk->second->type_block;
ifo->oper_block = tag;

View File

@ -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<OperInfo> 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);

View File

@ -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<OperInfo>(user_oper);
irc::sockets::sockaddrs sa;
if (irc::sockets::aptosa(client_addr, client_port, sa) || irc::sockets::untosa(client_addr, sa))

View File

@ -380,7 +380,7 @@ CullResult FakeUser::cull()
return User::cull();
}
void User::Oper(OperInfo* info)
void User::Oper(std::shared_ptr<OperInfo> info)
{
ModeHandler* opermh = ServerInstance->Modes.FindMode('o', MODETYPE_USER);
if (opermh)