plugin_auth_common.h 4.4 KB

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