mirror of
https://github.com/MariaDB/server.git
synced 2025-07-24 19:42:23 +03:00
5.3 merge
This commit is contained in:
124
sql/sql_acl.cc
124
sql/sql_acl.cc
@ -1,5 +1,5 @@
|
||||
/* Copyright (c) 2000, 2011, Oracle and/or its affiliates.
|
||||
Copyright (c) 2009-2011, Monty Program Ab
|
||||
Copyright (c) 2009, 2013, Monty Program Ab
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -560,7 +560,18 @@ static bool update_user_table(THD *thd, TABLE *table, const char *host,
|
||||
static my_bool acl_load(THD *thd, TABLE_LIST *tables);
|
||||
static my_bool grant_load(THD *thd, TABLE_LIST *tables);
|
||||
static inline void get_grantor(THD *thd, char* grantor);
|
||||
|
||||
/*
|
||||
Enumeration of various ACL's and Hashes used in handle_grant_struct()
|
||||
*/
|
||||
enum enum_acl_lists
|
||||
{
|
||||
USER_ACL= 0,
|
||||
DB_ACL,
|
||||
COLUMN_PRIVILEGES_HASH,
|
||||
PROC_PRIVILEGES_HASH,
|
||||
FUNC_PRIVILEGES_HASH,
|
||||
ACL_PROXY_USERS
|
||||
};
|
||||
/*
|
||||
Convert scrambled password to binary form, according to scramble type,
|
||||
Binary form is stored in user.salt.
|
||||
@ -767,7 +778,12 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
|
||||
convert db to lower case and give a warning if the db wasn't
|
||||
already in lower case
|
||||
*/
|
||||
(void) strmov(tmp_name, host.db);
|
||||
char *end = strnmov(tmp_name, host.db, sizeof(tmp_name));
|
||||
if (end >= tmp_name + sizeof(tmp_name))
|
||||
{
|
||||
sql_print_warning(ER(ER_WRONG_DB_NAME), host.db);
|
||||
continue;
|
||||
}
|
||||
my_casedn_str(files_charset_info, host.db);
|
||||
if (strcmp(host.db, tmp_name) != 0)
|
||||
sql_print_warning("'host' entry '%s|%s' had database in mixed "
|
||||
@ -1038,7 +1054,12 @@ static my_bool acl_load(THD *thd, TABLE_LIST *tables)
|
||||
convert db to lower case and give a warning if the db wasn't
|
||||
already in lower case
|
||||
*/
|
||||
(void)strmov(tmp_name, db.db);
|
||||
char *end = strnmov(tmp_name, db.db, sizeof(tmp_name));
|
||||
if (end >= tmp_name + sizeof(tmp_name))
|
||||
{
|
||||
sql_print_warning(ER(ER_WRONG_DB_NAME), db.db);
|
||||
continue;
|
||||
}
|
||||
my_casedn_str(files_charset_info, db.db);
|
||||
if (strcmp(db.db, tmp_name) != 0)
|
||||
{
|
||||
@ -3007,15 +3028,23 @@ static GRANT_NAME *name_hash_search(HASH *name_hash,
|
||||
const char *user, const char *tname,
|
||||
bool exact, bool name_tolower)
|
||||
{
|
||||
char helping [SAFE_NAME_LEN*2+USERNAME_LENGTH+3], *name_ptr;
|
||||
char helping[SAFE_NAME_LEN*2+USERNAME_LENGTH+3];
|
||||
char *hend = helping + sizeof(helping);
|
||||
uint len;
|
||||
GRANT_NAME *grant_name,*found=0;
|
||||
HASH_SEARCH_STATE state;
|
||||
|
||||
name_ptr= strmov(strmov(helping, user) + 1, db) + 1;
|
||||
len = (uint) (strmov(name_ptr, tname) - helping) + 1;
|
||||
char *db_ptr= strmov(helping, user) + 1;
|
||||
char *tname_ptr= strnmov(db_ptr, db, hend - db_ptr) + 1;
|
||||
if (tname_ptr > hend)
|
||||
return 0; // invalid name = not found
|
||||
char *end= strnmov(tname_ptr, tname, hend - tname_ptr) + 1;
|
||||
if (end > hend)
|
||||
return 0; // invalid name = not found
|
||||
|
||||
len = (uint) (end - helping);
|
||||
if (name_tolower)
|
||||
my_casedn_str(files_charset_info, name_ptr);
|
||||
my_casedn_str(files_charset_info, tname_ptr);
|
||||
for (grant_name= (GRANT_NAME*) my_hash_first(name_hash, (uchar*) helping,
|
||||
len, &state);
|
||||
grant_name ;
|
||||
@ -4016,7 +4045,12 @@ bool mysql_grant(THD *thd, const char *db, List <LEX_USER> &list,
|
||||
|
||||
if (lower_case_table_names && db)
|
||||
{
|
||||
strmov(tmp_db,db);
|
||||
char *end= strnmov(tmp_db,db, sizeof(tmp_db));
|
||||
if (end >= tmp_db + sizeof(tmp_db))
|
||||
{
|
||||
my_error(ER_WRONG_DB_NAME ,MYF(0), db);
|
||||
DBUG_RETURN(TRUE);
|
||||
}
|
||||
my_casedn_str(files_charset_info, tmp_db);
|
||||
db=tmp_db;
|
||||
}
|
||||
@ -6058,20 +6092,20 @@ static int handle_grant_table(TABLE_LIST *tables, uint table_no, bool drop,
|
||||
Delete from grant structure if drop is true.
|
||||
Update in grant structure if drop is false and user_to is not NULL.
|
||||
Search in grant structure if drop is false and user_to is NULL.
|
||||
Structures are numbered as follows:
|
||||
0 acl_users
|
||||
1 acl_dbs
|
||||
2 column_priv_hash
|
||||
3 proc_priv_hash
|
||||
4 func_priv_hash
|
||||
5 acl_proxy_users
|
||||
Structures are enumerated as follows:
|
||||
0 ACL_USER
|
||||
1 ACL_DB
|
||||
2 COLUMN_PRIVILEGES_HASH
|
||||
3 PROC_PRIVILEGES_HASH
|
||||
4 FUNC_PRIVILEGES_HASH
|
||||
5 ACL_PROXY_USERS
|
||||
|
||||
@retval > 0 At least one element matched.
|
||||
@retval 0 OK, but no element matched.
|
||||
@retval -1 Wrong arguments to function.
|
||||
@retval -1 Wrong arguments to function or Out of Memory
|
||||
*/
|
||||
|
||||
static int handle_grant_struct(uint struct_no, bool drop,
|
||||
static int handle_grant_struct(enum enum_acl_lists struct_no, bool drop,
|
||||
LEX_USER *user_from, LEX_USER *user_to)
|
||||
{
|
||||
int result= 0;
|
||||
@ -6095,21 +6129,21 @@ static int handle_grant_struct(uint struct_no, bool drop,
|
||||
|
||||
/* Get the number of elements in the in-memory structure. */
|
||||
switch (struct_no) {
|
||||
case 0:
|
||||
case USER_ACL:
|
||||
elements= acl_users.elements;
|
||||
break;
|
||||
case 1:
|
||||
case DB_ACL:
|
||||
elements= acl_dbs.elements;
|
||||
break;
|
||||
case 2:
|
||||
case COLUMN_PRIVILEGES_HASH:
|
||||
grant_name_hash= &column_priv_hash;
|
||||
elements= grant_name_hash->records;
|
||||
break;
|
||||
case 3:
|
||||
case PROC_PRIVILEGES_HASH:
|
||||
grant_name_hash= &proc_priv_hash;
|
||||
elements= grant_name_hash->records;
|
||||
break;
|
||||
case 4:
|
||||
case FUNC_PRIVILEGES_HASH:
|
||||
grant_name_hash= &func_priv_hash;
|
||||
elements= grant_name_hash->records;
|
||||
break;
|
||||
@ -6131,21 +6165,21 @@ static int handle_grant_struct(uint struct_no, bool drop,
|
||||
Get a pointer to the element.
|
||||
*/
|
||||
switch (struct_no) {
|
||||
case 0:
|
||||
case USER_ACL:
|
||||
acl_user= dynamic_element(&acl_users, idx, ACL_USER*);
|
||||
user= acl_user->user;
|
||||
host= acl_user->host.hostname;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case DB_ACL:
|
||||
acl_db= dynamic_element(&acl_dbs, idx, ACL_DB*);
|
||||
user= acl_db->user;
|
||||
host= acl_db->host.hostname;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case COLUMN_PRIVILEGES_HASH:
|
||||
case PROC_PRIVILEGES_HASH:
|
||||
case FUNC_PRIVILEGES_HASH:
|
||||
grant_name= (GRANT_NAME*) my_hash_element(grant_name_hash, idx);
|
||||
user= grant_name->user;
|
||||
host= grant_name->host.hostname;
|
||||
@ -6177,17 +6211,17 @@ static int handle_grant_struct(uint struct_no, bool drop,
|
||||
if ( drop )
|
||||
{
|
||||
switch ( struct_no ) {
|
||||
case 0:
|
||||
case USER_ACL:
|
||||
delete_dynamic_element(&acl_users, idx);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case DB_ACL:
|
||||
delete_dynamic_element(&acl_dbs, idx);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case COLUMN_PRIVILEGES_HASH:
|
||||
case PROC_PRIVILEGES_HASH:
|
||||
case FUNC_PRIVILEGES_HASH:
|
||||
my_hash_delete(grant_name_hash, (uchar*) grant_name);
|
||||
break;
|
||||
|
||||
@ -6215,19 +6249,19 @@ static int handle_grant_struct(uint struct_no, bool drop,
|
||||
else if ( user_to )
|
||||
{
|
||||
switch ( struct_no ) {
|
||||
case 0:
|
||||
case USER_ACL:
|
||||
acl_user->user= strdup_root(&mem, user_to->user.str);
|
||||
acl_user->host.hostname= strdup_root(&mem, user_to->host.str);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case DB_ACL:
|
||||
acl_db->user= strdup_root(&mem, user_to->user.str);
|
||||
acl_db->host.hostname= strdup_root(&mem, user_to->host.str);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case COLUMN_PRIVILEGES_HASH:
|
||||
case PROC_PRIVILEGES_HASH:
|
||||
case FUNC_PRIVILEGES_HASH:
|
||||
{
|
||||
/*
|
||||
Save old hash key and its length to be able properly update
|
||||
@ -6324,7 +6358,7 @@ static int handle_grant_data(TABLE_LIST *tables, bool drop,
|
||||
else
|
||||
{
|
||||
/* Handle user array. */
|
||||
if ((handle_grant_struct(0, drop, user_from, user_to)) || found)
|
||||
if ((handle_grant_struct(USER_ACL, drop, user_from, user_to)) || found)
|
||||
{
|
||||
result= 1; /* At least one record/element found. */
|
||||
/* If search is requested, we do not need to search further. */
|
||||
@ -6342,7 +6376,7 @@ static int handle_grant_data(TABLE_LIST *tables, bool drop,
|
||||
else
|
||||
{
|
||||
/* Handle db array. */
|
||||
if (((handle_grant_struct(1, drop, user_from, user_to) && ! result) ||
|
||||
if (((handle_grant_struct(DB_ACL, drop, user_from, user_to) && ! result) ||
|
||||
found) && ! result)
|
||||
{
|
||||
result= 1; /* At least one record/element found. */
|
||||
@ -6361,7 +6395,7 @@ static int handle_grant_data(TABLE_LIST *tables, bool drop,
|
||||
else
|
||||
{
|
||||
/* Handle procs array. */
|
||||
if (((handle_grant_struct(3, drop, user_from, user_to) && ! result) ||
|
||||
if (((handle_grant_struct(PROC_PRIVILEGES_HASH, drop, user_from, user_to) && ! result) ||
|
||||
found) && ! result)
|
||||
{
|
||||
result= 1; /* At least one record/element found. */
|
||||
@ -6370,7 +6404,7 @@ static int handle_grant_data(TABLE_LIST *tables, bool drop,
|
||||
goto end;
|
||||
}
|
||||
/* Handle funcs array. */
|
||||
if (((handle_grant_struct(4, drop, user_from, user_to) && ! result) ||
|
||||
if (((handle_grant_struct(FUNC_PRIVILEGES_HASH, drop, user_from, user_to) && ! result) ||
|
||||
found) && ! result)
|
||||
{
|
||||
result= 1; /* At least one record/element found. */
|
||||
@ -6405,7 +6439,7 @@ static int handle_grant_data(TABLE_LIST *tables, bool drop,
|
||||
else
|
||||
{
|
||||
/* Handle columns hash. */
|
||||
if (((handle_grant_struct(2, drop, user_from, user_to) && ! result) ||
|
||||
if (((handle_grant_struct(COLUMN_PRIVILEGES_HASH, drop, user_from, user_to) && ! result) ||
|
||||
found) && ! result)
|
||||
result= 1; /* At least one record/element found. */
|
||||
}
|
||||
@ -6414,7 +6448,7 @@ static int handle_grant_data(TABLE_LIST *tables, bool drop,
|
||||
/* Handle proxies_priv table. */
|
||||
if (tables[5].table)
|
||||
{
|
||||
if ((found= handle_grant_table(tables, 5, drop, user_from, user_to)) < 0)
|
||||
if ((found= handle_grant_table(tables, ACL_PROXY_USERS, drop, user_from, user_to)) < 0)
|
||||
{
|
||||
/* Handle of table failed, don't touch the in-memory array. */
|
||||
result= -1;
|
||||
@ -6422,7 +6456,7 @@ static int handle_grant_data(TABLE_LIST *tables, bool drop,
|
||||
else
|
||||
{
|
||||
/* Handle proxies_priv array. */
|
||||
if ((handle_grant_struct(5, drop, user_from, user_to) && !result) ||
|
||||
if ((handle_grant_struct(ACL_PROXY_USERS, drop, user_from, user_to) && !result) ||
|
||||
found)
|
||||
result= 1; /* At least one record/element found. */
|
||||
}
|
||||
|
Reference in New Issue
Block a user