1#ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
2/* Copyright (c) 2010, 2023, 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 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 Authentication was successful with limited operations.
99 It means that the both client and server side plugins decided to allow
100 authentication with very limited operations ALTER USER to do registration.
101*/
102#define CR_OK_AUTH_IN_SANDBOX_MODE -3
103/**
104Flag to be passed back to server from authentication plugins via
105authenticated_as when proxy mapping should be done by the server.
106*/
107#define PROXY_FLAG 0
108
109/*
110 We need HANDLE definition if on Windows. Define WIN32_LEAN_AND_MEAN (if
111 not already done) to minimize amount of imported declarations.
112*/
113#if defined(_WIN32) && !defined(MYSQL_ABI_CHECK)
114#ifndef WIN32_LEAN_AND_MEAN
115#define WIN32_LEAN_AND_MEAN
116#endif
117#include <windows.h>
118#endif
119
120struct MYSQL_PLUGIN_VIO_INFO {
121 enum {
122 MYSQL_VIO_INVALID,
123 MYSQL_VIO_TCP,
124 MYSQL_VIO_SOCKET,
125 MYSQL_VIO_PIPE,
126 MYSQL_VIO_MEMORY
127 } protocol;
128 int socket; /**< it's set, if the protocol is SOCKET or TCP */
129#if defined(_WIN32) && !defined(MYSQL_ABI_CHECK)
130 HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */
131#endif
132};
133
134/* state of an asynchronous operation */
135enum net_async_status {
136 NET_ASYNC_COMPLETE = 0,
137 NET_ASYNC_NOT_READY,
138 NET_ASYNC_ERROR,
139 NET_ASYNC_COMPLETE_NO_MORE_RESULTS
140};
141
142/**
143 Provides plugin access to communication channel
144*/
145typedef struct MYSQL_PLUGIN_VIO {
146 /**
147 Plugin provides a pointer reference and this function sets it to the
148 contents of any incoming packet. Returns the packet length, or -1 if
149 the plugin should terminate.
150 */
151 int (*read_packet)(struct MYSQL_PLUGIN_VIO *vio, unsigned char **buf);
152
153 /**
154 Plugin provides a buffer with data and the length and this
155 function sends it as a packet. Returns 0 on success, 1 on failure.
156 */
157 int (*write_packet)(struct MYSQL_PLUGIN_VIO *vio, const unsigned char *packet,
158 int packet_len);
159
160 /**
161 Fills in a MYSQL_PLUGIN_VIO_INFO structure, providing the information
162 about the connection.
163 */
164 void (*info)(struct MYSQL_PLUGIN_VIO *vio,
165 struct MYSQL_PLUGIN_VIO_INFO *info);
166
167 /**
168 Non blocking version of read_packet. This function points buf to starting
169 position of incoming packet. When this function returns NET_ASYNC_NOT_READY
170 plugin should call this function again until all incoming packets are read.
171 If return code is NET_ASYNC_COMPLETE, plugin can do further processing of
172 read packets.
173 */
174 enum net_async_status (*read_packet_nonblocking)(struct MYSQL_PLUGIN_VIO *vio,
175 unsigned char **buf,
176 int *result);
177 /**
178 Non blocking version of write_packet. Sends data available in pkt of length
179 pkt_len to server in asynchronous way.
180 */
181 enum net_async_status (*write_packet_nonblocking)(
182 struct MYSQL_PLUGIN_VIO *vio, const unsigned char *pkt, int pkt_len,
183 int *result);
184
185} MYSQL_PLUGIN_VIO;
186
187#endif
188

source code of include/mysql/plugin_auth_common.h