diff options
Diffstat (limited to 'sql/sql_acl.cc')
-rw-r--r-- | sql/sql_acl.cc | 157 |
1 files changed, 85 insertions, 72 deletions
diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 9e571e4b84c..cd20888cb98 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1225,8 +1225,7 @@ bool check_change_password(THD *thd, const char *host, const char *user, { if (!initialized) { - net_printf(thd,ER_OPTION_PREVENTS_STATEMENT, - "--skip-grant-tables"); + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables"); return(1); } if (!thd->slave_thread && @@ -1238,16 +1237,15 @@ bool check_change_password(THD *thd, const char *host, const char *user, } if (!thd->slave_thread && !thd->user[0]) { - send_error(thd, ER_PASSWORD_ANONYMOUS_USER); + my_message(ER_PASSWORD_ANONYMOUS_USER, ER(ER_PASSWORD_ANONYMOUS_USER), + MYF(0)); return(1); } uint len=strlen(new_password); if (len && len != SCRAMBLED_PASSWORD_CHAR_LENGTH && len != SCRAMBLED_PASSWORD_CHAR_LENGTH_323) { - net_printf(thd, 0, - "Password hash should be a %d-digit hexadecimal number", - SCRAMBLED_PASSWORD_CHAR_LENGTH); + my_error(ER_PASSWD_LENGTH, MYF(0), SCRAMBLED_PASSWORD_CHAR_LENGTH); return -1; } return(0); @@ -1285,7 +1283,7 @@ bool change_password(THD *thd, const char *host, const char *user, if (!(acl_user= find_acl_user(host, user))) { VOID(pthread_mutex_unlock(&acl_cache->lock)); - send_error(thd, ER_PASSWORD_NO_MATCH); + my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0)); DBUG_RETURN(1); } /* update loaded acl entry: */ @@ -1298,7 +1296,6 @@ bool change_password(THD *thd, const char *host, const char *user, new_password, new_password_len)) { VOID(pthread_mutex_unlock(&acl_cache->lock)); /* purecov: deadcode */ - send_error(thd,0); /* purecov: deadcode */ DBUG_RETURN(1); /* purecov: deadcode */ } @@ -1471,7 +1468,8 @@ static bool update_user_table(THD *thd, const char *host, const char *user, (byte*) table->field[0]->ptr,0, HA_READ_KEY_EXACT)) { - my_error(ER_PASSWORD_NO_MATCH,MYF(0)); /* purecov: deadcode */ + my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), + MYF(0)); /* purecov: deadcode */ DBUG_RETURN(1); /* purecov: deadcode */ } store_record(table,record[1]); @@ -1554,7 +1552,8 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, /* what == 'N' means revoke */ if (what == 'N') { - my_error(ER_NONEXISTING_GRANT, MYF(0), combo.user.str, combo.host.str); + my_printf_error(ER_NONEXISTING_GRANT, ER(ER_NONEXISTING_GRAN), MYF(0), + combo.user.str, combo.host.str); goto end; } /* @@ -1571,8 +1570,9 @@ static int replace_user_table(THD *thd, TABLE *table, const LEX_USER &combo, else if (((thd->variables.sql_mode & MODE_NO_AUTO_CREATE_USER) && !password_len) || !create_user) { - my_error(ER_NO_PERMISSION_TO_CREATE_USER, MYF(0), - thd->user, thd->host_or_ip); + my_printf_error(ER_NO_PERMISSION_TO_CREATE_USER, + ER(ER_NO_PERMISSION_TO_CREATE_USER), MYF(0), + thd->user, thd->host_or_ip); goto end; } old_row_exists = 0; @@ -1748,7 +1748,7 @@ static int replace_db_table(TABLE *table, const char *db, /* Check if there is such a user in user table in memory? */ if (!find_acl_user(combo.host.str,combo.user.str)) { - my_error(ER_PASSWORD_NO_MATCH,MYF(0)); + my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), MYF(0)); DBUG_RETURN(-1); } @@ -1760,7 +1760,8 @@ static int replace_db_table(TABLE *table, const char *db, { if (what == 'N') { // no row, no revoke - my_error(ER_NONEXISTING_GRANT, MYF(0), combo.user.str, combo.host.str); + my_printf_error(ER_NONEXISTING_GRANT, ER(ER_NONEXISTING_GRANT), MYF(0), + combo.user.str, combo.host.str); goto abort; } old_row_exists = 0; @@ -2067,8 +2068,10 @@ static int replace_column_table(GRANT_TABLE *g_t, { if (revoke_grant) { - my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0), - combo.user.str, combo.host.str, table_name); /* purecov: inspected */ + my_printf_error(ER_NONEXISTING_TABLE_GRANT, + ER(ER_NONEXISTING_TABLE_GRANT), MYF(0), + combo.user.str, combo.host.str, + table_name); /* purecov: inspected */ result= -1; /* purecov: inspected */ continue; /* purecov: inspected */ } @@ -2211,7 +2214,8 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, */ if (!find_acl_user(combo.host.str,combo.user.str)) { - my_error(ER_PASSWORD_NO_MATCH,MYF(0)); /* purecov: deadcode */ + my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH), + MYF(0)); /* purecov: deadcode */ DBUG_RETURN(-1); /* purecov: deadcode */ } @@ -2233,9 +2237,10 @@ static int replace_table_table(THD *thd, GRANT_TABLE *grant_table, */ if (revoke_grant) { // no row, no revoke - my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0), - combo.user.str, combo.host.str, - table_name); /* purecov: deadcode */ + my_printf_error(ER_NONEXISTING_TABLE_GRANT, + ER(ER_NONEXISTING_TABLE_GRANT), MYF(0), + combo.user.str, combo.host.str, + table_name); /* purecov: deadcode */ DBUG_RETURN(-1); /* purecov: deadcode */ } old_row_exists = 0; @@ -2317,11 +2322,11 @@ table_error: revoke_grant Set to 1 if this is a REVOKE command RETURN - 0 ok - 1 error + FALSE ok + TRUE error */ -int mysql_table_grant(THD *thd, TABLE_LIST *table_list, +bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, List <LEX_USER> &user_list, List <LEX_COLUMN> &columns, ulong rights, bool revoke_grant) @@ -2338,12 +2343,13 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, { my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables"); /* purecov: inspected */ - DBUG_RETURN(-1); /* purecov: inspected */ + DBUG_RETURN(TRUE); /* purecov: inspected */ } if (rights & ~TABLE_ACLS) { - my_error(ER_ILLEGAL_GRANT_FOR_TABLE,MYF(0)); - DBUG_RETURN(-1); + my_message(ER_ILLEGAL_GRANT_FOR_TABLE, ER(ER_ILLEGAL_GRANT_FOR_TABLE), + MYF(0)); + DBUG_RETURN(TRUE); } if (columns.elements && !revoke_grant) @@ -2352,8 +2358,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, List_iterator <LEX_COLUMN> column_iter(columns); int res; - if ((res= open_and_lock_tables(thd, table_list))) - DBUG_RETURN(res); + if (open_and_lock_tables(thd, table_list)) + DBUG_RETURN(TRUE); while ((column = column_iter++)) { @@ -2363,9 +2369,9 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, column->column.length(), 0, 0, 0, 0, &unused_field_idx)) { - my_error(ER_BAD_FIELD_ERROR, MYF(0), - column->column.c_ptr(), table_list->alias); - DBUG_RETURN(-1); + my_printf_error(ER_BAD_FIELD_ERROR, ER(ER_BAD_FIELD_ERROR), MYF(0), + column->column.c_ptr(), table_list->alias); + DBUG_RETURN(TRUE); } column_priv|= column->rights; } @@ -2379,8 +2385,9 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, fn_format(buf,buf,"","",4+16+32); if (access(buf,F_OK)) { - my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->alias); - DBUG_RETURN(-1); + my_printf_error(ER_NO_SUCH_TABLE, ER(ER_NO_SUCH_TABLE), MYF(0), + table_list->db, table_list->alias); + DBUG_RETURN(TRUE); } } @@ -2413,19 +2420,19 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, */ tables[0].updating= tables[1].updating= tables[2].updating= 1; if (!tables_ok(0, tables)) - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } #endif if (simple_open_n_lock_tables(thd,tables)) { // Should never happen close_thread_tables(thd); /* purecov: deadcode */ - DBUG_RETURN(-1); /* purecov: deadcode */ + DBUG_RETURN(TRUE); /* purecov: deadcode */ } if (!revoke_grant) create_new_users= test_if_create_new_users(thd); - int result=0; + bool result= FALSE; rw_wrlock(&LOCK_grant); MEM_ROOT *old_root= thd->mem_root; thd->mem_root= &memex; @@ -2437,8 +2444,9 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, if (Str->host.length > HOSTNAME_LENGTH || Str->user.length > USERNAME_LENGTH) { - my_error(ER_GRANT_WRONG_HOST_OR_USER,MYF(0)); - result= -1; + my_message(ER_GRANT_WRONG_HOST_OR_USER, ER(ER_GRANT_WRONG_HOST_OR_USER), + MYF(0)); + result= TRUE; continue; } /* Create user if needed */ @@ -2448,7 +2456,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, pthread_mutex_unlock(&acl_cache->lock); if (error) { - result= -1; // Remember error + result= TRUE; // Remember error continue; // Add next user } @@ -2466,9 +2474,10 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, { if (revoke_grant) { - my_error(ER_NONEXISTING_TABLE_GRANT, MYF(0), - Str->user.str, Str->host.str, table_list->real_name); - result= -1; + my_printf_error(ER_NONEXISTING_TABLE_GRANT, + ER(ER_NONEXISTING_TABLE_GRANT), MYF(0), + Str->user.str, Str->host.str, table_list->real_name); + result= TRUE; continue; } grant_table = new GRANT_TABLE (Str->host.str, db_name, @@ -2477,7 +2486,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, column_priv); if (!grant_table) // end of memory { - result= -1; /* purecov: deadcode */ + result= TRUE; /* purecov: deadcode */ continue; /* purecov: deadcode */ } my_hash_insert(&column_priv_hash,(byte*) grant_table); @@ -2522,7 +2531,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, rights, column_priv, revoke_grant)) { /* Should only happen if table is crashed */ - result= -1; /* purecov: deadcode */ + result= TRUE; /* purecov: deadcode */ } else if (tables[2].table) { @@ -2531,7 +2540,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, db_name, real_name, rights, revoke_grant))) { - result= -1; + result= TRUE; } } } @@ -2545,8 +2554,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) +bool 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; @@ -2558,7 +2567,7 @@ int mysql_grant(THD *thd, const char *db, List <LEX_USER> &list, { my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables"); /* purecov: tested */ - DBUG_RETURN(-1); /* purecov: tested */ + DBUG_RETURN(TRUE); /* purecov: tested */ } if (lower_case_table_names && db) @@ -2589,14 +2598,14 @@ int mysql_grant(THD *thd, const char *db, List <LEX_USER> &list, */ tables[0].updating= tables[1].updating= 1; if (!tables_ok(0, tables)) - DBUG_RETURN(0); + DBUG_RETURN(FALSE); } #endif if (simple_open_n_lock_tables(thd,tables)) { // This should never happen close_thread_tables(thd); /* purecov: deadcode */ - DBUG_RETURN(-1); /* purecov: deadcode */ + DBUG_RETURN(TRUE); /* purecov: deadcode */ } if (!revoke_grant) @@ -2613,7 +2622,8 @@ int mysql_grant(THD *thd, const char *db, List <LEX_USER> &list, if (Str->host.length > HOSTNAME_LENGTH || Str->user.length > USERNAME_LENGTH) { - my_error(ER_GRANT_WRONG_HOST_OR_USER,MYF(0)); + my_message(ER_GRANT_WRONG_HOST_OR_USER, ER(ER_GRANT_WRONG_HOST_OR_USER), + MYF(0)); result= -1; continue; } @@ -2910,11 +2920,12 @@ err: command= "create view"; else if (want_access & SHOW_VIEW_ACL) command= "show create view"; - net_printf(thd,ER_TABLEACCESS_DENIED_ERROR, - command, - thd->priv_user, - thd->host_or_ip, - table ? table->real_name : "unknown"); + my_printf_error(ER_TABLEACCESS_DENIED_ERROR, + ER(ER_TABLEACCESS_DENIED_ERROR), MYF(0), + command, + thd->priv_user, + thd->host_or_ip, + table ? table->real_name : "unknown"); } DBUG_RETURN(1); } @@ -3176,7 +3187,7 @@ static uint command_lengths[]= Send to client grant-like strings depicting user@host privileges */ -int mysql_show_grants(THD *thd,LEX_USER *lex_user) +bool mysql_show_grants(THD *thd,LEX_USER *lex_user) { ulong want_access; uint counter,index; @@ -3191,7 +3202,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) if (!initialized) { my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables"); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } if (!lex_user->host.str) @@ -3202,8 +3213,9 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) if (lex_user->host.length > HOSTNAME_LENGTH || lex_user->user.length > USERNAME_LENGTH) { - my_error(ER_GRANT_WRONG_HOST_OR_USER,MYF(0)); - DBUG_RETURN(-1); + my_message(ER_GRANT_WRONG_HOST_OR_USER, ER(ER_GRANT_WRONG_HOST_OR_USER), + MYF(0)); + DBUG_RETURN(TRUE); } for (counter=0 ; counter < acl_users.elements ; counter++) @@ -3220,9 +3232,10 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) } if (counter == acl_users.elements) { - my_error(ER_NONEXISTING_GRANT, MYF(0), - lex_user->user.str, lex_user->host.str); - DBUG_RETURN(-1); + my_printf_error(ER_NONEXISTING_GRANT, + ER(ER_NONEXISTING_GRANT), MYF(0), + lex_user->user.str, lex_user->host.str); + DBUG_RETURN(TRUE); } Item_string *field=new Item_string("",0,&my_charset_latin1); @@ -3234,7 +3247,7 @@ int mysql_show_grants(THD *thd,LEX_USER *lex_user) field_list.push_back(field); if (protocol->send_fields(&field_list, Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF)) - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); rw_wrlock(&LOCK_grant); VOID(pthread_mutex_lock(&acl_cache->lock)); @@ -3556,7 +3569,7 @@ int open_grant_tables(THD *thd, TABLE_LIST *tables) if (!initialized) { - net_printf(thd,ER_OPTION_PREVENTS_STATEMENT, "--skip-grant-tables"); + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--skip-grant-tables"); DBUG_RETURN(-1); } @@ -3625,7 +3638,7 @@ ACL_USER *check_acl_user(LEX_USER *user_name, } -int mysql_drop_user(THD *thd, List <LEX_USER> &list) +bool mysql_drop_user(THD *thd, List <LEX_USER> &list) { uint counter, acl_userd; int result; @@ -3636,7 +3649,7 @@ int mysql_drop_user(THD *thd, List <LEX_USER> &list) DBUG_ENTER("mysql_drop_user"); if ((result= open_grant_tables(thd, tables))) - DBUG_RETURN(result == 1 ? 0 : 1); + DBUG_RETURN(result != 1); rw_wrlock(&LOCK_grant); VOID(pthread_mutex_lock(&acl_cache->lock)); @@ -3724,7 +3737,7 @@ int mysql_drop_user(THD *thd, List <LEX_USER> &list) record[0]))) { tables[0].table->file->print_error(error, MYF(0)); - DBUG_RETURN(-1); + DBUG_RETURN(TRUE); } delete_dynamic_element(&acl_users, acl_userd); } @@ -3734,11 +3747,11 @@ int mysql_drop_user(THD *thd, List <LEX_USER> &list) rw_unlock(&LOCK_grant); close_thread_tables(thd); if (result) - my_error(ER_DROP_USER, MYF(0)); + my_message(ER_DROP_USER, ER(ER_DROP_USER), MYF(0)); DBUG_RETURN(result); } -int mysql_revoke_all(THD *thd, List <LEX_USER> &list) +bool mysql_revoke_all(THD *thd, List <LEX_USER> &list) { uint counter, revoked; int result; @@ -3747,7 +3760,7 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list) DBUG_ENTER("mysql_revoke_all"); if ((result= open_grant_tables(thd, tables))) - DBUG_RETURN(result == 1 ? 0 : 1); + DBUG_RETURN(result != 1); rw_wrlock(&LOCK_grant); VOID(pthread_mutex_lock(&acl_cache->lock)); @@ -3861,7 +3874,7 @@ int mysql_revoke_all(THD *thd, List <LEX_USER> &list) close_thread_tables(thd); if (result) - my_error(ER_REVOKE_GRANTS, MYF(0)); + my_message(ER_REVOKE_GRANTS, ER(ER_REVOKE_GRANTS), MYF(0)); DBUG_RETURN(result); } |