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