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