Addition of reload commands in the debug CLI for users and configuration
Fixed bug in reload configuration
This commit is contained in:
@ -34,6 +34,10 @@
|
|||||||
#include <dcb.h>
|
#include <dcb.h>
|
||||||
#include <service.h>
|
#include <service.h>
|
||||||
#include <users.h>
|
#include <users.h>
|
||||||
|
#include <skygw_utils.h>
|
||||||
|
#include <log_manager.h>
|
||||||
|
|
||||||
|
static int getUsers(SERVICE *service, struct users *users);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load the user/passwd form mysql.user table into the service users' hashtable
|
* Load the user/passwd form mysql.user table into the service users' hashtable
|
||||||
@ -44,6 +48,45 @@
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
load_mysql_users(SERVICE *service)
|
load_mysql_users(SERVICE *service)
|
||||||
|
{
|
||||||
|
return getUsers(service, service->users);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload the user/passwd form mysql.user table into the service users' hashtable
|
||||||
|
* environment.
|
||||||
|
*
|
||||||
|
* @param service The current service
|
||||||
|
* @return -1 on any error or the number of users inserted (0 means no users at all)
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
reload_mysql_users(SERVICE *service)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct users *newusers, *oldusers;
|
||||||
|
|
||||||
|
if ((newusers = users_alloc()) == NULL)
|
||||||
|
return 0;
|
||||||
|
i = getUsers(service, newusers);
|
||||||
|
spinlock_acquire(&service->spin);
|
||||||
|
oldusers = service->users;
|
||||||
|
service->users = newusers;
|
||||||
|
spinlock_release(&service->spin);
|
||||||
|
users_free(oldusers);
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the user/passwd form mysql.user table into the service users' hashtable
|
||||||
|
* environment.
|
||||||
|
*
|
||||||
|
* @param service The current service
|
||||||
|
* @param users The users table into which to load the users
|
||||||
|
* @return -1 on any error or the number of users inserted (0 means no users at all)
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
getUsers(SERVICE *service, struct users *users)
|
||||||
{
|
{
|
||||||
MYSQL *con = NULL;
|
MYSQL *con = NULL;
|
||||||
MYSQL_ROW row;
|
MYSQL_ROW row;
|
||||||
@ -52,14 +95,14 @@ load_mysql_users(SERVICE *service)
|
|||||||
char *service_user = NULL;
|
char *service_user = NULL;
|
||||||
char *service_passwd = NULL;
|
char *service_passwd = NULL;
|
||||||
int total_users = 0;
|
int total_users = 0;
|
||||||
SERVER *server;
|
SERVER *server;
|
||||||
|
|
||||||
serviceGetUser(service, &service_user, &service_passwd);
|
serviceGetUser(service, &service_user, &service_passwd);
|
||||||
/** multi-thread environment requires that thread init succeeds. */
|
/** multi-thread environment requires that thread init succeeds. */
|
||||||
if (mysql_thread_init()) {
|
if (mysql_thread_init()) {
|
||||||
skygw_log_write_flush(NULL, "ERROR : mysql_thread_init failed.\n");
|
skygw_log_write_flush(NULL, LOGFILE_ERROR, "ERROR : mysql_thread_init failed.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
con = mysql_init(NULL);
|
con = mysql_init(NULL);
|
||||||
|
|
||||||
@ -68,11 +111,11 @@ load_mysql_users(SERVICE *service)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mysql_options(con, MYSQL_OPT_USE_REMOTE_CONNECTION, NULL)) {
|
if (mysql_options(con, MYSQL_OPT_USE_REMOTE_CONNECTION, NULL)) {
|
||||||
skygw_log_write_flush(NULL, "Fatal : failed to set external connection. "
|
skygw_log_write_flush(NULL, LOGFILE_ERROR, "Fatal : failed to set external connection. "
|
||||||
"It is needed for backend server connections. Exiting.\n");
|
"It is needed for backend server connections. Exiting.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Attempt to connect to each database in the service in turn until
|
* 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
|
* we find one that we can connect to or until we run out of databases
|
||||||
@ -118,13 +161,13 @@ load_mysql_users(SERVICE *service)
|
|||||||
//printf("User %s , Passwd %s\n", row[0], row[1]);
|
//printf("User %s , Passwd %s\n", row[0], row[1]);
|
||||||
|
|
||||||
// now adding to the hastable user and passwd+1 (escaping the first byte that is '*')
|
// now adding to the hastable user and passwd+1 (escaping the first byte that is '*')
|
||||||
users_add(service->users, row[0], row[1]+1);
|
users_add(users, row[0], row[1]+1);
|
||||||
total_users++;
|
total_users++;
|
||||||
}
|
}
|
||||||
|
|
||||||
mysql_free_result(result);
|
mysql_free_result(result);
|
||||||
mysql_close(con);
|
mysql_close(con);
|
||||||
mysql_thread_end();
|
mysql_thread_end();
|
||||||
return total_users;
|
return total_users;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -617,7 +617,7 @@ void *router_obj;
|
|||||||
service->router = router_obj;
|
service->router = router_obj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strcmp(service->credentials.name, user) == 0 || strcmp(service->credentials.authdata, auth) == 0)
|
if (user && (strcmp(service->credentials.name, user) != 0 || strcmp(service->credentials.authdata, auth) != 0))
|
||||||
{
|
{
|
||||||
skygw_log_write(NULL, LOGFILE_MESSAGE, "Update credentials for service %s", service->name);
|
skygw_log_write(NULL, LOGFILE_MESSAGE, "Update credentials for service %s", service->name);
|
||||||
serviceSetUser(service, user, auth);
|
serviceSetUser(service, user, auth);
|
||||||
|
|||||||
@ -32,4 +32,5 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
extern int load_mysql_users(SERVICE *service);
|
extern int load_mysql_users(SERVICE *service);
|
||||||
|
extern int reload_mysql_users(SERVICE *service);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
*
|
*
|
||||||
* Date Who Description
|
* Date Who Description
|
||||||
* 20/06/13 Mark Riddoch Initial implementation
|
* 20/06/13 Mark Riddoch Initial implementation
|
||||||
|
* 17/07/13 Mark Riddoch Additional commands
|
||||||
*
|
*
|
||||||
* @endverbatim
|
* @endverbatim
|
||||||
*/
|
*/
|
||||||
@ -51,6 +52,8 @@
|
|||||||
#include <dcb.h>
|
#include <dcb.h>
|
||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <users.h>
|
#include <users.h>
|
||||||
|
#include <dbusers.h>
|
||||||
|
#include <config.h>
|
||||||
#include <debugcli.h>
|
#include <debugcli.h>
|
||||||
|
|
||||||
#define MAXARGS 5
|
#define MAXARGS 5
|
||||||
@ -148,6 +151,21 @@ struct subcommand clearoptions[] = {
|
|||||||
{0, 0, 0} }
|
{0, 0, 0} }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void reload_users(DCB *dcb, SERVICE *service);
|
||||||
|
static void reload_config(DCB *dcb);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The subcommands of the reload command
|
||||||
|
*/
|
||||||
|
struct subcommand reloadoptions[] = {
|
||||||
|
{ "users", 1, reload_users, "Reload the user data for a service. E.g. reload users 0x849420",
|
||||||
|
{ARG_TYPE_ADDRESS, 0, 0} },
|
||||||
|
{ "config", 0, reload_config, "Reload the configuration data for hte gateway.",
|
||||||
|
{ARG_TYPE_ADDRESS, 0, 0} },
|
||||||
|
{ NULL, 0, NULL, NULL,
|
||||||
|
{0, 0, 0} }
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The debug command table
|
* The debug command table
|
||||||
*/
|
*/
|
||||||
@ -160,6 +178,7 @@ static struct {
|
|||||||
{ "restart", restartoptions },
|
{ "restart", restartoptions },
|
||||||
{ "set", setoptions },
|
{ "set", setoptions },
|
||||||
{ "clear", clearoptions },
|
{ "clear", clearoptions },
|
||||||
|
{ "reload", reloadoptions },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -403,3 +422,27 @@ unsigned int bitvalue;
|
|||||||
else
|
else
|
||||||
dcb_printf(dcb, "Unknown status bit %s\n", bit);
|
dcb_printf(dcb, "Unknown status bit %s\n", bit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload the authenticaton data from the backend database of a service.
|
||||||
|
*
|
||||||
|
* @param dcb DCB to send output
|
||||||
|
* @param service The service to update
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
reload_users(DCB *dcb, SERVICE *service)
|
||||||
|
{
|
||||||
|
dcb_printf(dcb, "Loaded %d users.\n", reload_mysql_users(service));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relaod the configuration data from the config file
|
||||||
|
*
|
||||||
|
* @param dcb DCB to use to send output
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
reload_config(DCB *dcb)
|
||||||
|
{
|
||||||
|
dcb_printf(dcb, "Reloading configuration from file.\n");
|
||||||
|
config_reload();
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user