Skip to content

Commit 4c924ae

Browse files
adding the parser to the .lex and .y files
1 parent 835195f commit 4c924ae

4 files changed

Lines changed: 62 additions & 3 deletions

File tree

cfg.lex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ MCAST_TTL "mcast_ttl"
280280
TOS "tos"
281281
DISABLE_DNS_FAILOVER "disable_dns_failover"
282282
REDACT_PII_ "redact_pii_"
283+
REDACT_TEMPLATE "redact_template"
284+
REDACT_MODE "redact_mode"
283285
DISABLE_DNS_BLACKLIST "disable_dns_blacklist"
284286
DST_BLACKLIST "dst_blacklist"
285287
MAX_WHILE_LOOPS "max_while_loops"
@@ -527,6 +529,10 @@ SPACE [ ]
527529
return DISABLE_DNS_FAILOVER; }
528530
<INITIAL>{REDACT_PII_} { count(); yylval.strval=yytext;
529531
return REDACT_PII_;}
532+
<INITIAL>{REDACT_TEMPLATE} { count(); yylval.strval=yytext;
533+
return REDACT_TEMPLATE;}
534+
<INITIAL>{REDACT_MODE} { count(); yylval.strval=yytext;
535+
return REDACT_MODE;}
530536
<INITIAL>{DISABLE_DNS_BLACKLIST} { count(); yylval.strval=yytext;
531537
return DISABLE_DNS_BLACKLIST; }
532538
<INITIAL>{DST_BLACKLIST} { count(); yylval.strval=yytext;

cfg.y

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
#include "config.h"
112112
#include "mem/rpm_mem.h"
113113
#include "poll_types.h"
114+
#include "redact_pii.h"
114115

115116
#ifdef SHM_EXTRA_STATS
116117
#include "mem/module_info.h"
@@ -394,6 +395,8 @@ extern int cfg_parse_only_routes;
394395
%token TOS
395396
%token DISABLE_DNS_FAILOVER
396397
%token REDACT_PII_
398+
%token REDACT_TEMPLATE
399+
%token REDACT_MODE
397400
%token DISABLE_DNS_BLACKLIST
398401
%token DST_BLACKLIST
399402
%token DISABLE_STATELESS_FWD
@@ -1592,7 +1595,24 @@ assign_stm: LOGLEVEL EQUAL snumber { IFOR();
15921595
| REDACT_PII_ EQUAL NUMBER { IFOR();
15931596
redact_pii_=$3;
15941597
}
1595-
| REDACT_PII_ error { yyerror("boolean value expected"); }
1598+
| REDACT_PII_ error { yyerror("boolean value expected"); }
1599+
| REDACT_TEMPLATE EQUAL STRING { IFOR();
1600+
redact_template=$3;
1601+
}
1602+
| REDACT_TEMPLATE error { yyerror("string value expected"); }
1603+
| REDACT_MODE EQUAL STRING { IFOR();
1604+
if (strcasecmp($3, "replace")==0)
1605+
redact_mode=REDACT_REPLACE;
1606+
else if (strcasecmp($3, "append")==0)
1607+
redact_mode=REDACT_APPEND;
1608+
else if (strcasecmp($3, "prepend")==0)
1609+
redact_mode=REDACT_PREPEND;
1610+
else if (strcasecmp($3, "format")==0)
1611+
redact_mode=REDACT_FORMAT;
1612+
else
1613+
yyerror("redact_mode must be: replace|append|prepend|format");
1614+
}
1615+
| REDACT_MODE error { yyerror("string value expected (replace|append|prepend|format)"); }
15961616
| DISABLE_DNS_BLACKLIST EQUAL NUMBER { IFOR();
15971617
disable_dns_blacklist=$3;
15981618
}

redact_pii.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
11
#include <string.h>
2+
#include <stdio.h>
23
#include "ut.h"
34
#include "redact_pii.h"
45

56
int redact_pii_ = 0;
7+
char *redact_template = "****";
8+
int redact_mode = REDACT_REPLACE;
69

7-
inline const char* redact_pii(const char* input) {
8-
return redact_pii_ ? "****" : ZSW(input);
10+
inline const char* redact_pii(const char* input) {
11+
static char buf[512];
12+
const char *safe = ZSW(input);
13+
14+
if (!redact_pii_)
15+
return safe;
16+
17+
switch (redact_mode) {
18+
case REDACT_APPEND:
19+
snprintf(buf, sizeof(buf), "%s%s", safe, redact_template);
20+
return buf;
21+
case REDACT_PREPEND:
22+
snprintf(buf, sizeof(buf), "%s%s", redact_template, safe);
23+
return buf;
24+
case REDACT_FORMAT:
25+
snprintf(buf, sizeof(buf), redact_template, safe);
26+
return buf;
27+
case REDACT_REPLACE:
28+
default:
29+
return redact_template;
30+
}
931
}

redact_pii.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@
2020
#ifndef redact_pii_h
2121
#define redact_pii_h
2222

23+
enum {
24+
REDACT_REPLACE = 0,
25+
REDACT_APPEND,
26+
REDACT_PREPEND,
27+
REDACT_FORMAT
28+
};
29+
30+
extern int redact_pii_;
31+
extern char *redact_template;
32+
extern int redact_mode;
2333

2434
const char* redact_pii(const char* input);
35+
2536
#endif

0 commit comments

Comments
 (0)