1 /*  Copyright (c) 2014, 2021, Oracle and/or its affiliates.
2 
3     This program is free software; you can redistribute it and/or modify
4     it under the terms of the GNU General Public License, version 2.0,
5     as published by the Free Software Foundation.
6 
7     This program is also distributed with certain software (including
8     but not limited to OpenSSL) that is licensed under separate terms,
9     as designated in a particular file or component or in included license
10     documentation.  The authors of MySQL hereby grant you an additional
11     permission to link the program and your derivative works with the
12     separately licensed software that they have included with MySQL.
13 
14     This program is distributed in the hope that it will be useful,
15     but WITHOUT ANY WARRANTY; without even the implied warranty of
16     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17     GNU General Public License, version 2.0, for more details.
18 
19     You should have received a copy of the GNU General Public License
20     along with this program; if not, write to the Free Software
21     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 /**
24   @file
25 
26   mysql_no_login authentication plugin.
27 
28   This plugin exists to support system user accounts, which
29   cannot be accessed externally.  This is useful for privileged
30   stored programs, views and events.  Such objects can be created
31   with DEFINER = [sys account] SQL SECURITY DEFINER.
32 */
33 
34 #include <my_global.h>
35 #include <mysql/plugin_auth.h>
36 #include <string.h>
37 #include <stdio.h>
38 #include <stdlib.h>
39 
mysql_no_login(MYSQL_PLUGIN_VIO * vio MY_ATTRIBUTE ((unused)),MYSQL_SERVER_AUTH_INFO * info MY_ATTRIBUTE ((unused)))40 static int mysql_no_login(
41     MYSQL_PLUGIN_VIO *vio MY_ATTRIBUTE((unused)),
42     MYSQL_SERVER_AUTH_INFO *info MY_ATTRIBUTE((unused)))
43 {
44   return CR_ERROR;
45 }
46 
generate_auth_string_hash(char * outbuf MY_ATTRIBUTE ((unused)),unsigned int * buflen,const char * inbuf MY_ATTRIBUTE ((unused)),unsigned int inbuflen MY_ATTRIBUTE ((unused)))47 int generate_auth_string_hash(char *outbuf MY_ATTRIBUTE((unused)),
48                               unsigned int *buflen,
49                               const char *inbuf MY_ATTRIBUTE((unused)),
50                               unsigned int inbuflen MY_ATTRIBUTE((unused)))
51 {
52   *buflen= 0;
53   return 0;
54 }
55 
validate_auth_string_hash(char * const inbuf MY_ATTRIBUTE ((unused)),unsigned int buflen MY_ATTRIBUTE ((unused)))56 int validate_auth_string_hash(char* const inbuf  MY_ATTRIBUTE((unused)),
57                               unsigned int buflen  MY_ATTRIBUTE((unused)))
58 {
59   return 0;
60 }
61 
set_salt(const char * password MY_ATTRIBUTE ((unused)),unsigned int password_len MY_ATTRIBUTE ((unused)),unsigned char * salt MY_ATTRIBUTE ((unused)),unsigned char * salt_len)62 int set_salt(const char* password MY_ATTRIBUTE((unused)),
63              unsigned int password_len MY_ATTRIBUTE((unused)),
64              unsigned char* salt MY_ATTRIBUTE((unused)),
65              unsigned char* salt_len)
66 {
67   *salt_len= 0;
68   return 0;
69 }
70 
71 static struct st_mysql_auth mysql_no_login_handler=
72 {
73   MYSQL_AUTHENTICATION_INTERFACE_VERSION,
74   0,
75   mysql_no_login,
76   generate_auth_string_hash,
77   validate_auth_string_hash,
78   set_salt,
79   AUTH_FLAG_PRIVILEGED_USER_FOR_PASSWORD_CHANGE
80 };
81 
mysql_declare_plugin(mysql_no_login)82 mysql_declare_plugin(mysql_no_login)
83 {
84   MYSQL_AUTHENTICATION_PLUGIN,                  /* type constant    */
85   &mysql_no_login_handler,                      /* type descriptor  */
86   "mysql_no_login",                             /* Name             */
87   "Todd Farmer",                                /* Author           */
88   "No login authentication plugin",             /* Description      */
89   PLUGIN_LICENSE_GPL,                           /* License          */
90   NULL,                                         /* Init function    */
91   NULL,                                         /* Deinit function  */
92   0x0101,                                       /* Version (1.0)    */
93   NULL,                                         /* status variables */
94   NULL,                                         /* system variables */
95   NULL,                                         /* config options   */
96   0,                                            /* flags            */
97 }
98 mysql_declare_plugin_end;
99