1/* Copyright (c) 2010, 2011, 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
24/********************* SERVER SIDE ****************************************/
25
26static int qa_auth_interface (MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
27{
28 unsigned char *pkt;
29 int pkt_len, err= CR_OK;
30
31 /* send a password question */
32 if (vio->write_packet(vio, (const unsigned char *) PASSWORD_QUESTION, 1))
33 return CR_ERROR;
34
35 /* read the answer */
36 if ((pkt_len= vio->read_packet(vio, &pkt)) < 0)
37 return CR_ERROR;
38
39 info->password_used= PASSWORD_USED_YES;
40
41 /* fail if the password is wrong */
42 if (strcmp((const char *) pkt, info->auth_string))
43 return CR_ERROR;
44
45/* Test of default_auth */
46 if (strcmp(info->user_name, "qa_test_11_user")== 0)
47 {
48 strcpy(info->authenticated_as, "qa_test_11_dest");
49 }
50 else
51 err= CR_ERROR;
52 return err;
53}
54
55static struct st_mysql_auth qa_auth_test_handler=
56{
57 MYSQL_AUTHENTICATION_INTERFACE_VERSION,
58 "qa_auth_interface", /* requires test_plugin client's plugin */
59 qa_auth_interface
60};
61
62mysql_declare_plugin(test_plugin)
63{
64 MYSQL_AUTHENTICATION_PLUGIN,
65 &qa_auth_test_handler,
66 "qa_auth_server",
67 "Horst Hunger",
68 "plugin API test plugin",
69 PLUGIN_LICENSE_GPL,
70 NULL,
71 NULL,
72 0x0100,
73 NULL,
74 NULL,
75 NULL,
76 0,
77}
78mysql_declare_plugin_end;
79