plugin_auth_common.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. #ifndef MYSQL_PLUGIN_AUTH_COMMON_INCLUDED
  2. /* Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License, version 2.0,
  5. as published by the Free Software Foundation.
  6. This program is also distributed with certain software (including
  7. but not limited to OpenSSL) that is licensed under separate terms,
  8. as designated in a particular file or component or in included license
  9. documentation. The authors of MySQL hereby grant you an additional
  10. permission to link the program and your derivative works with the
  11. separately licensed software that they have included with MySQL.
  12. Without limiting anything contained in the foregoing, this file,
  13. which is part of C Driver for MySQL (Connector/C), is also subject to the
  14. Universal FOSS Exception, version 1.0, a copy of which can be found at
  15. http://oss.oracle.com/licenses/universal-foss-exception.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License, version 2.0, for more details.
  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. @file
  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. /** the max allowed length for a user name */
  30. #define MYSQL_USERNAME_LENGTH 96
  31. /**
  32. return values of the plugin authenticate_user() method.
  33. */
  34. /**
  35. Authentication failed, plugin internal error.
  36. An error occurred in the authentication plugin itself.
  37. These errors are reported in table performance_schema.host_cache,
  38. column COUNT_AUTH_PLUGIN_ERRORS.
  39. */
  40. #define CR_AUTH_PLUGIN_ERROR 3
  41. /**
  42. Authentication failed, client server handshake.
  43. An error occurred during the client server handshake.
  44. These errors are reported in table performance_schema.host_cache,
  45. column COUNT_HANDSHAKE_ERRORS.
  46. */
  47. #define CR_AUTH_HANDSHAKE 2
  48. /**
  49. Authentication failed, user credentials.
  50. For example, wrong passwords.
  51. These errors are reported in table performance_schema.host_cache,
  52. column COUNT_AUTHENTICATION_ERRORS.
  53. */
  54. #define CR_AUTH_USER_CREDENTIALS 1
  55. /**
  56. Authentication failed. Additionally, all other CR_xxx values
  57. (libmysql error code) can be used too.
  58. The client plugin may set the error code and the error message directly
  59. in the MYSQL structure and return CR_ERROR. If a CR_xxx specific error
  60. code was returned, an error message in the MYSQL structure will be
  61. overwritten. If CR_ERROR is returned without setting the error in MYSQL,
  62. CR_UNKNOWN_ERROR will be user.
  63. */
  64. #define CR_ERROR 0
  65. /**
  66. Authentication (client part) was successful. It does not mean that the
  67. authentication as a whole was successful, usually it only means
  68. that the client was able to send the user name and the password to the
  69. server. If CR_OK is returned, the libmysql reads the next packet expecting
  70. it to be one of OK, ERROR, or CHANGE_PLUGIN packets.
  71. */
  72. #define CR_OK -1
  73. /**
  74. Authentication was successful.
  75. It means that the client has done its part successfully and also that
  76. a plugin has read the last packet (one of OK, ERROR, CHANGE_PLUGIN).
  77. In this case, libmysql will not read a packet from the server,
  78. but it will use the data at mysql->net.read_pos.
  79. A plugin may return this value if the number of roundtrips in the
  80. authentication protocol is not known in advance, and the client plugin
  81. needs to read one packet more to determine if the authentication is finished
  82. or not.
  83. */
  84. #define CR_OK_HANDSHAKE_COMPLETE -2
  85. /**
  86. Flag to be passed back to server from authentication plugins via
  87. authenticated_as when proxy mapping should be done by the server.
  88. */
  89. #define PROXY_FLAG 0
  90. /*
  91. We need HANDLE definition if on Windows. Define WIN32_LEAN_AND_MEAN (if
  92. not already done) to minimize amount of imported declarations.
  93. */
  94. #ifdef _WIN32
  95. #ifndef WIN32_LEAN_AND_MEAN
  96. #define WIN32_LEAN_AND_MEAN
  97. #endif
  98. #include <windows.h>
  99. #endif
  100. typedef struct st_plugin_vio_info
  101. {
  102. enum { MYSQL_VIO_INVALID, MYSQL_VIO_TCP, MYSQL_VIO_SOCKET,
  103. MYSQL_VIO_PIPE, MYSQL_VIO_MEMORY } protocol;
  104. int socket; /**< it's set, if the protocol is SOCKET or TCP */
  105. #ifdef _WIN32
  106. HANDLE handle; /**< it's set, if the protocol is PIPE or MEMORY */
  107. #endif
  108. } MYSQL_PLUGIN_VIO_INFO;
  109. /**
  110. Provides plugin access to communication channel
  111. */
  112. typedef struct st_plugin_vio
  113. {
  114. /**
  115. Plugin provides a pointer reference and this function sets it to the
  116. contents of any incoming packet. Returns the packet length, or -1 if
  117. the plugin should terminate.
  118. */
  119. int (*read_packet)(struct st_plugin_vio *vio,
  120. unsigned char **buf);
  121. /**
  122. Plugin provides a buffer with data and the length and this
  123. function sends it as a packet. Returns 0 on success, 1 on failure.
  124. */
  125. int (*write_packet)(struct st_plugin_vio *vio,
  126. const unsigned char *packet,
  127. int packet_len);
  128. /**
  129. Fills in a st_plugin_vio_info structure, providing the information
  130. about the connection.
  131. */
  132. void (*info)(struct st_plugin_vio *vio, struct st_plugin_vio_info *info);
  133. } MYSQL_PLUGIN_VIO;
  134. #endif