Cleaned up the usage of the connector library
The monitor permission checks didn't use the standard connection timeouts but used hard-coded values. The config.c tried to connect to the embedded library but since it is not used by it anymore, it always fails.
This commit is contained in:
@ -387,45 +387,6 @@ config_load(char *file)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
MYSQL *conn;
|
||||
conn = mysql_init(NULL);
|
||||
if (conn)
|
||||
{
|
||||
if (mysql_real_connect(conn, NULL, NULL, NULL, NULL, 0, NULL, 0))
|
||||
{
|
||||
char *ptr, *tmp;
|
||||
|
||||
tmp = (char *)mysql_get_server_info(conn);
|
||||
unsigned int server_version = mysql_get_server_version(conn);
|
||||
|
||||
if (version_string)
|
||||
{
|
||||
free(version_string);
|
||||
}
|
||||
|
||||
if ((version_string = malloc(strlen(tmp) + strlen("5.5.5-") + 1)) == NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (server_version >= 100000)
|
||||
{
|
||||
strcpy(version_string, "5.5.5-");
|
||||
strcat(version_string, tmp);
|
||||
}
|
||||
else
|
||||
{
|
||||
strcpy(version_string, tmp);
|
||||
}
|
||||
|
||||
ptr = strstr(version_string, "-embedded");
|
||||
if (ptr)
|
||||
{
|
||||
*ptr = '\0';
|
||||
}
|
||||
}
|
||||
mysql_close(conn);
|
||||
}
|
||||
|
||||
global_defaults();
|
||||
feedback_defaults();
|
||||
|
||||
@ -790,34 +790,40 @@ get_all_users(SERVICE *service, USERS *users)
|
||||
|
||||
while (server != NULL)
|
||||
{
|
||||
con = gw_mysql_init();
|
||||
|
||||
if (!con)
|
||||
while (!service->svc_do_shutdown && server != NULL)
|
||||
{
|
||||
goto cleanup;
|
||||
con = gw_mysql_init();
|
||||
if (con)
|
||||
{
|
||||
if (mysql_real_connect(con, server->server->name, service_user, dpwd,
|
||||
NULL, server->server->port, NULL, 0) == NULL)
|
||||
{
|
||||
MXS_ERROR("Failure loading users data from backend "
|
||||
"[%s:%i] for service [%s]. MySQL error %i, %s",
|
||||
server->server->name, server->server->port,
|
||||
service->name, mysql_errno(con), mysql_error(con));
|
||||
mysql_close(con);
|
||||
}
|
||||
else
|
||||
{
|
||||
/** Successfully connected to a server */
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
server = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
while (!service->svc_do_shutdown &&
|
||||
server != NULL &&
|
||||
(mysql_real_connect(con,
|
||||
server->server->name,
|
||||
service_user,
|
||||
dpwd,
|
||||
NULL,
|
||||
server->server->port,
|
||||
NULL,
|
||||
0) == NULL))
|
||||
{
|
||||
server = server->next;
|
||||
}
|
||||
|
||||
|
||||
if (server == NULL)
|
||||
{
|
||||
MXS_ERROR("Unable to get user data from backend database "
|
||||
"for service [%s]. Missing server information.",
|
||||
service->name);
|
||||
mysql_close(con);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -830,28 +836,40 @@ get_all_users(SERVICE *service, USERS *users)
|
||||
|
||||
while (server != NULL)
|
||||
{
|
||||
con = gw_mysql_init();
|
||||
|
||||
if (!con)
|
||||
while (!service->svc_do_shutdown && server != NULL)
|
||||
{
|
||||
goto cleanup;
|
||||
con = gw_mysql_init();
|
||||
if (con)
|
||||
{
|
||||
if (mysql_real_connect(con, server->server->name, service_user, dpwd,
|
||||
NULL, server->server->port, NULL, 0) == NULL)
|
||||
{
|
||||
MXS_ERROR("Failure loading users data from backend "
|
||||
"[%s:%i] for service [%s]. MySQL error %i, %s",
|
||||
server->server->name, server->server->port,
|
||||
service->name, mysql_errno(con), mysql_error(con));
|
||||
mysql_close(con);
|
||||
}
|
||||
else
|
||||
{
|
||||
/** Successfully connected to a server */
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
server = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
while (!service->svc_do_shutdown && server != NULL &&
|
||||
(mysql_real_connect(con, server->server->name, service_user, dpwd,
|
||||
NULL, server->server->port, NULL, 0) == NULL))
|
||||
{
|
||||
server = server->next;
|
||||
}
|
||||
|
||||
|
||||
if (server == NULL)
|
||||
{
|
||||
MXS_ERROR("Unable to get user data from backend database "
|
||||
"for service [%s]. Missing server information.",
|
||||
service->name);
|
||||
mysql_close(con);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -1300,17 +1318,36 @@ get_users(SERVICE *service, USERS *users)
|
||||
}
|
||||
else
|
||||
{
|
||||
mysql_close(con);
|
||||
/* load data from other servers via loop */
|
||||
server = service->dbref;
|
||||
|
||||
while (!service->svc_do_shutdown && server != NULL &&
|
||||
(mysql_real_connect(con, server->server->name, service_user, dpwd,
|
||||
NULL, server->server->port, NULL, 0) == NULL))
|
||||
while (!service->svc_do_shutdown && server != NULL)
|
||||
{
|
||||
con = gw_mysql_init();
|
||||
if (con)
|
||||
{
|
||||
if (mysql_real_connect(con, server->server->name, service_user, dpwd,
|
||||
NULL, server->server->port, NULL, 0) == NULL)
|
||||
{
|
||||
MXS_ERROR("Failure loading users data from backend "
|
||||
"[%s:%i] for service [%s]. MySQL error %i, %s",
|
||||
server->server->name, server->server->port,
|
||||
service->name, mysql_errno(con), mysql_error(con));
|
||||
mysql_close(con);
|
||||
}
|
||||
else
|
||||
{
|
||||
/** Successfully connected to a server */
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
server = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
server = server->next;
|
||||
}
|
||||
|
||||
@ -1334,7 +1371,6 @@ get_users(SERVICE *service, USERS *users)
|
||||
{
|
||||
MXS_ERROR("Unable to get user data from backend database for service [%s]."
|
||||
" Failed to connect to any of the backend databases.", service->name);
|
||||
mysql_close(con);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@ -522,24 +522,25 @@ bool check_monitor_permissions(MONITOR* monitor)
|
||||
{
|
||||
MYSQL* mysql;
|
||||
MYSQL_RES* res;
|
||||
char *user,*dpasswd;
|
||||
char *user, *dpasswd;
|
||||
SERVER* server;
|
||||
int conn_timeout = 1;
|
||||
bool rval = true;
|
||||
|
||||
user = monitor->user;
|
||||
dpasswd = decryptPassword(monitor->password);
|
||||
|
||||
if ((mysql = mysql_init(NULL)) == NULL)
|
||||
{
|
||||
MXS_ERROR("[%s] Error: MySQL connection initialization failed.", __FUNCTION__);
|
||||
free(dpasswd);
|
||||
return false;
|
||||
}
|
||||
|
||||
GATEWAY_CONF* cnf = config_get_global_options();
|
||||
|
||||
mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, &cnf->auth_read_timeout);
|
||||
mysql_options(mysql, MYSQL_OPT_CONNECT_TIMEOUT, &cnf->auth_conn_timeout);
|
||||
mysql_options(mysql, MYSQL_OPT_WRITE_TIMEOUT, &cnf->auth_write_timeout);
|
||||
|
||||
user = monitor->user;
|
||||
dpasswd = decryptPassword(monitor->password);
|
||||
server = monitor->databases->server;
|
||||
mysql_options(mysql,MYSQL_OPT_USE_REMOTE_CONNECTION,NULL);
|
||||
mysql_options(mysql,MYSQL_OPT_CONNECT_TIMEOUT,&conn_timeout);
|
||||
|
||||
/** Connect to the first server. This assumes all servers have identical
|
||||
* user permissions. */
|
||||
@ -556,17 +557,17 @@ bool check_monitor_permissions(MONITOR* monitor)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mysql_query(mysql,"show slave status") != 0)
|
||||
if (mysql_query(mysql, "show slave status") != 0)
|
||||
{
|
||||
if (mysql_errno(mysql) == ER_SPECIFIC_ACCESS_DENIED_ERROR)
|
||||
{
|
||||
MXS_ERROR("%s: User '%s' is missing REPLICATION CLIENT privileges. MySQL error message: %s",
|
||||
monitor->name,user,mysql_error(mysql));
|
||||
monitor->name, user, mysql_error(mysql));
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_ERROR("%s: Monitor failed to query for slave status. MySQL error message: %s",
|
||||
monitor->name,mysql_error(mysql));
|
||||
monitor->name, mysql_error(mysql));
|
||||
}
|
||||
rval = false;
|
||||
}
|
||||
@ -575,7 +576,7 @@ bool check_monitor_permissions(MONITOR* monitor)
|
||||
if ((res = mysql_use_result(mysql)) == NULL)
|
||||
{
|
||||
MXS_ERROR("%s: Result retrieval failed when checking for REPLICATION CLIENT permissions: %s",
|
||||
monitor->name,mysql_error(mysql));
|
||||
monitor->name, mysql_error(mysql));
|
||||
rval = false;
|
||||
}
|
||||
else
|
||||
@ -906,37 +907,30 @@ mon_connect_to_db(MONITOR* mon, MONITOR_SERVERS *database)
|
||||
return rval;
|
||||
}
|
||||
|
||||
int connect_timeout = mon->connect_timeout;
|
||||
int read_timeout = mon->read_timeout;
|
||||
int write_timeout = mon->write_timeout;
|
||||
char *uname = database->server->monuser ? database->server->monuser : mon->user;
|
||||
char *passwd = database->server->monpw ? database->server->monpw : mon->password;
|
||||
char *dpwd = decryptPassword(passwd);
|
||||
|
||||
if (database->con)
|
||||
{
|
||||
mysql_close(database->con);
|
||||
}
|
||||
database->con = mysql_init(NULL);
|
||||
|
||||
mysql_options(database->con, MYSQL_OPT_CONNECT_TIMEOUT, (void *) &connect_timeout);
|
||||
mysql_options(database->con, MYSQL_OPT_READ_TIMEOUT, (void *) &read_timeout);
|
||||
mysql_options(database->con, MYSQL_OPT_WRITE_TIMEOUT, (void *) &write_timeout);
|
||||
if ((database->con = mysql_init(NULL)))
|
||||
{
|
||||
char *uname = database->server->monuser ? database->server->monuser : mon->user;
|
||||
char *passwd = database->server->monpw ? database->server->monpw : mon->password;
|
||||
char *dpwd = decryptPassword(passwd);
|
||||
|
||||
mysql_options(database->con, MYSQL_OPT_CONNECT_TIMEOUT, (void *) &mon->connect_timeout);
|
||||
mysql_options(database->con, MYSQL_OPT_READ_TIMEOUT, (void *) &mon->read_timeout);
|
||||
mysql_options(database->con, MYSQL_OPT_WRITE_TIMEOUT, (void *) &mon->write_timeout);
|
||||
|
||||
time_t start = time(NULL);
|
||||
bool result = (mysql_real_connect(database->con,
|
||||
database->server->name,
|
||||
uname,
|
||||
dpwd,
|
||||
NULL,
|
||||
database->server->port,
|
||||
NULL,
|
||||
0) != NULL);
|
||||
bool result = (mysql_real_connect(database->con, database->server->name,
|
||||
uname, dpwd, NULL, database->server->port,
|
||||
NULL, 0) != NULL);
|
||||
time_t end = time(NULL);
|
||||
|
||||
if (!result)
|
||||
{
|
||||
if ((int) difftime(end, start) >= connect_timeout)
|
||||
if ((int) difftime(end, start) >= mon->connect_timeout)
|
||||
{
|
||||
rval = MONITOR_CONN_TIMEOUT;
|
||||
}
|
||||
@ -947,6 +941,12 @@ mon_connect_to_db(MONITOR* mon, MONITOR_SERVERS *database)
|
||||
}
|
||||
|
||||
free(dpwd);
|
||||
}
|
||||
else
|
||||
{
|
||||
rval = MONITOR_CONN_REFUSED;
|
||||
}
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user