Entorno de compilacion reorganizado, bugs segfault solucionados

This commit is contained in:
Juan Ferrer Toribio 2015-10-14 13:03:33 +02:00
parent 9b0723bf13
commit e1d6fa5e0f
9 changed files with 77 additions and 67 deletions

15
Makefile.decl Normal file
View File

@ -0,0 +1,15 @@
mysql_LIBS = `mysql_config --libs`
mysql_CFLAGS = `mysql_config --cflags`
vn_mysql_libdir = $(libdir)/mysql/plugin
vn_mysql_CFLAGS = \
-Wall -O3 \
$(mysql_CFLAGS)
vn_mysql_LDFLAGS = \
-no-undefined \
-module \
-avoid-version \
-export-dynamic \
$(mysql_LIBS)

View File

@ -11,6 +11,7 @@ AM_SILENT_RULES([yes])
# Check for program dependencies # Check for program dependencies
AC_PROG_CC AC_PROG_CC
AC_PROG_CXX
PKG_CHECK_MODULES([glib], [glib-2.0]) PKG_CHECK_MODULES([glib], [glib-2.0])
AC_CONFIG_FILES([ AC_CONFIG_FILES([

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
vn-mysql (1.2-deb8) unstable; urgency=low vn-mysql (1.4-deb8) unstable; urgency=low
* Initial Release. * Initial Release.

View File

@ -3,7 +3,7 @@
I=0 I=0
NATTEMPS=$1 NATTEMPS=$1
while [ $I -lt $NATTEMPS ]; while [ $I -lt $NATTEMPS ]
do do
I=$((I+1)) I=$((I+1))
./command.sh ./command.sh

View File

@ -1,13 +1,18 @@
CREATE SCHEMA account; CREATE SCHEMA account;
DROP TABLE IF EXISTS account.user;
CREATE TABLE account.user CREATE TABLE account.user
SELECT 'proxy' mysql_user, 'test-user' user, '1234' password; SELECT 'proxy' mysql_user, 'test-user' user, '1234' password;
-- SELECT mysql_user FROM user WHERE user = #user AND password = #pass
DROP USER ''@'%';
CREATE USER ''@'%' IDENTIFIED WITH proxy_auth; CREATE USER ''@'%' IDENTIFIED WITH proxy_auth;
GRANT USAGE ON *.* TO ''@'%'; GRANT USAGE ON *.* TO ''@'%';
DROP USER 'proxy'@'%';
CREATE USER 'proxy'@'%' IDENTIFIED BY '123456'; CREATE USER 'proxy'@'%' IDENTIFIED BY '123456';
GRANT USAGE ON *.* TO 'proxy'@'%'; GRANT USAGE ON *.* TO 'proxy'@'%';
GRANT PROXY ON 'proxy'@'%' TO ''@'%'; GRANT PROXY ON 'proxy'@'%' TO ''@'%';
-- SELECT mysql_user FROM user WHERE user = #user AND password = #pass

View File

@ -1,58 +1,43 @@
plugindir = $(libdir)/mysql/plugin include $(top_srcdir)/Makefile.decl
# minacum # minacum
minacum_LTLIBRARIES = minacum.la minacum_LTLIBRARIES = minacum.la
minacum_la_SOURCES = minacum.c minacum_la_SOURCES = minacum.c
minacum_la_LIBADD = -lmysqlclient -lz minacum_la_LIBADD = $(vn_mysql_LIBS)
minacum_la_CFLAGS = -Wall -O3 -I/usr/include/mysql minacum_la_CFLAGS = $(vn_mysql_CFLAGS)
minacum_la_LDFLAGS = \ minacum_la_LDFLAGS = $(vn_mysql_LDFLAGS)
-no-undefined \ minacumdir = $(vn_mysql_libdir)
-module \
-avoid-version \
-export-dynamic \
-lmysqlclient
minacumdir = $(plugindir)
# sql_printf # sql_printf
sql_printf_LTLIBRARIES = sql_printf.la sql_printf_LTLIBRARIES = sql_printf.la
sql_printf_la_SOURCES = sql_printf.c sql_printf_la_SOURCES = sql_printf.c
sql_printf_la_LIBADD = -lmysqlclient -lz sql_printf_la_LIBADD = $(vn_mysql_LIBS)
sql_printf_la_CFLAGS = -Wall -O3 -I/usr/include/mysql sql_printf_la_CFLAGS = $(vn_mysql_CFLAGS)
sql_printf_la_LDFLAGS = \ sql_printf_la_LDFLAGS = $(vn_mysql_LDFLAGS)
-no-undefined \ sql_printfdir = $(vn_mysql_libdir)
-module \
-avoid-version \
-export-dynamic \
-lmysqlclient
sql_printfdir = $(plugindir)
# multimax # multimax
multimax_LTLIBRARIES = multimax.la multimax_LTLIBRARIES = multimax.la
multimax_la_SOURCES = multimax.c multimax_la_SOURCES = multimax.c
multimax_la_LIBADD = -lmysqlclient -lz multimax_la_LIBADD = $(vn_mysql_LIBS)
multimax_la_CFLAGS = -Wall -O3 -I/usr/include/mysql multimax_la_CFLAGS = $(vn_mysql_CFLAGS)
multimax_la_LDFLAGS = \ multimax_la_LDFLAGS = $(vn_mysql_LDFLAGS)
-no-undefined \ multimaxdir = $(vn_mysql_libdir)
-module \
-avoid-version \
-export-dynamic \
-lmysqlclient
multimaxdir = $(plugindir)
# Clean # Clean
install-data-hook: install-data-hook:
rm -f $(DESTDIR)$(plugindir)/minacum.la rm -f $(DESTDIR)$(vn_mysql_libdir)/minacum.la
rm -f $(DESTDIR)$(plugindir)/minacum.a rm -f $(DESTDIR)$(vn_mysql_libdir)/minacum.a
rm -f $(DESTDIR)$(plugindir)/sql_printf.la rm -f $(DESTDIR)$(vn_mysql_libdir)/sql_printf.la
rm -f $(DESTDIR)$(plugindir)/sql_printf.a rm -f $(DESTDIR)$(vn_mysql_libdir)/sql_printf.a
rm -f $(DESTDIR)$(plugindir)/multimax.la rm -f $(DESTDIR)$(vn_mysql_libdir)/multimax.la
rm -f $(DESTDIR)$(plugindir)/multimax.a rm -f $(DESTDIR)$(vn_mysql_libdir)/multimax.a
#$(FILE): $(SRC) #$(FILE): $(SRC)
# gcc -shared -o $@ $< -fPIC # gcc -shared -o $@ $< -fPIC

View File

@ -1,32 +1,26 @@
proxy_authdir = $(libdir)/mysql/plugin include $(top_srcdir)/Makefile.decl
proxy_auth_LTLIBRARIES = proxy_auth.la
proxy_auth_la_CPPFLAGS = \
-DMYSQL_DYNAMIC_PLUGIN \
$(glib_CFLAGS) \
-D_CONFIG_DIR=\"$(proxy_auth_datadir)\" \
-D_SQL_DIR=\"$(proxy_auth_datadir)\"
proxy_auth_la_LIBADD = \
$(glib_LIBS) \
-lmysqlclient \
-lz
proxy_auth_la_CFLAGS = \
-Wall -O3 \
-I/usr/include/mysql
proxy_auth_la_LDFLAGS = \
-no-undefined \
-module \
-avoid-version \
-export-dynamic \
-lmysqlclient
proxy_auth_la_SOURCES = proxy-auth.c
proxy_auth_datadir = $(sysconfdir)/mysql proxy_auth_datadir = $(sysconfdir)/mysql
proxy_auth_data_DATA = \ proxy_auth_data_DATA = \
proxy-auth.sql \ proxy-auth.sql \
proxy-auth.ini proxy-auth.ini
proxy_auth_LTLIBRARIES = proxy_auth.la
proxy_auth_la_SOURCES = proxy-auth.c
proxy_auth_la_LIBADD = \
$(glib_LIBS) \
$(vn_mysql_LIBS)
proxy_auth_la_CFLAGS = $(vn_mysql_CFLAGS)
proxy_auth_la_LDFLAGS = $(vn_mysql_LDFLAGS)
proxy_auth_la_CPPFLAGS = \
-DMYSQL_DYNAMIC_PLUGIN \
-D_CONFIG_DIR=\"$(proxy_auth_datadir)\" \
-D_SQL_DIR=\"$(proxy_auth_datadir)\" \
$(glib_CFLAGS) \
$(vn_mysql_CFLAGS)
proxy_authdir = $(vn_mysql_libdir)
install-data-hook: install-data-hook:
rm -f $(DESTDIR)$(proxy_authdir)/proxy_auth.la rm -f $(DESTDIR)$(vn_mysql_libdir)/proxy_auth.la
rm -f $(DESTDIR)$(proxy_authdir)/proxy_auth.a rm -f $(DESTDIR)$(vn_mysql_libdir)/proxy_auth.a

View File

@ -42,6 +42,7 @@ typedef struct
GAsyncQueue * conn_pool; GAsyncQueue * conn_pool;
GMutex mutex; GMutex mutex;
guint last_error; guint last_error;
gboolean debug;
} }
ProxyAuth; ProxyAuth;
@ -49,9 +50,9 @@ typedef struct
{ {
MYSQL * conn; MYSQL * conn;
gchar * user; gchar * user;
guint user_len; gulong user_len;
gchar * pass; gchar * pass;
guint pass_len; gulong pass_len;
} }
RegexData; RegexData;
@ -117,6 +118,7 @@ proxy_auth_init (ProxyAuth * self)
self->regex = NULL; self->regex = NULL;
self->conn_pool = NULL; self->conn_pool = NULL;
self->last_error = 0; self->last_error = 0;
self->debug = FALSE;
mysql_library_init (0, NULL, NULL); mysql_library_init (0, NULL, NULL);
@ -141,6 +143,7 @@ proxy_auth_init (ProxyAuth * self)
self->schema = g_key_file_get_string (key_file, "db", "schema", 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->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->max_connections = g_key_file_get_integer (key_file, "db", "maxConnections", NULL);
self->debug = g_key_file_get_boolean (key_file, "db", "debug", NULL);
// Reading the query template // Reading the query template
@ -248,7 +251,7 @@ proxy_auth_authenticate (ProxyAuth * self, MYSQL_PLUGIN_VIO * vio, MYSQL_SERVER_
// Check for the username // Check for the username
guint user_len = info->user_name_length; int user_len = info->user_name_length;
if (info->user_name == NULL if (info->user_name == NULL
&& (user_len = vio->read_packet (vio, &pkt)) < 0) && (user_len = vio->read_packet (vio, &pkt)) < 0)
@ -259,7 +262,7 @@ proxy_auth_authenticate (ProxyAuth * self, MYSQL_PLUGIN_VIO * vio, MYSQL_SERVER_
// Read the password and check if it's valid // Read the password and check if it's valid
guint pass_len = vio->read_packet (vio, &pkt) - 1; int pass_len = vio->read_packet (vio, &pkt) - 1;
if (pass_len < 0) if (pass_len < 0)
return CR_ERROR; return CR_ERROR;
@ -336,6 +339,9 @@ proxy_auth_authenticate (ProxyAuth * self, MYSQL_PLUGIN_VIO * vio, MYSQL_SERVER_
} }
// Sends the query to the database // Sends the query to the database
if (self->debug)
g_message ("ProxyAuth: Query: %s", query);
MYSQL_RES * result; MYSQL_RES * result;
@ -350,6 +356,9 @@ proxy_auth_authenticate (ProxyAuth * self, MYSQL_PLUGIN_VIO * vio, MYSQL_SERVER_
if (row_len > 0 && row_len <= MYSQL_USERNAME_LENGTH) if (row_len > 0 && row_len <= MYSQL_USERNAME_LENGTH)
{ {
if (self->debug)
g_message ("ProxyAuth: Proxy user: %s", row[0]);
strcpy (info->external_user, info->user_name); strcpy (info->external_user, info->user_name);
strncpy (info->authenticated_as, row[0], row_len); strncpy (info->authenticated_as, row[0], row_len);
res = CR_OK; res = CR_OK;

View File

@ -1,6 +1,7 @@
[db] [db]
user = authentication user = proxy-auth
pass = password pass = password
socket = /var/run/mysqld/mysqld.sock socket = /var/run/mysqld/mysqld.sock
schema = account schema = account
maxConnections = 4 maxConnections = 4
debug = false