plugin_auth.h 3.7 KB

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