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