MySQL  8.0.22
Source Code Documentation
client_async_authentication.h
Go to the documentation of this file.
1 /* Copyright (c) 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 
23 #include <openssl/ossl_typ.h>
25 #include "mysql_async.h"
26 
27 /* this is a "superset" of MYSQL_PLUGIN_VIO, in C++ I use inheritance */
28 struct MCPVIO_EXT {
30  int (*write_packet)(MYSQL_PLUGIN_VIO *vio, const uchar *pkt, int pkt_len);
33  unsigned char **buf, int *result);
35  const unsigned char *pkt,
36  int pkt_len, int *result);
37 
38  /* -= end of MYSQL_PLUGIN_VIO =- */
40  auth_plugin_t *plugin; /**< what plugin we're under */
41  const char *db;
42  struct {
43  uchar *pkt; /**< pointer into NET::buff */
46  int packets_read, packets_written; /**< counters for send/received packets */
47  int mysql_change_user; /**< if it's mysql_change_user() */
48  int last_read_packet_len; /**< the length of the last *read* packet */
49 };
50 
51 /* Our state machines have four simple return codes: */
53  STATE_MACHINE_FAILED, /* Completion with a failure. */
54  STATE_MACHINE_CONTINUE, /* Keep calling the state machine. */
55  STATE_MACHINE_WOULD_BLOCK, /* Needs to block to continue. */
56  STATE_MACHINE_DONE /* Completion with a success. */
57 };
58 
59 /* state machine for native password autheintication API */
63 };
64 
71 };
72 
81 };
82 
83 /* A state machine for authentication itself. */
84 struct mysql_async_auth;
86 
90 
91  char *data;
93  const char *data_plugin;
94  const char *db;
95 
96  const char *auth_plugin_name;
99  ulong pkt_length;
100  int res;
101 
104 
107 };
108 
109 /*
110  Connection is handled with a state machine. Each state is
111  represented by a function pointer (csm_function) which returns
112  a mysql_state_machine_status to indicate the state of the
113  connection.
114  This state machine has boundaries around network IO to allow
115  reuse between blocking and non-blocking clients.
116 */
117 struct mysql_async_connect;
119 
120 /*
121  define different states of an asynchronous SSL connection phase
122 */
124  SSL_REQUEST = 8100,
125  SSL_CONNECT = 8101,
126  SSL_COMPLETE = 8102,
127  SSL_NONE = 8103
128 };
129 
130 /*
131  Struct to track the state of a connection being established. Once
132  the connection is established, the context should be discarded and
133  relevant values copied out of it.
134 */
136  /* state for the overall connection process */
138  const char *host;
139  const char *user;
140  const char *passwd;
141  const char *db;
143  const char *unix_socket;
144  ulong client_flag;
146 
147  ulong pkt_length;
148  char *host_info;
149  char buff[NAME_LEN + USERNAME_LENGTH + 100];
152  const char *scramble_plugin;
155 
156  /* context needed to establish asynchronous authentication */
158  /* state for running init_commands */
161 
164  /* state function that will be called next */
166 };
int(* write_packet)(MYSQL_PLUGIN_VIO *vio, const uchar *pkt, int pkt_len)
Definition: client_async_authentication.h:30
const char * db
Definition: client_async_authentication.h:41
client_auth_caching_sha2_password_plugin_status
Definition: client_async_authentication.h:73
Definition: client_async_authentication.h:54
#define USERNAME_LENGTH
Definition: mysql_com.h:69
unsigned char uchar
Definition: my_inttypes.h:51
Definition: client_async_authentication.h:124
uint port
Definition: client_async_authentication.h:142
int packets_written
counters for send/received packets
Definition: client_async_authentication.h:46
const char * user
Definition: client_async_authentication.h:139
client_auth_sha256_password_plugin_status
Definition: client_async_authentication.h:65
bool scramble_buffer_allocated
Definition: client_async_authentication.h:154
struct result result
Definition: result.h:33
MCPVIO_EXT mpvio
Definition: client_async_authentication.h:98
Definition: client_async_authentication.h:76
MYSQL * mysql
Definition: client_async_authentication.h:137
static constexpr Flags SSL(1<< 11)
const char * scramble_plugin
Definition: client_async_authentication.h:152
Definition: client_async_authentication.h:66
Definition: client_async_authentication.h:75
char * host_info
Definition: client_async_authentication.h:148
void(* info)(MYSQL_PLUGIN_VIO *vio, MYSQL_PLUGIN_VIO_INFO *info)
Definition: client_async_authentication.h:31
char ** current_init_command
Definition: client_async_authentication.h:160
#define NAME_LEN
Definition: mysql_com.h:67
bool saved_reconnect
Definition: client_async_authentication.h:159
Definition: buf0block_hint.cc:29
net_async_status
Definition: plugin_auth_common.h:130
const char * passwd
Definition: client_async_authentication.h:140
Declarations for asynchronous client communication.
Definition: client_async_authentication.h:127
mysql_state_machine_status(* csm_function)(mysql_async_connect *)
Definition: client_async_authentication.h:118
Definition: client_async_authentication.h:67
net_async_status(* read_packet_nonblocking)(struct MYSQL_PLUGIN_VIO *vio, unsigned char **buf, int *result)
Definition: client_async_authentication.h:32
Definition: client_async_authentication.h:80
char * data
Definition: client_async_authentication.h:91
ssl_exchange_state
Definition: client_async_authentication.h:123
Definition: client_async_authentication.h:28
auth_plugin_t * auth_plugin
Definition: client_async_authentication.h:97
uint pkt_len
Definition: client_async_authentication.h:44
char * scramble_buffer
Definition: client_async_authentication.h:153
Definition: client_async_authentication.h:87
ulong client_flag
Definition: client_async_authentication.h:144
struct MCPVIO_EXT::@168 cached_server_reply
Definition: client_async_authentication.h:56
Definition: client_async_authentication.h:77
MYSQL * mysql
Definition: client_async_authentication.h:88
uint data_len
Definition: client_async_authentication.h:92
Definition: client_async_authentication.h:68
const char * unix_socket
Definition: client_async_authentication.h:143
unsigned int uint
Definition: uca-dump.cc:29
struct mysql_async_auth * auth_context
Definition: client_async_authentication.h:157
const char * db
Definition: client_async_authentication.h:94
auth_plugin_t * plugin
what plugin we&#39;re under
Definition: client_async_authentication.h:40
Definition: client_async_authentication.h:74
ulong pkt_length
Definition: client_async_authentication.h:99
const char * auth_plugin_name
Definition: client_async_authentication.h:96
mysql_state_machine_status
Definition: client_async_authentication.h:52
int last_read_packet_len
the length of the last read packet
Definition: client_async_authentication.h:48
Definition: client_async_authentication.h:61
This file defines constants and data structures that are the same for both client- and server-side au...
Definition: client_async_authentication.h:126
int change_user_buff_len
Definition: client_async_authentication.h:103
bool non_blocking
Definition: client_async_authentication.h:89
SSL * ssl
Definition: client_async_authentication.h:163
const char * db
Definition: client_async_authentication.h:141
MYSQL * mysql
Definition: client_async_authentication.h:39
Definition: plugin_auth_common.h:115
Definition: client_async_authentication.h:53
int(* read_packet)(MYSQL_PLUGIN_VIO *vio, uchar **buf)
Definition: client_async_authentication.h:29
int mysql_change_user
if it&#39;s mysql_change_user()
Definition: client_async_authentication.h:47
Definition: client_plugin.h:115
csm_function state_function
Definition: client_async_authentication.h:165
int scramble_data_len
Definition: client_async_authentication.h:150
Definition: client_async_authentication.h:69
mysql_state_machine_status(* authsm_function)(mysql_async_auth *)
Definition: client_async_authentication.h:85
client_auth_native_password_plugin_status
Definition: client_async_authentication.h:60
bool non_blocking
Definition: client_async_authentication.h:145
int packets_read
Definition: client_async_authentication.h:46
authsm_function state_function
Definition: client_async_authentication.h:106
Definition: client_async_authentication.h:79
const char * data_plugin
Definition: client_async_authentication.h:93
ulong pkt_length
Definition: client_async_authentication.h:147
Definition: client_async_authentication.h:125
Definition: client_async_authentication.h:135
Definition: client_async_authentication.h:62
Provides plugin access to communication channel.
Definition: plugin_auth_common.h:140
net_async_status(* write_packet_nonblocking)(struct MYSQL_PLUGIN_VIO *vio, const unsigned char *pkt, int pkt_len, int *result)
Definition: client_async_authentication.h:34
uchar * pkt
pointer into NET::buff
Definition: client_async_authentication.h:43
Definition: mysql.h:296
Definition: client_async_authentication.h:70
Definition: client_async_authentication.h:78
int res
Definition: client_async_authentication.h:100
const char * host
Definition: client_async_authentication.h:138
ssl_exchange_state ssl_state
Definition: client_async_authentication.h:162
char * scramble_data
Definition: client_async_authentication.h:151
char * change_user_buff
Definition: client_async_authentication.h:102
Definition: client_async_authentication.h:55
int client_auth_plugin_state
Definition: client_async_authentication.h:105