diff options
Diffstat (limited to 'sql/sql_acl.cc')
-rw-r--r-- | sql/sql_acl.cc | 261 |
1 files changed, 135 insertions, 126 deletions
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 867163be90d..5f8cf42c2bf 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -417,7 +417,7 @@ static ulong get_access(TABLE *form, uint fieldnr) { ulong access_bits=0,bit; char buff[2]; - String res(buff,sizeof(buff)); + String res(buff,sizeof(buff),default_charset_info); Field **pos; for (pos=form->field+fieldnr, bit=1; @@ -426,7 +426,7 @@ static ulong get_access(TABLE *form, uint fieldnr) pos++ , bit<<=1) { (*pos)->val_str(&res,&res); - if (toupper(res[0]) == 'Y') + if (my_toupper(system_charset_info, res[0]) == 'Y') access_bits|= bit; } return access_bits; @@ -644,7 +644,7 @@ static void acl_update_user(const char *user, const char *host, { if (!acl_user->host.hostname && !host[0] || acl_user->host.hostname && - !my_strcasecmp(host,acl_user->host.hostname)) + !my_strcasecmp(system_charset_info, host, acl_user->host.hostname)) { acl_user->access=privileges; if (mqh->bits & 1) @@ -733,7 +733,8 @@ static void acl_update_db(const char *user, const char *host, const char *db, !strcmp(user,acl_db->user)) { if (!acl_db->host.hostname && !host[0] || - acl_db->host.hostname && !my_strcasecmp(host,acl_db->host.hostname)) + acl_db->host.hostname && + !my_strcasecmp(system_charset_info, host, acl_db->host.hostname)) { if (!acl_db->db && !db[0] || acl_db->db && !strcmp(db,acl_db->db)) @@ -797,7 +798,7 @@ ulong acl_get(const char *host, const char *ip, const char *bin_ip, end=strmov((tmp_db=strmov(key+sizeof(struct in_addr),user)+1),db); if (lower_case_table_names) { - casedn_str(tmp_db); + my_casedn_str(system_charset_info, tmp_db); db=tmp_db; } key_length=(uint) (end-key); @@ -861,7 +862,7 @@ exit: } -int wild_case_compare(const char *str,const char *wildstr) +int wild_case_compare(CHARSET_INFO *cs, const char *str,const char *wildstr) { reg3 int flag; DBUG_ENTER("wild_case_compare"); @@ -872,7 +873,8 @@ int wild_case_compare(const char *str,const char *wildstr) { if (*wildstr == wild_prefix && wildstr[1]) wildstr++; - if (toupper(*wildstr++) != toupper(*str++)) DBUG_RETURN(1); + if (my_toupper(cs, *wildstr++) != + my_toupper(cs, *str++)) DBUG_RETURN(1); } if (! *wildstr ) DBUG_RETURN (*str != 0); if (*wildstr++ == wild_one) @@ -890,12 +892,12 @@ int wild_case_compare(const char *str,const char *wildstr) char cmp; if ((cmp= *wildstr) == wild_prefix && wildstr[1]) cmp=wildstr[1]; - cmp=toupper(cmp); - while (*str && toupper(*str) != cmp) + cmp=my_toupper(cs, cmp); + while (*str && my_toupper(cs, *str) != cmp) str++; if (!*str) DBUG_RETURN (1); } - if (wild_case_compare(str,wildstr) == 0) DBUG_RETURN (0); + if (wild_case_compare(cs, str,wildstr) == 0) DBUG_RETURN (0); } while (*str++); DBUG_RETURN(1); } @@ -914,7 +916,7 @@ static void init_check_host(void) DBUG_ENTER("init_check_host"); VOID(my_init_dynamic_array(&acl_wild_hosts,sizeof(struct acl_host_and_ip), acl_users.elements,1)); - VOID(hash_init(&acl_check_hosts,acl_users.elements,0,0, + VOID(hash_init(&acl_check_hosts,system_charset_info,acl_users.elements,0,0, (hash_get_key) check_get_key,0,HASH_CASE_INSENSITIVE)); if (!allow_all_hosts) { @@ -930,7 +932,8 @@ static void init_check_host(void) { // Check if host already exists acl_host_and_ip *acl=dynamic_element(&acl_wild_hosts,j, acl_host_and_ip *); - if (!my_strcasecmp(acl_user->host.hostname,acl->hostname)) + if (!my_strcasecmp(system_charset_info, + acl_user->host.hostname, acl->hostname)) break; // already stored } if (j == acl_wild_hosts.elements) // If new @@ -1003,19 +1006,19 @@ bool check_change_password(THD *thd, const char *host, const char *user) { if (!initialized) { - send_error(&thd->net, ER_PASSWORD_NOT_ALLOWED); /* purecov: inspected */ + send_error(thd, ER_PASSWORD_NOT_ALLOWED); /* purecov: inspected */ return(1); /* purecov: inspected */ } if (!thd->slave_thread && (strcmp(thd->user,user) || - my_strcasecmp(host,thd->host ? thd->host : thd->ip))) + my_strcasecmp(system_charset_info, host, thd->host_or_ip))) { if (check_access(thd, UPDATE_ACL, "mysql",0,1)) return(1); } if (!thd->slave_thread && !thd->user[0]) { - send_error(&thd->net, ER_PASSWORD_ANONYMOUS_USER); + send_error(thd, ER_PASSWORD_ANONYMOUS_USER); return(1); } return(0); @@ -1057,7 +1060,7 @@ bool change_password(THD *thd, const char *host, const char *user, ACL_USER *acl_user; if (!(acl_user= find_acl_user(host,user))) { - send_error(&thd->net, ER_PASSWORD_NO_MATCH); + send_error(thd, ER_PASSWORD_NO_MATCH); VOID(pthread_mutex_unlock(&acl_cache->lock)); DBUG_RETURN(1); } @@ -1067,7 +1070,7 @@ bool change_password(THD *thd, const char *host, const char *user, new_password)) { VOID(pthread_mutex_unlock(&acl_cache->lock)); /* purecov: deadcode */ - send_error(&thd->net,0); /* purecov: deadcode */ + send_error(thd,0); /* purecov: deadcode */ DBUG_RETURN(1); /* purecov: deadcode */ } get_salt_from_password(acl_user->salt,new_password); @@ -1168,7 +1171,8 @@ static bool compare_hostname(const acl_host_and_ip *host, const char *hostname, return (tmp & host->ip_mask) == host->ip; } return (!host->hostname || - (hostname && !wild_case_compare(hostname,host->hostname)) || + (hostname && !wild_case_compare(system_charset_info, + hostname,host->hostname)) || (ip && !wild_compare(ip,host->hostname))); } @@ -1191,8 +1195,8 @@ static bool update_user_table(THD *thd, const char *host, const char *user, tables.db=(char*) "mysql"; if (!(table=open_ltable(thd,&tables,TL_WRITE))) DBUG_RETURN(1); /* purecov: deadcode */ - table->field[0]->store(host,(uint) strlen(host)); - table->field[1]->store(user,(uint) strlen(user)); + table->field[0]->store(host,(uint) strlen(host), system_charset_info); + table->field[1]->store(user,(uint) strlen(user), system_charset_info); if (table->file->index_read_idx(table->record[0],0, (byte*) table->field[0]->ptr,0, @@ -1202,7 +1206,7 @@ static bool update_user_table(THD *thd, const char *host, const char *user, DBUG_RETURN(1); /* purecov: deadcode */ } store_record(table,1); - table->field[2]->store(new_password,(uint) strlen(new_password)); + table->field[2]->store(new_password,(uint) strlen(new_password), system_charset_info); if ((error=table->file->update_row(table->record[1],table->record[0]))) { table->file->print_error(error,MYF(0)); /* purecov: deadcode */ @@ -1268,8 +1272,8 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, password=combo.password.str; } - table->field[0]->store(combo.host.str,combo.host.length); - table->field[1]->store(combo.user.str,combo.user.length); + table->field[0]->store(combo.host.str,combo.host.length, system_charset_info); + table->field[1]->store(combo.user.str,combo.user.length, system_charset_info); table->file->index_init(0); if (table->file->index_read(table->record[0], (byte*) table->field[0]->ptr,0, @@ -1289,17 +1293,17 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, goto end; } old_row_exists = 0; - restore_record(table,2); // cp empty row from record[2] - table->field[0]->store(combo.host.str,combo.host.length); - table->field[1]->store(combo.user.str,combo.user.length); - table->field[2]->store(password,(uint) strlen(password)); + restore_record(table,2); // cp empty row from record[2] + table->field[0]->store(combo.host.str,combo.host.length, system_charset_info); + table->field[1]->store(combo.user.str,combo.user.length, system_charset_info); + table->field[2]->store(password,(uint) strlen(password), system_charset_info); } else { old_row_exists = 1; store_record(table,1); // Save copy for update if (combo.password.str) // If password given - table->field[2]->store(password,(uint) strlen(password)); + table->field[2]->store(password,(uint) strlen(password), system_charset_info); } /* Update table columns with new privileges */ @@ -1312,7 +1316,7 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, tmp_field++, priv <<= 1) { if (priv & rights) // set requested privileges - (*tmp_field)->store(&what,1); + (*tmp_field)->store(&what, 1, system_charset_info); } rights=get_access(table,3); DBUG_PRINT("info",("table->fields: %d",table->fields)); @@ -1321,31 +1325,31 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, /* We write down SSL related ACL stuff */ switch (thd->lex.ssl_type) { case SSL_TYPE_ANY: - table->field[24]->store("ANY",3); - table->field[25]->store("",0); - table->field[26]->store("",0); - table->field[27]->store("",0); + table->field[24]->store("ANY",3, system_charset_info); + table->field[25]->store("", 0, system_charset_info); + table->field[26]->store("", 0, system_charset_info); + table->field[27]->store("", 0, system_charset_info); break; case SSL_TYPE_X509: - table->field[24]->store("X509",4); - table->field[25]->store("",0); - table->field[26]->store("",0); - table->field[27]->store("",0); + table->field[24]->store("X509",4, system_charset_info); + table->field[25]->store("", 0, system_charset_info); + table->field[26]->store("", 0, system_charset_info); + table->field[27]->store("", 0, system_charset_info); break; case SSL_TYPE_SPECIFIED: - table->field[24]->store("SPECIFIED",9); - table->field[25]->store("",0); - table->field[26]->store("",0); - table->field[27]->store("",0); + table->field[24]->store("SPECIFIED",9, system_charset_info); + table->field[25]->store("", 0, system_charset_info); + table->field[26]->store("", 0, system_charset_info); + table->field[27]->store("", 0, system_charset_info); if (thd->lex.ssl_cipher) table->field[25]->store(thd->lex.ssl_cipher, - strlen(thd->lex.ssl_cipher)); + strlen(thd->lex.ssl_cipher), system_charset_info); if (thd->lex.x509_issuer) table->field[26]->store(thd->lex.x509_issuer, - strlen(thd->lex.x509_issuer)); + strlen(thd->lex.x509_issuer), system_charset_info); if (thd->lex.x509_subject) table->field[27]->store(thd->lex.x509_subject, - strlen(thd->lex.x509_subject)); + strlen(thd->lex.x509_subject), system_charset_info); break; case SSL_TYPE_NOT_SPECIFIED: case SSL_TYPE_NONE: // Impossible @@ -1437,9 +1441,9 @@ static int replace_db_table(TABLE *table, const char *db, DBUG_RETURN(-1); } - table->field[0]->store(combo.host.str,combo.host.length); - table->field[1]->store(db,(uint) strlen(db)); - table->field[2]->store(combo.user.str,combo.user.length); + table->field[0]->store(combo.host.str,combo.host.length, system_charset_info); + table->field[1]->store(db,(uint) strlen(db), system_charset_info); + table->field[2]->store(combo.user.str,combo.user.length, system_charset_info); table->file->index_init(0); if (table->file->index_read(table->record[0],(byte*) table->field[0]->ptr,0, HA_READ_KEY_EXACT)) @@ -1452,9 +1456,9 @@ static int replace_db_table(TABLE *table, const char *db, } old_row_exists = 0; restore_record(table,2); // cp empty row from record[2] - table->field[0]->store(combo.host.str,combo.host.length); - table->field[1]->store(db,(uint) strlen(db)); - table->field[2]->store(combo.user.str,combo.user.length); + table->field[0]->store(combo.host.str,combo.host.length, system_charset_info); + table->field[1]->store(db,(uint) strlen(db), system_charset_info); + table->field[2]->store(combo.user.str,combo.user.length, system_charset_info); } else { @@ -1466,7 +1470,7 @@ static int replace_db_table(TABLE *table, const char *db, for (i= 3, priv= 1; i < table->fields; i++, priv <<= 1) { if (priv & store_rights) // do it if priv is chosen - table->field [i]->store(&what,1); // set requested privileges + table->field [i]->store(&what,1, system_charset_info);// set requested privileges } rights=get_access(table,3); rights=fix_rights_for_db(rights); @@ -1547,13 +1551,14 @@ public: tname= strdup_root(&memex,t); if (lower_case_table_names) { - casedn_str(db); - casedn_str(tname); + my_casedn_str(system_charset_info, db); + my_casedn_str(system_charset_info, 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, + (void) hash_init(&hash_columns,system_charset_info, + 0,0,0, (hash_get_key) get_key_column,0, HASH_CASE_INSENSITIVE); } @@ -1575,8 +1580,8 @@ public: } if (lower_case_table_names) { - casedn_str(db); - casedn_str(tname); + my_casedn_str(system_charset_info, db); + my_casedn_str(system_charset_info, tname); } key_length = ((uint) strlen(db) + (uint) strlen(user) + (uint) strlen(tname) + 3); @@ -1587,21 +1592,22 @@ public: 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, + (void) hash_init(&hash_columns,system_charset_info, + 0,0,0, (hash_get_key) get_key_column,0, HASH_CASE_INSENSITIVE); if (cols) { 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)); + col_privs->field[0]->store(host,(uint) strlen(host), system_charset_info); + col_privs->field[1]->store(db,(uint) strlen(db), system_charset_info); + col_privs->field[2]->store(user,(uint) strlen(user), system_charset_info); + col_privs->field[3]->store(tname,(uint) strlen(tname), system_charset_info); 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->field[4]->store("",0, system_charset_info); col_privs->file->index_init(0); if (col_privs->file->index_read(col_privs->record[0], (byte*) col_privs->field[0]->ptr, @@ -1657,7 +1663,6 @@ static GRANT_TABLE *table_hash_search(const char *host,const char* ip, char helping [NAME_LEN*2+USERNAME_LENGTH+3]; uint len; GRANT_TABLE *grant_table,*found=0; - safe_mutex_assert_owner(&LOCK_grant); len = (uint) (strmov(strmov(strmov(helping,user)+1,db)+1,tname)-helping)+ 1; for (grant_table=(GRANT_TABLE*) hash_search(&hash_tables,(byte*) helping, @@ -1667,14 +1672,17 @@ static GRANT_TABLE *table_hash_search(const char *host,const char* ip, { if (exact) { - if ((host && !my_strcasecmp(host,grant_table->host)) || + if ((host && + !my_strcasecmp(system_charset_info, host, grant_table->host)) || (ip && !strcmp(ip,grant_table->host))) return grant_table; } else { - if ((host && !wild_case_compare(host,grant_table->host)) || - (ip && !wild_case_compare(ip,grant_table->host))) + if ((host && !wild_case_compare(system_charset_info, + host,grant_table->host)) || + (ip && !wild_case_compare(system_charset_info, + ip,grant_table->host))) found=grant_table; // Host ok } } @@ -1701,10 +1709,10 @@ static int replace_column_table(GRANT_TABLE *g_t, byte key[MAX_KEY_LENGTH]; DBUG_ENTER("replace_column_table"); - table->field[0]->store(combo.host.str,combo.host.length); - table->field[1]->store(db,(uint) strlen(db)); - table->field[2]->store(combo.user.str,combo.user.length); - table->field[3]->store(table_name,(uint) strlen(table_name)); + table->field[0]->store(combo.host.str,combo.host.length, system_charset_info); + table->field[1]->store(db,(uint) strlen(db), system_charset_info); + table->field[2]->store(combo.user.str,combo.user.length, system_charset_info); + table->field[3]->store(table_name,(uint) strlen(table_name), system_charset_info); key_length=(table->field[0]->pack_length()+ table->field[1]->pack_length()+ table->field[2]->pack_length()+ table->field[3]->pack_length()); key_copy(key,table,0,key_length); @@ -1721,7 +1729,7 @@ static int replace_column_table(GRANT_TABLE *g_t, ulong privileges = xx->rights; bool old_row_exists=0; key_restore(table,key,0,key_length); - table->field[4]->store(xx->column.ptr(),xx->column.length()); + table->field[4]->store(xx->column.ptr(),xx->column.length(),system_charset_info); if (table->file->index_read(table->record[0],(byte*) table->field[0]->ptr, 0, HA_READ_KEY_EXACT)) @@ -1735,9 +1743,9 @@ static int replace_column_table(GRANT_TABLE *g_t, continue; /* purecov: inspected */ } old_row_exists = 0; - restore_record(table,2); // Get empty record + restore_record(table,2); // Get empty record key_restore(table,key,0,key_length); - table->field[4]->store(xx->column.ptr(),xx->column.length()); + table->field[4]->store(xx->column.ptr(),xx->column.length(), system_charset_info); } else { @@ -1809,7 +1817,7 @@ static int replace_column_table(GRANT_TABLE *g_t, { GRANT_COLUMN *grant_column = NULL; char colum_name_buf[HOSTNAME_LENGTH+1]; - String column_name(colum_name_buf,sizeof(colum_name_buf)); + String column_name(colum_name_buf,sizeof(colum_name_buf),system_charset_info); privileges&= ~rights; table->field[6]->store((longlong) @@ -1865,7 +1873,6 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, int error=0; ulong store_table_rights, store_col_rights; DBUG_ENTER("replace_table_table"); - safe_mutex_assert_owner(&LOCK_grant); strxmov(grantor, thd->user, "@", thd->host_or_ip, NullS); @@ -1880,10 +1887,10 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, } restore_record(table,2); // Get empty record - table->field[0]->store(combo.host.str,combo.host.length); - table->field[1]->store(db,(uint) strlen(db)); - table->field[2]->store(combo.user.str,combo.user.length); - table->field[3]->store(table_name,(uint) strlen(table_name)); + table->field[0]->store(combo.host.str,combo.host.length, system_charset_info); + table->field[1]->store(db,(uint) strlen(db), system_charset_info); + table->field[2]->store(combo.user.str,combo.user.length, system_charset_info); + table->field[3]->store(table_name,(uint) strlen(table_name), system_charset_info); store_record(table,1); // store at pos 1 if (table->file->index_read_idx(table->record[0],0, @@ -1928,7 +1935,7 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, } } - table->field[4]->store(grantor,(uint) strlen(grantor)); + table->field[4]->store(grantor,(uint) strlen(grantor), system_charset_info); table->field[6]->store((longlong) store_table_rights); table->field[7]->store((longlong) store_col_rights); rights=fix_rights_for_table(store_table_rights); @@ -1983,7 +1990,7 @@ int mysql_table_grant (THD *thd, TABLE_LIST *table_list, if (!initialized) { - send_error(&(thd->net), ER_UNKNOWN_COM_ERROR); /* purecov: inspected */ + send_error(thd, ER_UNKNOWN_COM_ERROR); /* purecov: inspected */ return 1; /* purecov: inspected */ } if (rights & ~TABLE_ACLS) @@ -2049,7 +2056,7 @@ int mysql_table_grant (THD *thd, TABLE_LIST *table_list, if (!revoke_grant) create_new_users= test_if_create_new_users(thd); int result=0; - pthread_mutex_lock(&LOCK_grant); + rw_wrlock(&LOCK_grant); MEM_ROOT *old_root=my_pthread_getspecific_ptr(MEM_ROOT*,THR_MALLOC); my_pthread_setspecific_ptr(THR_MALLOC,&memex); @@ -2162,9 +2169,9 @@ int mysql_table_grant (THD *thd, TABLE_LIST *table_list, } grant_option=TRUE; my_pthread_setspecific_ptr(THR_MALLOC,old_root); - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); if (!result) - send_ok(&thd->net); + send_ok(thd); /* Tables are automatically closed */ DBUG_RETURN(result); } @@ -2182,14 +2189,14 @@ int mysql_grant (THD *thd, const char *db, List <LEX_USER> &list, if (!initialized) { - send_error(&(thd->net), ER_UNKNOWN_COM_ERROR); /* purecov: tested */ - return 1; /* purecov: tested */ + send_error(thd, ER_UNKNOWN_COM_ERROR); /* purecov: tested */ + return 1; /* purecov: tested */ } if (lower_case_table_names && db) { strmov(tmp_db,db); - casedn_str(tmp_db); + my_casedn_str(system_charset_info, tmp_db); db=tmp_db; } @@ -2212,7 +2219,7 @@ int mysql_grant (THD *thd, const char *db, List <LEX_USER> &list, create_new_users= test_if_create_new_users(thd); // go through users in user_list - pthread_mutex_lock(&LOCK_grant); + rw_wrlock(&LOCK_grant); VOID(pthread_mutex_lock(&acl_cache->lock)); grant_version++; @@ -2245,11 +2252,11 @@ int mysql_grant (THD *thd, const char *db, List <LEX_USER> &list, } } VOID(pthread_mutex_unlock(&acl_cache->lock)); - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); close_thread_tables(thd); if (!result) - send_ok(&thd->net); + send_ok(thd); DBUG_RETURN(result); } @@ -2278,7 +2285,8 @@ my_bool grant_init(void) DBUG_ENTER("grant_init"); grant_option = FALSE; - (void) hash_init(&hash_tables,0,0,0, (hash_get_key) get_grant_table, + (void) hash_init(&hash_tables,system_charset_info, + 0,0,0, (hash_get_key) get_grant_table, (hash_free_key) free_grant_table,0); init_sql_alloc(&memex,1024,0); @@ -2358,7 +2366,7 @@ void grant_reload(void) // Locked tables are checked by acl_init and doesn't have to be checked here - pthread_mutex_lock(&LOCK_grant); + rw_wrlock(&LOCK_grant); grant_version++; old_hash_tables=hash_tables; old_grant_option = grant_option; @@ -2376,7 +2384,7 @@ void grant_reload(void) hash_free(&old_hash_tables); free_root(&old_mem,MYF(0)); } - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); DBUG_VOID_RETURN; } @@ -2396,7 +2404,7 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, if (!want_access) return 0; // ok - pthread_mutex_lock(&LOCK_grant); + rw_rdlock(&LOCK_grant); for (table=tables; table ;table=table->next) { if (!(~table->grant.privilege & want_access)) @@ -2430,11 +2438,11 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, goto err; // impossible } } - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); return 0; err: - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); if (!no_errors) // Not a silent skip of table { const char *command=""; @@ -2456,7 +2464,7 @@ bool check_grant(THD *thd, ulong want_access, TABLE_LIST *tables, command = "index"; else if (want_access & GRANT_ACL) command = "grant"; - net_printf(&thd->net,ER_TABLEACCESS_DENIED_ERROR, + net_printf(thd,ER_TABLEACCESS_DENIED_ERROR, command, thd->priv_user, thd->host_or_ip, @@ -2476,7 +2484,7 @@ bool check_grant_column (THD *thd,TABLE *table, const char *name, if (!want_access) return 0; // Already checked - pthread_mutex_lock(&LOCK_grant); + rw_rdlock(&LOCK_grant); // reload table if someone has modified any grants @@ -2494,20 +2502,20 @@ bool check_grant_column (THD *thd,TABLE *table, const char *name, grant_column=column_hash_search(grant_table, name, length); if (grant_column && !(~grant_column->rights & want_access)) { - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); return 0; } #ifdef NOT_USED if (show_tables && (grant_column || table->grant.privilege & COL_ACLS)) { - pthread_mutex_unlock(&LOCK_grant); /* purecov: deadcode */ + rw_unlock(&LOCK_grant); /* purecov: deadcode */ return 0; /* purecov: deadcode */ } #endif /* We must use my_printf_error() here! */ err: - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); if (!show_tables) { char command[128]; @@ -2535,7 +2543,7 @@ bool check_grant_all_columns(THD *thd, ulong want_access, TABLE *table) if (!want_access) return 0; // Already checked - pthread_mutex_lock(&LOCK_grant); + rw_rdlock(&LOCK_grant); // reload table if someone has modified any grants @@ -2558,12 +2566,12 @@ bool check_grant_all_columns(THD *thd, ulong want_access, TABLE *table) if (!grant_column || (~grant_column->rights & want_access)) goto err; } - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); return 0; /* We must use my_printf_error() here! */ err: - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); const char *command=""; if (want_access & SELECT_ACL) @@ -2595,21 +2603,23 @@ bool check_grant_db(THD *thd,const char *db) bool error=1; len = (uint) (strmov(strmov(helping,thd->priv_user)+1,db)-helping)+ 1; - pthread_mutex_lock(&LOCK_grant); + rw_rdlock(&LOCK_grant); for (uint idx=0 ; idx < hash_tables.records ; idx++) { GRANT_TABLE *grant_table = (GRANT_TABLE*) hash_element(&hash_tables,idx); if (len < grant_table->key_length && !memcmp(grant_table->hash_key,helping,len) && - (thd->host && !wild_case_compare(thd->host,grant_table->host) || - (thd->ip && !wild_case_compare(thd->ip,grant_table->host)))) + (thd->host && !wild_case_compare(system_charset_info, + thd->host,grant_table->host) || + (thd->ip && !wild_case_compare(system_charset_info, + thd->ip,grant_table->host)))) { error=0; // Found match break; } } - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); return error; } @@ -2619,12 +2629,12 @@ bool check_grant_db(THD *thd,const char *db) ulong get_table_grant(THD *thd, TABLE_LIST *table) { - uint privilege; + ulong privilege; char *user = thd->priv_user; const char *db = table->db ? table->db : thd->db; GRANT_TABLE *grant_table; - pthread_mutex_lock(&LOCK_grant); + rw_rdlock(&LOCK_grant); grant_table = table_hash_search(thd->host,thd->ip,db,user, table->real_name,0); table->grant.grant_table=grant_table; // Remember for column test @@ -2632,7 +2642,7 @@ ulong get_table_grant(THD *thd, TABLE_LIST *table) if (grant_table) table->grant.privilege|= grant_table->privs; privilege= table->grant.privilege; - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); return privilege; } @@ -2643,7 +2653,7 @@ ulong get_column_grant(THD *thd, TABLE_LIST *table, Field *field) GRANT_COLUMN *grant_column; ulong priv; - pthread_mutex_lock(&LOCK_grant); + rw_rdlock(&LOCK_grant); // reload table if someone has modified any grants if (table->grant.version != grant_version) { @@ -2665,7 +2675,7 @@ ulong get_column_grant(THD *thd, TABLE_LIST *table, Field *field) else priv=table->grant.privilege | grant_column->rights; } - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); return priv; } @@ -2700,7 +2710,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) LINT_INIT(acl_user); if (!initialized) { - send_error(&(thd->net), ER_UNKNOWN_COM_ERROR); + send_error(thd, ER_UNKNOWN_COM_ERROR); DBUG_RETURN(-1); } if (!lex_user->host.str) @@ -2724,7 +2734,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) if (!(host=acl_user->host.hostname)) host="%"; if (!strcmp(lex_user->user.str,user) && - !my_strcasecmp(lex_user->host.str,host)) + !my_strcasecmp(system_charset_info, lex_user->host.str, host)) break; } if (counter == acl_users.elements) @@ -2734,7 +2744,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) DBUG_RETURN(-1); } - Item_string *field=new Item_string("",0); + Item_string *field=new Item_string("",0,system_charset_info); List<Item> field_list; field->name=buff; field->max_length=1024; @@ -2744,7 +2754,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) if (send_fields(thd,field_list,1)) DBUG_RETURN(-1); - pthread_mutex_lock(&LOCK_grant); + rw_wrlock(&LOCK_grant); VOID(pthread_mutex_lock(&acl_cache->lock)); /* Add first global access grants */ @@ -2752,7 +2762,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) acl_user->ssl_type != SSL_TYPE_NONE) { want_access=acl_user->access; - String global(buff,sizeof(buff)); + String global(buff,sizeof(buff),system_charset_info); global.length(0); global.append("GRANT ",6); @@ -2871,12 +2881,12 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) host=""; if (!strcmp(lex_user->user.str,user) && - !my_strcasecmp(lex_user->host.str,host)) + !my_strcasecmp(system_charset_info, lex_user->host.str, host)) { want_access=acl_db->access; if (want_access) { - String db(buff,sizeof(buff)); + String db(buff,sizeof(buff),system_charset_info); db.length(0); db.append("GRANT ",6); @@ -2930,12 +2940,12 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) host=""; if (!strcmp(lex_user->user.str,user) && - !my_strcasecmp(lex_user->host.str,host)) + !my_strcasecmp(system_charset_info, lex_user->host.str, host)) { want_access=grant_table->privs; if ((want_access | grant_table->cols) != 0) { - String global(buff,sizeof(buff)); + String global(buff,sizeof(buff),system_charset_info); global.length(0); global.append("GRANT ",6); @@ -2999,18 +3009,17 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) if (my_net_write(&thd->net,(char*) thd->packet.ptr(), thd->packet.length())) { - error=-1; + error= -1; break; } } } } - end: VOID(pthread_mutex_unlock(&acl_cache->lock)); - pthread_mutex_unlock(&LOCK_grant); + rw_unlock(&LOCK_grant); - send_eof(&thd->net); + send_eof(thd); DBUG_RETURN(error); } |