You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.4 KiB

16 years ago
  1. /* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or
  3. modify it under the terms of the GNU General Public License as
  4. published by the Free Software Foundation; version 2 of the
  5. License.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. GNU General Public License for more details.
  10. You should have received a copy of the GNU General Public License
  11. along with this program; if not, write to the Free Software
  12. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  13. #include <my_global.h>
  14. #include <mysql/plugin_auth.h>
  15. #include <mysql/client_plugin.h>
  16. #include <string.h>
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. /**
  20. first byte of the question string is the question "type".
  21. It can be a "ordinary" or a "password" question.
  22. The last bit set marks a last question in the authentication exchange.
  23. */
  24. #define ORDINARY_QUESTION "\2"
  25. #define LAST_QUESTION "\3"
  26. #define LAST_PASSWORD "\4"
  27. #define PASSWORD_QUESTION "\5"
  28. /********************* SERVER SIDE ****************************************/
  29. static int qa_auth_interface (MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
  30. {
  31. unsigned char *pkt;
  32. int pkt_len, err= CR_OK;
  33. /* send a password question */
  34. if (vio->write_packet(vio, (const unsigned char *) PASSWORD_QUESTION, 1))
  35. return CR_ERROR;
  36. /* read the answer */
  37. if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
  38. return CR_ERROR;
  39. info->password_used= PASSWORD_USED_YES;
  40. /* fail if the password is wrong */
  41. if (strcmp((const char *) pkt, info->auth_string))
  42. return CR_ERROR;
  43. /* Test of default_auth */
  44. if (strcmp(info->user_name, "qa_test_11_user")== 0)
  45. {
  46. strcpy(info->authenticated_as, "qa_test_11_dest");
  47. }
  48. else
  49. err= CR_ERROR;
  50. return err;
  51. }
  52. static struct st_mysql_auth qa_auth_test_handler=
  53. {
  54. MYSQL_AUTHENTICATION_INTERFACE_VERSION,
  55. "qa_auth_interface", /* requires test_plugin client's plugin */
  56. qa_auth_interface
  57. };
  58. mysql_declare_plugin(test_plugin)
  59. {
  60. MYSQL_AUTHENTICATION_PLUGIN,
  61. &qa_auth_test_handler,
  62. "qa_auth_server",
  63. "Horst Hunger",
  64. "plugin API test plugin",
  65. PLUGIN_LICENSE_GPL,
  66. NULL,
  67. NULL,
  68. 0x0100,
  69. NULL,
  70. NULL,
  71. NULL
  72. }
  73. mysql_declare_plugin_end;