plugin_auth.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef MYSQL_PLUGIN_AUTH_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. /**
  15. @file
  16. Authentication Plugin API.
  17. This file defines the API for server authentication plugins.
  18. */
  19. #define MYSQL_PLUGIN_AUTH_INCLUDED
  20. #include <mysql/plugin.h>
  21. #define MYSQL_AUTHENTICATION_INTERFACE_VERSION 0x0200
  22. #include <mysql/plugin_auth_common.h>
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* defines for MYSQL_SERVER_AUTH_INFO.password_used */
  27. #define PASSWORD_USED_NO 0
  28. #define PASSWORD_USED_YES 1
  29. #define PASSWORD_USED_NO_MENTION 2
  30. /**
  31. Provides server plugin access to authentication information
  32. */
  33. typedef struct st_mysql_server_auth_info
  34. {
  35. /**
  36. User name as sent by the client and shown in USER().
  37. NULL if the client packet with the user name was not received yet.
  38. */
  39. char *user_name;
  40. /**
  41. Length of user_name
  42. */
  43. unsigned int user_name_length;
  44. /**
  45. A corresponding column value from the mysql.user table for the
  46. matching account name
  47. */
  48. const char *auth_string;
  49. /**
  50. Length of auth_string
  51. */
  52. unsigned long auth_string_length;
  53. /**
  54. Matching account name as found in the mysql.user table.
  55. A plugin can override it with another name that will be
  56. used by MySQL for authorization, and shown in CURRENT_USER()
  57. */
  58. char authenticated_as[MYSQL_USERNAME_LENGTH+1];
  59. /**
  60. The unique user name that was used by the plugin to authenticate.
  61. Not used by the server.
  62. Available through the @@EXTERNAL_USER variable.
  63. */
  64. char external_user[MYSQL_USERNAME_LENGTH+1];
  65. /**
  66. This only affects the "Authentication failed. Password used: %s"
  67. error message. has the following values :
  68. 0 : %s will be NO.
  69. 1 : %s will be YES.
  70. 2 : there will be no %s.
  71. Set it as appropriate or ignore at will.
  72. */
  73. int password_used;
  74. /**
  75. Set to the name of the connected client host, if it can be resolved,
  76. or to its IP address otherwise.
  77. */
  78. const char *host_or_ip;
  79. /**
  80. Length of host_or_ip
  81. */
  82. unsigned int host_or_ip_length;
  83. } MYSQL_SERVER_AUTH_INFO;
  84. /**
  85. Server authentication plugin descriptor
  86. */
  87. struct st_mysql_auth
  88. {
  89. int interface_version; /**< version plugin uses */
  90. /**
  91. A plugin that a client must use for authentication with this server
  92. plugin. Can be NULL to mean "any plugin".
  93. */
  94. const char *client_auth_plugin;
  95. /**
  96. Function provided by the plugin which should perform authentication (using
  97. the vio functions if necessary) and return 0 if successful. The plugin can
  98. also fill the info.authenticated_as field if a different username should be
  99. used for authorization.
  100. */
  101. int (*authenticate_user)(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info);
  102. };
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif