summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mysql/plugin_audit.h.pp4
-rw-r--r--include/mysql/plugin_auth.h.pp4
-rw-r--r--include/mysql/plugin_data_type.h.pp4
-rw-r--r--include/mysql/plugin_encryption.h.pp4
-rw-r--r--include/mysql/plugin_ftparser.h.pp4
-rw-r--r--include/mysql/plugin_function.h.pp4
-rw-r--r--include/mysql/plugin_password_validation.h.pp4
-rw-r--r--include/mysql/service_sql.h7
-rw-r--r--mysql-test/suite/plugins/r/test_sql_service.result10
-rw-r--r--mysql-test/suite/plugins/t/test_sql_service.test7
-rw-r--r--plugin/password_reuse_check/password_reuse_check.c2
-rw-r--r--plugin/test_sql_service/test_sql_service.c6
-rw-r--r--sql/sql_prepare.cc30
13 files changed, 65 insertions, 25 deletions
diff --git a/include/mysql/plugin_audit.h.pp b/include/mysql/plugin_audit.h.pp
index fedfb5862b4..0c03d421a23 100644
--- a/include/mysql/plugin_audit.h.pp
+++ b/include/mysql/plugin_audit.h.pp
@@ -467,7 +467,7 @@ int json_unescape_json(const char *json_str, const char *json_end,
extern "C" {
extern struct sql_service_st {
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
- MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
+ MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql, const char *plugin_name);
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
const char *user, const char *passwd, const char *db, unsigned int port,
const char *unix_socket, unsigned long clientflag);
@@ -482,7 +482,7 @@ extern struct sql_service_st {
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
void (STDCALL *mysql_close_func)(MYSQL *mysql);
} *sql_service;
-MYSQL *mysql_real_connect_local(MYSQL *mysql);
+MYSQL *mysql_real_connect_local(MYSQL *mysql, const char *plugin_name);
}
}
struct st_mysql_xid {
diff --git a/include/mysql/plugin_auth.h.pp b/include/mysql/plugin_auth.h.pp
index f4adae35ffd..9bd18192cc0 100644
--- a/include/mysql/plugin_auth.h.pp
+++ b/include/mysql/plugin_auth.h.pp
@@ -467,7 +467,7 @@ int json_unescape_json(const char *json_str, const char *json_end,
extern "C" {
extern struct sql_service_st {
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
- MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
+ MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql, const char *plugin_name);
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
const char *user, const char *passwd, const char *db, unsigned int port,
const char *unix_socket, unsigned long clientflag);
@@ -482,7 +482,7 @@ extern struct sql_service_st {
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
void (STDCALL *mysql_close_func)(MYSQL *mysql);
} *sql_service;
-MYSQL *mysql_real_connect_local(MYSQL *mysql);
+MYSQL *mysql_real_connect_local(MYSQL *mysql, const char *plugin_name);
}
}
struct st_mysql_xid {
diff --git a/include/mysql/plugin_data_type.h.pp b/include/mysql/plugin_data_type.h.pp
index 68333230b00..db64dcfa2bd 100644
--- a/include/mysql/plugin_data_type.h.pp
+++ b/include/mysql/plugin_data_type.h.pp
@@ -467,7 +467,7 @@ int json_unescape_json(const char *json_str, const char *json_end,
extern "C" {
extern struct sql_service_st {
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
- MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
+ MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql, const char *plugin_name);
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
const char *user, const char *passwd, const char *db, unsigned int port,
const char *unix_socket, unsigned long clientflag);
@@ -482,7 +482,7 @@ extern struct sql_service_st {
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
void (STDCALL *mysql_close_func)(MYSQL *mysql);
} *sql_service;
-MYSQL *mysql_real_connect_local(MYSQL *mysql);
+MYSQL *mysql_real_connect_local(MYSQL *mysql, const char *plugin_name);
}
}
struct st_mysql_xid {
diff --git a/include/mysql/plugin_encryption.h.pp b/include/mysql/plugin_encryption.h.pp
index a7dca09334d..15bf26b862f 100644
--- a/include/mysql/plugin_encryption.h.pp
+++ b/include/mysql/plugin_encryption.h.pp
@@ -467,7 +467,7 @@ int json_unescape_json(const char *json_str, const char *json_end,
extern "C" {
extern struct sql_service_st {
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
- MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
+ MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql, const char *plugin_name);
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
const char *user, const char *passwd, const char *db, unsigned int port,
const char *unix_socket, unsigned long clientflag);
@@ -482,7 +482,7 @@ extern struct sql_service_st {
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
void (STDCALL *mysql_close_func)(MYSQL *mysql);
} *sql_service;
-MYSQL *mysql_real_connect_local(MYSQL *mysql);
+MYSQL *mysql_real_connect_local(MYSQL *mysql, const char *plugin_name);
}
}
struct st_mysql_xid {
diff --git a/include/mysql/plugin_ftparser.h.pp b/include/mysql/plugin_ftparser.h.pp
index 3270f88defd..f50d3b2b4db 100644
--- a/include/mysql/plugin_ftparser.h.pp
+++ b/include/mysql/plugin_ftparser.h.pp
@@ -467,7 +467,7 @@ int json_unescape_json(const char *json_str, const char *json_end,
extern "C" {
extern struct sql_service_st {
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
- MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
+ MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql, const char *plugin_name);
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
const char *user, const char *passwd, const char *db, unsigned int port,
const char *unix_socket, unsigned long clientflag);
@@ -482,7 +482,7 @@ extern struct sql_service_st {
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
void (STDCALL *mysql_close_func)(MYSQL *mysql);
} *sql_service;
-MYSQL *mysql_real_connect_local(MYSQL *mysql);
+MYSQL *mysql_real_connect_local(MYSQL *mysql, const char *plugin_name);
}
}
struct st_mysql_xid {
diff --git a/include/mysql/plugin_function.h.pp b/include/mysql/plugin_function.h.pp
index 4f0c15e74eb..50117fd5915 100644
--- a/include/mysql/plugin_function.h.pp
+++ b/include/mysql/plugin_function.h.pp
@@ -467,7 +467,7 @@ int json_unescape_json(const char *json_str, const char *json_end,
extern "C" {
extern struct sql_service_st {
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
- MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
+ MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql, const char *plugin_name);
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
const char *user, const char *passwd, const char *db, unsigned int port,
const char *unix_socket, unsigned long clientflag);
@@ -482,7 +482,7 @@ extern struct sql_service_st {
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
void (STDCALL *mysql_close_func)(MYSQL *mysql);
} *sql_service;
-MYSQL *mysql_real_connect_local(MYSQL *mysql);
+MYSQL *mysql_real_connect_local(MYSQL *mysql, const char *plugin_name);
}
}
struct st_mysql_xid {
diff --git a/include/mysql/plugin_password_validation.h.pp b/include/mysql/plugin_password_validation.h.pp
index d8dbd8b0dfe..dfff6fd771b 100644
--- a/include/mysql/plugin_password_validation.h.pp
+++ b/include/mysql/plugin_password_validation.h.pp
@@ -467,7 +467,7 @@ int json_unescape_json(const char *json_str, const char *json_end,
extern "C" {
extern struct sql_service_st {
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
- MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
+ MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql, const char *plugin_name);
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
const char *user, const char *passwd, const char *db, unsigned int port,
const char *unix_socket, unsigned long clientflag);
@@ -482,7 +482,7 @@ extern struct sql_service_st {
MYSQL_ROW (STDCALL *mysql_fetch_row_func)(MYSQL_RES *result);
void (STDCALL *mysql_close_func)(MYSQL *mysql);
} *sql_service;
-MYSQL *mysql_real_connect_local(MYSQL *mysql);
+MYSQL *mysql_real_connect_local(MYSQL *mysql, const char *plugin_name);
}
}
struct st_mysql_xid {
diff --git a/include/mysql/service_sql.h b/include/mysql/service_sql.h
index ef6de8b34ef..9a431824dbc 100644
--- a/include/mysql/service_sql.h
+++ b/include/mysql/service_sql.h
@@ -48,7 +48,7 @@ extern "C" {
extern struct sql_service_st {
MYSQL *(STDCALL *mysql_init_func)(MYSQL *mysql);
- MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql);
+ MYSQL *(*mysql_real_connect_local_func)(MYSQL *mysql, const char *plugin_name);
MYSQL *(STDCALL *mysql_real_connect_func)(MYSQL *mysql, const char *host,
const char *user, const char *passwd, const char *db, unsigned int port,
const char *unix_socket, unsigned long clientflag);
@@ -67,7 +67,8 @@ extern struct sql_service_st {
#ifdef MYSQL_DYNAMIC_PLUGIN
#define mysql_init(M) sql_service->mysql_init_func(M)
-#define mysql_real_connect_local(M) sql_service->mysql_real_connect_local_func(M)
+#define mysql_real_connect_local(M, P) \
+ sql_service->mysql_real_connect_local_func(M, P)
#define mysql_real_connect(M,H,U,PW,D,P,S,F) sql_service->mysql_real_connect_func(M,H,U,PW,D,P,S,F)
#define mysql_errno(M) sql_service->mysql_errno_func(M)
#define mysql_error(M) sql_service->mysql_error_func(M)
@@ -88,7 +89,7 @@ extern struct sql_service_st {
neither it has the current db, so the queries should have
database/table name specified.
*/
-MYSQL *mysql_real_connect_local(MYSQL *mysql);
+MYSQL *mysql_real_connect_local(MYSQL *mysql, const char *plugin_name);
/* The rest of the function declarations mest be taken from the mysql.h */
diff --git a/mysql-test/suite/plugins/r/test_sql_service.result b/mysql-test/suite/plugins/r/test_sql_service.result
index 00f0411b665..4d81152659f 100644
--- a/mysql-test/suite/plugins/r/test_sql_service.result
+++ b/mysql-test/suite/plugins/r/test_sql_service.result
@@ -65,6 +65,16 @@ show status like 'test_sql_query_result';
Variable_name Value
Test_sql_query_result Query returned 5 rows.
drop table t1;
+set global test_sql_service_execute_sql_global= 'create table test.t1 select current_user()';
+select * from t1;
+current_user()
+test_sql_service_gl@
+drop table t1;
+set global test_sql_service_execute_sql_local= 'create table test.t1 select current_user()';
+select * from t1;
+current_user()
+test_sql_service@
+drop table t1;
uninstall plugin test_sql_service;
Warnings:
Warning 1620 Plugin is busy and will be uninstalled on shutdown
diff --git a/mysql-test/suite/plugins/t/test_sql_service.test b/mysql-test/suite/plugins/t/test_sql_service.test
index b80d78fe6e5..f924f06dfc6 100644
--- a/mysql-test/suite/plugins/t/test_sql_service.test
+++ b/mysql-test/suite/plugins/t/test_sql_service.test
@@ -56,5 +56,12 @@ set global test_sql_service_execute_sql_local= 'select * FROM test.t1 WHERE time
show status like 'test_sql_query_result';
drop table t1;
+set global test_sql_service_execute_sql_global= 'create table test.t1 select current_user()';
+select * from t1;
+drop table t1;
+set global test_sql_service_execute_sql_local= 'create table test.t1 select current_user()';
+select * from t1;
+drop table t1;
+
uninstall plugin test_sql_service;
diff --git a/plugin/password_reuse_check/password_reuse_check.c b/plugin/password_reuse_check/password_reuse_check.c
index 8373b64ea8a..c0231d2146b 100644
--- a/plugin/password_reuse_check/password_reuse_check.c
+++ b/plugin/password_reuse_check/password_reuse_check.c
@@ -172,7 +172,7 @@ static int validate(const MYSQL_CONST_LEX_STRING *username,
buff[key_len]= 0;
memset(hash, 0, sizeof(hash));
my_sha512(hash, buff, key_len);
- if (mysql_real_connect_local(mysql) == NULL)
+ if (mysql_real_connect_local(mysql, "password_reuse_check") == NULL)
goto sql_error;
if (interval)
diff --git a/plugin/test_sql_service/test_sql_service.c b/plugin/test_sql_service/test_sql_service.c
index c2dbb93bf20..74a95ab0b88 100644
--- a/plugin/test_sql_service/test_sql_service.c
+++ b/plugin/test_sql_service/test_sql_service.c
@@ -104,7 +104,7 @@ static int do_tests()
int result= 1;
mysql= mysql_init(NULL);
- if (mysql_real_connect_local(mysql) == NULL)
+ if (mysql_real_connect_local(mysql, "test_sql_service_loc") == NULL)
return 1;
if (run_queries(mysql))
@@ -188,7 +188,7 @@ static int run_sql_local(MYSQL_THD thd, struct st_mysql_sys_var *var, void *save
int result= 1;
mysql= mysql_init(NULL);
- if (mysql_real_connect_local(mysql) == NULL)
+ if (mysql_real_connect_local(mysql, "test_sql_service") == NULL)
return 1;
if (run_sql(mysql, save, value))
@@ -218,7 +218,7 @@ static int test_sql_service_plugin_init(void *p)
global_mysql= mysql_init(NULL);
if (!global_mysql ||
- mysql_real_connect_local(global_mysql) == NULL)
+ mysql_real_connect_local(global_mysql, "test_sql_service_gl") == NULL)
return 1;
init_done= 1;
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index e025147c71e..a54f40cd56d 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -6314,9 +6314,11 @@ static void loc_on_close_free(MYSQL *mysql)
{
Protocol_local *p= (Protocol_local *) mysql->thd;
THD *thd= p->new_thd;
+ p->empty_ctx.user= NULL;
delete p;
if (thd)
{
+ thd->security_ctx->user= NULL;
delete thd;
local_connection_thread_count--;
}
@@ -6353,12 +6355,16 @@ static MYSQL_METHODS local_methods=
Atomic_counter<uint32_t> local_connection_thread_count;
+static const char *sql_service_user= "SQL_service";
-extern "C" MYSQL *mysql_real_connect_local(MYSQL *mysql)
+extern "C" MYSQL *mysql_real_connect_local(MYSQL *mysql, const char *user)
{
THD *thd_orig= current_thd;
THD *new_thd;
Protocol_local *p;
+ char *s_user;
+ size_t s_user_len= 0;
+ Security_context *query_ctx= NULL;
DBUG_ENTER("mysql_real_connect_local");
/* Test whether we're already connected */
@@ -6371,8 +6377,19 @@ extern "C" MYSQL *mysql_real_connect_local(MYSQL *mysql)
mysql->methods= &local_methods;
mysql->user= NULL;
+ if (user)
+ s_user_len= strlen(user) + 1;
+
mysql->info_buffer= (char *) my_malloc(PSI_INSTRUMENT_ME,
- MYSQL_ERRMSG_SIZE, MYF(0));
+ MYSQL_ERRMSG_SIZE+s_user_len, MYF(0));
+ if (user)
+ {
+ s_user= mysql->info_buffer + MYSQL_ERRMSG_SIZE;
+ strncpy(s_user, user, s_user_len);
+ }
+ else
+ s_user= (char *) sql_service_user;
+
if (!thd_orig || thd_orig->lock)
{
/*
@@ -6388,7 +6405,7 @@ extern "C" MYSQL *mysql_real_connect_local(MYSQL *mysql)
local_connection_thread_count++;
new_thd->thread_stack= (char*) &thd_orig;
new_thd->store_globals();
- new_thd->security_ctx->skip_grants();
+ query_ctx= new_thd->security_ctx;
new_thd->query_cache_is_applicable= 0;
new_thd->variables.wsrep_on= 0;
/*
@@ -6409,10 +6426,15 @@ extern "C" MYSQL *mysql_real_connect_local(MYSQL *mysql)
new_thd->protocol= p;
else
{
+ query_ctx= &p->empty_ctx;
p->empty_ctx.init();
- p->empty_ctx.skip_grants();
}
+ query_ctx->skip_grants();
+ query_ctx->user= s_user;
+ query_ctx->host= (char*) my_localhost;
+ strmake_buf(query_ctx->priv_user, s_user);
+
mysql->thd= p;
mysql->server_status= SERVER_STATUS_AUTOCOMMIT;