MXS-1354: Prevent removal of last admin account

Removing the last admin account is now forbidden. This should prevent most
cases where users could lock themselves out of the administrative
interface.

This change does allow a non-root network user to be the last admin
account. In practice this does not prevent the root user from gaining
access to maxadmin. Access can be gained by removing the users file and
restarting MaxScale or by editing the users file by hand.
This commit is contained in:
Markus Mäkelä
2017-08-17 09:59:30 +03:00
parent 828649ba99
commit 6cc3986db5
5 changed files with 34 additions and 27 deletions

View File

@ -104,9 +104,9 @@ public:
return rval;
}
bool have_admin() const
int admin_count() const
{
return std::find_if(m_data.begin(), m_data.end(), is_admin) != m_data.end();
return std::count_if(m_data.begin(), m_data.end(), is_admin);
}
bool check_permissions(std::string user, user_account_type perm) const
@ -302,10 +302,10 @@ bool users_is_admin(USERS* users, const char* user)
return u->check_permissions(user, USER_ACCOUNT_ADMIN);
}
bool users_have_admin(USERS* users)
int users_admin_count(USERS* users)
{
Users* u = reinterpret_cast<Users*>(users);
return u->have_admin();
return u->admin_count();
}
void users_diagnostic(DCB* dcb, USERS* users)