diff options
-rw-r--r-- | include/configreader.h | 10 | ||||
-rw-r--r-- | include/users.h | 12 | ||||
-rw-r--r-- | src/users.cpp | 78 |
3 files changed, 24 insertions, 76 deletions
diff --git a/include/configreader.h b/include/configreader.h index d4bc4b71b..6afea4504 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -113,6 +113,15 @@ class ServerLimits class CoreExport OperInfo : public refcountbase { public: + std::set<std::string> AllowedOperCommands; + std::set<std::string> AllowedPrivs; + + /** Allowed user modes from oper classes. */ + std::bitset<64> AllowedUserModes; + + /** Allowed channel modes from oper classes. */ + std::bitset<64> AllowedChanModes; + /** <oper> block used for this oper-up. May be NULL. */ reference<ConfigTag> oper_block; /** <type> block used for this oper-up. Valid for local users, may be NULL on remote */ @@ -124,6 +133,7 @@ class CoreExport OperInfo : public refcountbase /** Get a configuration item, searching in the oper, type, and class blocks (in that order) */ std::string getConfig(const std::string& key); + void init(); inline const char* NameStr() { diff --git a/include/users.h b/include/users.h index bb8fba007..241eed0c6 100644 --- a/include/users.h +++ b/include/users.h @@ -754,15 +754,6 @@ class CoreExport LocalUser : public User */ InvitedList invites; - std::set<std::string> *AllowedOperCommands; - std::set<std::string> *AllowedPrivs; - - /** Allowed user modes from oper classes. */ - std::bitset<64> AllowedUserModes; - - /** Allowed channel modes from oper classes. */ - std::bitset<64> AllowedChanModes; - public: LocalUser(); CullResult cull(); @@ -900,9 +891,6 @@ class CoreExport LocalUser : public User * @return True if the user can set or unset this mode. */ bool HasModePermission(unsigned char mode, ModeType type); - - void OperInternal(); - void UnOperInternal(); }; class CoreExport RemoteUser : public User diff --git a/src/users.cpp b/src/users.cpp index 0f760e27c..e8e4a4825 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -242,7 +242,6 @@ User::User(const std::string &uid) LocalUser::LocalUser() : User(ServerInstance->GetUID()) { - AllowedPrivs = AllowedOperCommands = NULL; bytes_in = bytes_out = cmds_in = cmds_out = 0; server_sa.sa.sa_family = AF_UNSPEC; Penalty = 0; @@ -434,7 +433,7 @@ bool LocalUser::HasModePermission(unsigned char mode, ModeType type) if (mode < 'A' || mode > ('A' + 64)) return false; - return ((type == MODETYPE_USER ? AllowedUserModes : AllowedChanModes))[(mode - 'A')]; + return ((type == MODETYPE_USER ? oper->AllowedUserModes : oper->AllowedChanModes))[(mode - 'A')]; } /* @@ -457,12 +456,9 @@ bool LocalUser::HasPermission(const std::string &command) return false; } - if (!AllowedOperCommands) - return false; - - if (AllowedOperCommands->find(command) != AllowedOperCommands->end()) + if (oper->AllowedOperCommands.find(command) != oper->AllowedOperCommands.end()) return true; - else if (AllowedOperCommands->find("*") != AllowedOperCommands->end()) + else if (oper->AllowedOperCommands.find("*") != oper->AllowedOperCommands.end()) return true; return false; @@ -482,18 +478,11 @@ bool LocalUser::HasPrivPermission(const std::string &privstr, bool noisy) return false; } - if (!AllowedPrivs) - { - if (noisy) - this->WriteServ("NOTICE %s :Privset empty(!?)", this->nick.c_str()); - return false; - } - - if (AllowedPrivs->find(privstr) != AllowedPrivs->end()) + if (oper->AllowedPrivs.find(privstr) != oper->AllowedPrivs.end()) { return true; } - else if (AllowedPrivs->find("*") != AllowedPrivs->end()) + else if (oper->AllowedPrivs.find("*") != oper->AllowedPrivs.end()) { return true; } @@ -620,18 +609,6 @@ CullResult LocalUser::cull() else ServerInstance->Logs->Log("USERS", DEBUG, "Failed to remove user from vector"); - if (this->AllowedOperCommands) - { - delete AllowedOperCommands; - AllowedOperCommands = NULL; - } - - if (this->AllowedPrivs) - { - delete AllowedPrivs; - AllowedPrivs = NULL; - } - if (client_sa.sa.sa_family != AF_UNSPEC) ServerInstance->Users->RemoveCloneCounts(this); return User::cull(); @@ -658,29 +635,22 @@ void User::Oper(OperInfo* info) ServerInstance->Logs->Log("OPER", DEFAULT, "%s!%s@%s opered as type: %s", this->nick.c_str(), this->ident.c_str(), this->host.c_str(), info->NameStr()); ServerInstance->Users->all_opers.push_back(this); + // Expand permissions from config for faster lookup if (IS_LOCAL(this)) - IS_LOCAL(this)->OperInternal(); + oper->init(); FOREACH_MOD(I_OnPostOper,OnPostOper(this, info->name, opername)); } -void LocalUser::OperInternal() +void OperInfo::init() { - if (AllowedOperCommands) - AllowedOperCommands->clear(); - else - AllowedOperCommands = new std::set<std::string>; - - if (AllowedPrivs) - AllowedPrivs->clear(); - else - AllowedPrivs = new std::set<std::string>; - + AllowedOperCommands.clear(); + AllowedPrivs.clear(); AllowedUserModes.reset(); AllowedChanModes.reset(); - this->AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want. + AllowedUserModes['o' - 'A'] = true; // Call me paranoid if you want. - for(std::vector<reference<ConfigTag> >::iterator iter = oper->class_blocks.begin(); iter != oper->class_blocks.end(); ++iter) + for(std::vector<reference<ConfigTag> >::iterator iter = class_blocks.begin(); iter != class_blocks.end(); ++iter) { ConfigTag* tag = *iter; std::string mycmd, mypriv; @@ -688,13 +658,13 @@ void LocalUser::OperInternal() irc::spacesepstream CommandList(tag->getString("commands")); while (CommandList.GetToken(mycmd)) { - this->AllowedOperCommands->insert(mycmd); + AllowedOperCommands.insert(mycmd); } irc::spacesepstream PrivList(tag->getString("privs")); while (PrivList.GetToken(mypriv)) { - this->AllowedPrivs->insert(mypriv); + AllowedPrivs.insert(mypriv); } for (unsigned char* c = (unsigned char*)tag->getString("usermodes").c_str(); *c; ++c) @@ -756,29 +726,9 @@ void User::UnOper() /* remove the user from the oper list. Will remove multiple entries as a safeguard against bug #404 */ ServerInstance->Users->all_opers.remove(this); - if (IS_LOCAL(this)) - IS_LOCAL(this)->UnOperInternal(); this->modes[UM_OPERATOR] = 0; } -void LocalUser::UnOperInternal() -{ - if (AllowedOperCommands) - { - delete AllowedOperCommands; - AllowedOperCommands = NULL; - } - - if (AllowedPrivs) - { - delete AllowedPrivs; - AllowedPrivs = NULL; - } - AllowedUserModes.reset(); - AllowedChanModes.reset(); -} - - /* adds or updates an entry in the whowas list */ void User::AddToWhoWas() { |