Merge branch 'develop' of github.com:skysql/MaxScale into develop
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
add_executable(test_mysql_users test_mysql_users.c)
|
||||
add_executable(test_hash testhash.c)
|
||||
add_executable(test_hint testhint.c)
|
||||
add_executable(test_spinlock testspinlock.c)
|
||||
@ -10,6 +11,7 @@ add_executable(test_service testservice.c)
|
||||
add_executable(test_server testserver.c)
|
||||
add_executable(test_users testusers.c)
|
||||
add_executable(test_adminusers testadminusers.c)
|
||||
target_link_libraries(test_mysql_users fullcore MySQLClient)
|
||||
target_link_libraries(test_hash fullcore)
|
||||
target_link_libraries(test_hint fullcore)
|
||||
target_link_libraries(test_spinlock fullcore)
|
||||
@ -22,6 +24,7 @@ target_link_libraries(test_service fullcore)
|
||||
target_link_libraries(test_server fullcore)
|
||||
target_link_libraries(test_users fullcore)
|
||||
target_link_libraries(test_adminusers fullcore)
|
||||
add_test(testMySQLUsers test_mysql_users)
|
||||
add_test(TestHash test_hash)
|
||||
add_test(TestHint test_hint)
|
||||
add_test(TestSpinlock test_spinlock)
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
# cleantests - clean local and subdirectories' tests
|
||||
# buildtests - build all local and subdirectories' tests
|
||||
# runtests - run all local tests
|
||||
# testall - clean, build and run local and subdirectories' tests
|
||||
|
||||
include ../../../build_gateway.inc
|
||||
include ../../../makefile.inc
|
||||
|
||||
CC=cc
|
||||
DEBUG=Y
|
||||
cleantests:
|
||||
- $(DEL) *.o
|
||||
- $(DEL) test_mysql_users
|
||||
- $(DEL) *~
|
||||
|
||||
testall: cleantests buildtests runtests
|
||||
|
||||
buildtests :
|
||||
$(CC) $(CFLAGS) \
|
||||
-I$(ROOT_PATH)/server/include \
|
||||
-I$(ROOT_PATH)/utils \
|
||||
-I$(ROOT_PATH)/log_manager \
|
||||
test_mysql_users.c ../secrets.o ../service.o ../gwbitmask.o ../load_utils.o ../session.o ../poll.o ../dcb.o ../utils.o ../buffer.o ../gw_utils.o ../hashtable.o ../atomic.o ../spinlock.o ../users.o ../dbusers.o ../../../utils/skygw_utils.o ../../../log_manager/log_manager.o -o test_mysql_users -L$(EMBEDDED_LIB) -lmysqlclient -lpthread -lssl -lz -lm -lcrypt -lcrypto -ldl -laio -lrt -lstdc++
|
||||
runtests:
|
||||
@echo ""
|
||||
@echo "-------------------------------"
|
||||
@echo $(shell date)
|
||||
@echo "Test MaxScale core"
|
||||
@echo "-------------------------------"
|
||||
@echo ""
|
||||
@echo "MaxSclale Load MySQL users"
|
||||
@./test_mysql_users
|
||||
@ -24,6 +24,7 @@
|
||||
* Date Who Description
|
||||
* 14/02/2014 Massimiliano Pinto Initial implementation
|
||||
* 17/02/2014 Massimiliano Pinto Added check ipv4
|
||||
* 03/10/2014 Massimiliano Pinto Added check for wildcard hosts
|
||||
*
|
||||
* @endverbatim
|
||||
*/
|
||||
@ -77,6 +78,7 @@ int set_and_get_single_mysql_users_ipv4(char *username, unsigned long ipv4, char
|
||||
/* add user@host as key and passwd as value in the MySQL users hash table */
|
||||
if (!mysql_users_add(mysql_users, &key, password)) {
|
||||
fprintf(stderr, "Failed adding %s@%s(%lu)\n", username, ret_ip, fix_ipv4);
|
||||
users_free(mysql_users);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -107,6 +109,7 @@ int set_and_get_single_mysql_users(char *username, char *hostname, char *passwor
|
||||
char *fetch_data;
|
||||
|
||||
mysql_users = mysql_users_alloc();
|
||||
|
||||
/* prepare the user@host data struct */
|
||||
memset(&serv_addr, 0, sizeof(serv_addr));
|
||||
memset(&key, 0, sizeof(key));
|
||||
@ -115,6 +118,7 @@ int set_and_get_single_mysql_users(char *username, char *hostname, char *passwor
|
||||
if (hostname)
|
||||
if(!setipaddress(&serv_addr.sin_addr, hostname)) {
|
||||
fprintf(stderr, "setipaddress failed for host [%s]\n", hostname);
|
||||
users_free(mysql_users);
|
||||
return 1;
|
||||
}
|
||||
if (username)
|
||||
@ -129,6 +133,7 @@ int set_and_get_single_mysql_users(char *username, char *hostname, char *passwor
|
||||
/* add user@host as key and passwd as value in the MySQL users hash table */
|
||||
if (!mysql_users_add(mysql_users, &key, password)) {
|
||||
fprintf(stderr, "mysql_users_add() failed for %s@%s\n", username, hostname);
|
||||
users_free(mysql_users);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -138,6 +143,7 @@ int set_and_get_single_mysql_users(char *username, char *hostname, char *passwor
|
||||
if (hostname)
|
||||
if(!setipaddress(&serv_addr.sin_addr, hostname)) {
|
||||
fprintf(stderr, "setipaddress failed for host [%s]\n", hostname);
|
||||
users_free(mysql_users);
|
||||
return 1;
|
||||
}
|
||||
key.user = username;
|
||||
@ -153,6 +159,73 @@ int set_and_get_single_mysql_users(char *username, char *hostname, char *passwor
|
||||
return 0;
|
||||
}
|
||||
|
||||
int set_and_get_mysql_users_wildcards(char *username, char *hostname, char *password, char *from) {
|
||||
USERS *mysql_users;
|
||||
int ret;
|
||||
struct sockaddr_in client_addr;
|
||||
DCB *dcb;
|
||||
SERVICE *service;
|
||||
|
||||
dcb = dcb_alloc(DCB_ROLE_INTERNAL);
|
||||
|
||||
if (dcb == NULL) {
|
||||
fprintf(stderr, "dcb_alloc() failed\n");
|
||||
return 1;
|
||||
}
|
||||
if ((service = (SERVICE *)calloc(1, sizeof(SERVICE))) == NULL) {
|
||||
fprintf(stderr, "service_alloc() failed\n");
|
||||
dcb_free(dcb);
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&client_addr, 0, sizeof(client_addr));
|
||||
|
||||
if (hostname) {
|
||||
if(!setipaddress(&client_addr.sin_addr, from)) {
|
||||
fprintf(stderr, "setipaddress failed for host [%s]\n", from);
|
||||
free(service);
|
||||
dcb_free(dcb);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* client IPv4 in raw data*/
|
||||
memcpy(&dcb->ipv4, (struct sockaddr_in *)&client_addr, sizeof(struct sockaddr_in));
|
||||
|
||||
dcb->service = service;
|
||||
|
||||
mysql_users = mysql_users_alloc();
|
||||
|
||||
service->users = mysql_users;
|
||||
|
||||
|
||||
// the routine returns 1 on success
|
||||
ret = add_mysql_users_with_host_ipv4(mysql_users, username, hostname, password);
|
||||
if (!ret) {
|
||||
fprintf(stderr, "add_mysql_users_with_host_ipv4 passed(%s@%s, %s) FAILED\n", username, hostname, password);
|
||||
users_free(mysql_users);
|
||||
free(service);
|
||||
dcb_free(dcb);
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
char db_passwd[100]="";
|
||||
|
||||
dcb->remote=strdup(from);
|
||||
//fprintf(stderr, "add_mysql_users_with_host_ipv4 passed(%s@%s, %s) OK\n", username, hostname, password);
|
||||
|
||||
fprintf(stderr, "Checking '%s' @ '%s' against (%s@%s)\n", username, from, username, hostname);
|
||||
|
||||
// returns 0 on success
|
||||
ret = gw_find_mysql_user_password_sha1(username, db_passwd, dcb);
|
||||
}
|
||||
|
||||
users_free(mysql_users);
|
||||
free(service);
|
||||
dcb_free(dcb);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int ret;
|
||||
@ -180,6 +253,7 @@ int main() {
|
||||
assert(ret == 1);
|
||||
ret = set_and_get_single_mysql_users(NULL, NULL, NULL);
|
||||
assert(ret == 1);
|
||||
|
||||
ret = set_and_get_single_mysql_users_ipv4("negative", -467295, "_ncd");
|
||||
assert(ret == 1);
|
||||
ret = set_and_get_single_mysql_users_ipv4("extra", 0xFFFFFFFFFUL * 100, "JJcd");
|
||||
@ -189,19 +263,77 @@ int main() {
|
||||
ret = set_and_get_single_mysql_users_ipv4(NULL, '\0', "JJcd");
|
||||
assert(ret == 1);
|
||||
|
||||
|
||||
for (i = 256*256*256; i <= 256*256*256 + 5; i++) {
|
||||
char user[129] = "";
|
||||
snprintf(user, 128, "user_%i", k);
|
||||
ret = set_and_get_single_mysql_users_ipv4(user, i, "JJcd");
|
||||
assert(ret == 0);
|
||||
k++;
|
||||
}
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "%", "one", "127.0.0.1");
|
||||
if (ret) fprintf(stderr, "\t-- Expecting no match\n");
|
||||
assert(ret == 1);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "%", "", "127.0.0.1");
|
||||
if (ret) fprintf(stderr, "\t-- Expecting no match\n");
|
||||
assert(ret == 1);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "%", "two", "192.168.2.2");
|
||||
if (!ret) fprintf(stderr, "\t-- Expecting ok\n");
|
||||
assert(ret == 0);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "192.168.1.%", "foo", "192.168.2.2");
|
||||
if (ret) fprintf(stderr, "\t-- Expecting no match\n");
|
||||
assert(ret == 1);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "192.168.%.%", "foo", "192.168.2.2");
|
||||
if (!ret) fprintf(stderr, "\t-- Expecting ok\n");
|
||||
assert(ret == 0);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "192.%.%.%", "foo", "192.68.0.2");
|
||||
if (!ret) fprintf(stderr, "\t-- Expecting ok\n");
|
||||
assert(ret == 0);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "192.%.%.%", "foo", "192.0.0.2");
|
||||
if (!ret) fprintf(stderr, "\t-- Expecting ok\n");
|
||||
assert(ret == 0);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "192.0.%.%", "foo", "192.2.0.2");
|
||||
if (ret) fprintf(stderr, "\t-- Expecting no match\n");
|
||||
assert(ret == 1);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "192.0.0.1", "foo", "192.0.0.2");
|
||||
if (ret) fprintf(stderr, "\t-- Expecting no match\n");
|
||||
assert(ret == 1);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "192.0.%.%", "foo", "192.1.0.2");
|
||||
if (ret) fprintf(stderr, "\t-- Expecting no match\n");
|
||||
assert(ret == 1);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "192.0.0.%", "y78764o", "192.3.2.1");
|
||||
if (ret) fprintf(stderr, "\t-- Expecting no match\n");
|
||||
assert(ret == 1);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "192.0.%.%", "1234567890123456789012345678901234567890", "192.3.2.1");
|
||||
if (ret) fprintf(stderr, "\t-- Expecting no match\n");
|
||||
assert(ret == 1);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "192.%.%.%", "1234567890123456789012345678901234567890f8__uuo5", "192.3.2.1");
|
||||
if (!ret) fprintf(stderr, "\t-- Expecting ok\n");
|
||||
assert(ret == 0);
|
||||
|
||||
ret = set_and_get_mysql_users_wildcards("pippo", "192.0.0.%", "fo887778o", "192.134.0.2");
|
||||
if (ret) fprintf(stderr, "\t-- Expecting no match\n");
|
||||
assert(ret == 1);
|
||||
|
||||
fprintf(stderr, "----------------\n");
|
||||
fprintf(stderr, "<<< Test completed\n");
|
||||
|
||||
time(&t);
|
||||
fprintf(stderr, "%s\n", asctime(localtime(&t)));
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user