3030 result = (EOF == yyc) ? 0 : (*(buf) = yyc, 1); \
3131}
3232#define PARSE_ERROR exit(1);
33+ #define MEMORY_ERROR { \
34+ logError("could not allocate memory when parsing configuration.\n"); \
35+ exit(1); \
36+ }
3337
3438#if defined __clang__
3539#pragma clang diagnostic ignored "-Wunused-parameter"
@@ -357,7 +361,7 @@ YY_ACTION(void) yy_1_sol(yycontext *yy, char *yytext, int yyleng)
357361#define yythunkpos yy->__thunkpos
358362 yyprintf ((stderr , "do yy_1_sol\n" ));
359363 {
360- #line 157
364+ #line 161
361365 ++ yy -> currentLine ; ;
362366 }
363367#undef yythunkpos
@@ -371,9 +375,9 @@ YY_ACTION(void) yy_1_invalid_syntax(yycontext *yy, char *yytext, int yyleng)
371375#define yythunkpos yy->__thunkpos
372376 yyprintf ((stderr , "do yy_1_invalid_syntax\n" ));
373377 {
374- #line 131
378+ #line 135
375379
376- logError ("rinetd: invalid syntax at line %d: %s\n" ,
380+ logError ("invalid syntax at line %d: %s\n" ,
377381 yy -> currentLine , yytext );
378382 PARSE_ERROR ; /* FIXME */
379383;
@@ -389,7 +393,7 @@ YY_ACTION(void) yy_1_logcommon(yycontext *yy, char *yytext, int yyleng)
389393#define yythunkpos yy->__thunkpos
390394 yyprintf ((stderr , "do yy_1_logcommon\n" ));
391395 {
392- #line 126
396+ #line 130
393397
394398 logFormatCommon = 1 ;
395399;
@@ -405,11 +409,11 @@ YY_ACTION(void) yy_1_pidlogfile(yycontext *yy, char *yytext, int yyleng)
405409#define yythunkpos yy->__thunkpos
406410 yyprintf ((stderr , "do yy_1_pidlogfile\n" ));
407411 {
408- #line 118
412+ #line 122
409413
410414 pidLogFileName = strdup (yytext );
411415 if (!pidLogFileName ) {
412- PARSE_ERROR ;
416+ MEMORY_ERROR ;
413417 }
414418;
415419 }
@@ -424,11 +428,11 @@ YY_ACTION(void) yy_1_logfile(yycontext *yy, char *yytext, int yyleng)
424428#define yythunkpos yy->__thunkpos
425429 yyprintf ((stderr , "do yy_1_logfile\n" ));
426430 {
427- #line 110
431+ #line 114
428432
429433 logFileName = strdup (yytext );
430434 if (!logFileName ) {
431- PARSE_ERROR ;
435+ MEMORY_ERROR ;
432436 }
433437;
434438 }
@@ -443,7 +447,7 @@ YY_ACTION(void) yy_1_auth_key(yycontext *yy, char *yytext, int yyleng)
443447#define yythunkpos yy->__thunkpos
444448 yyprintf ((stderr , "do yy_1_auth_key\n" ));
445449 {
446- #line 107
450+ #line 111
447451 yy -> isAuthAllow = (yytext [0 ] == 'a' ); ;
448452 }
449453#undef yythunkpos
@@ -457,16 +461,16 @@ YY_ACTION(void) yy_1_auth_rule(yycontext *yy, char *yytext, int yyleng)
457461#define yythunkpos yy->__thunkpos
458462 yyprintf ((stderr , "do yy_1_auth_rule\n" ));
459463 {
460- #line 85
464+ #line 89
461465
462466 allRules = (Rule * )
463467 realloc (allRules , sizeof (Rule ) * (allRulesCount + 1 ));
464468 if (!allRules ) {
465- PARSE_ERROR ;
469+ MEMORY_ERROR ;
466470 }
467471 allRules [allRulesCount ].pattern = strdup (yytext );
468472 if (!allRules [allRulesCount ].pattern ) {
469- PARSE_ERROR ;
473+ MEMORY_ERROR ;
470474 }
471475 allRules [allRulesCount ].type = yy -> isAuthAllow ? allowRule : denyRule ;
472476 if (seTotal > 0 ) {
@@ -491,7 +495,7 @@ YY_ACTION(void) yy_3_proto(yycontext *yy, char *yytext, int yyleng)
491495#define yythunkpos yy->__thunkpos
492496 yyprintf ((stderr , "do yy_3_proto\n" ));
493497 {
494- #line 82
498+ #line 86
495499 yy -> tmpProto = IPPROTO_TCP ; ;
496500 }
497501#undef yythunkpos
@@ -505,7 +509,7 @@ YY_ACTION(void) yy_2_proto(yycontext *yy, char *yytext, int yyleng)
505509#define yythunkpos yy->__thunkpos
506510 yyprintf ((stderr , "do yy_2_proto\n" ));
507511 {
508- #line 81
512+ #line 85
509513 yy -> tmpProto = IPPROTO_UDP ; ;
510514 }
511515#undef yythunkpos
@@ -519,7 +523,7 @@ YY_ACTION(void) yy_1_proto(yycontext *yy, char *yytext, int yyleng)
519523#define yythunkpos yy->__thunkpos
520524 yyprintf ((stderr , "do yy_1_proto\n" ));
521525 {
522- #line 80
526+ #line 84
523527 yy -> tmpProto = IPPROTO_TCP ; ;
524528 }
525529#undef yythunkpos
@@ -533,7 +537,7 @@ YY_ACTION(void) yy_1_port(yycontext *yy, char *yytext, int yyleng)
533537#define yythunkpos yy->__thunkpos
534538 yyprintf ((stderr , "do yy_1_port\n" ));
535539 {
536- #line 79
540+ #line 83
537541 yy -> tmpPort = strdup (yytext ); ;
538542 }
539543#undef yythunkpos
@@ -547,7 +551,7 @@ YY_ACTION(void) yy_1_option_source(yycontext *yy, char *yytext, int yyleng)
547551#define yythunkpos yy->__thunkpos
548552 yyprintf ((stderr , "do yy_1_option_source\n" ));
549553 {
550- #line 75
554+ #line 79
551555 yy -> sourceAddress = strdup (yytext ); ;
552556 }
553557#undef yythunkpos
@@ -561,7 +565,7 @@ YY_ACTION(void) yy_1_option_timeout(yycontext *yy, char *yytext, int yyleng)
561565#define yythunkpos yy->__thunkpos
562566 yyprintf ((stderr , "do yy_1_option_timeout\n" ));
563567 {
564- #line 74
568+ #line 78
565569 yy -> serverTimeout = atoi (yytext ); ;
566570 }
567571#undef yythunkpos
@@ -575,7 +579,7 @@ YY_ACTION(void) yy_1_connect_port(yycontext *yy, char *yytext, int yyleng)
575579#define yythunkpos yy->__thunkpos
576580 yyprintf ((stderr , "do yy_1_connect_port\n" ));
577581 {
578- #line 69
582+ #line 73
579583 yy -> connectPort = yy -> tmpPort ; yy -> connectProto = yy -> tmpProto ; ;
580584 }
581585#undef yythunkpos
@@ -589,7 +593,7 @@ YY_ACTION(void) yy_1_bind_port(yycontext *yy, char *yytext, int yyleng)
589593#define yythunkpos yy->__thunkpos
590594 yyprintf ((stderr , "do yy_1_bind_port\n" ));
591595 {
592- #line 68
596+ #line 72
593597 yy -> bindPort = yy -> tmpPort ; yy -> bindProto = yy -> tmpProto ; ;
594598 }
595599#undef yythunkpos
@@ -603,7 +607,7 @@ YY_ACTION(void) yy_1_connect_address(yycontext *yy, char *yytext, int yyleng)
603607#define yythunkpos yy->__thunkpos
604608 yyprintf ((stderr , "do yy_1_connect_address\n" ));
605609 {
606- #line 67
610+ #line 71
607611 yy -> connectAddress = strdup (yytext ); ;
608612 }
609613#undef yythunkpos
@@ -617,7 +621,7 @@ YY_ACTION(void) yy_1_bind_address(yycontext *yy, char *yytext, int yyleng)
617621#define yythunkpos yy->__thunkpos
618622 yyprintf ((stderr , "do yy_1_bind_address\n" ));
619623 {
620- #line 66
624+ #line 70
621625 yy -> bindAddress = strdup (yytext ); ;
622626 }
623627#undef yythunkpos
@@ -631,7 +635,7 @@ YY_ACTION(void) yy_1_server_rule(yycontext *yy, char *yytext, int yyleng)
631635#define yythunkpos yy->__thunkpos
632636 yyprintf ((stderr , "do yy_1_server_rule\n" ));
633637 {
634- #line 51
638+ #line 55
635639
636640 addServer (yy -> bindAddress , yy -> bindPort , yy -> bindProto ,
637641 yy -> connectAddress , yy -> connectPort , yy -> connectProto ,
@@ -1398,21 +1402,22 @@ YY_PARSE(yycontext *) YYRELEASE(yycontext *yyctx)
13981402}
13991403
14001404#endif
1401- #line 161 "parse.peg"
1405+ #line 165 "parse.peg"
14021406
14031407
14041408void parseConfiguration (char const * file )
14051409{
14061410 FILE * in = fopen (file , "r" );
14071411 if (!in ) {
1408- PARSE_ERROR ;
1412+ logError ("could not open configuration file %s.\n" , file );
1413+ exit (1 );
14091414 }
14101415
14111416 yycontext ctx ;
14121417 memset (& ctx , 0 , sizeof (yycontext ));
14131418 ctx .fp = in ;
14141419 if (!yyparse (& ctx )) {
1415- logError ("invalid syntax on file %s, line %d.\n" , file , -1 );
1420+ logError ("invalid syntax in file %s, line %d.\n" , file , -1 );
14161421 exit (1 );
14171422 }
14181423 yyrelease (& ctx );
0 commit comments