Skip to content

Commit

Permalink
sql_show: reduce ifdefs around grants checks
Browse files Browse the repository at this point in the history
Embedded server has an option to opt out grant checks.
sql_show.cc: reduce ifdefs by using embedded acl stub calls
sql_acl.cc: add stub for embedded get_column_grant
  • Loading branch information
FooBarrior authored and sanja-byelkin committed Feb 12, 2024
1 parent ba1c591 commit 85f9df2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
3 changes: 3 additions & 0 deletions sql/sql_acl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12205,6 +12205,9 @@ bool check_grant(THD *, privilege_t, TABLE_LIST *, bool, uint, bool)
{ return 0; }
inline privilege_t public_access()
{ return NO_ACL; }
privilege_t get_column_grant(THD *, GRANT_INFO *,
const char *, const char *, const char *)
{ return ALL_KNOWN_ACL; }
#endif /*NO_EMBEDDED_ACCESS_CHECKS */


Expand Down
18 changes: 4 additions & 14 deletions sql/sql_show.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5209,11 +5209,11 @@ static int fill_schema_table_from_frm(THD *thd, MEM_ROOT *mem_root,
}


#ifndef NO_EMBEDDED_ACCESS_CHECKS
static privilege_t get_schema_privileges_for_show(THD *thd, TABLE_LIST *tables,
const privilege_t need,
bool any)
{
#ifndef NO_EMBEDDED_ACCESS_CHECKS
/*
We know that the table or at least some of the columns have
necessary privileges, but the caller didn't pass down the GRANT_INFO
Expand All @@ -5226,8 +5226,10 @@ static privilege_t get_schema_privileges_for_show(THD *thd, TABLE_LIST *tables,
: tables->grant.privilege) & need;
}
return thd->col_access & need;
}
#else
return need;
#endif
}


class Warnings_only_error_handler : public Internal_error_handler
Expand Down Expand Up @@ -7089,10 +7091,8 @@ static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
set_statistics_for_table(thd, show_table);
}

#ifndef NO_EMBEDDED_ACCESS_CHECKS
bool need_column_checks= !get_schema_privileges_for_show(thd, tables,
TABLE_ACLS, false);
#endif

for (uint i=0 ; i < show_table->s->keys ; i++,key_info++)
{
Expand All @@ -7103,7 +7103,6 @@ static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
LEX_CSTRING *str;
LEX_CSTRING unknown= {STRING_WITH_LEN("?unknown field?") };

#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (need_column_checks)
{
uint j;
Expand All @@ -7120,7 +7119,6 @@ static int get_schema_stat_record(THD *thd, TABLE_LIST *tables,
continue;
key_part= key_info->key_part;
}
#endif

for (uint j=0 ; j < key_info->user_defined_key_parts ; j++,key_part++)
{
Expand Down Expand Up @@ -7434,12 +7432,10 @@ static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables,
}
else if (!tables->view)
{
#ifndef NO_EMBEDDED_ACCESS_CHECKS
/* need any non-SELECT privilege on the table or any of its columns */
if (!get_schema_privileges_for_show(thd, tables, TABLE_ACLS & ~SELECT_ACL,
true))
DBUG_RETURN(0);
#endif

List<FOREIGN_KEY_INFO> f_key_list;
TABLE *show_table= tables->table;
Expand Down Expand Up @@ -7637,18 +7633,15 @@ static int get_schema_key_column_usage_record(THD *thd, TABLE_LIST *tables,
show_table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK |
HA_STATUS_TIME);

#ifndef NO_EMBEDDED_ACCESS_CHECKS
bool need_column_checks= !get_schema_privileges_for_show(thd, tables,
TABLE_ACLS, false);
#endif

for (uint i=0 ; i < show_table->s->keys ; i++, key_info++)
{
if (i != primary_key && !(key_info->flags & HA_NOSAME))
continue;
uint f_idx= 0;
KEY_PART_INFO *key_part= key_info->key_part;
#ifndef NO_EMBEDDED_ACCESS_CHECKS
if (need_column_checks)
{
uint j;
Expand All @@ -7665,7 +7658,6 @@ static int get_schema_key_column_usage_record(THD *thd, TABLE_LIST *tables,
continue;
key_part= key_info->key_part;
}
#endif

for (uint j=0 ; j < key_info->user_defined_key_parts ; j++,key_part++)
{
Expand Down Expand Up @@ -8483,12 +8475,10 @@ get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
show_table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK |
HA_STATUS_TIME);

#ifndef NO_EMBEDDED_ACCESS_CHECKS
/* need any non-SELECT privilege on the table or any of its columns */
privilege_t need= TABLE_ACLS & ~SELECT_ACL;
if (!get_schema_privileges_for_show(thd, tables, need, true))
DBUG_RETURN(0);
#endif

show_table->file->get_foreign_key_list(thd, &f_key_list);
FOREIGN_KEY_INFO *f_key_info;
Expand Down

0 comments on commit 85f9df2

Please sign in to comment.