From 94f27716b78b16bc875b06bddf09caaa62b9b24c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 19 Nov 2019 01:04:06 +1100 Subject: [PATCH] Preparing SAVE MYSQL FIREWALL FROM RUNTIME --- include/query_processor.h | 1 + lib/ProxySQL_Admin.cpp | 19 ++++++++++++++++++- lib/Query_Processor.cpp | 11 +++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/query_processor.h b/include/query_processor.h index 39593c7cb..4a14c92ed 100644 --- a/include/query_processor.h +++ b/include/query_processor.h @@ -350,6 +350,7 @@ class Query_Processor { unsigned long long get_mysql_firewall_memory_users_config(); unsigned long long get_mysql_firewall_memory_rules_table(); unsigned long long get_mysql_firewall_memory_rules_config(); + void get_current_mysql_firewall_whitelist(SQLite3_result **u, SQLite3_result **r); }; typedef Query_Processor * create_Query_Processor_t(); diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index 795a6ef9b..c9c809861 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -7522,7 +7522,24 @@ void ProxySQL_Admin::save_mysql_query_rules_from_runtime(bool _runtime) { } void ProxySQL_Admin::save_mysql_firewall_from_runtime(bool _runtime) { - // FIXME: to be completed + if (_runtime) { + admindb->execute("DELETE FROM runtime_mysql_firewall_whitelist_rules"); + admindb->execute("DELETE FROM runtime_mysql_firewall_whitelist_users"); + } else { + admindb->execute("DELETE FROM mysql_firewall_whitelist_rules"); + admindb->execute("DELETE FROM mysql_firewall_whitelist_users"); + } + SQLite3_result * resultset_rules = NULL; + SQLite3_result * resultset_users = NULL; + + GloQPro->get_current_mysql_firewall_whitelist(&resultset_users, &resultset_rules); + + if (resultset_users) { + delete resultset_users; + } + if (resultset_rules) { + delete resultset_rules; + } } void ProxySQL_Admin::flush_admin_variables___runtime_to_database(SQLite3DB *db, bool replace, bool del, bool onlyifempty, bool runtime) { diff --git a/lib/Query_Processor.cpp b/lib/Query_Processor.cpp index 0895317c6..9dddac5a5 100644 --- a/lib/Query_Processor.cpp +++ b/lib/Query_Processor.cpp @@ -2891,6 +2891,17 @@ int Query_Processor::testing___find_HG_in_mysql_query_rules_fast_routing(char *u return ret; } +void Query_Processor::get_current_mysql_firewall_whitelist(SQLite3_result **u, SQLite3_result **r) { + pthread_mutex_lock(&global_mysql_firewall_whitelist_mutex); + if (global_mysql_firewall_whitelist_rules_runtime) { + *r = new SQLite3_result(global_mysql_firewall_whitelist_rules_runtime); + } + if (global_mysql_firewall_whitelist_users_runtime) { + *u = new SQLite3_result(global_mysql_firewall_whitelist_users_runtime); + } + pthread_mutex_unlock(&global_mysql_firewall_whitelist_mutex); +} + void Query_Processor::load_mysql_firewall(SQLite3_result *u, SQLite3_result *r) { pthread_mutex_lock(&global_mysql_firewall_whitelist_mutex); if (global_mysql_firewall_whitelist_rules_runtime) {