Added testing for encrypted password

connleak
René Cannaò 10 years ago
parent b24d9e8d2b
commit f99e1cb401

@ -0,0 +1,6 @@
client1
client2
client3
client4
client5
client6

@ -0,0 +1,79 @@
DEPS_PATH=../../deps
MARIADB_PATH=$(DEPS_PATH)/mariadb-client-library/mariadb_client
MARIADB_IDIR=$(MARIADB_PATH)/include
MARIADB_LDIR=$(MARIADB_PATH)/libmariadb
DAEMONPATH=$(DEPS_PATH)/libdaemon/libdaemon
DAEMONPATH_IDIR=$(DAEMONPATH)
DAEMONPATH_LDIR=$(DAEMONPATH)/libdaemon/.libs
JEMALLOC_PATH=$(DEPS_PATH)/jemalloc/jemalloc
JEMALLOC_IDIR=$(JEMALLOC_PATH)/include/jemalloc
JEMALLOC_LDIR=$(JEMALLOC_PATH)/lib
LIBCONFIG_PATH=$(DEPS_PATH)/libconfig/libconfig-1.4.9
LIBCONFIG_IDIR=-I$(LIBCONFIG_PATH)/lib
LIBCONFIG_LDIR=-L$(LIBCONFIG_PATH)/lib/.libs
LIBEVENT_PATH=$(DEPS_PATH)/libevent/libevent
LIBEVENT_IDIR=$(LIBEVENT_PATH)/include
LIBEVENT_LDIR=$(LIBEVENT_PATH)/.libs
RE2_PATH=$(DEPS_PATH)/re2/re2
RE2_IDIR=$(RE2_PATH)
SQLITE3_DIR=$(DEPS_PATH)/sqlite3/sqlite3
IDIR=../../include
LDIR=../../lib
IDIRS=-I$(IDIR) -I$(JEMALLOC_IDIR) -I$(MARIADB_IDIR) $(LIBCONFIG_IDIR) -I$(DAEMONPATH_IDIR) -I$(SQLITE3_DIR)
LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(LIBEVENT_LDIR) -L$(MARIADB_LDIR) -L$(DAEMONPATH_LDIR)
MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) -ggdb
LDFLAGS+=
MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -levent -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
MYLIBS+= -ldl
endif
ifeq ($(UNAME_S),FreeBSD)
MYLIBS+= -lexecinfo
endif
LIBPROXYSQLAR=$(LDIR)/libproxysql.a
.PHONY: default
default: client1
client1: client1.cpp
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
client2: client2.cpp
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
client3: client3.cpp
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
client4: client4.cpp
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
client5: client5.cpp
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
client6: client6.cpp
$(CXX) -o $@ $@.cpp $(LIBPROXYSQLAR) $(MYCPPFLAGS) $(CPPFLAGS) $(LDIRS) $(LIBS) $(LDFLAGS) $(MYLIBS)
default: $(EXECUTABLE)
clean:
rm -f *~ core $(default)

@ -0,0 +1,135 @@
#include "proxysql.h"
#include "cpp.h"
#include <ctime>
#include <thread>
#define QUERY1 "SELECT ?"
#define NUMPREP 100000
#define NUMPRO 1000
#define NTHREADS 40
int shutdown_test=0;
typedef struct _thread_data_t {
std::thread *thread;
MYSQL *mysql;
MYSQL_STMT **stmt;
} thread_data_t;
thread_data_t **GloThrData;
void * mysql_thread(int tid) {
std::thread::id this_id = std::this_thread::get_id();
std::hash<std::thread::id> hasher;
std::mt19937 mt_rand(time(0)*hasher(this_id));
MYSQL *mysql=mysql_init(NULL);
if (!mysql_real_connect(mysql,"127.0.0.1","admin","admin","main",6032,NULL,0)) {
fprintf(stderr, "Failed to connect: Error: %s\n", mysql_error(mysql));
exit(EXIT_FAILURE);
}
char *query=NULL;
while (__sync_fetch_and_add(&shutdown_test,0)==0) {
if ((uint32_t)mt_rand()%10) { // reconnect
mysql_close(mysql);
mysql=mysql_init(NULL);
if (!mysql_real_connect(mysql,"127.0.0.1","msandbox","msandbox",NULL,6033,NULL,0)) {
fprintf(stderr, "Failed to connect: Error: %s\n", mysql_error(mysql));
exit(EXIT_FAILURE);
}
}
query=(char *)"SELECT 1";
if (mysql_query(mysql,query)) {
fprintf(stderr, "Failed to run query: \"%s\" . Error: %s\n", query, mysql_error(mysql));
exit(EXIT_FAILURE);
}
MYSQL_RES *result = mysql_store_result(mysql);
mysql_free_result(result);
}
return NULL;
}
void * setup_admin() {
std::thread::id this_id = std::this_thread::get_id();
std::hash<std::thread::id> hasher;
std::mt19937 mt_rand(time(0)*hasher(this_id));
bool multiplex[2] = {false,false};
bool hashed[2] = {false,false};
MYSQL *mysql=mysql_init(NULL);
if (!mysql_real_connect(mysql,"127.0.0.1","admin","admin","main",6032,NULL,0)) {
fprintf(stderr, "Failed to connect to admin : Error: %s\n", mysql_error(mysql));
exit(EXIT_FAILURE);
}
char *query=NULL;
while (__sync_fetch_and_add(&shutdown_test,0)==0) {
usleep(1000000);
multiplex[0]=multiplex[1];
if ((uint32_t)mt_rand()%2) {
query=(char *)"SET mysql-multiplexing='true'";
multiplex[1]=true;
} else {
query=(char *)"SET mysql-multiplexing='false'";
multiplex[1]=false;
}
if (multiplex[0]!=multiplex[1]) {
if (mysql_query(mysql,query)) {
fprintf(stderr, "Failed to run query to admin : \"%s\" . Error: %s\n", query, mysql_error(mysql));
exit(EXIT_FAILURE);
}
query=(char *)"LOAD MYSQL VARIABLES TO RUNTIME";
if (mysql_query(mysql,query)) {
fprintf(stderr, "Failed to run query to admin : \"%s\" . Error: %s\n", query, mysql_error(mysql));
exit(EXIT_FAILURE);
}
}
usleep(100000);
hashed[0]=hashed[1];
if ((uint32_t)mt_rand()%2) {
query=(char *)"UPDATE mysql_users SET password='msandbox' WHERE username='msandbox'";
hashed[1]=false;
} else {
query=(char *)"UPDATE mysql_users SET password='*6c387fc3893dba1e3ba155e74754da6682d04747' WHERE username='msandbox'";
hashed[1]=true;
}
if (hashed[0]!=hashed[1]) {
if (mysql_query(mysql,query)) {
fprintf(stderr, "Failed to run query to admin : \"%s\" . Error: %s\n", query, mysql_error(mysql));
exit(EXIT_FAILURE);
}
query=(char *)"LOAD MYSQL USERS TO RUNTIME";
if (mysql_query(mysql,query)) {
fprintf(stderr, "Failed to run query to admin : \"%s\" . Error: %s\n", query, mysql_error(mysql));
exit(EXIT_FAILURE);
}
}
}
return NULL;
}
int main() {
// initialize mysql
mysql_library_init(0,NULL,NULL);
// create a new MySQL_STMT_Manager()
//GloMyStmt=new MySQL_STMT_Manager();
std::thread *admin_thread=new std::thread(&setup_admin);
GloThrData = (thread_data_t **)malloc(sizeof(thread_data_t *)*NTHREADS);
// starts N threads
int i;
for (i=0; i<NTHREADS; i++) {
GloThrData[i]=(thread_data_t *)malloc(sizeof(thread_data_t));
GloThrData[i]->thread = new std::thread(&mysql_thread,i);
}
sleep(30);
__sync_fetch_and_add(&shutdown_test,1);
admin_thread->join();
// wait for the threads to complete
for (i=0; i<NTHREADS; i++) {
GloThrData[i]->thread->join();
}
return 0;
}
Loading…
Cancel
Save