MySQL  8.0.21
Source Code Documentation
plugin_auth_common.h
Go to the documentation of this file.
1 #ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
2 /* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License, version 2.0,
6  as published by the Free Software Foundation.
7 
8  This program is also distributed with certain software (including
9  but not limited to OpenSSL) that is licensed under separate terms,
10  as designated in a particular file or component or in included license
11  documentation. The authors of MySQL hereby grant you an additional
12  permission to link the program and your derivative works with the
13  separately licensed software that they have included with MySQL.
14 
15  Without limiting anything contained in the foregoing, this file,
16  which is part of C Driver for MySQL (Connector/C), is also subject to the
17  Universal FOSS Exception, version 1.0, a copy of which can be found at
18  http://oss.oracle.com/licenses/universal-foss-exception.
19 
20  This program is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License, version 2.0, for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with this program; if not, write to the Free Software
27  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
28 
29 /**
30  @file include/mysql/plugin_auth_common.h
31 
32  This file defines constants and data structures that are the same for
33  both client- and server-side authentication plugins.
34 */
35 #define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
36 
37 /** the max allowed length for a user name */
38 #define MYSQL_USERNAME_LENGTH 96
39 
40 /**
41  return values of the plugin authenticate_user() method.
42 */
43 
44 /**
45  Authentication failed, plugin internal error.
46  An error occurred in the authentication plugin itself.
47  These errors are reported in table performance_schema.host_cache,
48  column COUNT_AUTH_PLUGIN_ERRORS.
49 */
50 #define CR_AUTH_PLUGIN_ERROR 3
51 /**
52  Authentication failed, client server handshake.
53  An error occurred during the client server handshake.
54  These errors are reported in table performance_schema.host_cache,
55  column COUNT_HANDSHAKE_ERRORS.
56 */
57 #define CR_AUTH_HANDSHAKE 2
58 /**
59  Authentication failed, user credentials.
60  For example, wrong passwords.
61  These errors are reported in table performance_schema.host_cache,
62  column COUNT_AUTHENTICATION_ERRORS.
63 */
64 #define CR_AUTH_USER_CREDENTIALS 1
65 /**
66  Authentication failed. Additionally, all other CR_xxx values
67  (libmysql error code) can be used too.
68 
69  The client plugin may set the error code and the error message directly
70  in the MYSQL structure and return CR_ERROR. If a CR_xxx specific error
71  code was returned, an error message in the MYSQL structure will be
72  overwritten. If CR_ERROR is returned without setting the error in MYSQL,
73  CR_UNKNOWN_ERROR will be user.
74 */
75 #define CR_ERROR 0
76 /**
77  Authentication (client part) was successful. It does not mean that the
78  authentication as a whole was successful, usually it only means
79  that the client was able to send the user name and the password to the
80  server. If CR_OK is returned, the libmysql reads the next packet expecting
81  it to be one of OK, ERROR, or CHANGE_PLUGIN packets.
82 */
83 #define CR_OK -1
84 /**
85  Authentication was successful.
86  It means that the client has done its part successfully and also that
87  a plugin has read the last packet (one of OK, ERROR, CHANGE_PLUGIN).
88  In this case, libmysql will not read a packet from the server,
89  but it will use the data at mysql->net.read_pos.
90 
91  A plugin may return this value if the number of roundtrips in the
92  authentication protocol is not known in advance, and the client plugin
93  needs to read one packet more to determine if the authentication is finished
94  or not.
95 */
96 #define CR_OK_HANDSHAKE_COMPLETE -2
97 
98 /**
99 Flag to be passed back to server from authentication plugins via
100 authenticated_as when proxy mapping should be done by the server.
101 */
102 #define PROXY_FLAG 0
103 
104 /*
105  We need HANDLE definition if on Windows. Define WIN32_LEAN_AND_MEAN (if
106  not already done) to minimize amount of imported declarations.
107 */
108 #ifdef _WIN32
109 #ifndef WIN32_LEAN_AND_MEAN
110 #define WIN32_LEAN_AND_MEAN
111 #endif
112 #include <windows.h>
113 #endif
114 
116  enum {
122  } protocol;
123  int socket; /**< it's set, if the protocol is SOCKET or TCP */
124 #ifdef _WIN32
125  HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */
126 #endif
127 };
128 
129 /* state of an asynchronous operation */
135 };
136 
137 /**
138  Provides plugin access to communication channel
139 */
140 typedef struct MYSQL_PLUGIN_VIO {
141  /**
142  Plugin provides a pointer reference and this function sets it to the
143  contents of any incoming packet. Returns the packet length, or -1 if
144  the plugin should terminate.
145  */
146  int (*read_packet)(struct MYSQL_PLUGIN_VIO *vio, unsigned char **buf);
147 
148  /**
149  Plugin provides a buffer with data and the length and this
150  function sends it as a packet. Returns 0 on success, 1 on failure.
151  */
152  int (*write_packet)(struct MYSQL_PLUGIN_VIO *vio, const unsigned char *packet,
153  int packet_len);
154 
155  /**
156  Fills in a MYSQL_PLUGIN_VIO_INFO structure, providing the information
157  about the connection.
158  */
159  void (*info)(struct MYSQL_PLUGIN_VIO *vio,
160  struct MYSQL_PLUGIN_VIO_INFO *info);
161 
162  /**
163  Non blocking version of read_packet. This function points buf to starting
164  position of incoming packet. When this function returns NET_ASYNC_NOT_READY
165  plugin should call this function again until all incoming packets are read.
166  If return code is NET_ASYNC_COMPLETE, plugin can do further processing of
167  read packets.
168  */
169  enum net_async_status (*read_packet_nonblocking)(struct MYSQL_PLUGIN_VIO *vio,
170  unsigned char **buf,
171  int *result);
172  /**
173  Non blocking version of write_packet. Sends data available in pkt of length
174  pkt_len to server in asynchrnous way.
175  */
177  struct MYSQL_PLUGIN_VIO *vio, const unsigned char *pkt, int pkt_len,
178  int *result);
179 
181 
182 #endif
void read_packet(socket_t client_socket, uint8_t *data, size_t size, int flags)
Definition: mysql_protocol_utils.cc:121
Definition: plugin_auth_common.h:120
int socket
it&#39;s set, if the protocol is SOCKET or TCP
Definition: plugin_auth_common.h:123
enum net_async_status(* write_packet_nonblocking)(struct MYSQL_PLUGIN_VIO *vio, const unsigned char *pkt, int pkt_len, int *result)
Non blocking version of write_packet.
Definition: plugin_auth_common.h:176
Definition: plugin_auth_common.h:131
void * handle
Definition: engine_loader.c:19
struct result result
Definition: result.h:33
net_async_status
Definition: plugin_auth_common.h:130
Definition: plugin_auth_common.h:132
Definition: plugin_auth_common.h:121
Definition: plugin_auth_common.h:134
int(* write_packet)(struct MYSQL_PLUGIN_VIO *vio, const unsigned char *packet, int packet_len)
Plugin provides a buffer with data and the length and this function sends it as a packet...
Definition: plugin_auth_common.h:152
#define HANDLE
Definition: violite.h:158
struct MYSQL_PLUGIN_VIO MYSQL_PLUGIN_VIO
Provides plugin access to communication channel.
Definition: plugin_auth_common.h:117
Definition: plugin_auth_common.h:115
Definition: plugin_auth_common.h:119
enum MYSQL_PLUGIN_VIO_INFO::@5 protocol
Definition: plugin_auth_common.h:133
Definition: plugin_auth_common.h:118
Log info(cout, "NOTE")
Provides plugin access to communication channel.
Definition: plugin_auth_common.h:140