MySQL 8.3.0
Source Code Documentation
acl_table_user.h
Go to the documentation of this file.
1/* Copyright (c) 2018, 2023, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is also distributed with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have included with MySQL.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License, version 2.0, for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef ACL_TABLE_USER_INCLUDED
24#define ACL_TABLE_USER_INCLUDED
25
26#include "my_config.h"
27
28#ifdef HAVE_SYS_TIME_H
29#include <sys/time.h>
30#endif
31
32#include <sys/types.h>
33#include <functional>
34#include <memory>
35#include <string>
36#include <utility>
37
38#include "my_alloc.h"
39#include "sql-common/json_dom.h"
42#include "sql/auth/sql_mfa.h" /* I_multi_factor_auth */
43#include "sql/auth/user_table.h"
44
45class ACL_USER;
46class RowIterator;
47class THD;
49struct LEX_USER;
50struct TABLE;
51
52namespace acl_table {
58 COMMENT,
60};
61
63 /**
64 read from the user config. The number of days to keep the account locked
65 */
67 /**
68 read from the user config. The number of failed login attempts before the
69 account is locked
70 */
72
74
76
78
79 Password_lock(const Password_lock &other);
80
82};
83
84/**
85 Class to handle information stored in mysql.user.user_attributes
86*/
88 public:
89 /**
90 Default constructor.
91 */
92 Acl_user_attributes(MEM_ROOT *mem_root, bool read_restrictions,
93 Auth_id &auth_id, ulong global_privs);
94
95 Acl_user_attributes(MEM_ROOT *mem_root, bool read_restrictions,
98
100
101 public:
102 /**
103 Obtain info from JSON representation of user attributes
104
105 @param [in] json_object JSON object that holds user attributes
106
107 @returns status of parsing json_object
108 @retval false Success
109 @retval true Error parsing the JSON object
110 */
111 bool deserialize(const Json_object &json_object);
112
113 /**
114 Create JSON object from user attributes
115
116 @param [out] json_object Object to store serialized user attributes
117
118 @returns status of serialization
119 @retval false Success
120 @retval true Error serializing user attributes
121 */
122 bool serialize(Json_object &json_object) const;
123
124 /**
125 Update second password for user. We replace existing one if any.
126
127 @param [in] credential Second password
128
129 @returns status of password update
130 @retval false Success
131 @retval true Error. Second password is empty
132 */
133 bool update_additional_password(std::string &credential);
134
135 /**
136 Discard second password.
137 */
139
140 /**
141 Get second password
142
143 @returns second password
144 */
145 const std::string get_additional_password() const;
146
147 /**
148 Get the restriction list for the user
149
150 @returns Restriction list
151 */
153
154 void update_restrictions(const Restrictions &restricitions);
155
158 }
161 }
162 auto get_password_lock() const { return m_password_lock; }
163 void set_password_lock(Password_lock password_lock) {
164 m_password_lock = password_lock;
165 }
166
168 void set_mfa(I_multi_factor_auth *mfa) { m_mfa = mfa; }
169
170 /**
171 Take over ownership of the json pointer.
172 @return Error state
173 @retval true An error occurred
174 @retval false Success
175 */
177
178 private:
180 DB_restrictions &db_restrictions, ulong mask, enum loglevel level,
181 ulonglong errcode);
182 bool deserialize_password_lock(const Json_object &json_object);
183 bool deserialize_multi_factor(const Json_object &json_object);
184
185 private:
186 /** Mem root */
188 /** Operation for restrictions */
190 /** Auth ID */
192 /** Second password for user */
194 /** Restrictions_list on certain databases for user */
196 /** Global static privileges */
198 /** password locking */
200 /** multi factor auth info */
202 /** Save the original json object */
204};
205
206// Forward and alias declarations
208 std::pair<Table_op_error_code, struct timeval>;
209
210/**
211 mysql.user table writer. It updates or drop a one single row from the table.
212*/
213
215 public:
218 my_timeval pwd_timestamp, std::string cred,
222 updated_rights(rights),
223 error(err),
224 password_change_timestamp(pwd_timestamp),
225 second_cred(cred),
226 restrictions(),
229
234 std::string second_cred;
238};
239
241 public:
242 Acl_table_user_writer(THD *thd, TABLE *table, LEX_USER *combo, ulong rights,
243 bool revoke_grant, bool can_create_user,
244 Pod_user_what_to_update what_to_update,
245 Restrictions *restrictions, I_multi_factor_auth *mfa);
246 ~Acl_table_user_writer() override;
249
250 bool setup_table(int &error, bool &builtin_password);
251
252 /* Set of functions to set user table data */
262 bool update_user_attributes(std::string &current_password,
263 Acl_table_user_writer_status &return_value);
264
266 std::function<bool(TABLE *table)> const &update);
267 ulong get_user_privileges();
268 std::string get_current_credentials();
269
270 private:
272 bool write_user_attributes_column(const Acl_user_attributes &user_attributes);
275 ulong m_rights;
283};
284
285/**
286 mysql.user table reader. It reads all raws from table and create in-memory
287 cache.
288*/
289
291 public:
293 ~Acl_table_user_reader() override;
294 bool driver();
295 bool setup_table(bool &is_old_db_layout);
296 bool read_row(bool &is_old_db_layout, bool &super_users_with_empty_plugin);
298
299 /* Set of function to read user table data */
306 bool read_plugin_info(ACL_USER &user, bool &super_users_with_empty_plugin,
307 bool &is_old_db_layout);
308 bool read_password_expiry(ACL_USER &user, bool &password_expired);
317
318 private:
324};
325
326} // namespace acl_table
327#endif /* ACL_TABLE_USER_INCLUDED */
Definition: sql_auth_cache.h:245
Storage container for default auth ids.
Definition: auth_common.h:1065
DB Restrictions representation in memory.
Definition: partial_revokes.h:81
An interface to access information about Multi factor authentication methods.
Definition: sql_mfa.h:47
Represents a JSON container value of type "object" (ECMA), type J_OBJECT here.
Definition: json_dom.h:367
Container of all restrictions for a given user.
Definition: partial_revokes.h:154
A context for reading through a single table using a chosen access method: index read,...
Definition: row_iterator.h:81
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:35
Definition: auth_common.h:373
mysql.user table reader.
Definition: acl_table_user.h:290
void read_password_last_changed(ACL_USER &user)
Get password change time.
Definition: acl_table_user.cc:1771
Restrictions * m_restrictions
Definition: acl_table_user.h:322
void read_password_reuse_time_fields(ACL_USER &user)
Get password reuse time restriction.
Definition: acl_table_user.cc:1838
void read_user_resources(ACL_USER &user)
Read user resource restrictions.
Definition: acl_table_user.cc:1587
void add_row_to_acl_users(ACL_USER &user)
Add a recently read row in acl_users.
Definition: acl_table_user.cc:1955
bool setup_table(bool &is_old_db_layout)
Make table ready to read.
Definition: acl_table_user.cc:1380
bool read_row(bool &is_old_db_layout, bool &super_users_with_empty_plugin)
Read a row from mysql.user table and add it to in-memory structure.
Definition: acl_table_user.cc:2009
bool read_plugin_info(ACL_USER &user, bool &super_users_with_empty_plugin, bool &is_old_db_layout)
Read plugin information.
Definition: acl_table_user.cc:1627
void read_privileges(ACL_USER &user)
Get global privilege information.
Definition: acl_table_user.cc:1480
void read_password_require_current(ACL_USER &user)
Get information about requiring current password while changing password.
Definition: acl_table_user.cc:1858
bool driver()
Driver function for mysql.user reader.
Definition: acl_table_user.cc:2050
void read_password_locked(ACL_USER &user)
Determine if user account is locked.
Definition: acl_table_user.cc:1755
bool read_user_attributes(ACL_USER &user)
Read user attributes.
Definition: acl_table_user.cc:1882
MEM_ROOT m_mem_root
Definition: acl_table_user.h:321
void reset_acl_user(ACL_USER &user)
Scrub ACL_USER.
Definition: acl_table_user.cc:1406
void read_ssl_fields(ACL_USER &user)
Read SSL restrictions.
Definition: acl_table_user.cc:1557
bool read_password_expiry(ACL_USER &user, bool &password_expired)
Read password expiry field.
Definition: acl_table_user.cc:1730
User_table_schema * m_table_schema
Definition: acl_table_user.h:319
bool read_authentication_string(ACL_USER &user)
Read authentication string for the account.
Definition: acl_table_user.cc:1455
Acl_table_user_reader(THD *thd, TABLE *table)
mysql.user table reader constructor.
Definition: acl_table_user.cc:1343
void read_account_name(ACL_USER &user)
Get user and host information for the account.
Definition: acl_table_user.cc:1431
Acl_table_op_status finish_operation(Table_op_error_code &error) override
Finish mysql.user table read operation.
Definition: acl_table_user.cc:1362
~Acl_table_user_reader() override
Free resources before we destroy.
Definition: acl_table_user.cc:1350
Json_object * m_user_application_user_metadata_json
Definition: acl_table_user.h:323
void read_password_lifetime(ACL_USER &user)
Get password expiry policy infomration.
Definition: acl_table_user.cc:1799
void read_password_history_fields(ACL_USER &user)
Get password history restriction.
Definition: acl_table_user.cc:1817
unique_ptr_destroy_only< RowIterator > m_iterator
Definition: acl_table_user.h:320
mysql.user table writer.
Definition: acl_table_user.h:214
std::string second_cred
Definition: acl_table_user.h:234
Restrictions restrictions
Definition: acl_table_user.h:235
ulong updated_rights
Definition: acl_table_user.h:231
my_timeval password_change_timestamp
Definition: acl_table_user.h:233
Password_lock password_lock
Definition: acl_table_user.h:236
Acl_table_user_writer_status(bool skip, ulong rights, Table_op_error_code err, my_timeval pwd_timestamp, std::string cred, Password_lock &password_lock, I_multi_factor_auth *multi_factor)
Definition: acl_table_user.h:217
Table_op_error_code error
Definition: acl_table_user.h:232
I_multi_factor_auth * multi_factor
Definition: acl_table_user.h:237
Acl_table_user_writer_status()
Definition: acl_table_user.cc:436
bool skip_cache_update
Definition: acl_table_user.h:230
Definition: acl_table_user.h:240
std::function< bool(TABLE *table)> m_user_application_user_metadata
Definition: acl_table_user.h:282
bool update_password_reuse()
Password reuse time updates.
Definition: acl_table_user.cc:1114
bool write_user_attributes_column(const Acl_user_attributes &user_attributes)
Helper function to write updated user_attributes in the column.
Definition: acl_table_user.cc:1279
bool update_privileges(Acl_table_user_writer_status &return_value)
Update global privileges for user.
Definition: acl_table_user.cc:854
Acl_table_user_writer(THD *thd, TABLE *table, LEX_USER *combo, ulong rights, bool revoke_grant, bool can_create_user, Pod_user_what_to_update what_to_update, Restrictions *restrictions, I_multi_factor_auth *mfa)
mysql.user table writer constructor
Definition: acl_table_user.cc:462
I_multi_factor_auth * m_mfa
Definition: acl_table_user.h:281
bool update_user_attributes(std::string &current_password, Acl_table_user_writer_status &return_value)
User_attributes updates.
Definition: acl_table_user.cc:1183
LEX_USER * m_combo
Definition: acl_table_user.h:274
bool update_password_expiry()
Update password expiration info.
Definition: acl_table_user.cc:1010
Acl_table_op_status finish_operation(Table_op_error_code &error) override
Finish the operation.
Definition: acl_table_user.cc:724
bool m_revoke_grant
Definition: acl_table_user.h:276
User_table_schema * m_table_schema
Definition: acl_table_user.h:279
bool update_password_history()
Password history updates.
Definition: acl_table_user.cc:1083
bool update_ssl_properties()
Update SSL properties.
Definition: acl_table_user.cc:901
Pod_user_what_to_update m_what_to_update
Definition: acl_table_user.h:278
~Acl_table_user_writer() override
Cleanup.
Definition: acl_table_user.cc:483
bool update_authentication_info(Acl_table_user_writer_status &return_value)
Update user's authentication information.
Definition: acl_table_user.cc:790
bool update_password_require_current()
Whether current password is required to update existing one.
Definition: acl_table_user.cc:1143
Acl_table_user_writer_status driver()
Perform add/update to mysql.user table.
Definition: acl_table_user.cc:493
bool update_user_application_user_metadata()
Helper function for updating the user metadata JSON.
Definition: acl_table_user.cc:1271
std::string get_current_credentials()
Get current password from mysql.user.authentication_string.
Definition: acl_table_user.cc:1328
bool m_can_create_user
Definition: acl_table_user.h:277
ulong m_rights
Definition: acl_table_user.h:275
ulong get_user_privileges()
Helper function to get global privileges from mysql.user table.
Definition: acl_table_user.cc:1302
bool update_account_locking()
Update account locking info.
Definition: acl_table_user.cc:1051
void replace_user_application_user_metadata(std::function< bool(TABLE *table)> const &update)
Send the function for updating the user metadata JSON code to the table processor.
Definition: acl_table_user.cc:1262
bool m_has_user_application_user_metadata
Definition: acl_table_user.h:273
Restrictions * m_restrictions
Definition: acl_table_user.h:280
bool setup_table(int &error, bool &builtin_password)
Position user table.
Definition: acl_table_user.cc:578
bool update_user_resources()
Update user resource restrictions.
Definition: acl_table_user.cc:978
Base class to handle ACL table manipulation.
Definition: acl_table_base.h:43
Class to handle information stored in mysql.user.user_attributes.
Definition: acl_table_user.h:87
bool deserialize_password_lock(const Json_object &json_object)
Definition: acl_table_user.cc:238
bool deserialize(const Json_object &json_object)
Obtain info from JSON representation of user attributes.
Definition: acl_table_user.cc:284
bool serialize(Json_object &json_object) const
Create JSON object from user attributes.
Definition: acl_table_user.cc:319
Password_lock m_password_lock
password locking
Definition: acl_table_user.h:199
void update_restrictions(const Restrictions &restricitions)
Definition: acl_table_user.cc:398
void set_mfa(I_multi_factor_auth *mfa)
Definition: acl_table_user.h:168
Auth_id m_auth_id
Auth ID.
Definition: acl_table_user.h:191
bool consume_user_attributes_json(Json_dom_ptr json)
Take over ownership of the json pointer.
Definition: acl_table_user.cc:158
bool update_additional_password(std::string &credential)
Update second password for user.
Definition: acl_table_user.cc:377
I_multi_factor_auth * m_mfa
multi factor auth info
Definition: acl_table_user.h:201
Json_dom_ptr m_user_attributes_json
Save the original json object.
Definition: acl_table_user.h:203
void set_password_lock(Password_lock password_lock)
Definition: acl_table_user.h:163
void report_and_remove_invalid_db_restrictions(DB_restrictions &db_restrictions, ulong mask, enum loglevel level, ulonglong errcode)
Definition: acl_table_user.cc:177
ulong m_global_privs
Global static privileges.
Definition: acl_table_user.h:197
MEM_ROOT * m_mem_root
Mem root.
Definition: acl_table_user.h:187
auto get_failed_login_attempts() const
Definition: acl_table_user.h:156
Restrictions m_restrictions
Restrictions_list on certain databases for user.
Definition: acl_table_user.h:195
Restrictions get_restrictions() const
Get the restriction list for the user.
Definition: acl_table_user.cc:394
const std::string get_additional_password() const
Get second password.
Definition: acl_table_user.cc:390
auto get_password_lock_time_days() const
Definition: acl_table_user.h:159
~Acl_user_attributes()
Definition: acl_table_user.cc:156
bool m_read_restrictions
Operation for restrictions.
Definition: acl_table_user.h:189
Acl_user_attributes(MEM_ROOT *mem_root, bool read_restrictions, Auth_id &auth_id, ulong global_privs)
Default constructor.
Definition: acl_table_user.cc:133
auto get_password_lock() const
Definition: acl_table_user.h:162
std::string m_additional_password
Second password for user.
Definition: acl_table_user.h:193
bool deserialize_multi_factor(const Json_object &json_object)
Definition: acl_table_user.cc:215
void discard_additional_password()
Discard second password.
Definition: acl_table_user.cc:386
I_multi_factor_auth * get_mfa()
Definition: acl_table_user.h:167
Definition: user_table.h:46
static MEM_ROOT mem_root
Definition: client_plugin.cc:113
JSON DOM.
std::unique_ptr< Json_dom > Json_dom_ptr
Definition: json_dom.h:63
static mi_bit_type mask[]
Definition: mi_packrec.cc:140
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
std::unique_ptr< T, Destroy_only< T > > unique_ptr_destroy_only
std::unique_ptr, but only destroying.
Definition: my_alloc.h:476
unsigned long long int ulonglong
Definition: my_inttypes.h:55
loglevel
Definition: my_loglevel.h:40
static uint update
Definition: myisamlog.cc:93
char * user
Definition: mysqladmin.cc:64
Definition: acl_table_base.h:32
int Table_op_error_code
Definition: acl_table_base.h:34
Acl_table_op_status
Definition: acl_table_base.h:36
User_attribute_type
Definition: acl_table_user.h:53
std::pair< Table_op_error_code, struct timeval > acl_table_user_writer_status
Definition: acl_table_user.h:208
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
static Value err()
Create a Value object that represents an error condition.
Definition: json_binary.cc:926
static size_t skip(size_t pos_start, size_t match_len)
Definition: uri.cc:81
constexpr const size_t ACL_ALLOC_BLOCK_SIZE
Definition: sql_const.h:147
Definition: table.h:2720
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:82
Definition: table.h:1403
Definition: acl_table_user.h:62
int password_lock_time_days
read from the user config.
Definition: acl_table_user.h:66
Password_lock()
Definition: acl_table_user.cc:2074
Password_lock & operator=(const Password_lock &other)
Definition: acl_table_user.cc:2077
uint failed_login_attempts
read from the user config.
Definition: acl_table_user.h:71
Replacement of system's struct timeval to ensure we can carry 64 bit values even on a platform which ...
Definition: my_time_t.h:44
Include file for Sun RPC to compile out of the box.
#define PSI_NOT_INSTRUMENTED
Definition: validate_password_imp.cc:41