Skip to content

Commit 4b9cff3

Browse files
committed
Partially adds the REMOTE_USER variable support
1 parent f989ecd commit 4b9cff3

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ VARIABLES = \
4444
variables/env.cc \
4545
variables/highest_severity.cc \
4646
variables/modsec_build.cc \
47+
variables/remote_user.cc \
4748
variables/time.cc \
4849
variables/time_day.cc \
4950
variables/time_epoch.cc \

src/parser/seclang-parser.yy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Driver;
5353
#include "variables/env.h"
5454
#include "variables/highest_severity.h"
5555
#include "variables/modsec_build.h"
56+
#include "variables/remote_user.h"
5657
#include "variables/time_day.h"
5758
#include "variables/time_epoch.h"
5859
#include "variables/time.h"
@@ -96,6 +97,7 @@ using modsecurity::Variables::Duration;
9697
using modsecurity::Variables::Env;
9798
using modsecurity::Variables::HighestSeverity;
9899
using modsecurity::Variables::ModsecBuild;
100+
using modsecurity::Variables::RemoteUser;
99101
using modsecurity::Variables::Time;
100102
using modsecurity::Variables::TimeDay;
101103
using modsecurity::Variables::TimeEpoch;
@@ -227,6 +229,8 @@ using modsecurity::Variables::XML;
227229
%token <std::string> RUN_TIME_VAR_BLD
228230
%token <std::string> RUN_TIME_VAR_HSV
229231

232+
%token <std::string> RUN_TIME_VAR_REMOTE_USER
233+
230234
%token <std::string> RUN_TIME_VAR_TIME
231235
%token <std::string> RUN_TIME_VAR_TIME_DAY
232236
%token <std::string> RUN_TIME_VAR_TIME_EPOCH
@@ -752,6 +756,15 @@ var:
752756
if (!var) { var = new HighestSeverity(name); }
753757
$$ = var;
754758
}
759+
| RUN_TIME_VAR_REMOTE_USER
760+
{
761+
std::string name($1);
762+
CHECK_VARIATION_DECL
763+
CHECK_VARIATION(&) { var = new Count(new RemoteUser(name)); }
764+
CHECK_VARIATION(!) { var = new Exclusion(new RemoteUser(name)); }
765+
if (!var) { var = new RemoteUser(name); }
766+
$$ = var;
767+
}
755768
| RUN_TIME_VAR_TIME
756769
{
757770
std::string name($1);

src/parser/seclang-scanner.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ VARIABLE_COL (?i:(SESSION|GLOBAL|ARGS_POST|ARGS_GET|ARGS|FILES_SIZES|FILES_NAMES
124124
VARIABLE_TX (?i:TX)
125125
VARIABLE_WEBSERVER_ERROR_LOG (?:WEBSERVER_ERROR_LOG)
126126

127+
RUN_TIME_VAR_REMOTE_USER (?i:REMOTE_USER)
127128
RUN_TIME_VAR_DUR (?i:DURATION)
128129
RUN_TIME_VAR_ENV (?i:ENV)
129130
RUN_TIME_VAR_BLD (?i:MODSEC_BUILD)
@@ -235,6 +236,7 @@ CONFIG_DIR_UNICODE_MAP_FILE (?i:SecUnicodeMapFile)
235236
[!&]?{VARIABLE_TX}(\:{DICT_ELEMENT})? { BEGIN(EXPECTING_OPERATOR); return yy::seclang_parser::make_VARIABLE_TX(yytext, *driver.loc.back()); }
236237
[!&]?{VARIABLE_TX}(\:[\']{FREE_TEXT_QUOTE}[\'])? { BEGIN(EXPECTING_OPERATOR); return yy::seclang_parser::make_VARIABLE_TX(yytext, *driver.loc.back()); }
237238
[!&]?{RUN_TIME_VAR_DUR} { BEGIN(EXPECTING_OPERATOR); return yy::seclang_parser::make_RUN_TIME_VAR_DUR(yytext, *driver.loc.back()); }
239+
[!&]?{RUN_TIME_VAR_REMOTE_USER} { BEGIN(EXPECTING_OPERATOR); return yy::seclang_parser::make_RUN_TIME_VAR_REMOTE_USER(yytext, *driver.loc.back()); }
238240
[!&]?{RUN_TIME_VAR_ENV}(\:{DICT_ELEMENT})? { BEGIN(EXPECTING_OPERATOR); return yy::seclang_parser::make_RUN_TIME_VAR_ENV(yytext, *driver.loc.back()); }
239241
[!&]?{RUN_TIME_VAR_ENV}(\:[\']{FREE_TEXT_QUOTE}[\'])? { BEGIN(EXPECTING_OPERATOR); return yy::seclang_parser::make_RUN_TIME_VAR_ENV(yytext, *driver.loc.back()); }
240242
[!&]?{RUN_TIME_VAR_BLD} { BEGIN(EXPECTING_OPERATOR); return yy::seclang_parser::make_RUN_TIME_VAR_BLD(yytext, *driver.loc.back()); }

0 commit comments

Comments
 (0)