Commit cb2f36d3 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-14975: Cleanup check_all_privileges()

Remove an unused variable, and propagate the error to the caller
instead of calling exit().
parent 6639fc3f
...@@ -5742,32 +5742,29 @@ int check_privilege( ...@@ -5742,32 +5742,29 @@ int check_privilege(
} }
/******************************************************************//** /**
Check DB user privileges according to the intended actions. Check DB user privileges according to the intended actions.
Fetches DB user privileges, determines intended actions based on Fetches DB user privileges, determines intended actions based on
command-line arguments and prints missing privileges. command-line arguments and prints missing privileges.
May terminate application with EXIT_FAILURE exit code.*/ @return whether all the necessary privileges are granted */
static void static bool check_all_privileges()
check_all_privileges()
{ {
if (!mysql_connection) { if (!mysql_connection) {
/* Not connected, no queries is going to be executed. */ /* Not connected, no queries is going to be executed. */
return; return true;
} }
/* Fetch effective privileges. */ /* Fetch effective privileges. */
std::list<std::string> granted_privileges; std::list<std::string> granted_privileges;
MYSQL_ROW row = 0;
MYSQL_RES* result = xb_mysql_query(mysql_connection, "SHOW GRANTS", MYSQL_RES* result = xb_mysql_query(mysql_connection, "SHOW GRANTS",
true); true);
while ((row = mysql_fetch_row(result))) { while (MYSQL_ROW row = mysql_fetch_row(result)) {
granted_privileges.push_back(*row); granted_privileges.push_back(*row);
} }
mysql_free_result(result); mysql_free_result(result);
int check_result = PRIVILEGE_OK; int check_result = PRIVILEGE_OK;
bool reload_checked = false;
/* FLUSH TABLES WITH READ LOCK */ /* FLUSH TABLES WITH READ LOCK */
if (!opt_no_lock) if (!opt_no_lock)
...@@ -5775,14 +5772,9 @@ check_all_privileges() ...@@ -5775,14 +5772,9 @@ check_all_privileges()
check_result |= check_privilege( check_result |= check_privilege(
granted_privileges, granted_privileges,
"RELOAD", "*", "*"); "RELOAD", "*", "*");
reload_checked = true;
}
if (!opt_no_lock)
{
check_result |= check_privilege( check_result |= check_privilege(
granted_privileges, granted_privileges,
"PROCESS", "*", "*"); "PROCESS", "*", "*");
} }
/* KILL ... */ /* KILL ... */
...@@ -5805,10 +5797,7 @@ check_all_privileges() ...@@ -5805,10 +5797,7 @@ check_all_privileges()
PRIVILEGE_WARNING); PRIVILEGE_WARNING);
} }
if (check_result & PRIVILEGE_ERROR) { return !(check_result & PRIVILEGE_ERROR);
mysql_close(mysql_connection);
exit(EXIT_FAILURE);
}
} }
bool bool
...@@ -5875,8 +5864,8 @@ xb_init() ...@@ -5875,8 +5864,8 @@ xb_init()
if (!get_mysql_vars(mysql_connection)) { if (!get_mysql_vars(mysql_connection)) {
return(false); return(false);
} }
if (opt_check_privileges) { if (opt_check_privileges && !check_all_privileges()) {
check_all_privileges(); return(false);
} }
history_start_time = time(NULL); history_start_time = time(NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment