From a4903cff7340bf3597dea25e7c1c384cffe051ba Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 7 Sep 2016 09:20:45 +0300 Subject: [PATCH] Accept 'password' in addition to 'passwd' In the configuration section of services and monitors, the password to be used can now be specified using 'password' in addition to 'passwd'. If both are provided, then the value of 'passwd' is used. That way there cannot be any surprises, should someone for whatever reason currently (in 1.4.3 an invalid parameter will not prevent MaxScale from starting) have a 'password' entry in his config file. In the next release 'passwd' can be deprecated and in the release after that removed. --- .../MaxScale-2.0.1-Release-Notes.md | 11 ++++++ server/core/config.c | 39 ++++++++++++++++--- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/Documentation/Release-Notes/MaxScale-2.0.1-Release-Notes.md b/Documentation/Release-Notes/MaxScale-2.0.1-Release-Notes.md index 9f7b538bd..3ccb0cba3 100644 --- a/Documentation/Release-Notes/MaxScale-2.0.1-Release-Notes.md +++ b/Documentation/Release-Notes/MaxScale-2.0.1-Release-Notes.md @@ -13,6 +13,17 @@ report at [Jira](https://jira.mariadb.org). ## Updated Features +### Password parameter + +In the configuration entry for a _service_ or _monitor_, the value of +the password to be used can now be specified using `password` in addition +to `passwd`. The use of the latter will be deprecated and removed in later +releases of MaxScale. + + [SomeService] + ... + password=mypasswd + ### Routing hint priority change Routing hints now have the highest priority when a routing decision is made. If diff --git a/server/core/config.c b/server/core/config.c index 2ca6dcdab..6e6b517d9 100644 --- a/server/core/config.c +++ b/server/core/config.c @@ -80,6 +80,7 @@ static bool process_config_context(CONFIG_CONTEXT *); static int process_config_update(CONFIG_CONTEXT *); static void free_config_context(CONFIG_CONTEXT *); static char *config_get_value(CONFIG_PARAMETER *, const char *); +static char *config_get_password(CONFIG_PARAMETER *); static const char *config_get_value_string(CONFIG_PARAMETER *, const char *); static int handle_global_item(const char *, const char *); static int handle_feedback_item(const char *, const char *); @@ -115,7 +116,8 @@ static char *service_params[] = "router_options", "servers", "user", - "passwd", + "passwd", // DEPRECATE: See config_get_password. + "password", "enable_root_user", "max_connections", /* "max_queued_connections", */ @@ -163,7 +165,8 @@ static char *monitor_params[] = "module", "servers", "user", - "passwd", + "passwd", // DEPRECATE: See config_get_password. + "password", "script", "events", "mysql51_replication", @@ -592,6 +595,30 @@ config_get_value(CONFIG_PARAMETER *params, const char *name) return NULL; } +// DEPRECATE: In 2.1 complain but accept if "passwd" is provided, in 2.2 +// DEPRECATE: drop support for "passwd". +/** + * Get the value of the password parameter + * + * The words looked for are "password" and "passwd". + * + * @param params The linked list of config parameters + * @return the parameter value or NULL if not found + */ +static char * +config_get_password(CONFIG_PARAMETER *params) +{ + char *password = config_get_value(params, "password"); + char *passwd = config_get_value(params, "passwd"); + + if (password && passwd) + { + MXS_WARNING("Both 'password' and 'passwd' specified. Using value of 'password'."); + } + + return passwd ? passwd : password; +} + /** * Get the value of a config parameter as a string * @@ -1310,7 +1337,7 @@ process_config_update(CONFIG_CONTEXT *context) max_queued_connections = config_get_value_string(obj->parameters, "max_queued_connections"); queued_connection_timeout = config_get_value_string(obj->parameters, "queued_connection_timeout"); user = config_get_value(obj->parameters, "user"); - auth = config_get_value(obj->parameters, "passwd"); + auth = config_get_password(obj->parameters); auth_all_servers = config_get_value(obj->parameters, "auth_all_servers"); strip_db_esc = config_get_value(obj->parameters, "strip_db_esc"); @@ -2243,7 +2270,7 @@ int create_new_service(CONFIG_CONTEXT *obj) } char *user = config_get_value(obj->parameters, "user"); - char *auth = config_get_value(obj->parameters, "passwd"); + char *auth = config_get_password(obj->parameters); if (user && auth) { @@ -2256,7 +2283,7 @@ int create_new_service(CONFIG_CONTEXT *obj) obj->object, user ? "" : "the 'user' parameter", !user && !auth ? " and " : "", - auth ? "" : "the 'passwd' parameter"); + auth ? "" : "the 'password' or 'passwd' parameter"); } char *subservices = config_get_value(obj->parameters, "subservices"); @@ -2660,7 +2687,7 @@ int create_new_monitor(CONFIG_CONTEXT *context, CONFIG_CONTEXT *obj, HASHTABLE* } char *user = config_get_value(obj->parameters, "user"); - char *passwd = config_get_value(obj->parameters, "passwd"); + char *passwd = config_get_password(obj->parameters); if (user && passwd) { monitorAddUser(obj->element, user, passwd);