diff --git a/lib/Standard_ProxySQL_Admin.cpp b/lib/Standard_ProxySQL_Admin.cpp index ea6bdb914..ed2020891 100644 --- a/lib/Standard_ProxySQL_Admin.cpp +++ b/lib/Standard_ProxySQL_Admin.cpp @@ -151,6 +151,7 @@ class Standard_ProxySQL_Admin: public ProxySQL_Admin { virtual void print_version(); virtual bool init(); virtual void init_users(); + void save_mysql_users_runtime_to_database(); virtual void admin_shutdown(); bool is_command(std::string); void SQLite3_to_MySQL(SQLite3_result *result, char *error, int affected_rows, MySQL_Protocol *myprot); @@ -234,7 +235,7 @@ bool admin_handler_command_proxysql(char *query_no_space, unsigned int query_no_ bool admin_handler_command_load_or_save(char *query_no_space, unsigned int query_no_space_length, MySQL_Session *sess, ProxySQL_Admin *pa, char **q, unsigned int *ql) { #ifdef DEBUG - if ((query_no_space_length>11) && ( (!strncasecmp("SAVE DEBUG ", query_no_space, 11)) || (!strncasecmp("LOAD DEBUG ", query_no_space, 5))) ) { + if ((query_no_space_length>11) && ( (!strncasecmp("SAVE DEBUG ", query_no_space, 11)) || (!strncasecmp("LOAD DEBUG ", query_no_space, 11))) ) { if ( (query_no_space_length==strlen("LOAD DEBUG TO MEMORY") && !strncasecmp("LOAD DEBUG TO MEMORY",query_no_space, query_no_space_length)) || @@ -305,6 +306,74 @@ bool admin_handler_command_load_or_save(char *query_no_space, unsigned int query } #endif /* DEBUG */ + + if ((query_no_space_length>17) && ( (!strncasecmp("SAVE MYSQL USERS ", query_no_space, 17)) || (!strncasecmp("LOAD MYSQL USERS ", query_no_space, 17))) ) { + + if ( + (query_no_space_length==strlen("LOAD MYSQL USERS TO MEMORY") && !strncasecmp("LOAD MYSQL USERS TO MEMORY",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("LOAD MYSQL USERS TO MEM") && !strncasecmp("LOAD MYSQL USERS TO MEM",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("LOAD MYSQL USERS FROM DISK") && !strncasecmp("LOAD MYSQL USERS FROM DISK",query_no_space, query_no_space_length)) + ) { + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received %s command\n", query_no_space); + l_free(*ql,*q); + *q=l_strdup("INSERT OR REPLACE INTO main.mysql_users SELECT * FROM disk.mysql_users"); + *ql=strlen(*q)+1; + return true; + } + + if ( + (query_no_space_length==strlen("SAVE MYSQL USERS FROM MEMORY") && !strncasecmp("SAVE MYSQL USERS FROM MEMORY",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("SAVE MYSQL USERS FROM MEM") && !strncasecmp("SAVE MYSQL USERS FROM MEM",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("SAVE MYSQL USERS TO DISK") && !strncasecmp("SAVE MYSQL USERS TO DISK",query_no_space, query_no_space_length)) + ) { + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received %s command\n", query_no_space); + l_free(*ql,*q); + *q=l_strdup("INSERT OR REPLACE INTO disk.mysql_users SELECT * FROM main.mysql_users"); + *ql=strlen(*q)+1; + return true; + } + + if ( + (query_no_space_length==strlen("LOAD MYSQL USERS FROM MEMORY") && !strncasecmp("LOAD MYSQL USERS FROM MEMORY",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("LOAD MYSQL USERS FROM MEM") && !strncasecmp("LOAD MYSQL USERS FROM MEM",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("LOAD MYSQL USERS TO RUNTIME") && !strncasecmp("LOAD MYSQL USERS TO RUNTIME",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("LOAD MYSQL USERS TO RUN") && !strncasecmp("LOAD MYSQL USERS TO RUN",query_no_space, query_no_space_length)) + ) { + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received %s command\n", query_no_space); + + Standard_ProxySQL_Admin *SPA=(Standard_ProxySQL_Admin *)pa; + SPA->init_users(); + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Loaded mysql users to RUNTIME\n"); + SPA->send_MySQL_OK(&sess->myprot_client, NULL); + return false; + } + + if ( + (query_no_space_length==strlen("SAVE MYSQL USERS TO MEMORY") && !strncasecmp("SAVE MYSQL USERS TO MEMORY",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("SAVE MYSQL USERS TO MEM") && !strncasecmp("SAVE MYSQL USERS TO MEM",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("SAVE MYSQL USERS FROM RUNTIME") && !strncasecmp("SAVE MYSQL USERS FROM RUNTIME",query_no_space, query_no_space_length)) + || + (query_no_space_length==strlen("SAVE MYSQL USERS FROM RUN") && !strncasecmp("SAVE MYSQL USERS FROM RUN",query_no_space, query_no_space_length)) + ) { + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Received %s command\n", query_no_space); + Standard_ProxySQL_Admin *SPA=(Standard_ProxySQL_Admin *)pa; + SPA->save_mysql_users_runtime_to_database(); + proxy_debug(PROXY_DEBUG_ADMIN, 4, "Saved mysql users from RUNTIME\n"); + SPA->send_MySQL_OK(&sess->myprot_client, NULL); + return false; + } + + } + return true; } @@ -1006,7 +1075,7 @@ void Standard_ProxySQL_Admin::__delete_inactive_users(enum cred_username_type us char *str=(char *)"SELECT username FROM main.mysql_users WHERE %s=1 AND active=0"; char *query=(char *)malloc(strlen(str)+15); sprintf(query,str,(usertype==USERNAME_BACKEND ? "backend" : "frontend")); -admindb->execute_statement(query, &error , &cols , &affected_rows , &resultset); + admindb->execute_statement(query, &error , &cols , &affected_rows , &resultset); if (error) { proxy_error("Error on %s : %s\n", query, error); } else { @@ -1028,7 +1097,7 @@ void Standard_ProxySQL_Admin::__add_active_users(enum cred_username_type usertyp char *str=(char *)"SELECT username,password,use_ssl FROM main.mysql_users WHERE %s=1 AND active=1"; char *query=(char *)malloc(strlen(str)+15); sprintf(query,str,(usertype==USERNAME_BACKEND ? "backend" : "frontend")); -admindb->execute_statement(query, &error , &cols , &affected_rows , &resultset); + admindb->execute_statement(query, &error , &cols , &affected_rows , &resultset); if (error) { proxy_error("Error on %s : %s\n", query, error); } else { @@ -1042,6 +1111,8 @@ admindb->execute_statement(query, &error , &cols , &affected_rows , &resultset); free(query); } +void Standard_ProxySQL_Admin::save_mysql_users_runtime_to_database() { +} extern "C" ProxySQL_Admin * create_ProxySQL_Admin_func() { return new Standard_ProxySQL_Admin();