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

Function mysql_create_user

sql/sql_acl.cc:11218–11378  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11216*/
11217
11218bool 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 {

Callers 1

sql_parse.ccFile · 0.85

Calls 15

sp_process_definerFunction · 0.85
append_strFunction · 0.85
check_role_nameFunction · 0.85
append_userFunction · 0.85
handle_grant_dataFunction · 0.85
push_warning_printfFunction · 0.85
replace_user_tableFunction · 0.85
find_acl_user_baseFunction · 0.85
find_acl_roleFunction · 0.85
add_role_user_mappingFunction · 0.85

Tested by

no test coverage detected