@@ -1944,13 +1944,14 @@ static void
1944
1944
server_mpvio_initialize (THD *thd, MPVIO_EXT *mpvio,
1945
1945
Thd_charset_adapter *charset_adapter)
1946
1946
{
1947
+ LEX_CSTRING sctx_host_or_ip= thd->security_context ()->host_or_ip ();
1948
+
1947
1949
memset (mpvio, 0 , sizeof (MPVIO_EXT));
1948
1950
mpvio->read_packet = server_mpvio_read_packet;
1949
1951
mpvio->write_packet = server_mpvio_write_packet;
1950
1952
mpvio->info = server_mpvio_info;
1951
- mpvio->auth_info .host_or_ip = thd->security_ctx ->host_or_ip ;
1952
- mpvio->auth_info .host_or_ip_length =
1953
- (unsigned int ) strlen (thd->security_ctx ->host_or_ip );
1953
+ mpvio->auth_info .host_or_ip = sctx_host_or_ip.str ;
1954
+ mpvio->auth_info .host_or_ip_length = sctx_host_or_ip.length ;
1954
1955
mpvio->auth_info .user_name = NULL ;
1955
1956
mpvio->auth_info .user_name_length = 0 ;
1956
1957
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
@@ -1968,8 +1969,8 @@ server_mpvio_initialize(THD *thd, MPVIO_EXT *mpvio,
1968
1969
mpvio->thread_id = thd->thread_id ();
1969
1970
mpvio->server_status = &thd->server_status ;
1970
1971
mpvio->net = &thd->net ;
1971
- mpvio->ip = (char *) thd->security_ctx -> get_ip ()->ptr () ;
1972
- mpvio->host = (char *) thd->security_ctx -> get_host ()->ptr () ;
1972
+ mpvio->ip = (char *) thd->security_context ()->ip (). str ;
1973
+ mpvio->host = (char *) thd->security_context ()->host (). str ;
1973
1974
mpvio->charset_adapter = charset_adapter;
1974
1975
}
1975
1976
@@ -1982,7 +1983,14 @@ server_mpvio_update_thd(THD *thd, MPVIO_EXT *mpvio)
1982
1983
thd->max_client_packet_length = mpvio->max_client_packet_length ;
1983
1984
if (mpvio->client_capabilities & CLIENT_INTERACTIVE)
1984
1985
thd->variables .net_wait_timeout = thd->variables .net_interactive_timeout ;
1985
- thd->security_ctx ->user = mpvio->auth_info .user_name ;
1986
+ thd->security_context ()->assign_user (
1987
+ mpvio->auth_info .user_name ,
1988
+ (mpvio->auth_info .user_name ? strlen (mpvio->auth_info .user_name ) : 0 ));
1989
+ if (mpvio->auth_info .user_name )
1990
+ my_free (mpvio->auth_info .user_name );
1991
+ LEX_CSTRING sctx_user= thd->security_context ()->user ();
1992
+ mpvio->auth_info .user_name = (char *) sctx_user.str ;
1993
+ mpvio->auth_info .user_name_length = sctx_user.length ;
1986
1994
if (thd->client_capabilities & CLIENT_IGNORE_SPACE)
1987
1995
thd->variables .sql_mode |= MODE_IGNORE_SPACE;
1988
1996
}
@@ -2133,7 +2141,7 @@ acl_authenticate(THD *thd, size_t com_change_user_pkt_len)
2133
2141
2134
2142
server_mpvio_update_thd (thd, &mpvio);
2135
2143
2136
- Security_context *sctx= thd->security_ctx ;
2144
+ Security_context *sctx= thd->security_context () ;
2137
2145
const ACL_USER *acl_user= mpvio.acl_user ;
2138
2146
2139
2147
thd->password = mpvio.auth_info .password_used ; // remember for error messages
@@ -2193,7 +2201,7 @@ acl_authenticate(THD *thd, size_t com_change_user_pkt_len)
2193
2201
DBUG_RETURN (1 );
2194
2202
}
2195
2203
2196
- sctx->proxy_user [ 0 ]= 0 ;
2204
+ sctx->assign_proxy_user ( " " , 0 ) ;
2197
2205
2198
2206
if (initialized) // if not --skip-grant-tables
2199
2207
{
@@ -2203,13 +2211,13 @@ acl_authenticate(THD *thd, size_t com_change_user_pkt_len)
2203
2211
const char *auth_user = acl_user->user ? acl_user->user : " " ;
2204
2212
ACL_PROXY_USER *proxy_user;
2205
2213
/* check if the user is allowed to proxy as another user */
2206
- proxy_user= acl_find_proxy_user (auth_user, sctx->get_host ()->ptr (),
2207
- sctx->get_ip ()->ptr (),
2214
+ proxy_user= acl_find_proxy_user (auth_user, sctx->host ().str , sctx->ip ().str ,
2208
2215
mpvio.auth_info .authenticated_as ,
2209
2216
&is_proxy_user);
2210
2217
if (is_proxy_user)
2211
2218
{
2212
2219
ACL_USER *acl_proxy_user;
2220
+ char proxy_user_buf[USERNAME_LENGTH + MAX_HOSTNAME + 5 ];
2213
2221
2214
2222
/* we need to find the proxy user, but there was none */
2215
2223
if (!proxy_user)
@@ -2222,9 +2230,10 @@ acl_authenticate(THD *thd, size_t com_change_user_pkt_len)
2222
2230
DBUG_RETURN (1 );
2223
2231
}
2224
2232
2225
- my_snprintf (sctx-> proxy_user , sizeof (sctx-> proxy_user ) - 1 ,
2233
+ my_snprintf (proxy_user_buf , sizeof (proxy_user_buf ) - 1 ,
2226
2234
" '%s'@'%s'" , auth_user,
2227
2235
acl_user->host .get_host () ? acl_user->host .get_host () : " " );
2236
+ sctx->assign_proxy_user (proxy_user_buf, strlen (proxy_user_buf));
2228
2237
2229
2238
/* we're proxying : find the proxy user definition */
2230
2239
mysql_mutex_lock (&acl_cache->lock );
@@ -2248,18 +2257,14 @@ acl_authenticate(THD *thd, size_t com_change_user_pkt_len)
2248
2257
}
2249
2258
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
2250
2259
2251
- sctx->master_access = acl_user->access ;
2252
- if (acl_user->user )
2253
- strmake (sctx->priv_user , acl_user->user , USERNAME_LENGTH - 1 );
2254
- else
2255
- *sctx->priv_user = 0 ;
2256
-
2257
- if (acl_user->host .get_host ())
2258
- strmake (sctx->priv_host , acl_user->host .get_host (), MAX_HOSTNAME - 1 );
2259
- else
2260
- *sctx->priv_host = 0 ;
2260
+ sctx->set_master_access (acl_user->access );
2261
+ sctx->assign_priv_user (acl_user->user , acl_user->user ?
2262
+ strlen (acl_user->user ) : 0 );
2263
+ sctx->assign_priv_host (acl_user->host .get_host (),
2264
+ acl_user->host .get_host () ?
2265
+ strlen (acl_user->host .get_host ()) : 0 );
2261
2266
2262
- if (!(sctx->master_access & SUPER_ACL) && !thd->is_error ())
2267
+ if (!(sctx->check_access ( SUPER_ACL) ) && !thd->is_error ())
2263
2268
{
2264
2269
mysql_mutex_lock (&LOCK_offline_mode);
2265
2270
bool tmp_offline_mode= MY_TEST (offline_mode);
@@ -2318,8 +2323,10 @@ acl_authenticate(THD *thd, size_t com_change_user_pkt_len)
2318
2323
acl_user->user_resource .user_conn ||
2319
2324
global_system_variables.max_user_connections ) &&
2320
2325
get_or_create_user_conn (thd,
2321
- (opt_old_style_user_limits ? sctx->user : sctx->priv_user ),
2322
- (opt_old_style_user_limits ? sctx->host_or_ip : sctx->priv_host ),
2326
+ (opt_old_style_user_limits ? sctx->user ().str :
2327
+ sctx->priv_user ().str ),
2328
+ (opt_old_style_user_limits ? sctx->host_or_ip ().str :
2329
+ sctx->priv_host ().str ),
2323
2330
&acl_user->user_resource ))
2324
2331
DBUG_RETURN (1 ); // The error is set by get_or_create_user_conn()
2325
2332
@@ -2329,7 +2336,8 @@ acl_authenticate(THD *thd, size_t com_change_user_pkt_len)
2329
2336
This allows proxy user to execute queries even if proxied user password
2330
2337
expires.
2331
2338
*/
2332
- sctx->password_expired = mpvio.acl_user ->password_expired || password_time_expired;
2339
+ sctx->set_password_expired (mpvio.acl_user ->password_expired ||
2340
+ password_time_expired);
2333
2341
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
2334
2342
}
2335
2343
else
@@ -2349,12 +2357,12 @@ acl_authenticate(THD *thd, size_t com_change_user_pkt_len)
2349
2357
" Login user: '%s' Priv_user: '%s' Using password: %s "
2350
2358
" Access: %lu db: '%s'" ,
2351
2359
thd->client_capabilities , thd->max_client_packet_length ,
2352
- sctx->host_or_ip , sctx->user , sctx->priv_user ,
2360
+ sctx->host_or_ip (). str , sctx->user (). str , sctx->priv_user (). str ,
2353
2361
thd->password ? " yes" : " no" ,
2354
- sctx->master_access , mpvio.db .str ));
2362
+ sctx->master_access () , mpvio.db .str ));
2355
2363
2356
2364
if (command == COM_CONNECT &&
2357
- !(thd->main_security_ctx . master_access & SUPER_ACL))
2365
+ !(thd->m_main_security_ctx . check_access ( SUPER_ACL) ))
2358
2366
{
2359
2367
#ifndef EMBEDDED_LIBRARY
2360
2368
if (!Connection_handler_manager::get_instance ()->valid_connection_count ())
@@ -2371,7 +2379,7 @@ acl_authenticate(THD *thd, size_t com_change_user_pkt_len)
2371
2379
set to 0 here because we don't have an active database yet (and we
2372
2380
may not have an active database to set.
2373
2381
*/
2374
- sctx->db_access = 0 ;
2382
+ sctx->set_db_access ( 0 ) ;
2375
2383
2376
2384
/* Change a database if necessary */
2377
2385
if (mpvio.db .length )
@@ -2388,8 +2396,8 @@ acl_authenticate(THD *thd, size_t com_change_user_pkt_len)
2388
2396
}
2389
2397
2390
2398
if (mpvio.auth_info .external_user [0 ])
2391
- sctx->set_external_user ( my_strdup (key_memory_MPVIO_EXT_auth_info ,
2392
- mpvio.auth_info .external_user , MYF ( 0 ) ));
2399
+ sctx->assign_external_user (mpvio. auth_info . external_user ,
2400
+ strlen ( mpvio.auth_info .external_user ));
2393
2401
2394
2402
2395
2403
if (res == CR_OK_HANDSHAKE_COMPLETE)
@@ -2398,9 +2406,11 @@ acl_authenticate(THD *thd, size_t com_change_user_pkt_len)
2398
2406
my_ok (thd);
2399
2407
2400
2408
#ifdef HAVE_PSI_THREAD_INTERFACE
2409
+ LEX_CSTRING main_sctx_user= thd->m_main_security_ctx .user ();
2410
+ LEX_CSTRING main_sctx_host_or_ip= thd->m_main_security_ctx .host_or_ip ();
2401
2411
PSI_THREAD_CALL (set_thread_account)
2402
- (thd-> main_security_ctx . user , strlen (thd-> main_security_ctx . user ) ,
2403
- thd-> main_security_ctx . host_or_ip , strlen (thd-> main_security_ctx . host_or_ip ) );
2412
+ (main_sctx_user. str , main_sctx_user. length ,
2413
+ main_sctx_host_or_ip. str , main_sctx_host_or_ip. length );
2404
2414
#endif /* HAVE_PSI_THREAD_INTERFACE */
2405
2415
2406
2416
/* Ready to handle queries */
0 commit comments