1
/* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
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
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.
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 */
20
auth_socket authentication plugin.
22
Authentication is successful if the connection is done via a unix socket and
23
the owner of the client process matches the user name that was used when
26
#define _GNU_SOURCE /* for struct ucred */
28
#include <mysql/plugin_auth.h>
29
#include <sys/socket.h>
33
static int socket_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info)
36
MYSQL_PLUGIN_VIO_INFO vio_info;
38
socklen_t cred_len= sizeof(cred);
39
struct passwd pwd_buf, *pwd;
42
/* no user name yet ? read the client handshake packet with the user name */
43
if (info->user_name == 0)
45
if (vio->read_packet(vio, &pkt) < 0)
49
info->password_used= PASSWORD_USED_NO_MENTION;
51
vio->info(vio, &vio_info);
52
if (vio_info.protocol != MYSQL_VIO_SOCKET)
55
/* get the UID of the client process */
56
if (getsockopt(vio_info.socket, SOL_SOCKET, SO_PEERCRED, &cred, &cred_len))
59
if (cred_len != sizeof(cred))
62
/* and find the username for this uid */
63
getpwuid_r(cred.uid, &pwd_buf, buf, sizeof(buf), &pwd);
67
/* now it's simple as that */
68
return strcmp(pwd->pw_name, info->user_name) ? CR_ERROR : CR_OK;
71
static struct st_mysql_auth socket_auth_handler=
73
MYSQL_AUTHENTICATION_INTERFACE_VERSION,
78
mysql_declare_plugin(socket_auth)
80
MYSQL_AUTHENTICATION_PLUGIN,
84
"Unix Socket based authentication",
94
mysql_declare_plugin_end;