| 1 |
|
/* |
| 2 |
|
* Copyright (c) 2002 Erik Fears |
| 3 |
< |
* Copyright (c) 2014-2016 ircd-hybrid development team |
| 3 |
> |
* Copyright (c) 2014-2018 ircd-hybrid development team |
| 4 |
|
* |
| 5 |
|
* This program is free software; you can redistribute it and/or modify |
| 6 |
|
* it under the terms of the GNU General Public License as published by |
| 20 |
|
|
| 21 |
|
%option case-insensitive |
| 22 |
|
%option noyywrap |
| 23 |
+ |
%option noinput |
| 24 |
|
%option nounput |
| 25 |
|
%option never-interactive |
| 26 |
|
|
| 27 |
+ |
%x IN_COMMENT |
| 28 |
+ |
|
| 29 |
|
%{ |
| 30 |
|
#include <stdio.h> |
| 31 |
|
#include <string.h> |
| 32 |
|
|
| 33 |
|
#include "compat.h" |
| 34 |
|
#include "config.h" |
| 35 |
< |
#include "config-parser.h" |
| 35 |
> |
#include "config-parser.h" /* autogenerated header file */ |
| 36 |
> |
#include "log.h" |
| 37 |
> |
|
| 38 |
> |
/* libopm includes */ |
| 39 |
> |
#include "libopm/src/opm_types.h" |
| 40 |
> |
|
| 41 |
> |
#undef YY_FATAL_ERROR |
| 42 |
> |
#define YY_FATAL_ERROR(msg) conf_yy_fatal_error(msg) |
| 43 |
|
|
| 44 |
+ |
#undef YY_INPUT |
| 45 |
+ |
#define YY_INPUT(buf,result,max_size) \ |
| 46 |
+ |
if (!(result = conf_yy_input(buf, max_size))) \ |
| 47 |
+ |
YY_FATAL_ERROR("input in flex scanner failed"); |
| 48 |
+ |
#define MAX_INCLUDE_DEPTH 10 |
| 49 |
|
|
| 35 |
– |
static void ccomment(void); |
| 50 |
|
|
| 51 |
< |
unsigned int linenum = 1; |
| 51 |
> |
unsigned int lineno = 1; |
| 52 |
|
char linebuf[512]; |
| 53 |
+ |
char conffilebuf[512]; |
| 54 |
|
|
| 55 |
< |
%} |
| 55 |
> |
static struct included_file |
| 56 |
> |
{ |
| 57 |
> |
YY_BUFFER_STATE state; |
| 58 |
> |
unsigned int lineno; |
| 59 |
> |
FILE *file; |
| 60 |
> |
char conffile[512]; |
| 61 |
> |
} include_stack[MAX_INCLUDE_DEPTH]; |
| 62 |
|
|
| 63 |
< |
string \"[^\"\n]*[\"\n] |
| 43 |
< |
comment ("//"|"#").* |
| 44 |
< |
whitespace [ \t\r]* |
| 63 |
> |
static unsigned int include_stack_ptr; |
| 64 |
|
|
| 46 |
– |
%% |
| 65 |
|
|
| 66 |
< |
"/*" { ccomment(); } |
| 66 |
> |
static void conf_include(void); |
| 67 |
> |
static int conf_eof(void); |
| 68 |
> |
|
| 69 |
> |
static int |
| 70 |
> |
conf_yy_input(char *lbuf, unsigned int max_size) |
| 71 |
> |
{ |
| 72 |
> |
return fgets(lbuf, max_size, conf_file) == NULL ? 0 : strlen(lbuf); |
| 73 |
> |
} |
| 74 |
> |
|
| 75 |
> |
static int |
| 76 |
> |
conf_yy_fatal_error(const char *msg) |
| 77 |
> |
{ |
| 78 |
> |
return 0; |
| 79 |
> |
} |
| 80 |
> |
%} |
| 81 |
|
|
| 82 |
< |
{comment} ; |
| 82 |
> |
WS [[:blank:]]* |
| 83 |
> |
DIGIT [[:digit:]]+ |
| 84 |
> |
COMMENT ("//"|"#").* |
| 85 |
> |
qstring \"[^\"\n]*[\"\n] |
| 86 |
> |
include \.include{WS}(\<.*\>|\".*\") |
| 87 |
|
|
| 88 |
< |
{string} { |
| 53 |
< |
/* QSTRING from Hybrid7. Why re-invent the wheel? */ |
| 88 |
> |
%% |
| 89 |
|
|
| 90 |
< |
if(yytext[yyleng-2] == '\\') |
| 91 |
< |
{ |
| 92 |
< |
yyless(yyleng-1); /* return last quote */ |
| 93 |
< |
yymore(); /* append next string */ |
| 94 |
< |
} |
| 95 |
< |
else |
| 96 |
< |
{ |
| 97 |
< |
yylval.string = yytext+1; |
| 98 |
< |
if(yylval.string[yyleng-2] != '"') ; /* log error */ |
| 99 |
< |
else |
| 100 |
< |
{ |
| 101 |
< |
int i,j; |
| 102 |
< |
|
| 103 |
< |
yylval.string[yyleng-2] = '\0'; /* remove close |
| 104 |
< |
* quote |
| 105 |
< |
*/ |
| 106 |
< |
|
| 107 |
< |
for (j=i=0 ;yylval.string[i] != '\0'; i++,j++) |
| 108 |
< |
{ |
| 109 |
< |
if (yylval.string[i] != '\\') |
| 110 |
< |
{ |
| 111 |
< |
yylval.string[j] = yylval.string[i]; |
| 112 |
< |
} |
| 113 |
< |
else |
| 114 |
< |
{ |
| 115 |
< |
i++; |
| 116 |
< |
yylval.string[j] = yylval.string[i]; |
| 117 |
< |
} |
| 118 |
< |
} |
| 119 |
< |
yylval.string[j] = '\0'; |
| 120 |
< |
return STRING; |
| 121 |
< |
} |
| 122 |
< |
} |
| 123 |
< |
} |
| 90 |
> |
"/*" { BEGIN IN_COMMENT; } |
| 91 |
> |
<IN_COMMENT>"*/" { BEGIN INITIAL; } |
| 92 |
> |
<IN_COMMENT>. ; /* Eat everything but a newline */ |
| 93 |
> |
<IN_COMMENT>\n { ++lineno; } |
| 94 |
> |
<IN_COMMENT><<EOF>> { BEGIN INITIAL; if (conf_eof()) yyterminate(); } |
| 95 |
> |
|
| 96 |
> |
{include} { conf_include(); } |
| 97 |
> |
\n.* { strlcpy(linebuf, yytext + 1, sizeof(linebuf)); ++lineno; yyless(1); } |
| 98 |
> |
{WS} ; |
| 99 |
> |
{COMMENT} ; |
| 100 |
> |
{DIGIT} { yylval.number = atoi(yytext); return NUMBER; } |
| 101 |
> |
{qstring} { if (yytext[yyleng - 2] == '\\') |
| 102 |
> |
{ |
| 103 |
> |
yyless(yyleng - 1); /* Return last quote */ |
| 104 |
> |
yymore(); /* Append next string */ |
| 105 |
> |
} |
| 106 |
> |
else |
| 107 |
> |
{ |
| 108 |
> |
yylval.string = yytext + 1; |
| 109 |
> |
|
| 110 |
> |
if (yylval.string[yyleng - 2] != '"') |
| 111 |
> |
log_printf("CONFIG ->Unterminated character string"); |
| 112 |
> |
else |
| 113 |
> |
{ |
| 114 |
> |
unsigned int i = 0, j = 0; |
| 115 |
> |
|
| 116 |
> |
yylval.string[yyleng - 2] = '\0'; /* Remove close quote */ |
| 117 |
> |
|
| 118 |
> |
for (; yylval.string[i] != '\0'; ++i, ++j) |
| 119 |
> |
{ |
| 120 |
> |
if (yylval.string[i] != '\\') |
| 121 |
> |
yylval.string[j] = yylval.string[i]; |
| 122 |
> |
else |
| 123 |
> |
{ |
| 124 |
> |
++i; |
| 125 |
> |
|
| 126 |
> |
if (yylval.string[i] == '\0') /* XXX: should not happen */ |
| 127 |
> |
{ |
| 128 |
> |
log_printf("CONFIG -> Unterminated character string"); |
| 129 |
> |
break; |
| 130 |
> |
} |
| 131 |
> |
|
| 132 |
> |
yylval.string[j] = yylval.string[i]; |
| 133 |
> |
} |
| 134 |
> |
} |
| 135 |
> |
|
| 136 |
> |
yylval.string[j] = '\0'; |
| 137 |
> |
return STRING; |
| 138 |
> |
} |
| 139 |
> |
} |
| 140 |
> |
} |
| 141 |
|
|
| 142 |
+ |
ADDRESS_FAMILY { return ADDRESS_FAMILY; } |
| 143 |
|
AWAY { return AWAY; } |
| 144 |
|
BAN_UNKNOWN { return BAN_UNKNOWN; } |
| 145 |
|
BLACKLIST { return BLACKLIST; } |
| 146 |
|
CHANNEL { return CHANNEL; } |
| 147 |
+ |
COMMAND_INTERVAL { return COMMAND_INTERVAL; } |
| 148 |
+ |
COMMAND_QUEUE_SIZE { return COMMAND_QUEUE_SIZE; } |
| 149 |
+ |
COMMAND_TIMEOUT { return COMMAND_TIMEOUT; } |
| 150 |
|
CONNREGEX { return CONNREGEX; } |
| 151 |
|
DNS_FDLIMIT { return DNS_FDLIMIT; } |
| 152 |
|
DNS_TIMEOUT { return DNS_TIMEOUT; } |
| 155 |
|
EXEMPT { return EXEMPT; } |
| 156 |
|
FD { return FD; } |
| 157 |
|
INVITE { return INVITE; } |
| 158 |
+ |
IPV4 { return IPV4; } |
| 159 |
+ |
IPV6 { return IPV6; } |
| 160 |
|
IRC { return IRC; } |
| 161 |
|
KLINE { return KLINE; } |
| 162 |
|
KEY { return KEY; } |
| 268 |
|
} |
| 269 |
|
|
| 270 |
|
|
| 271 |
< |
|
| 272 |
< |
[0-9]+ { |
| 273 |
< |
yylval.number=atoi(yytext); |
| 216 |
< |
return NUMBER; |
| 271 |
> |
SSH { |
| 272 |
> |
yylval.number = OPM_TYPE_SSH; |
| 273 |
> |
return PROTOCOLTYPE; |
| 274 |
|
} |
| 275 |
|
|
| 219 |
– |
|
| 220 |
– |
|
| 221 |
– |
|
| 222 |
– |
|
| 276 |
|
TRUE { |
| 277 |
|
yylval.number=1; |
| 278 |
|
return NUMBER; |
| 303 |
|
return NUMBER; |
| 304 |
|
} |
| 305 |
|
|
| 306 |
< |
|
| 307 |
< |
\n.* { |
| 255 |
< |
strlcpy(linebuf, yytext + 1, sizeof(linebuf)); |
| 256 |
< |
++linenum; |
| 257 |
< |
yyless(1); |
| 258 |
< |
} |
| 259 |
< |
|
| 260 |
< |
{whitespace} /* ignore whitespace */; |
| 261 |
< |
|
| 262 |
< |
. return yytext[0]; |
| 306 |
> |
. { return yytext[0]; } |
| 307 |
> |
<<EOF>> { if (conf_eof()) yyterminate(); } |
| 308 |
|
|
| 309 |
|
%% |
| 310 |
|
|
| 266 |
– |
|
| 267 |
– |
/* C-comment ignoring routine -kre*/ |
| 311 |
|
static void |
| 312 |
< |
ccomment(void) |
| 312 |
> |
conf_include(void) |
| 313 |
|
{ |
| 314 |
< |
int c = 0; |
| 314 |
> |
char *p = NULL; |
| 315 |
> |
char filenamebuf[512]; |
| 316 |
> |
|
| 317 |
> |
if ((p = strchr(yytext, '<')) == NULL) |
| 318 |
> |
*strchr(p = strchr(yytext, '"') + 1, '"') = '\0'; |
| 319 |
> |
else |
| 320 |
> |
*strchr(++p, '>') = '\0'; |
| 321 |
|
|
| 322 |
< |
/* log(L_NOTICE, "got comment"); */ |
| 323 |
< |
while (1) |
| 322 |
> |
/* do stacking and co. */ |
| 323 |
> |
if (include_stack_ptr >= MAX_INCLUDE_DEPTH) |
| 324 |
|
{ |
| 325 |
< |
while ((c = input()) != '*' && c != EOF) |
| 326 |
< |
if (c == '\n') |
| 278 |
< |
++linenum; |
| 279 |
< |
|
| 280 |
< |
if (c == '*') |
| 281 |
< |
{ |
| 282 |
< |
while ((c = input()) == '*') |
| 283 |
< |
/* Nothing */ ; |
| 284 |
< |
if (c == '/') |
| 285 |
< |
break; |
| 286 |
< |
else if (c == '\n') |
| 287 |
< |
++linenum; |
| 288 |
< |
} |
| 289 |
< |
|
| 290 |
< |
if (c == EOF) |
| 291 |
< |
{ |
| 292 |
< |
YY_FATAL_ERROR("EOF in comment"); |
| 293 |
< |
|
| 294 |
< |
/* XXX hack alert this disables |
| 295 |
< |
* the stupid unused function warning |
| 296 |
< |
* gcc generates |
| 297 |
< |
*/ |
| 298 |
< |
if (1 == 0) |
| 299 |
< |
yy_fatal_error("EOF in comment"); |
| 300 |
< |
break; |
| 301 |
< |
} |
| 325 |
> |
log_printf("CONFIG -> Includes nested too deep in %s", p); |
| 326 |
> |
return; |
| 327 |
|
} |
| 328 |
+ |
|
| 329 |
+ |
if (*p == '/') /* if it is an absolute path */ |
| 330 |
+ |
snprintf(filenamebuf, sizeof(filenamebuf), "%s", p); |
| 331 |
+ |
else |
| 332 |
+ |
snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", HOPM_ETCDIR, p); |
| 333 |
+ |
|
| 334 |
+ |
FILE *tmp_fbfile_in = fopen(filenamebuf, "r"); |
| 335 |
+ |
if (!tmp_fbfile_in) |
| 336 |
+ |
{ |
| 337 |
+ |
log_printf("CONFIG -> Unable to read configuration file '%s': %s", |
| 338 |
+ |
filenamebuf, strerror(errno)); |
| 339 |
+ |
return; |
| 340 |
+ |
} |
| 341 |
+ |
|
| 342 |
+ |
struct included_file *file = &include_stack[include_stack_ptr++]; |
| 343 |
+ |
file->lineno = lineno; |
| 344 |
+ |
file->file = conf_file; |
| 345 |
+ |
file->state = YY_CURRENT_BUFFER; |
| 346 |
+ |
strlcpy(file->conffile, conffilebuf, sizeof(file->conffile)); |
| 347 |
+ |
|
| 348 |
+ |
lineno = 1; |
| 349 |
+ |
conf_file = tmp_fbfile_in; |
| 350 |
+ |
strlcpy(conffilebuf, filenamebuf, sizeof(conffilebuf)); |
| 351 |
+ |
|
| 352 |
+ |
yy_switch_to_buffer(yy_create_buffer(NULL, YY_BUF_SIZE)); |
| 353 |
+ |
} |
| 354 |
+ |
|
| 355 |
+ |
static int |
| 356 |
+ |
conf_eof(void) |
| 357 |
+ |
{ |
| 358 |
+ |
if (include_stack_ptr == 0) |
| 359 |
+ |
return 1; |
| 360 |
+ |
|
| 361 |
+ |
/* switch buffer */ |
| 362 |
+ |
struct included_file *file = &include_stack[--include_stack_ptr]; |
| 363 |
+ |
|
| 364 |
+ |
/* close current file */ |
| 365 |
+ |
fclose(conf_file); |
| 366 |
+ |
|
| 367 |
+ |
/* switch buffers */ |
| 368 |
+ |
yy_delete_buffer(YY_CURRENT_BUFFER); |
| 369 |
+ |
yy_switch_to_buffer(file->state); |
| 370 |
+ |
|
| 371 |
+ |
/* switch lineno */ |
| 372 |
+ |
lineno = file->lineno; |
| 373 |
+ |
|
| 374 |
+ |
/* switch file */ |
| 375 |
+ |
conf_file = file->file; |
| 376 |
+ |
|
| 377 |
+ |
strlcpy(conffilebuf, file->conffile, sizeof(conffilebuf)); |
| 378 |
+ |
return 0; |
| 379 |
|
} |