MySQL 8.4.0
Source Code Documentation
auth_acls.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23#ifndef AUTH_ACLS_INCLUDED
24#define AUTH_ACLS_INCLUDED
25
26#include <string>
27#include <unordered_map>
28#include <vector>
29
30/* Total Number of ACLs present in mysql.user */
31#define NUM_ACLS 31
32
33#define SELECT_ACL (1L << 0)
34#define INSERT_ACL (1L << 1)
35#define UPDATE_ACL (1L << 2)
36#define DELETE_ACL (1L << 3)
37#define CREATE_ACL (1L << 4)
38#define DROP_ACL (1L << 5)
39#define RELOAD_ACL (1L << 6)
40#define SHUTDOWN_ACL (1L << 7)
41#define PROCESS_ACL (1L << 8)
42#define FILE_ACL (1L << 9)
43/** Set to true by both
44 GRANT GRANT OPTION ... TO ...
45and
46 GRANT ... TO ... WITH GRANT OPTION
47
48 Stored into the relevant column in the priv tables for static privileges.
49 And into the the GRANT_OPTION column for dynamic privilege grants.
50 Note that, once granted GRANT_OPTION applies to all static privs on the
51 same level, i.e. the following:
52 GRANT SELECT ON *.* TO foo;
53 GRANT INSERT ON *.* TO foo WITH GRANT OPTION;
54 is equivalent to:
55 GRANT SELECT,INSERT ON *.* TO foo WITH GRANT OPTION;
56 And is also equivalent to
57 GRANT SELECT,INSERT, GRANT OPTION ON *.* TO foo;
58
59 @sa @ref LEX::grant_privilege
60*/
61#define GRANT_ACL (1L << 10)
62#define REFERENCES_ACL (1L << 11)
63#define INDEX_ACL (1L << 12)
64#define ALTER_ACL (1L << 13)
65#define SHOW_DB_ACL (1L << 14)
66#define SUPER_ACL (1L << 15)
67#define CREATE_TMP_ACL (1L << 16)
68#define LOCK_TABLES_ACL (1L << 17)
69#define EXECUTE_ACL (1L << 18)
70#define REPL_SLAVE_ACL (1L << 19)
71#define REPL_CLIENT_ACL (1L << 20)
72#define CREATE_VIEW_ACL (1L << 21)
73#define SHOW_VIEW_ACL (1L << 22)
74#define CREATE_PROC_ACL (1L << 23)
75#define ALTER_PROC_ACL (1L << 24)
76#define CREATE_USER_ACL (1L << 25)
77#define EVENT_ACL (1L << 26)
78#define TRIGGER_ACL (1L << 27)
79#define CREATE_TABLESPACE_ACL (1L << 28)
80#define CREATE_ROLE_ACL (1L << 29)
81#define DROP_ROLE_ACL (1L << 30)
82/*
83 don't forget to update
84 1. static struct show_privileges_st sys_privileges[]
85 2. static const char *command_array[] and static uint command_lengths[]
86 3. mysql_system_tables.sql and mysql_system_tables_fix.sql
87 4. acl_init() or whatever - to define behaviour for old privilege tables
88 5. sql_yacc.yy - for GRANT/REVOKE to work
89 6. global_privileges map and vector
90*/
91
92#define NO_ACCESS (1L << 31)
93
94/**
95 Privileges to perform database related operations.
96 Use this macro over DB_ACLS unless there is real need to use
97 additional privileges present in the DB_ACLS
98*/
99#define DB_OP_ACLS \
100 (UPDATE_ACL | SELECT_ACL | INSERT_ACL | DELETE_ACL | CREATE_ACL | DROP_ACL | \
101 REFERENCES_ACL | INDEX_ACL | ALTER_ACL | CREATE_TMP_ACL | LOCK_TABLES_ACL | \
102 EXECUTE_ACL | CREATE_VIEW_ACL | SHOW_VIEW_ACL | CREATE_PROC_ACL | \
103 ALTER_PROC_ACL | EVENT_ACL | TRIGGER_ACL)
104
105/**
106 Privileges to perform table related operations.
107 Use this macro over TABLE_ACLS unless there is real need to use
108 additional privileges present in the DB_ACLS
109*/
110#define TABLE_OP_ACLS \
111 (SELECT_ACL | INSERT_ACL | UPDATE_ACL | DELETE_ACL | CREATE_ACL | DROP_ACL | \
112 REFERENCES_ACL | INDEX_ACL | ALTER_ACL | CREATE_VIEW_ACL | SHOW_VIEW_ACL | \
113 TRIGGER_ACL)
114
115/**
116 Privileges to modify or execute stored procedures.
117 Use this macro over PROC_ACLS unless there is real need to use
118 additional privileges present in the PROC_ACLS
119*/
120#define PROC_OP_ACLS (ALTER_PROC_ACL | EXECUTE_ACL)
121
122/**
123 Represents all privileges which could be granted to users at DB-level. It
124 essentially represents all the privileges present in the mysql.db table.
125*/
126#define DB_ACLS (DB_OP_ACLS | GRANT_ACL)
127
128/**
129 Represents all privileges which could be granted to users at table-level. It
130 essentially represents all the privileges present in the mysql.tables_priv
131 table.
132*/
133#define TABLE_ACLS (TABLE_OP_ACLS | GRANT_ACL)
134
135/**
136 Represents all privileges which could be granted to users at column-level. It
137 essentially represents all the privileges present in the columns_priv table.
138*/
139#define COL_ACLS (SELECT_ACL | INSERT_ACL | UPDATE_ACL | REFERENCES_ACL)
140
141/**
142 Represents all privileges which could be granted to users for stored
143 procedures. It essentially represents all the privileges present in the
144 mysql.procs_priv table.
145*/
146#define PROC_ACLS (PROC_OP_ACLS | GRANT_ACL)
147
148/**
149 Represents all privileges which are required to show the stored procedure.
150*/
151#define SHOW_PROC_ACLS (PROC_OP_ACLS | CREATE_PROC_ACL)
152
153/**
154 Represents all privileges which could be granted to users globally.
155 It essentially represents all the privileges present in the mysql.user table
156*/
157#define GLOBAL_ACLS \
158 (SELECT_ACL | INSERT_ACL | UPDATE_ACL | DELETE_ACL | CREATE_ACL | DROP_ACL | \
159 RELOAD_ACL | SHUTDOWN_ACL | PROCESS_ACL | FILE_ACL | GRANT_ACL | \
160 REFERENCES_ACL | INDEX_ACL | ALTER_ACL | SHOW_DB_ACL | SUPER_ACL | \
161 CREATE_TMP_ACL | LOCK_TABLES_ACL | REPL_SLAVE_ACL | REPL_CLIENT_ACL | \
162 EXECUTE_ACL | CREATE_VIEW_ACL | SHOW_VIEW_ACL | CREATE_PROC_ACL | \
163 ALTER_PROC_ACL | CREATE_USER_ACL | EVENT_ACL | TRIGGER_ACL | \
164 CREATE_TABLESPACE_ACL | CREATE_ROLE_ACL | DROP_ROLE_ACL)
165
166#define DEFAULT_CREATE_PROC_ACLS (ALTER_PROC_ACL | EXECUTE_ACL)
167
168/**
169 Table-level privileges which are automatically "granted" to everyone on
170 existing temporary tables (CREATE_ACL is necessary for ALTER ... RENAME).
171*/
172#define TMP_TABLE_ACLS \
173 (SELECT_ACL | INSERT_ACL | UPDATE_ACL | DELETE_ACL | CREATE_ACL | DROP_ACL | \
174 INDEX_ACL | ALTER_ACL)
175
176/*
177 Defines to change the above bits to how things are stored in tables
178 This is needed as the 'host' and 'db' table is missing a few privileges
179*/
180
181/* Privileges that need to be reallocated (in continuous chunks) */
182#define DB_CHUNK0 \
183 (SELECT_ACL | INSERT_ACL | UPDATE_ACL | DELETE_ACL | CREATE_ACL | DROP_ACL)
184#define DB_CHUNK1 (GRANT_ACL | REFERENCES_ACL | INDEX_ACL | ALTER_ACL)
185#define DB_CHUNK2 (CREATE_TMP_ACL | LOCK_TABLES_ACL)
186#define DB_CHUNK3 \
187 (CREATE_VIEW_ACL | SHOW_VIEW_ACL | CREATE_PROC_ACL | ALTER_PROC_ACL)
188#define DB_CHUNK4 (EXECUTE_ACL)
189#define DB_CHUNK5 (EVENT_ACL | TRIGGER_ACL)
190
191#define fix_rights_for_db(A) \
192 (((A)&DB_CHUNK0) | (((A) << 4) & DB_CHUNK1) | (((A) << 6) & DB_CHUNK2) | \
193 (((A) << 9) & DB_CHUNK3) | (((A) << 2) & DB_CHUNK4)) | \
194 (((A) << 9) & DB_CHUNK5)
195#define get_rights_for_db(A) \
196 (((A)&DB_CHUNK0) | (((A)&DB_CHUNK1) >> 4) | (((A)&DB_CHUNK2) >> 6) | \
197 (((A)&DB_CHUNK3) >> 9) | (((A)&DB_CHUNK4) >> 2)) | \
198 (((A)&DB_CHUNK5) >> 9)
199#define TBL_CHUNK0 DB_CHUNK0
200#define TBL_CHUNK1 DB_CHUNK1
201#define TBL_CHUNK2 (CREATE_VIEW_ACL | SHOW_VIEW_ACL)
202#define TBL_CHUNK3 TRIGGER_ACL
203#define fix_rights_for_table(A) \
204 (((A)&TBL_CHUNK0) | (((A) << 4) & TBL_CHUNK1) | (((A) << 11) & TBL_CHUNK2) | \
205 (((A) << 15) & TBL_CHUNK3))
206#define get_rights_for_table(A) \
207 (((A)&TBL_CHUNK0) | (((A)&TBL_CHUNK1) >> 4) | (((A)&TBL_CHUNK2) >> 11) | \
208 (((A)&TBL_CHUNK3) >> 15))
209#define fix_rights_for_column(A) (((A)&7) | (((A) & ~7) << 8))
210#define get_rights_for_column(A) (((A)&7) | ((A) >> 8))
211#define fix_rights_for_procedure(A) \
212 ((((A) << 18) & EXECUTE_ACL) | (((A) << 23) & ALTER_PROC_ACL) | \
213 (((A) << 8) & GRANT_ACL))
214#define get_rights_for_procedure(A) \
215 ((((A)&EXECUTE_ACL) >> 18) | (((A)&ALTER_PROC_ACL) >> 23) | \
216 (((A)&GRANT_ACL) >> 8))
217
218extern const std::vector<std::string> global_acls_vector;
219extern const std::unordered_map<std::string, int> global_acls_map;
220
221#endif /* AUTH_ACLS_INCLUDED */
const std::unordered_map< std::string, int > global_acls_map
Bitmap offsets for static privileges.
Definition: auth_acls.cc:96
const std::vector< std::string > global_acls_vector
Consts for static privileges.
Definition: auth_acls.cc:62