Rename mxs_mysql_account_to_pcre
The function is not capable of doing the right thing for an entire account string, but only separately for user and host names, so the function name should reflect that.
This commit is contained in:
@ -48,17 +48,24 @@ bool mxs_mysql_trim_quotes(char *s);
|
|||||||
typedef enum mxs_pcre_quote_approach
|
typedef enum mxs_pcre_quote_approach
|
||||||
{
|
{
|
||||||
MXS_PCRE_QUOTE_VERBATIM, /*<! Quote all PCRE characters. */
|
MXS_PCRE_QUOTE_VERBATIM, /*<! Quote all PCRE characters. */
|
||||||
MXS_PCRE_QUOTE_QUERY /*<! Quote all PCRE characters, except % that is converted into .*. */
|
MXS_PCRE_QUOTE_WILDCARD /*<! Quote all PCRE characters, except % that is converted into .*. */
|
||||||
} mxs_pcre_quote_approach_t;
|
} mxs_pcre_quote_approach_t;
|
||||||
|
|
||||||
typedef enum mxs_mysql_account_kind
|
typedef enum mxs_mysql_name_kind
|
||||||
{
|
{
|
||||||
MXS_MYSQL_ACCOUNT_WITH_WILDCARD, /*<! The input string contains a %. */
|
MXS_MYSQL_NAME_WITH_WILDCARD, /*<! The input string contains a %. */
|
||||||
MXS_MYSQL_ACCOUNT_WITHOUT_WILDCARD /*<! The input string does not contain a %. */
|
MXS_MYSQL_NAME_WITHOUT_WILDCARD /*<! The input string does not contain a %. */
|
||||||
} mxs_mysql_account_kind_t;
|
} mxs_mysql_name_kind_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert MySQL/MariaDB account string to a pcre compatible one.
|
* Convert a MySQL/MariaDB name string to a pcre compatible one.
|
||||||
|
*
|
||||||
|
* Note that the string is expected to be a user name or a host name,
|
||||||
|
* but not a full account name. Further, if converting a user name,
|
||||||
|
* then the approach should be @c MXS_PCRE_QUOTE_VERBATIM and if converting
|
||||||
|
* a host name, the approach should be @c MXS_PCRE_QUOTE_WILDCARD.
|
||||||
|
*
|
||||||
|
* Note also that this function will not trim surrounding quotes.
|
||||||
*
|
*
|
||||||
* In principle:
|
* In principle:
|
||||||
* - Quote all characters that have a special meaning in a PCRE context.
|
* - Quote all characters that have a special meaning in a PCRE context.
|
||||||
@ -67,12 +74,12 @@ typedef enum mxs_mysql_account_kind
|
|||||||
* @param pcre The string to which the conversion should be copied.
|
* @param pcre The string to which the conversion should be copied.
|
||||||
* To be on the safe size, the buffer should be twice the
|
* To be on the safe size, the buffer should be twice the
|
||||||
* size of 'mysql'.
|
* size of 'mysql'.
|
||||||
* @param mysql The mysql account string.
|
* @param mysql The mysql user or host string.
|
||||||
* @param approach Whether % should be converted or not.
|
* @param approach Whether % should be converted or not.
|
||||||
*
|
*
|
||||||
* @return Whether or not the account contains a wildcard.
|
* @return Whether or not the name contains a wildcard.
|
||||||
*/
|
*/
|
||||||
mxs_mysql_account_kind_t mxs_mysql_account_to_pcre(char *pcre,
|
mxs_mysql_name_kind_t mxs_mysql_name_to_pcre(char *pcre,
|
||||||
const char *mysql,
|
const char *mysql,
|
||||||
mxs_pcre_quote_approach_t approach);
|
mxs_pcre_quote_approach_t approach);
|
||||||
|
|
||||||
|
@ -237,24 +237,24 @@ bool mxs_mysql_trim_quotes(char *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mxs_mysql_account_kind_t mxs_mysql_account_to_pcre(char *pcre,
|
mxs_mysql_name_kind_t mxs_mysql_name_to_pcre(char *pcre,
|
||||||
const char *mysql,
|
const char *mysql,
|
||||||
mxs_pcre_quote_approach_t approach)
|
mxs_pcre_quote_approach_t approach)
|
||||||
{
|
{
|
||||||
mxs_mysql_account_kind_t rv = MXS_MYSQL_ACCOUNT_WITHOUT_WILDCARD;
|
mxs_mysql_name_kind_t rv = MXS_MYSQL_NAME_WITHOUT_WILDCARD;
|
||||||
|
|
||||||
while (*mysql)
|
while (*mysql)
|
||||||
{
|
{
|
||||||
switch (*mysql)
|
switch (*mysql)
|
||||||
{
|
{
|
||||||
case '%':
|
case '%':
|
||||||
if (approach == MXS_PCRE_QUOTE_QUERY)
|
if (approach == MXS_PCRE_QUOTE_WILDCARD)
|
||||||
{
|
{
|
||||||
*pcre = '.';
|
*pcre = '.';
|
||||||
pcre++;
|
pcre++;
|
||||||
*pcre = '*';
|
*pcre = '*';
|
||||||
}
|
}
|
||||||
rv = MXS_MYSQL_ACCOUNT_WITH_WILDCARD;
|
rv = MXS_MYSQL_NAME_WITH_WILDCARD;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '\'':
|
case '\'':
|
||||||
|
6
server/modules/filter/cache/rules.cc
vendored
6
server/modules/filter/cache/rules.cc
vendored
@ -603,16 +603,16 @@ static CACHE_RULE *cache_rule_create_simple_user(cache_rule_attribute_t attribut
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mxs_mysql_account_to_pcre(pcre_user, user, MXS_PCRE_QUOTE_VERBATIM);
|
mxs_mysql_name_to_pcre(pcre_user, user, MXS_PCRE_QUOTE_VERBATIM);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mxs_mysql_trim_quotes(host))
|
if (mxs_mysql_trim_quotes(host))
|
||||||
{
|
{
|
||||||
char pcre_host[2 * len + 1]; // Surely enough
|
char pcre_host[2 * len + 1]; // Surely enough
|
||||||
|
|
||||||
mxs_mysql_account_kind_t rv = mxs_mysql_account_to_pcre(pcre_host, host, MXS_PCRE_QUOTE_QUERY);
|
mxs_mysql_name_kind_t rv = mxs_mysql_name_to_pcre(pcre_host, host, MXS_PCRE_QUOTE_WILDCARD);
|
||||||
|
|
||||||
if (rv == MXS_MYSQL_ACCOUNT_WITH_WILDCARD)
|
if (rv == MXS_MYSQL_NAME_WITH_WILDCARD)
|
||||||
{
|
{
|
||||||
op = (op == CACHE_OP_EQ ? CACHE_OP_LIKE : CACHE_OP_UNLIKE);
|
op = (op == CACHE_OP_EQ ? CACHE_OP_LIKE : CACHE_OP_UNLIKE);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user