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