| 3025 | */ |
| 3026 | |
| 3027 | bool acl_reload(THD *thd) |
| 3028 | { |
| 3029 | DYNAMIC_ARRAY old_acl_hosts, old_acl_users, old_acl_proxy_users; |
| 3030 | Dynamic_array<ACL_DB> old_acl_dbs(PSI_INSTRUMENT_MEM, 0, 0); |
| 3031 | HASH old_acl_roles, old_acl_roles_mappings; |
| 3032 | ACL_ROLE *old_acl_public; |
| 3033 | MEM_ROOT old_mem; |
| 3034 | int result; |
| 3035 | DBUG_ENTER("acl_reload"); |
| 3036 | |
| 3037 | |
| 3038 | Grant_tables tables; |
| 3039 | /* |
| 3040 | To avoid deadlocks we should obtain table locks before |
| 3041 | obtaining acl_cache->lock mutex. |
| 3042 | */ |
| 3043 | const uint tables_to_open= Table_host | Table_user | Table_db | |
| 3044 | Table_proxies_priv | Table_roles_mapping; |
| 3045 | if ((result= tables.open_and_lock(thd, tables_to_open, TL_READ))) |
| 3046 | { |
| 3047 | DBUG_ASSERT(result <= 0); |
| 3048 | /* |
| 3049 | Execution might have been interrupted; only print the error message |
| 3050 | if an error condition has been raised. |
| 3051 | */ |
| 3052 | if (thd->get_stmt_da()->is_error()) |
| 3053 | sql_print_error("Fatal error: Can't open and lock privilege tables: %s", |
| 3054 | thd->get_stmt_da()->message()); |
| 3055 | goto end; |
| 3056 | } |
| 3057 | |
| 3058 | acl_cache->clear(0); |
| 3059 | mysql_mutex_record_order(&acl_cache->lock, &LOCK_status); |
| 3060 | mysql_mutex_lock(&acl_cache->lock); |
| 3061 | |
| 3062 | old_acl_hosts= acl_hosts; |
| 3063 | old_acl_users= acl_users; |
| 3064 | old_acl_roles= acl_roles; |
| 3065 | old_acl_public= acl_public; |
| 3066 | old_acl_roles_mappings= acl_roles_mappings; |
| 3067 | old_acl_proxy_users= acl_proxy_users; |
| 3068 | old_acl_dbs= acl_dbs; |
| 3069 | my_init_dynamic_array(key_memory_acl_mem, &acl_hosts, sizeof(ACL_HOST), 20, 50, MYF(0)); |
| 3070 | my_init_dynamic_array(key_memory_acl_mem, &acl_users, sizeof(ACL_USER), 50, 100, MYF(0)); |
| 3071 | acl_dbs.init(key_memory_acl_mem, 50, 100); |
| 3072 | my_init_dynamic_array(key_memory_acl_mem, &acl_proxy_users, sizeof(ACL_PROXY_USER), 50, 100, MYF(0)); |
| 3073 | my_hash_init2(key_memory_acl_mem, &acl_roles, 50, &my_charset_utf8mb3_bin, 0, |
| 3074 | 0, 0, acl_role_get_key, 0, free_acl_role, 0); |
| 3075 | my_hash_init2(key_memory_acl_mem, &acl_roles_mappings, 50, |
| 3076 | &my_charset_utf8mb3_bin, 0, 0, 0, acl_role_map_get_key, 0, 0, |
| 3077 | 0); |
| 3078 | old_mem= acl_memroot; |
| 3079 | delete_dynamic(&acl_wild_hosts); |
| 3080 | my_hash_free(&acl_check_hosts); |
| 3081 | acl_public= NULL; |
| 3082 | |
| 3083 | if ((result= acl_load(thd, tables))) |
| 3084 | { // Error. Revert to old list |
no test coverage detected