MXS-2290 Reject use of whitespace in section names

Whitespace in section names was deprecated in 2.2 and in 2.4 it
will be rejected.
This commit is contained in:
Johan Wikman 2019-01-25 10:01:04 +02:00
parent f78df53f30
commit 9083ea2d02
7 changed files with 92 additions and 32 deletions

View File

@ -3,6 +3,7 @@
## MariaDB MaxScale 2.4
* Names starting with `@@` are reserved for use by MaxScale.
* Names can no longer contain whitespace.
For more details, please refer to:

View File

@ -244,6 +244,11 @@ not supported.
some_parameter=123
```
### Names
Section names may not contain whitespace and must not start with the characters
`@@`, but otherwise there are no restrictions.
### Special Parameter Types
#### Sizes

View File

@ -16,6 +16,9 @@ Section and object names starting with `@@` are now reserved for
use by MaxScale itself. If any such names are encountered in
configuration files, then MaxScale will not start.
Whitespace in section names that was deprecated in 2.2 will now be
rejected and cause the startup of MaxScale to fail.
## Dropped Features
## New Features

View File

@ -22,3 +22,25 @@ Those files are:
* The main configuration file; typically `/etc/maxscale.cnf`.
* All nested configuration files; typically `/etc/maxscale.cnf.d/*`.
* All dynamic configuration files; typically `/var/lib/maxscale/maxscale.cnd.d/*`.
Further, whitespace in section names that was deprecated in MaxScale 2.2
will now be rejected, which will cause the startup of MaxScale to fail.
To prevent that, section names like
```
[My Server]
...
[My Service]
...
servers=My Server
```
must be changed, for instance, to
```
[MyServer]
...
[MyService]
...
servers=MyServer
```

View File

@ -0,0 +1,57 @@
[maxscale]
threads=###threads###
[server 1]
type=server
address=###node_server_IP_1###
port=###node_server_port_1###
protocol=MySQLBackend
[server 2]
type=server
address=###node_server_IP_2###
port=###node_server_port_2###
protocol=MySQLBackend
[server 3]
type=server
address=###node_server_IP_3###
port=###node_server_port_3###
protocol=MySQLBackend
[server 4]
type=server
address=###node_server_IP_4###
port=###node_server_port_4###
protocol=MySQLBackend
[MySQL Monitor]
type=monitor
module=mysqlmon
servers=server 1,server 2,server 3,server 4
user=maxskysql
password=skysql
monitor_interval=1000
[RW Split Router]
type=service
router=readwritesplit
servers=server 1,server 2,server 3,server 4
user=maxskysql
password=skysql
[RW Split Listener]
type=listener
service=RW Split Router
protocol=MySQLClient
port=4006
[CLI]
type=service
router=cli
[CLI Listener]
type=listener
service=CLI
protocol=maxscaled
socket=default

View File

@ -24,6 +24,7 @@ const char* bad_configs[] =
// passwd is still supported
// "old_passwd",
"no_use_of_reserved_names",
"no_spaces_in_section_names",
NULL
};

View File

@ -616,34 +616,9 @@ CONFIG_CONTEXT* config_context_create(const char* section)
return ctx;
}
/** A set that holds all the section names that contain whitespace */
static std::set<string> warned_whitespace;
static void fix_section_name(char* section)
{
for (char* s = section; *s; s++)
{
if (isspace(*s))
{
if (warned_whitespace.find(section) == warned_whitespace.end())
{
warned_whitespace.insert(section);
MXS_WARNING("Whitespace in object names is deprecated, "
"converting to hyphens: %s",
section);
}
break;
}
}
fix_object_name(section);
}
void fix_object_name(char* name)
{
squeeze_whitespace(name);
mxb::trim(name);
replace_whitespace(name);
}
void fix_object_name(std::string& name)
@ -747,12 +722,8 @@ static int ini_handler(void* userdata, const char* section, const char* name, co
return 0;
}
char fixed_section[strlen(section) + 1];
strcpy(fixed_section, section);
fix_section_name(fixed_section);
string reason;
if (!config_is_valid_name(fixed_section, &reason))
if (!config_is_valid_name(section, &reason))
{
/* A set that holds all the section names that are invalid. As the configuration file
* is parsed multiple times, we need to do this to prevent the same complaint from
@ -773,14 +744,14 @@ static int ini_handler(void* userdata, const char* section, const char* name, co
* add the parameters to that object. If not create
* a new object.
*/
while (ptr && strcmp(ptr->object, fixed_section) != 0)
while (ptr && strcmp(ptr->object, section) != 0)
{
ptr = ptr->next;
}
if (!ptr)
{
if ((ptr = config_context_create(fixed_section)) == NULL)
if ((ptr = config_context_create(section)) == NULL)
{
return 0;
}