2015-09-20 11:51:50 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 - Alejandro T. Colombini
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
#define MYSQL_ABI_CHECK
|
|
|
|
|
2015-09-20 11:51:50 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <mysql.h>
|
|
|
|
#include <mysql/errmsg.h>
|
|
|
|
#include <mysql/plugin_auth.h>
|
2018-07-02 15:20:11 +00:00
|
|
|
|
2015-09-20 11:51:50 +00:00
|
|
|
#include <glib-unix.h>
|
|
|
|
|
2015-10-01 09:27:02 +00:00
|
|
|
#define CONFIG_FILE _CONFIG_DIR"/proxy-auth.ini"
|
|
|
|
#define SQL_FILE _SQL_DIR"/proxy-auth.sql"
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
gboolean initialized;
|
|
|
|
gchar * socket;
|
|
|
|
gchar * host;
|
|
|
|
gchar * user;
|
|
|
|
gchar * pass;
|
|
|
|
gchar * schema;
|
|
|
|
guint port;
|
|
|
|
GRegex * regex;
|
|
|
|
gchar * queryt;
|
|
|
|
gsize queryt_len;
|
|
|
|
gint pool_size;
|
|
|
|
gint max_connections;
|
|
|
|
GAsyncQueue * conn_pool;
|
|
|
|
GMutex mutex;
|
|
|
|
guint last_error;
|
2015-10-14 11:03:33 +00:00
|
|
|
gboolean debug;
|
2015-09-20 11:51:50 +00:00
|
|
|
}
|
|
|
|
ProxyAuth;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
MYSQL * conn;
|
|
|
|
gchar * user;
|
2015-10-14 11:03:33 +00:00
|
|
|
gulong user_len;
|
2015-09-20 11:51:50 +00:00
|
|
|
gchar * pass;
|
2015-10-14 11:03:33 +00:00
|
|
|
gulong pass_len;
|
2015-09-20 11:51:50 +00:00
|
|
|
}
|
|
|
|
RegexData;
|
|
|
|
|
|
|
|
ProxyAuth *
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_new()
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
ProxyAuth * self = g_new(ProxyAuth, 1);
|
2015-09-20 11:51:50 +00:00
|
|
|
self->initialized = FALSE;
|
2018-07-02 15:20:11 +00:00
|
|
|
g_mutex_init(&self->mutex);
|
2015-09-20 11:51:50 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_deinit(ProxyAuth * self)
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
|
|
|
if (!self->initialized)
|
|
|
|
return;
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
g_free(self->socket);
|
|
|
|
g_free(self->host);
|
|
|
|
g_free(self->user);
|
|
|
|
g_free(self->pass);
|
|
|
|
g_free(self->schema);
|
|
|
|
g_free(self->queryt);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
if (self->regex)
|
2018-07-02 15:20:11 +00:00
|
|
|
g_regex_unref(self->regex);
|
2015-10-01 09:27:02 +00:00
|
|
|
|
|
|
|
// FIXME: Connection can't be closed because mysql_close() causes MySQL
|
|
|
|
// process crash with signal 11 when the process is shutdown.
|
|
|
|
// MySQL version 5.5.40
|
|
|
|
//if (self->conn_pool)
|
2018-07-02 15:20:11 +00:00
|
|
|
// g_async_queue_unref(self->conn_pool);
|
2015-09-20 11:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_free(ProxyAuth * self)
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
g_return_if_fail(self != NULL);
|
2015-10-01 09:27:02 +00:00
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_deinit(self);
|
|
|
|
g_mutex_clear(&self->mutex);
|
|
|
|
g_free(self);
|
2015-09-20 11:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_init(ProxyAuth * self)
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
g_return_val_if_fail(self != NULL, FALSE);
|
2015-10-01 09:27:02 +00:00
|
|
|
|
2015-09-20 11:51:50 +00:00
|
|
|
gboolean res = FALSE;
|
|
|
|
GError * error = NULL;
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_deinit(self);
|
2015-09-20 11:51:50 +00:00
|
|
|
self->initialized = TRUE;
|
|
|
|
self->socket = NULL;
|
|
|
|
self->host = NULL;
|
|
|
|
self->user = NULL;
|
|
|
|
self->pass = NULL;
|
|
|
|
self->schema = NULL;
|
|
|
|
self->queryt = NULL;
|
|
|
|
self->queryt_len = 0;
|
|
|
|
self->regex = NULL;
|
|
|
|
self->conn_pool = NULL;
|
|
|
|
self->last_error = 0;
|
2015-10-14 11:03:33 +00:00
|
|
|
self->debug = FALSE;
|
2015-09-20 11:51:50 +00:00
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
mysql_library_init(0, NULL, NULL);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
// Reading the configuration file
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
GKeyFile * key_file = g_key_file_new();
|
2015-09-20 11:51:50 +00:00
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
if (!g_key_file_load_from_file(key_file, CONFIG_FILE, G_KEY_FILE_NONE, &error))
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
g_warning("ProxyAuth: Can't open configuration file: %s", error->message);
|
2015-09-20 11:51:50 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->socket = NULL;
|
2018-07-02 15:20:11 +00:00
|
|
|
self->host = g_key_file_get_string(key_file, "db", "host", NULL);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
if (!self->host)
|
2018-07-02 15:20:11 +00:00
|
|
|
self->socket = g_key_file_get_string(key_file, "db", "socket", NULL);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
self->user = g_key_file_get_string(key_file, "db", "user", NULL);
|
|
|
|
self->pass = g_key_file_get_string(key_file, "db", "pass", NULL);
|
|
|
|
self->schema = g_key_file_get_string(key_file, "db", "schema", NULL);
|
|
|
|
self->port = (guint) g_key_file_get_integer(key_file, "db", "port", NULL);
|
|
|
|
self->max_connections = g_key_file_get_integer(key_file, "db", "maxConnections", NULL);
|
|
|
|
self->debug = g_key_file_get_boolean(key_file, "db", "debug", NULL);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
// Reading the query template
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
if (!g_file_get_contents(SQL_FILE, &self->queryt, &self->queryt_len, &error))
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
g_warning("ProxyAuth: Can't read the query template: %s", error->message);
|
2015-09-20 11:51:50 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creates the regular expression
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
self->regex = g_regex_new("#\\w+",
|
2015-09-20 11:51:50 +00:00
|
|
|
G_REGEX_OPTIMIZE | G_REGEX_MULTILINE, 0, &error);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
g_warning("ProxyAuth: Can't create the regex: %s", error->message);
|
2015-09-20 11:51:50 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Creates the connection pool
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
self->conn_pool = g_async_queue_new_full((GDestroyNotify) mysql_close);
|
2015-09-20 11:51:50 +00:00
|
|
|
self->pool_size = 0;
|
|
|
|
self->last_error = 0;
|
|
|
|
|
|
|
|
if (self->max_connections < 1)
|
|
|
|
self->max_connections = 1;
|
|
|
|
|
|
|
|
res = TRUE;
|
|
|
|
end:
|
2018-07-02 15:20:11 +00:00
|
|
|
g_clear_error(&error);
|
|
|
|
g_key_file_free(key_file);
|
2015-09-20 11:51:50 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_regex_func(const GMatchInfo * info, GString * res, gpointer data)
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
|
|
|
RegexData * regex_data = (RegexData *) data;
|
2018-07-02 15:20:11 +00:00
|
|
|
gchar * match = g_match_info_fetch(info, 0);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
gchar * str = NULL;
|
|
|
|
gulong str_len;
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
if (!g_strcmp0(match, "#user"))
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
|
|
|
str = regex_data->user;
|
|
|
|
str_len = regex_data->user_len;
|
|
|
|
}
|
2018-07-02 15:20:11 +00:00
|
|
|
else if (!g_strcmp0(match, "#pass"))
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
|
|
|
str = regex_data->pass;
|
|
|
|
str_len = regex_data->pass_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str)
|
|
|
|
{
|
2015-10-01 09:27:02 +00:00
|
|
|
unsigned long scaped_len;
|
|
|
|
char escaped_str[str_len * 2 + 1];
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
g_string_append_c(res, '\'');
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
// FIXME: mysql_real_escape_string() causes MySQL process crash with signal 11
|
2018-07-02 15:20:11 +00:00
|
|
|
//scaped_len = mysql_real_escape_string(regex_data->conn, escaped_str, str, str_len);
|
|
|
|
scaped_len = mysql_escape_string(escaped_str, str, str_len);
|
2015-10-01 09:27:02 +00:00
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
g_string_append_len(res, escaped_str,(gssize) scaped_len);
|
|
|
|
g_string_append_c(res, '\'');
|
2015-09-20 11:51:50 +00:00
|
|
|
}
|
|
|
|
else
|
2018-07-02 15:20:11 +00:00
|
|
|
g_string_append(res, match);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
g_free(match);
|
2015-09-20 11:51:50 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_reconnect(ProxyAuth * self, MYSQL * conn)
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
g_return_val_if_fail(self != NULL, FALSE);
|
2015-10-01 09:27:02 +00:00
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
gboolean connected = mysql_real_connect(conn,
|
2015-09-20 11:51:50 +00:00
|
|
|
self->host, self->user, self->pass, self->schema, self->port, self->socket, 0) != NULL;
|
2018-07-02 15:20:11 +00:00
|
|
|
guint conn_error = mysql_errno(conn);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
if (conn_error && self->last_error != conn_error)
|
2018-07-02 15:20:11 +00:00
|
|
|
g_warning("ProxyAuth: Can't connect to database: %s", mysql_error(conn));
|
|
|
|
else if (mysql_set_character_set(conn, "latin1"))
|
|
|
|
g_warning("ProxyAuth: Can't set character set: %s", mysql_error(conn));
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
self->last_error = conn_error;
|
|
|
|
return connected;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_authenticate(ProxyAuth * self, MYSQL_PLUGIN_VIO * vio, MYSQL_SERVER_AUTH_INFO * info)
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
g_return_val_if_fail(self != NULL, CR_ERROR);
|
2015-10-01 09:27:02 +00:00
|
|
|
|
2015-09-20 11:51:50 +00:00
|
|
|
int res = CR_ERROR;
|
|
|
|
gchar * query = NULL;
|
2015-09-20 12:18:40 +00:00
|
|
|
GError * error = NULL;
|
2015-09-20 11:51:50 +00:00
|
|
|
unsigned char * pkt;
|
|
|
|
|
|
|
|
// Check for the username
|
|
|
|
|
2015-10-14 11:03:33 +00:00
|
|
|
int user_len = info->user_name_length;
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
if (info->user_name == NULL
|
2018-07-02 15:20:11 +00:00
|
|
|
&&(user_len = vio->read_packet(vio, &pkt)) < 0)
|
2015-09-20 11:51:50 +00:00
|
|
|
return CR_ERROR;
|
|
|
|
|
|
|
|
if (user_len > MYSQL_USERNAME_LENGTH)
|
|
|
|
return CR_ERROR;
|
|
|
|
|
|
|
|
// Read the password and check if it's valid
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
int pass_len = vio->read_packet(vio, &pkt) - 1;
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
if (pass_len < 0)
|
|
|
|
return CR_ERROR;
|
|
|
|
|
|
|
|
if (!pass_len || *pkt == '\0')
|
|
|
|
{
|
|
|
|
info->password_used = PASSWORD_USED_NO;
|
|
|
|
return CR_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
char pass[pass_len + 1];
|
2018-07-02 15:20:11 +00:00
|
|
|
memcpy(pass, pkt, pass_len);
|
2015-09-20 11:51:50 +00:00
|
|
|
pass[pass_len] = '\0';
|
|
|
|
|
|
|
|
info->password_used = PASSWORD_USED_YES;
|
|
|
|
|
|
|
|
// Gets a connection from the pool
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
MYSQL * conn = (MYSQL *) g_async_queue_try_pop(self->conn_pool);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
if (!conn)
|
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
g_mutex_lock(&self->mutex);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
if (self->pool_size < self->max_connections)
|
|
|
|
{
|
|
|
|
self->pool_size++;
|
2018-07-02 15:20:11 +00:00
|
|
|
g_mutex_unlock(&self->mutex);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
conn = mysql_init(NULL);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
if (!proxy_auth_reconnect(self, conn))
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
g_mutex_lock(&self->mutex);
|
2015-09-20 11:51:50 +00:00
|
|
|
self->pool_size--;
|
2018-07-02 15:20:11 +00:00
|
|
|
g_mutex_unlock(&self->mutex);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
mysql_close(conn);
|
2015-09-20 11:51:50 +00:00
|
|
|
conn = NULL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
g_mutex_unlock(&self->mutex);
|
|
|
|
conn = (MYSQL *) g_async_queue_pop(self->conn_pool);
|
2015-09-20 11:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
switch (mysql_errno(conn))
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
|
|
|
case CR_SERVER_LOST:
|
|
|
|
case CR_SERVER_GONE_ERROR:
|
2018-07-02 15:20:11 +00:00
|
|
|
if (!proxy_auth_reconnect(self, conn))
|
2015-09-20 11:51:50 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replaces the user and the pass on the query template
|
|
|
|
|
|
|
|
RegexData regex_data;
|
|
|
|
regex_data.conn = conn;
|
|
|
|
regex_data.user = info->user_name;
|
|
|
|
regex_data.user_len = user_len;
|
|
|
|
regex_data.pass = pass;
|
|
|
|
regex_data.pass_len = pass_len;
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
query = g_regex_replace_eval(self->regex,
|
2015-09-20 11:51:50 +00:00
|
|
|
self->queryt, self->queryt_len, 0, 0, proxy_auth_regex_func, ®ex_data, &error);
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
g_warning("ProxyAuth: Can't evaluate regex: %s", error->message);
|
2015-09-20 11:51:50 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sends the query to the database
|
2015-10-14 11:03:33 +00:00
|
|
|
|
|
|
|
if (self->debug)
|
2018-07-02 15:20:11 +00:00
|
|
|
g_message("ProxyAuth: Query: %s", query);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
MYSQL_RES * result;
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
if (!mysql_query(conn, query)
|
|
|
|
&&(result = mysql_store_result(conn)))
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
MYSQL_ROW row = mysql_fetch_row(result);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
if (row && row[0])
|
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
unsigned long row_len = mysql_fetch_lengths(result)[0];
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
if (row_len > 0 && row_len <= MYSQL_USERNAME_LENGTH)
|
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
strcpy(info->external_user, info->user_name);
|
|
|
|
strncpy(info->authenticated_as, row[0], row_len);
|
2016-05-08 14:18:45 +00:00
|
|
|
info->authenticated_as[row_len] = '\0';
|
2015-09-20 11:51:50 +00:00
|
|
|
res = CR_OK;
|
2016-05-08 14:18:45 +00:00
|
|
|
|
|
|
|
if (self->debug)
|
2018-07-02 15:20:11 +00:00
|
|
|
g_message("ProxyAuth: Proxy user: %s", info->authenticated_as);
|
2015-09-20 11:51:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
mysql_free_result(result);
|
2015-09-20 11:51:50 +00:00
|
|
|
}
|
|
|
|
else
|
2018-07-02 15:20:11 +00:00
|
|
|
g_warning("ProxyAuth: Error executing query: %s", mysql_error(conn));
|
2015-09-20 11:51:50 +00:00
|
|
|
end:
|
|
|
|
if (conn)
|
2018-07-02 15:20:11 +00:00
|
|
|
g_async_queue_push(self->conn_pool, conn);
|
2015-09-20 11:51:50 +00:00
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
g_clear_error(&error);
|
|
|
|
g_free(query);
|
2015-09-20 11:51:50 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-10-01 09:27:02 +00:00
|
|
|
ProxyAuth * pauth = NULL;
|
2015-09-20 11:51:50 +00:00
|
|
|
|
|
|
|
static int
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_plugin_main(MYSQL_PLUGIN_VIO * vio, MYSQL_SERVER_AUTH_INFO * info)
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
return proxy_auth_authenticate(pauth, vio, info);
|
2015-09-20 11:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_plugin_init()
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
pauth = proxy_auth_new();
|
|
|
|
return proxy_auth_init(pauth) ? 0 : 1;
|
2015-09-20 11:51:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2018-07-02 15:20:11 +00:00
|
|
|
proxy_auth_plugin_deinit()
|
|
|
|
{
|
|
|
|
proxy_auth_free(pauth);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
generate_auth_string_hash(
|
|
|
|
char *outbuf, unsigned int *buflen,
|
|
|
|
const char *inbuf,
|
|
|
|
unsigned int inbuflen)
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
if (*buflen < inbuflen)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
strncpy(outbuf, inbuf, inbuflen);
|
|
|
|
*buflen = strlen(inbuf);
|
2015-09-20 11:51:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-02 15:20:11 +00:00
|
|
|
int
|
|
|
|
validate_auth_string_hash(
|
|
|
|
char* const inbuf __attribute__((unused)),
|
|
|
|
unsigned int buflen __attribute__((unused)))
|
2015-09-20 11:51:50 +00:00
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
set_salt(
|
|
|
|
const char* password __attribute__((unused)),
|
|
|
|
unsigned int password_len __attribute__((unused)),
|
|
|
|
unsigned char* salt __attribute__((unused)),
|
|
|
|
unsigned char* salt_len)
|
|
|
|
{
|
|
|
|
*salt_len = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct st_mysql_auth
|
|
|
|
proxy_auth_handler =
|
|
|
|
{
|
|
|
|
MYSQL_AUTHENTICATION_INTERFACE_VERSION,
|
|
|
|
"mysql_clear_password", // Cleartext plugin required in the client
|
|
|
|
proxy_auth_plugin_main,
|
|
|
|
generate_auth_string_hash,
|
|
|
|
validate_auth_string_hash,
|
|
|
|
set_salt,
|
|
|
|
AUTH_FLAG_PRIVILEGED_USER_FOR_PASSWORD_CHANGE
|
2015-09-20 11:51:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
mysql_declare_plugin(proxy_auth)
|
|
|
|
{
|
2018-07-02 15:20:11 +00:00
|
|
|
MYSQL_AUTHENTICATION_PLUGIN,
|
|
|
|
&proxy_auth_handler,
|
|
|
|
"proxy_auth",
|
|
|
|
"Alejandro T. Colombini",
|
|
|
|
"Proxy user authentication server-side plugin",
|
|
|
|
PLUGIN_LICENSE_GPL,
|
|
|
|
proxy_auth_plugin_init,
|
|
|
|
proxy_auth_plugin_deinit,
|
|
|
|
0x0100, // version 1.0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
2015-09-20 11:51:50 +00:00
|
|
|
}
|
|
|
|
mysql_declare_plugin_end;
|