Skip to content

Commit 83e75b3

Browse files
committed
MDEV-21702 Add a data type for privileges
1 parent f79f537 commit 83e75b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+781
-546
lines changed

libmysqld/lib_sql.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ void *create_embedded_thd(int client_flag)
704704
thd->db= null_clex_str;
705705
#ifndef NO_EMBEDDED_ACCESS_CHECKS
706706
thd->security_ctx->db_access= DB_ACLS;
707-
thd->security_ctx->master_access= ~NO_ACCESS;
707+
thd->security_ctx->master_access= ALL_KNOWN_ACL;
708708
#endif
709709
thd->cur_data= 0;
710710
thd->first_data= 0;

plugin/feedback/sender_thread.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ static int prepare_for_fill(TABLE_LIST *tables)
106106
thd->db= null_clex_str;
107107
thd->security_ctx->host_or_ip= "";
108108
thd->security_ctx->db_access= DB_ACLS;
109-
thd->security_ctx->master_access= ~NO_ACCESS;
109+
thd->security_ctx->master_access= ALL_KNOWN_ACL;
110110
bzero((char*) &thd->net, sizeof(thd->net));
111111
lex_start(thd);
112112
mysql_init_select(thd->lex);

plugin/userstat/index_stats.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static int index_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond)
2929
tmp_table.db.length= strlen(index_stats->index);
3030
tmp_table.table_name.str= index_stats->index + tmp_table.db.length + 1;
3131
tmp_table.table_name.length= strlen(tmp_table.table_name.str);
32-
tmp_table.grant.privilege= 0;
32+
tmp_table.grant.privilege= NO_ACL;
3333
if (check_access(thd, SELECT_ACL, tmp_table.db.str,
3434
&tmp_table.grant.privilege, NULL, 0, 1) ||
3535
check_grant(thd, SELECT_ACL, &tmp_table, 1, UINT_MAX, 1))

plugin/userstat/table_stats.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static int table_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond)
3434
tmp_table.db.length= schema_length;
3535
tmp_table.table_name.str= end_of_schema+1;
3636
tmp_table.table_name.length= table_name_length;
37-
tmp_table.grant.privilege= 0;
37+
tmp_table.grant.privilege= NO_ACL;
3838
if (check_access(thd, SELECT_ACL, tmp_table.db.str,
3939
&tmp_table.grant.privilege, NULL, 0, 1) ||
4040
check_grant(thd, SELECT_ACL, &tmp_table, 1, UINT_MAX,

sql/event_data_objects.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,8 +1480,6 @@ Event_job_data::execute(THD *thd, bool drop)
14801480
ret= 1;
14811481
else
14821482
{
1483-
ulong saved_master_access;
1484-
14851483
thd->set_query(sp_sql.c_ptr_safe(), sp_sql.length());
14861484

14871485
/*
@@ -1493,7 +1491,7 @@ Event_job_data::execute(THD *thd, bool drop)
14931491
Temporarily reset it to read-write.
14941492
*/
14951493

1496-
saved_master_access= thd->security_ctx->master_access;
1494+
privilege_t saved_master_access(thd->security_ctx->master_access);
14971495
thd->security_ctx->master_access |= SUPER_ACL;
14981496
bool save_tx_read_only= thd->tx_read_only;
14991497
thd->tx_read_only= false;

sql/event_scheduler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ pre_init_event_thread(THD* thd)
177177

178178
set_current_thd(thd);
179179
thd->client_capabilities= 0;
180-
thd->security_ctx->master_access= 0;
181-
thd->security_ctx->db_access= 0;
180+
thd->security_ctx->master_access= NO_ACL;
181+
thd->security_ctx->db_access= NO_ACL;
182182
thd->security_ctx->host_or_ip= (char*)my_localhost;
183183
my_net_init(&thd->net, NULL, thd, MYF(MY_THREAD_SPECIFIC));
184184
thd->security_ctx->set_user((char*)"event_scheduler");

sql/events.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,6 @@ Events::load_events_from_db(THD *thd)
11451145
READ_RECORD read_record_info;
11461146
bool ret= TRUE;
11471147
uint count= 0;
1148-
ulong saved_master_access;
11491148
DBUG_ENTER("Events::load_events_from_db");
11501149
DBUG_PRINT("enter", ("thd: %p", thd));
11511150

@@ -1158,7 +1157,7 @@ Events::load_events_from_db(THD *thd)
11581157
Temporarily reset it to read-write.
11591158
*/
11601159

1161-
saved_master_access= thd->security_ctx->master_access;
1160+
privilege_t saved_master_access(thd->security_ctx->master_access);
11621161
thd->security_ctx->master_access |= SUPER_ACL;
11631162
bool save_tx_read_only= thd->tx_read_only;
11641163
thd->tx_read_only= false;

sql/grant.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
bool Grant_privilege::add_column_privilege(THD *thd,
2222
const Lex_ident_sys &name,
23-
uint which_grant)
23+
privilege_t which_grant)
2424
{
2525
String *new_str= new (thd->mem_root) String((const char*) name.str,
2626
name.length,
@@ -51,7 +51,7 @@ bool Grant_privilege::add_column_privilege(THD *thd,
5151

5252
bool Grant_privilege::add_column_list_privilege(THD *thd,
5353
List<Lex_ident_sys> &list,
54-
uint privilege)
54+
privilege_t privilege)
5555
{
5656
Lex_ident_sys *col;
5757
List_iterator<Lex_ident_sys> it(list);
@@ -64,22 +64,22 @@ bool Grant_privilege::add_column_list_privilege(THD *thd,
6464
}
6565

6666

67-
uint Grant_object_name::all_privileges_by_type() const
67+
privilege_t Grant_object_name::all_privileges_by_type() const
6868
{
6969
switch (m_type) {
7070
case STAR: return DB_ACLS & ~GRANT_ACL;
7171
case IDENT_STAR: return DB_ACLS & ~GRANT_ACL;
7272
case STAR_STAR: return GLOBAL_ACLS & ~GRANT_ACL;
7373
case TABLE_IDENT: return TABLE_ACLS & ~GRANT_ACL;
7474
}
75-
return 0;
75+
return NO_ACL;
7676
}
7777

7878

7979
bool Grant_privilege::set_object_name(THD *thd,
8080
const Grant_object_name &ident,
8181
SELECT_LEX *sel,
82-
uint with_grant_option)
82+
privilege_t with_grant_option)
8383
{
8484
DBUG_ASSERT(!m_all_privileges || !m_columns.elements);
8585

sql/grant.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SQL_GRANT_INCLUDED
1919

2020
#include "lex_string.h"
21+
#include "privilege.h"
2122

2223
class LEX_COLUMN;
2324
class Lex_ident_sys;
@@ -50,7 +51,7 @@ class Grant_object_name
5051
m_table_ident(NULL),
5152
m_type(type)
5253
{ }
53-
uint all_privileges_by_type() const;
54+
privilege_t all_privileges_by_type() const;
5455
};
5556

5657

@@ -65,30 +66,32 @@ class Grant_privilege
6566
protected:
6667
List<LEX_COLUMN> m_columns;
6768
Lex_cstring m_db;
68-
uint m_object_privilege;
69-
uint m_column_privilege_total;
69+
privilege_t m_object_privilege;
70+
privilege_t m_column_privilege_total;
7071
bool m_all_privileges;
7172
public:
7273
Grant_privilege()
73-
:m_object_privilege(0), m_column_privilege_total(0), m_all_privileges(false)
74+
:m_object_privilege(NO_ACL),
75+
m_column_privilege_total(NO_ACL),
76+
m_all_privileges(false)
7477
{ }
75-
Grant_privilege(uint privilege, bool all_privileges)
78+
Grant_privilege(privilege_t privilege, bool all_privileges)
7679
:m_object_privilege(privilege),
77-
m_column_privilege_total(0),
80+
m_column_privilege_total(NO_ACL),
7881
m_all_privileges(all_privileges)
7982
{ }
80-
void add_object_privilege(uint privilege)
83+
void add_object_privilege(privilege_t privilege)
8184
{
8285
m_object_privilege|= privilege;
8386
}
8487
bool add_column_privilege(THD *thd, const Lex_ident_sys &col,
85-
uint privilege);
88+
privilege_t privilege);
8689
bool add_column_list_privilege(THD *thd, List<Lex_ident_sys> &list,
87-
uint privilege);
90+
privilege_t privilege);
8891
bool set_object_name(THD *thd,
8992
const Grant_object_name &ident,
9093
SELECT_LEX *sel,
91-
uint with_grant_option);
94+
privilege_t with_grant_option);
9295
const List<LEX_COLUMN> & columns() const { return m_columns; }
9396
};
9497

sql/item.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,7 @@ Item_field::Item_field(THD *thd, Field *f)
28922892
:Item_ident(thd, 0, null_clex_str,
28932893
Lex_cstring_strlen(*f->table_name), f->field_name),
28942894
item_equal(0),
2895-
have_privileges(0), any_privileges(0)
2895+
have_privileges(NO_ACL), any_privileges(0)
28962896
{
28972897
set_field(f);
28982898
/*
@@ -2917,7 +2917,7 @@ Item_field::Item_field(THD *thd, Name_resolution_context *context_arg,
29172917
:Item_ident(thd, context_arg, f->table->s->db,
29182918
Lex_cstring_strlen(*f->table_name), f->field_name),
29192919
item_equal(0),
2920-
have_privileges(0), any_privileges(0)
2920+
have_privileges(NO_ACL), any_privileges(0)
29212921
{
29222922
/*
29232923
We always need to provide Item_field with a fully qualified field
@@ -2961,7 +2961,7 @@ Item_field::Item_field(THD *thd, Name_resolution_context *context_arg,
29612961
const LEX_CSTRING &field_name_arg)
29622962
:Item_ident(thd, context_arg, db_arg, table_name_arg, field_name_arg),
29632963
field(0), item_equal(0),
2964-
have_privileges(0), any_privileges(0)
2964+
have_privileges(NO_ACL), any_privileges(0)
29652965
{
29662966
SELECT_LEX *select= thd->lex->current_select;
29672967
collation.set(DERIVATION_IMPLICIT);

0 commit comments

Comments
 (0)