| 4879 | static USER_AUTH auth_no_password; |
| 4880 | |
| 4881 | static int replace_user_table(THD *thd, const User_table &user_table, |
| 4882 | LEX_USER * const combo, privilege_t rights, |
| 4883 | const bool revoke_grant, |
| 4884 | const bool can_create_user, |
| 4885 | const bool no_auto_create) |
| 4886 | { |
| 4887 | int error = -1; |
| 4888 | uint nauth= 0; |
| 4889 | bool old_row_exists=0; |
| 4890 | uchar user_key[MAX_KEY_LENGTH]; |
| 4891 | bool handle_as_role= combo->is_role(); |
| 4892 | LEX *lex= thd->lex; |
| 4893 | TABLE *table= user_table.table(); |
| 4894 | ACL_USER new_acl_user, *old_acl_user= 0; |
| 4895 | DBUG_ENTER("replace_user_table"); |
| 4896 | |
| 4897 | mysql_mutex_assert_owner(&acl_cache->lock); |
| 4898 | |
| 4899 | table->use_all_columns(); |
| 4900 | user_table.set_host(combo->host.str,combo->host.length); |
| 4901 | user_table.set_user(combo->user.str,combo->user.length); |
| 4902 | key_copy(user_key, table->record[0], table->key_info, |
| 4903 | table->key_info->key_length); |
| 4904 | |
| 4905 | if (table->file->ha_index_read_idx_map(table->record[0], 0, user_key, |
| 4906 | HA_WHOLE_KEY, HA_READ_KEY_EXACT)) |
| 4907 | { |
| 4908 | if (revoke_grant) |
| 4909 | { |
| 4910 | if (combo->host.length) |
| 4911 | my_error(ER_NONEXISTING_GRANT, MYF(0), combo->user.str, |
| 4912 | combo->host.str); |
| 4913 | else |
| 4914 | my_error(ER_INVALID_ROLE, MYF(0), combo->user.str); |
| 4915 | goto end; |
| 4916 | } |
| 4917 | /* |
| 4918 | There are four options which affect the process of creation of |
| 4919 | a new user (mysqld option --safe-create-user, 'insert' privilege |
| 4920 | on 'mysql.user' table, using 'GRANT' with 'IDENTIFIED BY' and |
| 4921 | SQL_MODE flag NO_AUTO_CREATE_USER). Below is the simplified rule |
| 4922 | how it should work. |
| 4923 | if (safe-user-create && ! INSERT_priv) => reject |
| 4924 | else if (identified_by) => create |
| 4925 | else if (no_auto_create_user) => reject |
| 4926 | else create |
| 4927 | |
| 4928 | see also test_if_create_new_users() |
| 4929 | */ |
| 4930 | else if (!combo->has_auth() && no_auto_create) |
| 4931 | { |
| 4932 | my_error(ER_PASSWORD_NO_MATCH, MYF(0)); |
| 4933 | goto end; |
| 4934 | } |
| 4935 | else if (!can_create_user) |
| 4936 | { |
| 4937 | my_error(ER_CANT_CREATE_USER_WITH_GRANT, MYF(0)); |
| 4938 | goto end; |
no test coverage detected