mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-12 12:09:03 -04:00
Implement roadmap item: "userrec::HasPermission -> map of maps, for (even faster) access"
This is not a map of maps, but a single level map per oper, in non-opers this member is NULL. Please note that this is not yet tested. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8564 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
7336f449eb
commit
7eebbe7da1
@ -489,6 +489,8 @@ class CoreExport User : public connection
|
||||
*/
|
||||
unsigned int MaxChans;
|
||||
|
||||
std::map<std::string, bool>* AllowedOperCommands;
|
||||
|
||||
public:
|
||||
/** Contains a pointer to the connect class a user is on from - this will be NULL for remote connections.
|
||||
* The pointer is guarenteed to *always* be valid. :)
|
||||
|
@ -190,6 +190,7 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance
|
||||
Visibility = NULL;
|
||||
ip = NULL;
|
||||
MyClass = NULL;
|
||||
AllowedOperCommands = NULL;
|
||||
chans.clear();
|
||||
invites.clear();
|
||||
memset(modes,0,sizeof(modes));
|
||||
@ -242,6 +243,11 @@ User::~User()
|
||||
this->MyClass->RefCount--;
|
||||
ServerInstance->Log(DEBUG, "User destructor -- connect refcount now: %u", this->MyClass->RefCount);
|
||||
}
|
||||
if (this->AllowedOperCommands)
|
||||
{
|
||||
delete AllowedOperCommands;
|
||||
AllowedOperCommands = NULL;
|
||||
}
|
||||
|
||||
this->InvalidateCache();
|
||||
this->DecrementModes();
|
||||
@ -419,10 +425,6 @@ void User::RemoveInvite(const irc::string &channel)
|
||||
|
||||
bool User::HasPermission(const std::string &command)
|
||||
{
|
||||
char* mycmd;
|
||||
char* savept;
|
||||
char* savept2;
|
||||
|
||||
/*
|
||||
* users on remote servers can completely bypass all permissions based checks.
|
||||
* This prevents desyncs when one server has different type/class tags to another.
|
||||
@ -439,38 +441,13 @@ bool User::HasPermission(const std::string &command)
|
||||
return false;
|
||||
}
|
||||
|
||||
// check their opertype exists (!). This won't affect local users, of course.
|
||||
opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
|
||||
if (iter_opertype == ServerInstance->Config->opertypes.end())
|
||||
{
|
||||
if (!AllowedOperCommands)
|
||||
return false;
|
||||
}
|
||||
|
||||
/* XXX all this strtok/strdup stuff is a bit ick and horrid -- w00t */
|
||||
char* Classes = strdup(iter_opertype->second);
|
||||
char* myclass = strtok_r(Classes," ",&savept);
|
||||
while (myclass)
|
||||
{
|
||||
operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
|
||||
if (iter_operclass != ServerInstance->Config->operclass.end())
|
||||
{
|
||||
char* CommandList = strdup(iter_operclass->second);
|
||||
mycmd = strtok_r(CommandList," ",&savept2);
|
||||
while (mycmd)
|
||||
{
|
||||
if ((!strcasecmp(mycmd,command.c_str())) || (*mycmd == '*'))
|
||||
{
|
||||
free(Classes);
|
||||
free(CommandList);
|
||||
return true;
|
||||
}
|
||||
mycmd = strtok_r(NULL," ",&savept2);
|
||||
}
|
||||
free(CommandList);
|
||||
}
|
||||
myclass = strtok_r(NULL," ",&savept);
|
||||
}
|
||||
free(Classes);
|
||||
if (AllowedOperCommands->find(command) != AllowedOperCommands->end())
|
||||
return true;
|
||||
else if (AllowedOperCommands->find("*") != AllowedOperCommands->end())
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -672,6 +649,10 @@ const char* User::GetWriteError()
|
||||
|
||||
void User::Oper(const std::string &opertype)
|
||||
{
|
||||
char* mycmd;
|
||||
char* savept;
|
||||
char* savept2;
|
||||
|
||||
try
|
||||
{
|
||||
this->modes[UM_OPERATOR] = 1;
|
||||
@ -680,6 +661,37 @@ void User::Oper(const std::string &opertype)
|
||||
ServerInstance->Log(DEFAULT,"OPER: %s!%s@%s opered as type: %s", this->nick, this->ident, this->host, opertype.c_str());
|
||||
strlcpy(this->oper, opertype.c_str(), NICKMAX - 1);
|
||||
ServerInstance->all_opers.push_back(this);
|
||||
|
||||
opertype_t::iterator iter_opertype = ServerInstance->Config->opertypes.find(this->oper);
|
||||
if (iter_opertype != ServerInstance->Config->opertypes.end())
|
||||
{
|
||||
|
||||
if (AllowedOperCommands)
|
||||
AllowedOperCommands->clear();
|
||||
else
|
||||
AllowedOperCommands = new std::map<std::string, bool>;
|
||||
|
||||
char* Classes = strdup(iter_opertype->second);
|
||||
char* myclass = strtok_r(Classes," ",&savept);
|
||||
while (myclass)
|
||||
{
|
||||
operclass_t::iterator iter_operclass = ServerInstance->Config->operclass.find(myclass);
|
||||
if (iter_operclass != ServerInstance->Config->operclass.end())
|
||||
{
|
||||
char* CommandList = strdup(iter_operclass->second);
|
||||
mycmd = strtok_r(CommandList," ",&savept2);
|
||||
while (mycmd)
|
||||
{
|
||||
this->AllowedOperCommands->insert(std::make_pair(mycmd, true));
|
||||
mycmd = strtok_r(NULL," ",&savept2);
|
||||
}
|
||||
free(CommandList);
|
||||
}
|
||||
myclass = strtok_r(NULL," ",&savept);
|
||||
}
|
||||
free(Classes);
|
||||
}
|
||||
|
||||
FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype));
|
||||
}
|
||||
|
||||
@ -701,6 +713,12 @@ void User::UnOper()
|
||||
|
||||
// remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404
|
||||
ServerInstance->all_opers.remove(this);
|
||||
|
||||
if (AllowedOperCommands)
|
||||
{
|
||||
delete AllowedOperCommands;
|
||||
AllowedOperCommands = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user