Skip to content

Commit 01995e7

Browse files
committed
Merge branch 'mysql-8.0' into mysql-trunk
2 parents d95718f + 8275e64 commit 01995e7

File tree

5 files changed

+34
-17
lines changed

5 files changed

+34
-17
lines changed

plugin/x/src/sql_data_context.cc

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,19 +305,6 @@ ngs::Error_code Sql_data_context::authenticate_internal(
305305
std::string user_name = get_user_name();
306306
std::string host_or_ip = get_host_or_ip();
307307

308-
/*
309-
Instead of modifying the current security context in switch_user()
310-
method above, we must create a security_context to do the
311-
security_context_lookup() on newly created security_context then set
312-
that in the THD. Until that happens, we have to get the existing security
313-
context and set that again in the THD. The latter opertion is nedded as
314-
it may toggle the system_user flag in THD iff security_context has
315-
SYSTEM_USER privilege.
316-
*/
317-
MYSQL_SECURITY_CONTEXT scontext;
318-
thd_get_security_context(get_thd(), &scontext);
319-
thd_set_security_context(get_thd(), scontext);
320-
321308
#ifdef HAVE_PSI_THREAD_INTERFACE
322309
PSI_THREAD_CALL(set_thread_account)
323310
(user_name.c_str(), static_cast<int>(user_name.length()),

sql/auth/service_security_context.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -82,6 +82,7 @@ my_svc_bool thd_set_security_context(MYSQL_THD _thd,
8282
try {
8383
if (in_ctx) {
8484
thd->set_security_context(in_ctx);
85+
in_ctx->set_thd(thd);
8586
// Turn ON the flag in THD iff the user is granted SYSTEM_USER privilege
8687
set_system_user_flag(thd);
8788
}
@@ -182,6 +183,12 @@ my_svc_bool security_context_lookup(MYSQL_SECURITY_CONTEXT ctx,
182183
retval = acl_getroot(tmp_thd ? tmp_thd : current_thd, ctx, user, host, ip, db)
183184
? true
184185
: false;
186+
/*
187+
If it is not a new security context then update the
188+
system_user flag in its referenced THD.
189+
*/
190+
THD *sctx_thd = ctx->get_thd();
191+
if (sctx_thd) set_system_user_flag(sctx_thd);
185192

186193
if (tmp_thd) {
187194
destroy_thd(tmp_thd);

sql/auth/sql_security_ctx.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,8 +630,13 @@ std::pair<bool, bool> Security_context::has_global_grant(const char *priv,
630630
std::string privilege(priv, priv_len);
631631

632632
if (m_acl_map == nullptr) {
633-
Acl_cache_lock_guard acl_cache_lock(current_thd,
634-
Acl_cache_lock_mode::READ_MODE);
633+
THD *thd = m_thd ? m_thd : current_thd;
634+
if (thd == nullptr) {
635+
DBUG_PRINT("error", ("Security Context must have valid THD handle to"
636+
" probe grants.\n"));
637+
return {false, false};
638+
}
639+
Acl_cache_lock_guard acl_cache_lock(thd, Acl_cache_lock_mode::READ_MODE);
635640
if (!acl_cache_lock.lock(false)) return std::make_pair(false, false);
636641
Role_id key(&m_priv_user[0], m_priv_user_length, &m_priv_host[0],
637642
m_priv_host_length);

sql/auth/sql_security_ctx.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -299,6 +299,10 @@ class Security_context {
299299

300300
void clear_db_restrictions();
301301

302+
void set_thd(THD *thd);
303+
304+
THD *get_thd();
305+
302306
private:
303307
void init();
304308
void destroy();
@@ -481,4 +485,8 @@ inline void Security_context::clear_db_restrictions() {
481485
m_restrictions.clear_db();
482486
}
483487

488+
inline void Security_context::set_thd(THD *thd) { m_thd = thd; }
489+
490+
inline THD *Security_context::get_thd() { return m_thd; }
491+
484492
#endif /* SQL_SECURITY_CTX_INCLUDED */

sql/server_component/security_context_imp.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ DEFINE_BOOL_METHOD(mysql_security_context_imp::set,
7070
Security_context *in_sctx = reinterpret_cast<Security_context *>(in_ctx);
7171
if (in_sctx) {
7272
thd->set_security_context(in_sctx);
73+
in_sctx->set_thd(thd);
74+
7375
// Turn ON the flag in THD iff the user is granted SYSTEM_USER privilege
7476
set_system_user_flag(thd);
7577
}
@@ -179,6 +181,14 @@ DEFINE_BOOL_METHOD(mysql_security_context_imp::lookup,
179181
? true
180182
: false;
181183

184+
/*
185+
If it is not a new security context then update the
186+
system_user flag in its referenced THD.
187+
*/
188+
Security_context *sctx = reinterpret_cast<Security_context *>(ctx);
189+
THD *sctx_thd = sctx->get_thd();
190+
if (sctx_thd) set_system_user_flag(sctx_thd);
191+
182192
if (tmp_thd) {
183193
destroy_thd(tmp_thd);
184194
tmp_thd = nullptr;

0 commit comments

Comments
 (0)