| 11216 | */ |
| 11217 | |
| 11218 | bool mysql_create_user(THD *thd, List <LEX_USER> &list, bool handle_as_role) |
| 11219 | { |
| 11220 | int result; |
| 11221 | String wrong_users; |
| 11222 | LEX_USER *user_name; |
| 11223 | List_iterator <LEX_USER> user_list(list); |
| 11224 | bool binlog= false; |
| 11225 | bool some_users_dropped= false; |
| 11226 | DBUG_ENTER("mysql_create_user"); |
| 11227 | DBUG_PRINT("entry", ("Handle as %s", handle_as_role ? "role" : "user")); |
| 11228 | |
| 11229 | if (handle_as_role && sp_process_definer(thd)) |
| 11230 | DBUG_RETURN(TRUE); |
| 11231 | |
| 11232 | /* CREATE USER may be skipped on replication client. */ |
| 11233 | Grant_tables tables; |
| 11234 | const uint tables_to_open= Table_user | Table_db | Table_tables_priv | |
| 11235 | Table_columns_priv | Table_procs_priv | |
| 11236 | Table_proxies_priv | Table_roles_mapping; |
| 11237 | if ((result= tables.open_and_lock(thd, tables_to_open, TL_WRITE))) |
| 11238 | DBUG_RETURN(result != 1); |
| 11239 | |
| 11240 | mysql_rwlock_wrlock(&LOCK_grant); |
| 11241 | mysql_mutex_lock(&acl_cache->lock); |
| 11242 | |
| 11243 | while ((user_name= user_list++)) |
| 11244 | { |
| 11245 | if (user_name->user.str == current_user.str) |
| 11246 | { |
| 11247 | append_str(&wrong_users, STRING_WITH_LEN("CURRENT_USER")); |
| 11248 | result= TRUE; |
| 11249 | continue; |
| 11250 | } |
| 11251 | |
| 11252 | if (user_name->user.str == current_role.str) |
| 11253 | { |
| 11254 | append_str(&wrong_users, STRING_WITH_LEN("CURRENT_ROLE")); |
| 11255 | result= TRUE; |
| 11256 | continue; |
| 11257 | } |
| 11258 | |
| 11259 | if (handle_as_role && |
| 11260 | (check_role_name(&user_name->user, false) == ROLE_NAME_INVALID)) |
| 11261 | { |
| 11262 | append_user(thd, &wrong_users, user_name); |
| 11263 | result= TRUE; |
| 11264 | continue; |
| 11265 | } |
| 11266 | |
| 11267 | if (!user_name->host.str) |
| 11268 | user_name->host= host_not_specified; |
| 11269 | |
| 11270 | /* |
| 11271 | Search all in-memory structures and grant tables |
| 11272 | for a mention of the new user/role name. |
| 11273 | */ |
| 11274 | if (handle_grant_data(thd, tables, 0, user_name, NULL)) |
| 11275 | { |
no test coverage detected