From afa51c3baa0adc602294afc4aef9c7881fdc11c6 Mon Sep 17 00:00:00 2001 From: jingxiaobing Date: Thu, 7 Jun 2018 15:15:32 +0800 Subject: [PATCH] admin: check param for UPDATE BACKENDS; add con_timeout --- plugins/admin/admin-commands.c | 16 +++++++++++++--- plugins/admin/admin-plugin.c | 10 ++++++++++ src/network-backend.c | 3 --- src/network-backend.h | 1 - 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/plugins/admin/admin-commands.c b/plugins/admin/admin-commands.c index 76aa8d6..b55ba52 100644 --- a/plugins/admin/admin-commands.c +++ b/plugins/admin/admin-commands.c @@ -399,7 +399,7 @@ void admin_show_connectionlist(network_mysqld_con *admin_con, int show_count) g_ptr_array_add(fields, field); field = network_mysqld_proto_fielddef_new(); - field->name = g_strdup("Time"); + field->name = g_strdup("ProcessTime"); field->type = MYSQL_TYPE_STRING; g_ptr_array_add(fields, field); @@ -976,25 +976,31 @@ void admin_delete_user_password(network_mysqld_con* con, char* user) SERVER_STATUS_AUTOCOMMIT, 0); } +#define ERROR_PARAM -1 + static backend_type_t backend_type(const char* str) { - backend_type_t type = BACKEND_TYPE_UNKNOWN; + backend_type_t type = ERROR_PARAM; if (strcasecmp(str, "ro")==0) type = BACKEND_TYPE_RO; else if (strcasecmp(str, "rw")==0) type = BACKEND_TYPE_RW; + else if (strcasecmp(str, "unknown")==0) + type = BACKEND_TYPE_UNKNOWN; return type; } static backend_state_t backend_state(const char* str) { - backend_state_t state = BACKEND_STATE_UNKNOWN; + backend_state_t state = ERROR_PARAM; if (strcasecmp(str, "up")==0) state = BACKEND_STATE_UP; else if (strcasecmp(str, "down")==0) state = BACKEND_STATE_DOWN; else if (strcasecmp(str, "maintaining")==0) state = BACKEND_STATE_MAINTAINING; + else if (strcasecmp(str, "unknown") == 0) + state = BACKEND_STATE_UNKNOWN; return state; } @@ -1047,6 +1053,10 @@ void admin_update_backend(network_mysqld_con* con, GList* equations, } int type = type_str ? backend_type(type_str) : bk->type; int state = state_str ? backend_state(state_str) : bk->state; + if (type == ERROR_PARAM || state == ERROR_PARAM) { + network_mysqld_con_send_error(con->client, C("parameter error")); + return; + } int ok = network_backends_modify(g->backends, backend_ndx, type, state, NO_PREVIOUS_STATE); int affected_rows = ok ? 1 : 0; network_mysqld_con_send_ok_full(con->client, affected_rows, 0, diff --git a/plugins/admin/admin-plugin.c b/plugins/admin/admin-plugin.c index 80d8426..808b293 100644 --- a/plugins/admin/admin-plugin.c +++ b/plugins/admin/admin-plugin.c @@ -424,6 +424,14 @@ NETWORK_MYSQLD_PLUGIN_PROTO(server_read_query) { return NETWORK_SOCKET_SUCCESS; } +NETWORK_MYSQLD_PLUGIN_PROTO(server_timeout) +{ + con->prev_state = con->state; + con->state = ST_SEND_ERROR; + + return NETWORK_SOCKET_SUCCESS; +} + /** * cleanup the admin specific data on the current connection * @@ -444,6 +452,8 @@ static int network_mysqld_server_connection_init(network_mysqld_con *con) { con->plugins.con_read_query = server_read_query; + con->plugins.con_timeout = server_timeout; + con->plugins.con_cleanup = admin_disconnect_client; return 0; diff --git a/src/network-backend.c b/src/network-backend.c index 1deeedb..11be207 100644 --- a/src/network-backend.c +++ b/src/network-backend.c @@ -326,9 +326,6 @@ network_backends_modify(network_backends_t *bs, guint ndx, g_get_current_time(&now); if (ndx >= network_backends_count(bs)) return -1; - if(state >= BACKEND_STATE_END) { - return -1; - } network_backend_t *cur = bs->backends->pdata[ndx]; diff --git a/src/network-backend.h b/src/network-backend.h index e190552..9137dac 100644 --- a/src/network-backend.h +++ b/src/network-backend.h @@ -38,7 +38,6 @@ typedef enum { BACKEND_STATE_DOWN, BACKEND_STATE_MAINTAINING, BACKEND_STATE_DELETED, - BACKEND_STATE_END, } backend_state_t; #define NO_PREVIOUS_STATE -1