| 48 |
|
char linebuf[IRCD_BUFSIZE]; |
| 49 |
|
char conffilebuf[IRCD_BUFSIZE]; |
| 50 |
|
|
| 51 |
< |
static int include_stack_ptr = 0; |
| 52 |
< |
static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH]; |
| 53 |
< |
static unsigned int lineno_stack[MAX_INCLUDE_DEPTH]; |
| 54 |
< |
static FILE *inc_fbfile_in[MAX_INCLUDE_DEPTH]; |
| 55 |
< |
static char conffile_stack[MAX_INCLUDE_DEPTH][IRCD_BUFSIZE]; |
| 51 |
> |
static struct included_file |
| 52 |
> |
{ |
| 53 |
> |
YY_BUFFER_STATE state; |
| 54 |
> |
unsigned int lineno; |
| 55 |
> |
FILE *file; |
| 56 |
> |
char conffile[IRCD_BUFSIZE]; |
| 57 |
> |
} include_stack[MAX_INCLUDE_DEPTH]; |
| 58 |
> |
|
| 59 |
> |
static unsigned int include_stack_ptr; |
| 60 |
> |
|
| 61 |
|
static void ccomment(void); |
| 62 |
|
static void cinclude(void); |
| 63 |
|
static int ieof(void); |
| 433 |
|
cinclude(void) |
| 434 |
|
{ |
| 435 |
|
char *p = NULL; |
| 436 |
+ |
char filenamebuf[IRCD_BUFSIZE]; |
| 437 |
|
|
| 438 |
|
if ((p = strchr(yytext, '<')) == NULL) |
| 439 |
|
*strchr(p = strchr(yytext, '"') + 1, '"') = '\0'; |
| 440 |
|
else |
| 441 |
|
*strchr(++p, '>') = '\0'; |
| 442 |
|
|
| 437 |
– |
/* log(L_NOTICE, "got include %s!", c); */ |
| 438 |
– |
|
| 443 |
|
/* do stacking and co. */ |
| 444 |
|
if (include_stack_ptr >= MAX_INCLUDE_DEPTH) |
| 445 |
+ |
{ |
| 446 |
|
ilog(LOG_TYPE_IRCD, "Includes nested too deep in %s", p); |
| 447 |
+ |
return; |
| 448 |
+ |
} |
| 449 |
+ |
|
| 450 |
+ |
if (*p == '/') /* if it is an absolute path */ |
| 451 |
+ |
snprintf(filenamebuf, sizeof(filenamebuf), "%s", p); |
| 452 |
|
else |
| 453 |
< |
{ |
| 444 |
< |
FILE *tmp_fbfile_in = NULL; |
| 445 |
< |
char filenamebuf[IRCD_BUFSIZE]; |
| 453 |
> |
snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", ETCPATH, p); |
| 454 |
|
|
| 455 |
< |
if (*p == '/') /* if it is an absolute path */ |
| 456 |
< |
snprintf(filenamebuf, sizeof(filenamebuf), "%s", p); |
| 457 |
< |
else |
| 458 |
< |
snprintf(filenamebuf, sizeof(filenamebuf), "%s/%s", ETCPATH, p); |
| 455 |
> |
FILE *tmp_fbfile_in = fopen(filenamebuf, "r"); |
| 456 |
> |
if (!tmp_fbfile_in) |
| 457 |
> |
{ |
| 458 |
> |
ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s", |
| 459 |
> |
filenamebuf, strerror(errno)); |
| 460 |
> |
return; |
| 461 |
> |
} |
| 462 |
|
|
| 463 |
< |
tmp_fbfile_in = fopen(filenamebuf, "r"); |
| 463 |
> |
struct included_file *file = &include_stack[include_stack_ptr++]; |
| 464 |
> |
file->lineno = lineno; |
| 465 |
> |
file->file = conf_parser_ctx.conf_file; |
| 466 |
> |
file->state = YY_CURRENT_BUFFER; |
| 467 |
> |
strlcpy(file->conffile, conffilebuf, sizeof(file->conffile)); |
| 468 |
|
|
| 469 |
< |
if (tmp_fbfile_in == NULL) |
| 470 |
< |
{ |
| 456 |
< |
ilog(LOG_TYPE_IRCD, "Unable to read configuration file '%s': %s", |
| 457 |
< |
filenamebuf, strerror(errno)); |
| 458 |
< |
return; |
| 459 |
< |
} |
| 469 |
> |
lineno = 1; |
| 470 |
> |
conf_parser_ctx.conf_file = tmp_fbfile_in; |
| 471 |
|
|
| 472 |
< |
lineno_stack[include_stack_ptr] = lineno; |
| 473 |
< |
lineno = 1; |
| 463 |
< |
inc_fbfile_in[include_stack_ptr] = conf_parser_ctx.conf_file; |
| 464 |
< |
strlcpy(conffile_stack[include_stack_ptr], conffilebuf, IRCD_BUFSIZE); |
| 465 |
< |
include_stack[include_stack_ptr++] = YY_CURRENT_BUFFER; |
| 466 |
< |
conf_parser_ctx.conf_file = tmp_fbfile_in; |
| 467 |
< |
snprintf(conffilebuf, sizeof(conffilebuf), "%s", filenamebuf); |
| 468 |
< |
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); |
| 469 |
< |
} |
| 472 |
> |
snprintf(conffilebuf, sizeof(conffilebuf), "%s", filenamebuf); |
| 473 |
> |
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); |
| 474 |
|
} |
| 475 |
|
|
| 476 |
|
/* This is function that will be called on EOF in conf file. It will |
| 479 |
|
static int |
| 480 |
|
ieof(void) |
| 481 |
|
{ |
| 482 |
< |
/* log(L_NOTICE, "return from include stack!"); */ |
| 479 |
< |
if (include_stack_ptr) |
| 480 |
< |
fclose(conf_parser_ctx.conf_file); |
| 481 |
< |
if (--include_stack_ptr < 0) |
| 482 |
> |
if (include_stack_ptr == 0) |
| 483 |
|
{ |
| 483 |
– |
/* log(L_NOTICE, "terminating lexer"); */ |
| 484 |
– |
/* We will now exit the lexer - restore init values if we get /rehash |
| 485 |
– |
* later and reenter lexer -kre */ |
| 486 |
– |
include_stack_ptr = 0; |
| 484 |
|
lineno = 1; |
| 485 |
|
return 1; |
| 486 |
|
} |
| 487 |
|
|
| 488 |
|
/* switch buffer */ |
| 489 |
< |
/* log(L_NOTICE, "deleting include_stack_ptr=%d", include_stack_ptr); */ |
| 489 |
> |
struct included_file *file = &include_stack[--include_stack_ptr]; |
| 490 |
> |
|
| 491 |
> |
/* close current file */ |
| 492 |
> |
fclose(conf_parser_ctx.conf_file); |
| 493 |
> |
|
| 494 |
> |
/* switch buffers */ |
| 495 |
|
yy_delete_buffer(YY_CURRENT_BUFFER); |
| 496 |
< |
lineno = lineno_stack[include_stack_ptr]; |
| 497 |
< |
conf_parser_ctx.conf_file = inc_fbfile_in[include_stack_ptr]; |
| 498 |
< |
strlcpy(conffilebuf, conffile_stack[include_stack_ptr], sizeof(conffilebuf)); |
| 499 |
< |
yy_switch_to_buffer(include_stack[include_stack_ptr]); |
| 496 |
> |
yy_switch_to_buffer(file->state); |
| 497 |
> |
|
| 498 |
> |
/* switch lineno */ |
| 499 |
> |
lineno = file->lineno; |
| 500 |
> |
|
| 501 |
> |
/* switch file */ |
| 502 |
> |
conf_parser_ctx.conf_file = file->file; |
| 503 |
|
|
| 504 |
+ |
strlcpy(conffilebuf, file->conffile, sizeof(conffilebuf)); |
| 505 |
|
return 0; |
| 506 |
|
} |