Add support for comparison operators in dbfwfilter functions

The dbfwfilter now supports the main comparison operators in MySQL. The
string versions (IS, NOT, IS NOT etc.) are not supported.
This commit is contained in:
Markus Mäkelä 2017-01-10 15:26:54 +02:00
parent 6c9a80e957
commit dffad71804
3 changed files with 12 additions and 5 deletions

View File

@ -117,7 +117,9 @@ This rule expects a list of values after the `columns` keyword. These values are
This rule expects a list of values after the `function` keyword. These values
are interpreted as function names and if a query uses any of these, it is
blocked.
blocked. The symbolic comparison operators (`<`, `>`, `>=` etc.) are also
considered functions whereas the text versions (`NOT`, `IS`, `IS NOT` etc.) are
not considered functions.
#### `regex`

View File

@ -37,7 +37,7 @@
%token FWTOK_RULE <strval>FWTOK_RULENAME FWTOK_USERS <strval>FWTOK_USER FWTOK_RULES FWTOK_MATCH FWTOK_ANY FWTOK_ALL FWTOK_STRICT_ALL FWTOK_DENY
%token FWTOK_WILDCARD FWTOK_COLUMNS FWTOK_REGEX FWTOK_LIMIT_QUERIES FWTOK_WHERE_CLAUSE FWTOK_AT_TIMES FWTOK_ON_QUERIES
%token <strval>FWTOK_SQLOP FWTOK_COMMENT <intval>FWTOK_INT <floatval>FWTOK_FLOAT FWTOK_PIPE <strval>FWTOK_TIME
%token <strval>FWTOK_BTSTR <strval>FWTOK_QUOTEDSTR <strval>FWTOK_STR FWTOK_FUNCTION
%token <strval>FWTOK_BTSTR <strval>FWTOK_QUOTEDSTR <strval>FWTOK_STR FWTOK_FUNCTION <strval>FWTOK_CMP
/** Non-terminal symbols */
%type <strval>rulename
@ -124,10 +124,13 @@ columnlist:
;
functionlist:
FWTOK_BTSTR {if (!define_function_rule(scanner, $1)){YYERROR;}}
functionvalue
| functionlist functionvalue
;
functionvalue:
FWTOK_CMP {if (!define_function_rule(scanner, $1)){YYERROR;}}
| FWTOK_STR {if (!define_function_rule(scanner, $1)){YYERROR;}}
| functionlist FWTOK_BTSTR {if (!define_function_rule(scanner, $2)){YYERROR;}}
| functionlist FWTOK_STR {if (!define_function_rule(scanner, $2)){YYERROR;}}
;
optional:

View File

@ -33,6 +33,7 @@ USER [^[:space:]]*[@]
IP [0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}
BTSTR `[^`]*`
USTR [%-_[:alnum:][:punct:]]+
CMP [=<>!]+
%%
"\n"+ return '\n';
@ -53,6 +54,7 @@ match return FWTOK_MATCH;
any return FWTOK_ANY;
all return FWTOK_ALL;
strict_all return FWTOK_STRICT_ALL;
{CMP} yylval->strval = yytext;return FWTOK_CMP;
{USTR}@{USTR} yylval->strval = yytext;return FWTOK_USER;
{BTSTR}@{BTSTR} yylval->strval = yytext;return FWTOK_USER;
{QSTR}@{QSTR} yylval->strval = yytext;return FWTOK_USER;