This commit is contained in:
vraatikka
2013-07-09 09:54:07 +03:00
21 changed files with 832 additions and 89 deletions

View File

@ -45,14 +45,15 @@
int
load_mysql_users(SERVICE *service)
{
MYSQL* con = NULL;
MYSQL *con = NULL;
MYSQL_ROW row;
MYSQL_RES* result = NULL;
MYSQL_RES *result = NULL;
int num_fields = 0;
char* service_user = NULL;
char* service_passwd = NULL;
char *service_user = NULL;
char *service_passwd = NULL;
int total_users = 0;
SERVER *server;
serviceGetUser(service, &service_user, &service_passwd);
/** multi-thread environment requires that thread init succeeds. */
if (mysql_thread_init()) {
@ -66,20 +67,30 @@ load_mysql_users(SERVICE *service)
fprintf(stderr, "%s\n", mysql_error(con));
return -1;
}
if (mysql_real_connect(
con,
service->databases->name,
service_user,
service_passwd,
NULL,
service->databases->port,
NULL, 0) == NULL)
{
/*
* Attempt to connect to each database in the service in turn until
* we find one that we can connect to or until we run out of databases
* to try
*/
server = service->databases;
while (server && mysql_real_connect(con,
server->name,
service_user,
service_passwd,
NULL,
server->port,
NULL,
0) == NULL)
{
server = server->nextdb;
}
if (server == NULL)
{
fprintf(stderr, "%s\n", mysql_error(con));
mysql_close(con);
return -1;
}
}
if (mysql_query(con, "SELECT user, password FROM mysql.user")) {
fprintf(stderr, ">>>>> %s\n", mysql_error(con));