diff options
author | unknown <monty@mysql.com> | 2004-04-28 17:45:08 +0300 |
---|---|---|
committer | unknown <monty@mysql.com> | 2004-04-28 17:45:08 +0300 |
commit | 8b9ecce08ccccf645546465b505550a9241dff9d (patch) | |
tree | 44b9496a8f3b14561950eae22c33c0f3de67bd70 /sql/sql_acl.cc | |
parent | b0a8fde89732a11475144f0f2ab88acedcebdf86 (diff) | |
download | mariadb-git-8b9ecce08ccccf645546465b505550a9241dff9d.tar.gz |
Fixed http address in some scripts (Bug #3460)
Output TIMESTAMP in 4.1 format for 4.1 tables (or for TIMESTAMP(19)) (portability fix)
Fixed that INTERVAL can handle big integers. (Bug #3498)
Fixed that hostname="" works identical as hostname="%" for table/column grants (Bug #3473)
mysql-test/mysql-test-run.sh:
Fixed wrong http address (Bug #3460)
mysql-test/r/func_time.result:
Results for new test cases
mysql-test/t/func_time.test:
Added test of INTERVAL with big integers
scripts/mysqld_safe.sh:
Added html address to manual in case of error
sql/field.cc:
Output TIMESTAMP in 4.1 format for 4.1 tables (or for TIMESTAMP(19))
sql/item_timefunc.cc:
Fixed that INTERVAL can handle big integers. (Bug #3498)
sql/mysql_priv.h:
Removed not needed prototype
sql/sql_acl.cc:
Fixed that hostname="" works identical as hostname="%" for table/column grants (Bug #3473)
Moved GRANT_TABLE::GRANT_TABLE functions ou from class definition to make it possible to debug them
sql/structs.h:
Fix for long values to INTERVAL
Diffstat (limited to 'sql/sql_acl.cc')
-rw-r--r-- | sql/sql_acl.cc | 211 |
1 files changed, 112 insertions, 99 deletions
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 596619b3955..9385c4aa7f5 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -740,12 +740,12 @@ static void acl_insert_user(const char *user, const char *host, { ACL_USER acl_user; acl_user.user=*user ? strdup_root(&mem,user) : 0; - update_hostname(&acl_user.host,strdup_root(&mem,host)); + update_hostname(&acl_user.host, *host ? strdup_root(&mem,host): 0); acl_user.password=0; acl_user.access=privileges; acl_user.user_resource = *mqh; acl_user.sort=get_sort(2,acl_user.host.hostname,acl_user.user); - acl_user.hostname_length=(uint) strlen(acl_user.host.hostname); + acl_user.hostname_length=(uint) strlen(host); acl_user.ssl_type= (ssl_type != SSL_TYPE_NOT_SPECIFIED ? ssl_type : SSL_TYPE_NONE); acl_user.ssl_cipher= ssl_cipher ? strdup_root(&mem,ssl_cipher) : 0; @@ -1611,107 +1611,121 @@ static byte* get_key_column(GRANT_COLUMN *buff,uint *length, class GRANT_TABLE :public Sql_alloc { public: - char *host,*db,*user,*tname, *hash_key; + char *host,*db,*user,*tname, *hash_key, *orig_host; ulong privs, cols; ulong sort; uint key_length; HASH hash_columns; - GRANT_TABLE (const char *h, const char *d,const char *u, const char *t, - ulong p, ulong c) - : privs(p), cols(c) - { - host = strdup_root(&memex,h); - db = strdup_root(&memex,d); - user = strdup_root(&memex,u); - sort= get_sort(3,host,db,user); - tname= strdup_root(&memex,t); - if (lower_case_table_names) - { - casedn_str(db); - casedn_str(tname); - } - key_length =(uint) strlen(d)+(uint) strlen(u)+(uint) strlen(t)+3; - hash_key = (char*) alloc_root(&memex,key_length); - strmov(strmov(strmov(hash_key,user)+1,db)+1,tname); - (void) hash_init(&hash_columns,0,0,0, (hash_get_key) get_key_column,0, - HASH_CASE_INSENSITIVE); - } + GRANT_TABLE(const char *h, const char *d,const char *u, const char *t, + ulong p, ulong c); + GRANT_TABLE(TABLE *form, TABLE *col_privs); + bool ok() { return privs != 0 || cols != 0; } +}; - GRANT_TABLE (TABLE *form, TABLE *col_privs) + +GRANT_TABLE::GRANT_TABLE(const char *h, const char *d,const char *u, + const char *t, ulong p, ulong c) + :privs(p), cols(c) +{ + /* Host given by user */ + orig_host= strdup_root(&memex,h); + /* Convert empty hostname to '%' for easy comparision */ + host= orig_host[0] ? orig_host : (char*) "%"; + db = strdup_root(&memex,d); + user = strdup_root(&memex,u); + sort= get_sort(3,host,db,user); + tname= strdup_root(&memex,t); + if (lower_case_table_names) { - byte key[MAX_KEY_LENGTH]; + casedn_str(db); + casedn_str(tname); + } + key_length =(uint) strlen(d)+(uint) strlen(u)+(uint) strlen(t)+3; + hash_key = (char*) alloc_root(&memex,key_length); + strmov(strmov(strmov(hash_key,user)+1,db)+1,tname); + (void) hash_init(&hash_columns,0,0,0, (hash_get_key) get_key_column,0, + HASH_CASE_INSENSITIVE); +} + + +GRANT_TABLE::GRANT_TABLE(TABLE *form, TABLE *col_privs) +{ + byte key[MAX_KEY_LENGTH]; - host = get_field(&memex,form,0); - db = get_field(&memex,form,1); - user = get_field(&memex,form,2); - if (!user) - user=(char*) ""; - sort= get_sort(3,host,db,user); - tname = get_field(&memex,form,3); - if (!host || !db || !tname) + orig_host= host= get_field(&memex,form,0); + db = get_field(&memex,form,1); + user = get_field(&memex,form,2); + if (!user) + user= (char*) ""; + if (!orig_host) + { + orig_host= (char*) ""; + host= (char*) "%"; + } + sort= get_sort(3,orig_host,db,user); + tname = get_field(&memex,form,3); + if (!db || !tname) + { + /* Wrong table row; Ignore it */ + privs = cols = 0; /* purecov: inspected */ + return; /* purecov: inspected */ + } + if (lower_case_table_names) + { + casedn_str(db); + casedn_str(tname); + } + key_length = ((uint) strlen(db) + (uint) strlen(user) + + (uint) strlen(tname) + 3); + hash_key = (char*) alloc_root(&memex,key_length); + strmov(strmov(strmov(hash_key,user)+1,db)+1,tname); + privs = (ulong) form->field[6]->val_int(); + cols = (ulong) form->field[7]->val_int(); + privs = fix_rights_for_table(privs); + cols = fix_rights_for_column(cols); + + (void) hash_init(&hash_columns,0,0,0, (hash_get_key) get_key_column,0, + HASH_CASE_INSENSITIVE); + if (cols) + { + int key_len; + col_privs->field[0]->store(orig_host,(uint) strlen(orig_host)); + col_privs->field[1]->store(db,(uint) strlen(db)); + col_privs->field[2]->store(user,(uint) strlen(user)); + col_privs->field[3]->store(tname,(uint) strlen(tname)); + key_len=(col_privs->field[0]->pack_length()+ + col_privs->field[1]->pack_length()+ + col_privs->field[2]->pack_length()+ + col_privs->field[3]->pack_length()); + key_copy(key,col_privs,0,key_len); + col_privs->field[4]->store("",0); + col_privs->file->index_init(0); + if (col_privs->file->index_read(col_privs->record[0], + (byte*) col_privs->field[0]->ptr, + key_len, HA_READ_KEY_EXACT)) { - /* Wrong table row; Ignore it */ - privs = cols = 0; /* purecov: inspected */ - return; /* purecov: inspected */ + cols = 0; /* purecov: deadcode */ + return; } - if (lower_case_table_names) - { - casedn_str(db); - casedn_str(tname); - } - key_length = ((uint) strlen(db) + (uint) strlen(user) + - (uint) strlen(tname) + 3); - hash_key = (char*) alloc_root(&memex,key_length); - strmov(strmov(strmov(hash_key,user)+1,db)+1,tname); - privs = (ulong) form->field[6]->val_int(); - cols = (ulong) form->field[7]->val_int(); - privs = fix_rights_for_table(privs); - cols = fix_rights_for_column(cols); - - (void) hash_init(&hash_columns,0,0,0, (hash_get_key) get_key_column,0, - HASH_CASE_INSENSITIVE); - if (cols) + do { - int key_len; - col_privs->field[0]->store(host,(uint) strlen(host)); - col_privs->field[1]->store(db,(uint) strlen(db)); - col_privs->field[2]->store(user,(uint) strlen(user)); - col_privs->field[3]->store(tname,(uint) strlen(tname)); - key_len=(col_privs->field[0]->pack_length()+ - col_privs->field[1]->pack_length()+ - col_privs->field[2]->pack_length()+ - col_privs->field[3]->pack_length()); - key_copy(key,col_privs,0,key_len); - col_privs->field[4]->store("",0); - col_privs->file->index_init(0); - if (col_privs->file->index_read(col_privs->record[0], - (byte*) col_privs->field[0]->ptr, - key_len, HA_READ_KEY_EXACT)) + String *res,column_name; + GRANT_COLUMN *mem_check; + /* As column name is a string, we don't have to supply a buffer */ + res=col_privs->field[4]->val_str(&column_name,&column_name); + ulong priv= (ulong) col_privs->field[6]->val_int(); + if (!(mem_check = new GRANT_COLUMN(*res, + fix_rights_for_column(priv)))) { - cols = 0; /* purecov: deadcode */ - return; + /* Don't use this entry */ + privs = cols = 0; /* purecov: deadcode */ + return; /* purecov: deadcode */ } - do - { - String *res,column_name; - GRANT_COLUMN *mem_check; - /* As column name is a string, we don't have to supply a buffer */ - res=col_privs->field[4]->val_str(&column_name,&column_name); - ulong priv= (ulong) col_privs->field[6]->val_int(); - if (!(mem_check = new GRANT_COLUMN(*res, - fix_rights_for_column(priv)))) - { - /* Don't use this entry */ - privs = cols = 0; /* purecov: deadcode */ - return; /* purecov: deadcode */ - } - hash_insert(&hash_columns, (byte *) mem_check); - } while (!col_privs->file->index_next(col_privs->record[0]) && - !key_cmp(col_privs,key,0,key_len)); - } + hash_insert(&hash_columns, (byte *) mem_check); + } while (!col_privs->file->index_next(col_privs->record[0]) && + !key_cmp(col_privs,key,0,key_len)); } - bool ok() { return privs != 0 || cols != 0; } -}; +} static byte* get_grant_table(GRANT_TABLE *buff,uint *length, @@ -2286,8 +2300,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, } -int mysql_grant (THD *thd, const char *db, List <LEX_USER> &list, - ulong rights, bool revoke_grant) +int mysql_grant(THD *thd, const char *db, List <LEX_USER> &list, + ulong rights, bool revoke_grant) { List_iterator <LEX_USER> str_list (list); LEX_USER *Str; @@ -2538,7 +2552,7 @@ void grant_reload(THD *thd) /**************************************************************************** - Check grants + Check table level grants All errors are written directly to the client if no_errors is given ! ****************************************************************************/ @@ -2898,7 +2912,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) if (!(user=acl_user->user)) user=""; if (!(host=acl_user->host.hostname)) - host="%"; + host=""; if (!strcmp(lex_user->user.str,user) && !my_strcasecmp(lex_user->host.str,host)) break; @@ -3079,19 +3093,17 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) } } - /* Add column access */ + /* Add table & column access */ for (index=0 ; index < hash_tables.records ; index++) { const char *user,*host; GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&hash_tables,index); if (!(user=grant_table->user)) - user=""; - if (!(host=grant_table->host)) - host=""; + user= ""; if (!strcmp(lex_user->user.str,user) && - !my_strcasecmp(lex_user->host.str,host)) + !my_strcasecmp(lex_user->host.str, grant_table->orig_host)) { ulong table_access= grant_table->privs; if ((table_access | grant_table->cols) != 0) @@ -3108,6 +3120,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) global.append("USAGE",5); else { + /* Add specific column access */ int found= 0; ulong j; |