plugin_auth.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #ifndef MYSQL_PLUGIN_AUTH_INCLUDED
  2. /* Copyright (c) 2010, 2016 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. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License, version 2.0, for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  19. /**
  20. @file
  21. Authentication Plugin API.
  22. This file defines the API for server authentication plugins.
  23. */
  24. #define MYSQL_PLUGIN_AUTH_INCLUDED
  25. #include <mysql/plugin.h>
  26. #define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0101
  27. #include "plugin_auth_common.h"
  28. /* defines for MYSQL_SERVER_AUTH_INFO.password_used */
  29. #define PASSWORD_USED_NO 0
  30. #define PASSWORD_USED_YES 1
  31. #define PASSWORD_USED_NO_MENTION 2
  32. /* Authentication flags */
  33. #define AUTH_FLAG_PRIVILEGED_USER_FOR_PASSWORD_CHANGE (1L << 0)
  34. #define AUTH_FLAG_USES_INTERNAL_STORAGE (1L << 1)
  35. /**
  36. Provides server plugin access to authentication information
  37. */
  38. typedef struct st_mysql_server_auth_info
  39. {
  40. /**
  41. User name as sent by the client and shown in USER().
  42. NULL if the client packet with the user name was not received yet.
  43. */
  44. char *user_name;
  45. /**
  46. Length of user_name
  47. */
  48. unsigned int user_name_length;
  49. /**
  50. A corresponding column value from the mysql.user table for the
  51. matching account name
  52. */
  53. const char *auth_string;
  54. /**
  55. Length of auth_string
  56. */
  57. unsigned long auth_string_length;
  58. /**
  59. Matching account name as found in the mysql.user table.
  60. A plugin can override it with another name that will be
  61. used by MySQL for authorization, and shown in CURRENT_USER()
  62. */
  63. char authenticated_as[MYSQL_USERNAME_LENGTH+1];
  64. /**
  65. The unique user name that was used by the plugin to authenticate.
  66. Plugins should put null-terminated UTF-8 here.
  67. Available through the @@EXTERNAL_USER variable.
  68. */
  69. char external_user[512];
  70. /**
  71. This only affects the "Authentication failed. Password used: %s"
  72. error message. has the following values :
  73. 0 : %s will be NO.
  74. 1 : %s will be YES.
  75. 2 : there will be no %s.
  76. Set it as appropriate or ignore at will.
  77. */
  78. int password_used;
  79. /**
  80. Set to the name of the connected client host, if it can be resolved,
  81. or to its IP address otherwise.
  82. */
  83. const char *host_or_ip;
  84. /**
  85. Length of host_or_ip
  86. */
  87. unsigned int host_or_ip_length;
  88. } MYSQL_SERVER_AUTH_INFO;
  89. /**
  90. Server authentication plugin descriptor
  91. */
  92. struct st_mysql_auth
  93. {
  94. int interface_version; /** version plugin uses */
  95. /**
  96. A plugin that a client must use for authentication with this server
  97. plugin. Can be NULL to mean "any plugin".
  98. */
  99. const char *client_auth_plugin;
  100. /**
  101. Function provided by the plugin which should perform authentication (using
  102. the vio functions if necessary) and return 0 if successful. The plugin can
  103. also fill the info.authenticated_as field if a different username should be
  104. used for authorization.
  105. */
  106. int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info);
  107. /**
  108. New plugin API to generate password digest out of authentication string.
  109. This function will first invoke a service to check for validity of the
  110. password based on the policies defined and then generate encrypted hash
  111. @param[OUT] outbuf A buffer provided by server which will hold the
  112. authentication string generated by plugin.
  113. @param[INOUT] outbuflen Length of server provided buffer as IN param and
  114. length of plugin generated string as OUT param.
  115. @param[IN] inbuf auth string provided by user.
  116. @param[IN] inbuflen auth string length.
  117. @retval 0 OK
  118. 1 ERROR
  119. */
  120. int (*generate_authentication_string)(char *outbuf,
  121. unsigned int *outbuflen, const char *inbuf, unsigned int inbuflen);
  122. /**
  123. Plugin API to validate password digest.
  124. @param[IN] inbuf hash string to be validated.
  125. @param[IN] buflen hash string length.
  126. @retval 0 OK
  127. 1 ERROR
  128. */
  129. int (*validate_authentication_string)(char* const inbuf, unsigned int buflen);
  130. /**
  131. Plugin API to convert scrambled password to binary form
  132. based on scramble type.
  133. @param[IN] password The password hash containing the salt.
  134. @param[IN] password_len The length of the password hash.
  135. @param[INOUT] salt Used as password hash based on the
  136. authentication plugin.
  137. @param[INOUT] salt_len The length of salt.
  138. @retval 0 OK
  139. 1 ERROR
  140. */
  141. int (*set_salt)(const char *password, unsigned int password_len,
  142. unsigned char* salt, unsigned char *salt_len);
  143. /**
  144. Authentication plugin capabilities
  145. */
  146. const unsigned long authentication_flags;
  147. };
  148. #endif