Skip to content

Commit c66b83a

Browse files
committed
x
1 parent 54702b2 commit c66b83a

5 files changed

Lines changed: 15 additions & 9 deletions

File tree

sql/sql_acl.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10043,7 +10043,7 @@ static bool check_grant_db_routine(THD *thd, const char *db, HASH *hash)
1004310043
strcmp(item->db, db) == 0 &&
1004410044
(!item->host.hostname || !item->host.hostname[0]))
1004510045
{
10046-
if (item->init_privs.certainly_allowed(ALL_KNOWN_ACL))
10046+
if (item->privs.certainly_allowed(ALL_KNOWN_ACL))
1004710047
return FALSE; /* Found current role match */
1004810048
}
1004910049
}
@@ -10089,14 +10089,20 @@ static bool has_some_table_privs(GRANT_TABLE *grant_table)
1008910089
Return 1 if access is denied
1009010090
*/
1009110091

10092-
bool check_grant_db(THD *thd, const char *db)
10092+
bool check_grant_db(THD *thd, const access_t &access, const char *db)
1009310093
{
1009410094
Security_context *sctx= thd->security_ctx;
1009510095
constexpr size_t key_data_size= SAFE_NAME_LEN + USERNAME_LENGTH + 1;
1009610096
// See earlier comments on MY_CS_MBMAXLEN above
1009710097
CharBuffer<key_data_size + MY_CS_MBMAXLEN> key, key2;
1009810098
bool error= TRUE;
1009910099

10100+
if (access.is_denied_all(TABLE_ACLS|PROC_ACLS))
10101+
return 1; // all table and routine privileges are denied
10102+
10103+
if (access & (TABLE_ACLS | PROC_ACLS))
10104+
return 0; // some table or routine privileges are allowed
10105+
1010010106
key.append(Lex_cstring_strlen(sctx->priv_user)).append_char('\0')
1010110107
.append_opt_casedn(files_charset_info, Lex_cstring_strlen(db),
1010210108
lower_case_table_names)

sql/sql_acl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ bool check_grant_all_columns(THD *thd, privilege_t want_access,
123123
bool check_grant_routine(THD *thd, privilege_t want_access,
124124
TABLE_LIST *procs, const Sp_handler *sph,
125125
bool no_error);
126-
bool check_grant_db(THD *thd,const char *db);
126+
bool check_grant_db(THD *thd,const access_t& priv, const char *db);
127127
bool check_global_access(THD *thd, const privilege_t want_access, bool no_errors= false);
128128
bool check_access(THD *thd, privilege_t want_access,
129129
const char *db, access_t *save_priv,

sql/sql_db.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,8 +1791,7 @@ uint mysql_change_db(THD *thd, const LEX_CSTRING &new_db_name, bool force)
17911791

17921792
if (!force)
17931793
{
1794-
if (db_access.is_denied_all(DB_ACLS) ||
1795-
(!(db_access & DB_ACLS) && check_grant_db(thd, new_db_file_name.str)))
1794+
if (!(db_access & DB_ACLS) && check_grant_db(thd, db_access, new_db_file_name.str))
17961795
{
17971796
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), sctx->priv_user,
17981797
sctx->priv_host, new_db_file_name.str);

sql/sql_parse.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6946,7 +6946,7 @@ static bool check_show_access(THD *thd, TABLE_LIST *table)
69466946
&thd->col_access, NULL, FALSE, FALSE))
69476947
return TRUE;
69486948

6949-
if (!thd->col_access && check_grant_db(thd, dst_db_name))
6949+
if (!thd->col_access && check_grant_db(thd, thd->col_access, dst_db_name))
69506950
{
69516951
status_var_increment(thd->status_var.access_denied_errors);
69526952
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),

sql/sql_show.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ bool mysqld_show_create_db(THD *thd, LEX_CSTRING *dbname,
14551455
else
14561456
db_access= acl_get_all3(sctx, dbname->str, FALSE);
14571457

1458-
if (!(db_access & DB_ACLS) && !db_access.is_denied_all(DB_ACLS) && check_grant_db(thd,dbname->str))
1458+
if (!(db_access & DB_ACLS) && check_grant_db(thd, db_access, dbname->str))
14591459
{
14601460
status_var_increment(thd->status_var.access_denied_errors);
14611461
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0),
@@ -5798,9 +5798,10 @@ int fill_schema_schemata(THD *thd, TABLE_LIST *tables, COND *cond)
57985798
continue;
57995799
}
58005800
#ifndef NO_EMBEDDED_ACCESS_CHECKS
5801+
access_t db_access=acl_get_all3(sctx, db_name->str, false);
58015802
if (sctx->master_access & (DB_ACLS | SHOW_DB_ACL) ||
5802-
!acl_get_all3(sctx, db_name->str, false).is_empty() ||
5803-
!check_grant_db(thd, db_name->str))
5803+
!db_access.is_empty() || /*??*/
5804+
!check_grant_db(thd, db_access ,db_name->str))
58045805
#endif
58055806
{
58065807
load_db_opt_by_name(thd, db_name->str, &create);

0 commit comments

Comments
 (0)