1 /*
2   (C) 2011 Percona Inc.
3 
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 
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 Street, Fifth Floor, Boston, MA  02110-1301, USA
16 */
17 
18 /**
19  @file
20 
21  PAM authentication for MySQL, the test version of the client-side plugin.
22 */
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include <string.h>
28 
29 #define STDCALL
30 
31 #include <mysql/plugin_auth.h>
32 #include <mysql/client_plugin.h>
33 
34 #include "lib_auth_pam_client.h"
35 
36 const char * echo_off_reply_1 = "aaaaaaa";
37 const char * echo_off_reply_2 = "AAAAAAA";
38 
39 const char * echo_on_reply_1 = "bbbbbbbbbb";
40 const char * echo_on_reply_2 = "BBBBBBBBBB";
41 
42 /* Returns alternating echo_off_reply_1 and echo_off_reply_2 */
test_prompt_echo_off(const char * prompt)43 static char * test_prompt_echo_off (const char * prompt __attribute__((unused)))
44 {
45   static unsigned call_no= 0;
46   return strdup((call_no++ % 2) == 0 ? echo_off_reply_1 : echo_off_reply_2);
47 }
48 
49 /* Returns alternating echo_on_reply_1 and echo_on_reply_2 */
test_prompt_echo_on(const char * prompt)50 static char * test_prompt_echo_on (const char * prompt __attribute__((unused)))
51 {
52   static unsigned call_no= 0;
53   return strdup((call_no++ % 2) == 0 ? echo_on_reply_1 : echo_on_reply_2);
54 }
55 
56 /* Pretend we have shown the message to the user */
test_show_anything(const char * message)57 static void test_show_anything(const char * message __attribute__((unused)))
58 {
59 }
60 
test_pam_auth_client(MYSQL_PLUGIN_VIO * vio,struct st_mysql * mysql)61 static int test_pam_auth_client (MYSQL_PLUGIN_VIO *vio, struct st_mysql *mysql)
62 {
63   return authenticate_user_with_pam_client_common (vio, mysql,
64                                                    &test_prompt_echo_off,
65                                                    &test_prompt_echo_on,
66                                                    &test_show_anything,
67                                                    &test_show_anything);
68 }
69 
70 mysql_declare_client_plugin(AUTHENTICATION)
71   "auth_pam_test",
72   "Percona, Inc.",
73   "Test version of the client PAM authentication plugin. "
74   "DO NOT USE IN PRODUCTION.",
75   {0,1,0},
76   "GPL",
77   NULL,
78   NULL, /* init */
79   NULL, /* deinit */
80   NULL, /* options */
81   &test_pam_auth_client
82 mysql_end_client_plugin;
83