MCPcopy Create free account
hub / github.com/MariaDB/server / handle_grant_table

Function handle_grant_table

sql/sql_acl.cc:10485–10615  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10483*/
10484
10485static int handle_grant_table(THD *thd, const Grant_table_base& grant_table,
10486 enum enum_acl_tables which_table, bool drop,
10487 LEX_USER *user_from, LEX_USER *user_to)
10488{
10489 int result= 0;
10490 int error;
10491 TABLE *table= grant_table.table();
10492 DBUG_ENTER("handle_grant_table");
10493 if (!table)
10494 DBUG_RETURN(0);
10495
10496 Field *host_field= table->field[0];
10497 Field *user_field= table->field[which_table == USER_TABLE ||
10498 which_table == PROXIES_PRIV_TABLE ? 1 : 2];
10499 uchar user_key[MAX_KEY_LENGTH];
10500 uint key_prefix_length;
10501
10502 if (which_table == ROLES_MAPPING_TABLE)
10503 {
10504 result= handle_roles_mappings_table(table, drop, user_from, user_to);
10505 DBUG_RETURN(result);
10506 }
10507
10508 table->use_all_columns();
10509 if (which_table == USER_TABLE) // mysql.user table
10510 {
10511 /*
10512 The 'user' table has an unique index on (host, user).
10513 Thus, we can handle everything with a single index access.
10514 The host- and user fields are consecutive in the user table records.
10515 So we set host- and user fields of table->record[0] and use the
10516 pointer to the host field as key.
10517 index_read_idx() will replace table->record[0] (its first argument)
10518 by the searched record, if it exists.
10519 */
10520 DBUG_PRINT("info",("read table: '%s' search: '%s'@'%s'",
10521 table->s->table_name.str,
10522 user_from->user.str, user_from->host.str));
10523 host_field->store(user_from->host, system_charset_info);
10524 user_field->store(user_from->user, system_charset_info);
10525
10526 key_prefix_length= (table->key_info->key_part[0].store_length +
10527 table->key_info->key_part[1].store_length);
10528 key_copy(user_key, table->record[0], table->key_info, key_prefix_length);
10529
10530 error= table->file->ha_index_read_idx_map(table->record[0], 0,
10531 user_key, (key_part_map)3,
10532 HA_READ_KEY_EXACT);
10533 if (!unlikely(error) && !*user_from->host.str)
10534 {
10535 // verify that we got a role or a user, as needed
10536 if (static_cast<const User_table&>(grant_table).get_is_role() !=
10537 user_from->is_role())
10538 error= HA_ERR_KEY_NOT_FOUND;
10539 }
10540 if (unlikely(error))
10541 {
10542 if (error != HA_ERR_KEY_NOT_FOUND && error != HA_ERR_END_OF_FILE)

Callers 1

handle_grant_dataFunction · 0.85

Calls 15

key_copyFunction · 0.85
modify_grant_tableFunction · 0.85
use_all_columnsMethod · 0.80
ha_index_read_idx_mapMethod · 0.80
is_roleMethod · 0.80
ha_rnd_nextMethod · 0.80
val_lex_cstringMethod · 0.80
get_fieldFunction · 0.70
tableMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected