Skip to content

Commit

Permalink
Core/RBAC: Add config option to set comma separated list of groups to…
Browse files Browse the repository at this point in the history
… add by default

- Allows to reduce the rows in rbac_account_groups
  • Loading branch information
xurxogr committed Feb 18, 2013
1 parent 028c72a commit 4fc7fca
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/server/game/Accounts/AccountMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ AccountOpResult AccountMgr::CreateAccount(std::string username, std::string pass
RBACData* rbac = new RBACData(GetId(username), username, -1);
// No need to Load From DB, as it's new data

RBACGroupContainer const& groupsToAdd = _defaultGroups[0]; // 0: Default sec level
RBACGroupContainer const& groupsToAdd = _defaultSecGroups[0]; // 0: Default sec level
for (RBACGroupContainer::const_iterator it = groupsToAdd.begin(); it != groupsToAdd.end(); ++it)
rbac->AddGroup(*it, -1);

Expand Down Expand Up @@ -426,13 +426,23 @@ void AccountMgr::LoadRBAC()
uint8 secId = field[0].GetUInt8();

if (lastSecId != secId)
groups = &_defaultGroups[secId];
groups = &_defaultSecGroups[secId];

groups->insert(field[1].GetUInt32());
}
while (result->NextRow());

sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u permission definitions, %u role definitions and %u group definitions in %u ms", count1, count2, count3, GetMSTimeDiffToNow(oldMSTime));

// Load default groups to be added to any RBAC Object.
std::string defaultGroups = ConfigMgr::GetStringDefault("RBAC.DefaultGroups", "");
Tokenizer tokens(defaultGroups, ',');
for (Tokenizer::const_iterator itr = tokens.begin(); itr != tokens.end(); ++itr)
if (uint32 groupId = atoi(*itr))
{
sLog->outError(LOG_FILTER_LFG, "Adding default group %u", groupId);
_defaultGroups.insert(groupId);
}
}

void AccountMgr::UpdateAccountAccess(RBACData* rbac, uint32 accountId, uint8 securityLevel, int32 realmId)
Expand All @@ -459,15 +469,15 @@ void AccountMgr::UpdateAccountAccess(RBACData* rbac, uint32 accountId, uint8 sec
uint8 secLevel = field[0].GetUInt8();
int32 realmId = field[1].GetUInt32();

RBACGroupContainer const& groupsToRemove = _defaultGroups[secLevel];
RBACGroupContainer const& groupsToRemove = _defaultSecGroups[secLevel];
for (RBACGroupContainer::const_iterator it = groupsToRemove.begin(); it != groupsToRemove.end(); ++it)
rbac->RemoveGroup(*it, realmId);
}
while (result->NextRow());
}

// Add new groups depending on the new security Level
RBACGroupContainer const& groupsToAdd = _defaultGroups[securityLevel];
RBACGroupContainer const& groupsToAdd = _defaultSecGroups[securityLevel];
for (RBACGroupContainer::const_iterator it = groupsToAdd.begin(); it != groupsToAdd.end(); ++it)
rbac->AddGroup(*it, realmId);

Expand Down
4 changes: 3 additions & 1 deletion src/server/game/Accounts/AccountMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ class AccountMgr
RBACGroupsContainer const& GetRBACGroupList() const { return _groups; }
RBACRolesContainer const& GetRBACRoleList() const { return _roles; }
RBACPermissionsContainer const& GetRBACPermissionList() const { return _permissions; }
RBACGroupContainer const& GetRBACDefaultGroups() const { return _defaultGroups; }

private:
RBACPermissionsContainer _permissions;
RBACRolesContainer _roles;
RBACGroupsContainer _groups;
RBACDefaultSecurityGroupContainer _defaultGroups;
RBACDefaultSecurityGroupContainer _defaultSecGroups;
RBACGroupContainer _defaultGroups;
};

#define sAccountMgr ACE_Singleton<AccountMgr, ACE_Null_Mutex>::instance()
Expand Down
5 changes: 5 additions & 0 deletions src/server/game/Accounts/RBAC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ void RBACData::LoadFromDB()
while (result->NextRow());
}

// Add default groups
RBACGroupContainer const& groups = sAccountMgr->GetRBACDefaultGroups();
for (RBACGroupContainer::const_iterator itr = groups.begin(); itr != groups.end(); ++itr)
AddGroup(*itr);

// Force calculation of permissions, it wasn't performed at load time
// while adding groups, roles and permissions
CalculateNewPermissions();
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/Accounts/RBAC.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class RBACGroup: public RBACObject
RBACRoleContainer _roles; ///> Set of Roles
};

/*
/**
* @name RBACData
* @brief Contains all needed information about the acccount
*
Expand Down
8 changes: 8 additions & 0 deletions src/server/worldserver/worldserver.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,14 @@ DBC.EnforceItemAttributes = 1

AccountInstancesPerHour = 5

#
# RBAC.DefaultGroups
# Description: Comma separated list of groups to be added to any account
# Check auth.rbac_groups for correct ids
# Default: "" (No group)

RBAC.DefaultGroups = ""

#
###################################################################################################

Expand Down

0 comments on commit 4fc7fca

Please sign in to comment.