1 #ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
2 /* Copyright (c) 2010, 2012, 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    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License, version 2.0, for more details.
19 
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
23 
24 /**
25   @file
26 
27   This file defines constants and data structures that are the same for
28   both client- and server-side authentication plugins.
29 */
30 #define MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
31 
32 /** the max allowed length for a user name */
33 #define MYSQL_USERNAME_LENGTH 48
34 
35 /**
36   return values of the plugin authenticate_user() method.
37 */
38 
39 /**
40   Authentication failed, plugin internal error.
41   An error occurred in the authentication plugin itself.
42   These errors are reported in table performance_schema.host_cache,
43   column COUNT_AUTH_PLUGIN_ERRORS.
44 */
45 #define CR_AUTH_PLUGIN_ERROR 3
46 /**
47   Authentication failed, client server handshake.
48   An error occurred during the client server handshake.
49   These errors are reported in table performance_schema.host_cache,
50   column COUNT_HANDSHAKE_ERRORS.
51 */
52 #define CR_AUTH_HANDSHAKE 2
53 /**
54   Authentication failed, user credentials.
55   For example, wrong passwords.
56   These errors are reported in table performance_schema.host_cache,
57   column COUNT_AUTHENTICATION_ERRORS.
58 */
59 #define CR_AUTH_USER_CREDENTIALS 1
60 /**
61   Authentication failed. Additionally, all other CR_xxx values
62   (libmysql error code) can be used too.
63 
64   The client plugin may set the error code and the error message directly
65   in the MYSQL structure and return CR_ERROR. If a CR_xxx specific error
66   code was returned, an error message in the MYSQL structure will be
67   overwritten. If CR_ERROR is returned without setting the error in MYSQL,
68   CR_UNKNOWN_ERROR will be user.
69 */
70 #define CR_ERROR 0
71 /**
72   Authentication (client part) was successful. It does not mean that the
73   authentication as a whole was successful, usually it only means
74   that the client was able to send the user name and the password to the
75   server. If CR_OK is returned, the libmysql reads the next packet expecting
76   it to be one of OK, ERROR, or CHANGE_PLUGIN packets.
77 */
78 #define CR_OK -1
79 /**
80   Authentication was successful.
81   It means that the client has done its part successfully and also that
82   a plugin has read the last packet (one of OK, ERROR, CHANGE_PLUGIN).
83   In this case, libmysql will not read a packet from the server,
84   but it will use the data at mysql->net.read_pos.
85 
86   A plugin may return this value if the number of roundtrips in the
87   authentication protocol is not known in advance, and the client plugin
88   needs to read one packet more to determine if the authentication is finished
89   or not.
90 */
91 #define CR_OK_HANDSHAKE_COMPLETE -2
92 
93 typedef struct st_plugin_vio_info
94 {
95   enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET,
96          MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol;
97   int socket;     /**< it's set, if the protocol is SOCKET or TCP */
98 #ifdef _WIN32
99   HANDLE handle;  /**< it's set, if the protocol is PIPE or MEMORY */
100 #endif
101 } MYSQL_PLUGIN_VIO_INFO;
102 
103 /**
104   Provides plugin access to communication channel
105 */
106 typedef struct st_plugin_vio
107 {
108   /**
109     Plugin provides a pointer reference and this function sets it to the
110     contents of any incoming packet. Returns the packet length, or -1 if
111     the plugin should terminate.
112   */
113   int (*read_packet)(struct st_plugin_vio *vio,
114                      unsigned char **buf);
115 
116   /**
117     Plugin provides a buffer with data and the length and this
118     function sends it as a packet. Returns 0 on success, 1 on failure.
119   */
120   int (*write_packet)(struct st_plugin_vio *vio,
121                       const unsigned char *packet,
122                       int packet_len);
123 
124   /**
125     Fills in a st_plugin_vio_info structure, providing the information
126     about the connection.
127   */
128   void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
129 
130 } MYSQL_PLUGIN_VIO;
131 
132 #endif
133 
134