@@ -12341,8 +12341,57 @@ inline privilege_t public_access()
12341
12341
privilege_t get_column_grant (THD *, GRANT_INFO *, const char *, const char *,
12342
12342
const Lex_ident_column &)
12343
12343
{ return ALL_KNOWN_ACL; }
12344
+ int acl_check_setrole (THD *, const LEX_CSTRING &, privilege_t *) { return 0 ; }
12345
+ int acl_setrole (THD *, const LEX_CSTRING &, privilege_t ) { return 0 ; }
12344
12346
#endif /* NO_EMBEDDED_ACCESS_CHECKS */
12345
12347
12348
+ static int set_privs_on_login (THD *thd, const ACL_USER *acl_user)
12349
+ {
12350
+ Security_context *sctx= thd->security_ctx ;
12351
+ strmake_buf (sctx->priv_user , acl_user->user .str );
12352
+
12353
+ if (acl_user->host .hostname )
12354
+ strmake_buf (sctx->priv_host , acl_user->host .hostname );
12355
+
12356
+ sctx->master_access = acl_user->access | public_access ();
12357
+
12358
+ if (acl_user->default_rolename .length )
12359
+ {
12360
+ privilege_t access (NO_ACL);
12361
+ int result= acl_check_setrole (thd, acl_user->default_rolename , &access);
12362
+ if (!result)
12363
+ result= acl_setrole (thd, acl_user->default_rolename , access);
12364
+ thd->clear_error ();
12365
+ }
12366
+
12367
+ /*
12368
+ Don't allow the user to connect if he has done too many queries.
12369
+ As we are testing max_user_connections == 0 here, it means that we
12370
+ can't let the user change max_user_connections from 0 in the server
12371
+ without a restart as it would lead to wrong connect counting.
12372
+ */
12373
+ if ((acl_user->user_resource .questions ||
12374
+ acl_user->user_resource .updates ||
12375
+ acl_user->user_resource .conn_per_hour ||
12376
+ acl_user->user_resource .user_conn ||
12377
+ acl_user->user_resource .max_statement_time != 0.0 ||
12378
+ max_user_connections_checking) &&
12379
+ get_or_create_user_conn (thd,
12380
+ (opt_old_style_user_limits ? sctx->user : sctx->priv_user ),
12381
+ (opt_old_style_user_limits ? sctx->host_or_ip : sctx->priv_host ),
12382
+ &acl_user->user_resource ))
12383
+ return 1 ; // The error is set by get_or_create_user_conn()
12384
+
12385
+ if (acl_user->user_resource .max_statement_time != 0.0 )
12386
+ {
12387
+ thd->variables .max_statement_time_double =
12388
+ acl_user->user_resource .max_statement_time ;
12389
+ thd->variables .max_statement_time =
12390
+ (ulonglong) (thd->variables .max_statement_time_double * 1e6 + 0.1 );
12391
+ }
12392
+ return 0 ;
12393
+ }
12394
+
12346
12395
12347
12396
#ifdef NO_EMBEDDED_ACCESS_CHECKS
12348
12397
@@ -14992,40 +15041,8 @@ bool acl_authenticate(THD *thd, uint com_change_user_pkt_len)
14992
15041
}
14993
15042
#endif
14994
15043
14995
- sctx->master_access = (acl_user->access | public_access ());
14996
- strmake_buf (sctx->priv_user , acl_user->user .str );
14997
-
14998
- if (acl_user->host .hostname )
14999
- strmake_buf (sctx->priv_host , acl_user->host .hostname );
15000
- else
15001
- *sctx->priv_host = 0 ;
15002
-
15003
-
15004
- /*
15005
- Don't allow the user to connect if he has done too many queries.
15006
- As we are testing max_user_connections == 0 here, it means that we
15007
- can't let the user change max_user_connections from 0 in the server
15008
- without a restart as it would lead to wrong connect counting.
15009
- */
15010
- if ((acl_user->user_resource .questions ||
15011
- acl_user->user_resource .updates ||
15012
- acl_user->user_resource .conn_per_hour ||
15013
- acl_user->user_resource .user_conn ||
15014
- acl_user->user_resource .max_statement_time != 0.0 ||
15015
- max_user_connections_checking) &&
15016
- get_or_create_user_conn (thd,
15017
- (opt_old_style_user_limits ? sctx->user : sctx->priv_user ),
15018
- (opt_old_style_user_limits ? sctx->host_or_ip : sctx->priv_host ),
15019
- &acl_user->user_resource ))
15020
- DBUG_RETURN (1 ); // The error is set by get_or_create_user_conn()
15021
-
15022
- if (acl_user->user_resource .max_statement_time != 0.0 )
15023
- {
15024
- thd->variables .max_statement_time_double =
15025
- acl_user->user_resource .max_statement_time ;
15026
- thd->variables .max_statement_time =
15027
- (ulonglong) (thd->variables .max_statement_time_double * 1e6 + 0.1 );
15028
- }
15044
+ if (set_privs_on_login (thd, acl_user))
15045
+ DBUG_RETURN (1 );
15029
15046
}
15030
15047
else
15031
15048
sctx->skip_grants ();
@@ -15061,29 +15078,6 @@ bool acl_authenticate(THD *thd, uint com_change_user_pkt_len)
15061
15078
}
15062
15079
}
15063
15080
15064
- /*
15065
- This is the default access rights for the current database. It's
15066
- set to 0 here because we don't have an active database yet (and we
15067
- may not have an active database to set.
15068
- */
15069
- sctx->db_access = NO_ACL;
15070
-
15071
- #ifndef NO_EMBEDDED_ACCESS_CHECKS
15072
- /*
15073
- In case the user has a default role set, attempt to set that role
15074
- */
15075
- if (initialized && acl_user->default_rolename .length ) {
15076
- privilege_t access (NO_ACL);
15077
- int result;
15078
- result= acl_check_setrole (thd, acl_user->default_rolename , &access);
15079
- if (!result)
15080
- result= acl_setrole (thd, acl_user->default_rolename , access);
15081
- if (result)
15082
- thd->clear_error (); // even if the default role was not granted, do not
15083
- // close the connection
15084
- }
15085
- #endif
15086
-
15087
15081
/* Change a database if necessary */
15088
15082
if (mpvio.db .length )
15089
15083
{
0 commit comments