--- mysql-5.1.35/sql/mysql_priv.h 2009-05-14 20:34:58.000000000 +0900 +++ mysql-5.1.35-known-hosts/sql/mysql_priv.h 2009-06-30 22:03:15.000000000 +0900 @@ -2283,6 +2283,7 @@ bool hostname_cache_init(); void hostname_cache_free(); void hostname_cache_refresh(void); +bool fill_hostname_entries(THD* thd, TABLE *table); /* sql_cache.cc */ extern bool sql_cache_init(); --- mysql-5.1.35/sql/table.h 2009-05-14 20:35:05.000000000 +0900 +++ mysql-5.1.35-known-hosts/sql/table.h 2009-06-30 22:03:15.000000000 +0900 @@ -880,6 +880,7 @@ SCH_GLOBAL_STATUS, SCH_GLOBAL_VARIABLES, SCH_KEY_COLUMN_USAGE, + SCH_KNOWN_HOSTS, SCH_OPEN_TABLES, SCH_PARTITIONS, SCH_PLUGINS, --- mysql-5.1.35/sql/sql_lex.h 2009-05-14 20:35:03.000000000 +0900 +++ mysql-5.1.35-known-hosts/sql/sql_lex.h 2009-06-30 22:18:05.000000000 +0900 @@ -110,7 +110,7 @@ SQLCOM_ALTER_TABLESPACE, SQLCOM_INSTALL_PLUGIN, SQLCOM_UNINSTALL_PLUGIN, SQLCOM_SHOW_AUTHORS, SQLCOM_BINLOG_BASE64_EVENT, - SQLCOM_SHOW_PLUGINS, + SQLCOM_SHOW_PLUGINS, SQLCOM_SHOW_HOSTS, SQLCOM_SHOW_CONTRIBUTORS, SQLCOM_CREATE_SERVER, SQLCOM_DROP_SERVER, SQLCOM_ALTER_SERVER, SQLCOM_CREATE_EVENT, SQLCOM_ALTER_EVENT, SQLCOM_DROP_EVENT, --- mysql-5.1.35/sql/sql_yacc.yy 2009-05-14 20:35:05.000000000 +0900 +++ mysql-5.1.35-known-hosts/sql/sql_yacc.yy 2009-06-30 22:17:44.000000000 +0900 @@ -9893,6 +9893,13 @@ if (prepare_schema_table(YYTHD, lex, 0, SCH_PLUGINS)) MYSQL_YYABORT; } + | HOSTS_SYM + { + LEX *lex= Lex; + lex->sql_command= SQLCOM_SHOW_HOSTS; + if (prepare_schema_table(YYTHD, lex, 0, SCH_KNOWN_HOSTS)) + MYSQL_YYABORT; + } | ENGINE_SYM known_storage_engines show_engine_param { Lex->create_info.db_type= $2; } | ENGINE_SYM ALL show_engine_param --- mysql-5.1.35/sql/hostname.cc 2009-05-14 20:34:57.000000000 +0900 +++ mysql-5.1.35-known-hosts/sql/hostname.cc 2009-06-30 22:03:15.000000000 +0900 @@ -276,3 +276,44 @@ add_wrong_ip(in); DBUG_RETURN(0); } + +bool fill_hostname_entries(THD* thd, TABLE *table) +{ + DBUG_ENTER("show_hostname_cache"); + if (hostname_cache == NULL) + goto err; + + CHARSET_INFO *cs= system_charset_info; + VOID(pthread_mutex_lock(&hostname_cache->lock)); + HASH *hash = &hostname_cache->cache; + uint idx, total = hash->records; + for (idx= 0; idx < total; idx++) + { + host_entry *ent= (class host_entry *) hash_element(hash, idx); + if(!ent) continue; + + restore_record(table, s->default_values); + + struct in_addr addr; + char in_str[40]; + bzero(in_str, sizeof(in_str)); + bcopy(ent->ip, &addr, sizeof(addr)); + my_inet_ntoa(addr, in_str); + table->field[0]->store(in_str, strlen(in_str), cs); + if(ent->hostname == NULL) + table->field[1]->set_null(); + else { + table->field[1]->set_notnull(); + table->field[1]->store(ent->hostname, strlen(ent->hostname), cs); + } + table->field[2]->store(ent->errors, TRUE); + if(schema_table_store_record(thd, table)) goto err; + } + + VOID(pthread_mutex_unlock(&hostname_cache->lock)); + DBUG_RETURN(FALSE); +err: + VOID(pthread_mutex_unlock(&hostname_cache->lock)); + DBUG_RETURN(TRUE); +} + --- mysql-5.1.35/sql/sql_show.cc 2009-05-14 20:35:04.000000000 +0900 +++ mysql-5.1.35-known-hosts/sql/sql_show.cc 2009-06-30 22:47:50.000000000 +0900 @@ -203,6 +203,22 @@ DBUG_RETURN(0); } +/*************************************************************************** +** List all entries in host cache +***************************************************************************/ + +int fill_cached_hosts(THD *thd, TABLE_LIST *tables, COND *cond) +{ + DBUG_ENTER("fill_cached_hosts"); + TABLE *table= tables->table; + + if (fill_hostname_entries(thd, table)) + DBUG_RETURN(1); + + DBUG_RETURN(0); +} + + /*************************************************************************** ** List all Authors. @@ -6672,6 +6688,14 @@ {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE} }; +ST_FIELD_INFO host_cache_fields_info[]= +{ + {"IP_ADDRESS", 40, MYSQL_TYPE_STRING, 0, 0, "IP_Address", SKIP_OPEN_TABLE}, + {"HOSTNAME", HOSTNAME_LENGTH, MYSQL_TYPE_STRING, 0, 1, "Hostname", SKIP_OPEN_TABLE}, + {"ERRORS", 10, MYSQL_TYPE_LONG, 0, 0, "Errors", SKIP_OPEN_TABLE}, + {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE} +}; + /* Description of ST_FIELD_INFO in table.h @@ -6711,6 +6735,8 @@ {"KEY_COLUMN_USAGE", key_column_usage_fields_info, create_schema_table, get_all_tables, 0, get_schema_key_column_usage_record, 4, 5, 0, OPEN_TABLE_ONLY}, + {"KNOWN_HOSTS", host_cache_fields_info, create_schema_table, + fill_cached_hosts, make_old_format, 0, -1, -1, 1, 0}, {"OPEN_TABLES", open_tables_fields_info, create_schema_table, fill_open_tables, make_old_format, 0, -1, -1, 1, 0}, {"PARTITIONS", partitions_fields_info, create_schema_table, --- mysql-5.1.35/sql/sql_parse.cc 2009-05-14 20:35:04.000000000 +0900 +++ mysql-5.1.35-known-hosts/sql/sql_parse.cc 2009-06-30 22:50:42.000000000 +0900 @@ -293,6 +293,7 @@ sql_command_flags[SQLCOM_SHOW_EVENTS]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE; sql_command_flags[SQLCOM_SHOW_OPEN_TABLES]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE; sql_command_flags[SQLCOM_SHOW_PLUGINS]= CF_STATUS_COMMAND; + sql_command_flags[SQLCOM_SHOW_HOSTS]= CF_STATUS_COMMAND; sql_command_flags[SQLCOM_SHOW_FIELDS]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE; sql_command_flags[SQLCOM_SHOW_KEYS]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE; sql_command_flags[SQLCOM_SHOW_VARIABLES]= CF_STATUS_COMMAND | CF_REEXECUTION_FRAGILE; @@ -2174,6 +2175,9 @@ pthread_mutex_unlock(&LOCK_status); break; } + case SQLCOM_SHOW_HOSTS: + if (check_global_access(thd, SUPER_ACL)) + goto error; case SQLCOM_SHOW_DATABASES: case SQLCOM_SHOW_TABLES: case SQLCOM_SHOW_TRIGGERS: