MySQL 9.7.0
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, 2026, Oracle and/or its affiliates.
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 designed to work 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 either included with
14 the program or referenced in the documentation.
15
16 Without limiting anything contained in the foregoing, this file,
17 which is part of C Driver for MySQL (Connector/C), is also subject to the
18 Universal FOSS Exception, version 1.0, a copy of which can be found at
19 http://oss.oracle.com/licenses/universal-foss-exception.
20
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License, version 2.0, for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
29
30/**
31 @file include/mysql/plugin_auth_common.h
32
33 This file defines constants and data structures that are the same for
34 both client- and server-side authentication plugins.
35*/
36#define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
37
38/** the max allowed length for a user name */
39#define MYSQL_USERNAME_LENGTH 96
40
41/**
42 return values of the plugin authenticate_user() method.
43*/
44
45/**
46 Authentication failed, account locked error.
47 The account is locked.
48 These errors are reported in table performance_schema.host_cache,
49 column COUNT_ACCOUNT_LOCKED_ERRORS.
50*/
51#define CR_AUTH_ACCOUNT_LOCKED_ERROR 5
52/**
53 Authentication failed, temporary account locked error.
54 The account is temporarily locked.
55 These errors are reported in table performance_schema.host_cache,
56 column COUNT_TEMPORARY_ACCOUNT_LOCKED_ERRORS.
57*/
58#define CR_AUTH_TEMPORARY_ACCOUNT_LOCKED_ERROR 4
59/**
60 Authentication failed, plugin internal error.
61 An error occurred in the authentication plugin itself.
62 These errors are reported in table performance_schema.host_cache,
63 column COUNT_AUTH_PLUGIN_ERRORS.
64*/
65#define CR_AUTH_PLUGIN_ERROR 3
66/**
67 Authentication failed, client server handshake.
68 An error occurred during the client server handshake.
69 These errors are reported in table performance_schema.host_cache,
70 column COUNT_HANDSHAKE_ERRORS.
71*/
72#define CR_AUTH_HANDSHAKE 2
73/**
74 Authentication failed, user credentials.
75 For example, wrong passwords.
76 These errors are reported in table performance_schema.host_cache,
77 column COUNT_AUTHENTICATION_ERRORS.
78*/
79#define CR_AUTH_USER_CREDENTIALS 1
80/**
81 Authentication failed. Additionally, all other CR_xxx values
82 (libmysql error code) can be used too.
83
84 The client plugin may set the error code and the error message directly
85 in the MYSQL structure and return CR_ERROR. If a CR_xxx specific error
86 code was returned, an error message in the MYSQL structure will be
87 overwritten. If CR_ERROR is returned without setting the error in MYSQL,
88 CR_UNKNOWN_ERROR will be user.
89*/
90#define CR_ERROR 0
91/**
92 Authentication (client part) was successful. It does not mean that the
93 authentication as a whole was successful, usually it only means
94 that the client was able to send the user name and the password to the
95 server. If CR_OK is returned, the libmysql reads the next packet expecting
96 it to be one of OK, ERROR, or CHANGE_PLUGIN packets.
97*/
98#define CR_OK -1
99/**
100 Authentication was successful.
101 It means that the client has done its part successfully and also that
102 a plugin has read the last packet (one of OK, ERROR, CHANGE_PLUGIN).
103 In this case, libmysql will not read a packet from the server,
104 but it will use the data at mysql->net.read_pos.
105
106 A plugin may return this value if the number of roundtrips in the
107 authentication protocol is not known in advance, and the client plugin
108 needs to read one packet more to determine if the authentication is finished
109 or not.
110*/
111#define CR_OK_HANDSHAKE_COMPLETE -2
112/**
113 Authentication was successful with limited operations.
114 It means that the both client and server side plugins decided to allow
115 authentication with very limited operations ALTER USER to do registration.
116*/
117#define CR_OK_AUTH_IN_SANDBOX_MODE -3
118/**
119 Authentication was successful with limited operations.
120 User should change the password.
121*/
122#define CR_OK_FORCE_PASSWORD_CHANGE -4
123
124/**
125Flag to be passed back to server from authentication plugins via
126authenticated_as when proxy mapping should be done by the server.
127*/
128#define PROXY_FLAG 0
129
130/*
131 We need HANDLE definition if on Windows. Define WIN32_LEAN_AND_MEAN (if
132 not already done) to minimize amount of imported declarations.
133*/
134#if defined(_WIN32) && !defined(MYSQL_ABI_CHECK)
135#ifndef WIN32_LEAN_AND_MEAN
136#define WIN32_LEAN_AND_MEAN
137#endif
138#include <windows.h>
139#endif
140
142 enum {
149 int socket; /**< it's set, if the protocol is SOCKET or TCP */
151#if defined(_WIN32) && !defined(MYSQL_ABI_CHECK)
152 HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */
153#endif
154};
155
156/* state of an asynchronous operation */
163
164/**
165 Provides plugin access to communication channel
166*/
167typedef struct MYSQL_PLUGIN_VIO {
168 /**
169 Plugin provides a pointer reference and this function sets it to the
170 contents of any incoming packet. Returns the packet length, or -1 if
171 the plugin should terminate.
172 */
173 int (*read_packet)(struct MYSQL_PLUGIN_VIO *vio, unsigned char **buf);
174
175 /**
176 Plugin provides a buffer with data and the length and this
177 function sends it as a packet. Returns 0 on success, 1 on failure.
178 */
179 int (*write_packet)(struct MYSQL_PLUGIN_VIO *vio, const unsigned char *packet,
180 int packet_len);
181
182 /**
183 Fills in a MYSQL_PLUGIN_VIO_INFO structure, providing the information
184 about the connection.
185 */
186 void (*info)(struct MYSQL_PLUGIN_VIO *vio,
188
189 /**
190 Non blocking version of read_packet. This function points buf to starting
191 position of incoming packet. When this function returns NET_ASYNC_NOT_READY
192 plugin should call this function again until all incoming packets are read.
193 If return code is NET_ASYNC_COMPLETE, plugin can do further processing of
194 read packets.
195 */
197 unsigned char **buf,
198 int *result);
199 /**
200 Non blocking version of write_packet. Sends data available in pkt of length
201 pkt_len to server in asynchronous way.
202 */
204 struct MYSQL_PLUGIN_VIO *vio, const unsigned char *pkt, int pkt_len,
205 int *result);
206
208
209#endif
static char buf[MAX_BUF]
Definition: conf_to_src.cc:74
static int handle(int sql_errno, const char *sqlstate, const char *message, void *state)
Bridge function between the C++ API offered by this module and the C API of the parser service.
Definition: services.cc:64
struct result result
Definition: result.h:34
struct MYSQL_PLUGIN_VIO MYSQL_PLUGIN_VIO
Provides plugin access to communication channel.
net_async_status
Definition: plugin_auth_common.h:157
@ NET_ASYNC_NOT_READY
Definition: plugin_auth_common.h:159
@ NET_ASYNC_COMPLETE_NO_MORE_RESULTS
Definition: plugin_auth_common.h:161
@ NET_ASYNC_ERROR
Definition: plugin_auth_common.h:160
@ NET_ASYNC_COMPLETE
Definition: plugin_auth_common.h:158
Definition: plugin_auth_common.h:141
@ MYSQL_VIO_INVALID
Definition: plugin_auth_common.h:143
@ MYSQL_VIO_TCP
Definition: plugin_auth_common.h:144
@ MYSQL_VIO_PIPE
Definition: plugin_auth_common.h:146
@ MYSQL_VIO_SOCKET
Definition: plugin_auth_common.h:145
@ MYSQL_VIO_MEMORY
Definition: plugin_auth_common.h:147
int socket
it's set, if the protocol is SOCKET or TCP
Definition: plugin_auth_common.h:149
bool is_tls_established
Definition: plugin_auth_common.h:150
enum MYSQL_PLUGIN_VIO_INFO::@6 protocol
Provides plugin access to communication channel.
Definition: plugin_auth_common.h:167
enum net_async_status(* read_packet_nonblocking)(struct MYSQL_PLUGIN_VIO *vio, unsigned char **buf, int *result)
Non blocking version of read_packet.
Definition: plugin_auth_common.h:196
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:179
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:203
void(* info)(struct MYSQL_PLUGIN_VIO *vio, struct MYSQL_PLUGIN_VIO_INFO *info)
Fills in a MYSQL_PLUGIN_VIO_INFO structure, providing the information about the connection.
Definition: plugin_auth_common.h:186
int(* read_packet)(struct MYSQL_PLUGIN_VIO *vio, unsigned char **buf)
Plugin provides a pointer reference and this function sets it to the contents of any incoming packet.
Definition: plugin_auth_common.h:173
#define HANDLE
Definition: violite.h:159