X-Git-Url: https://git.distorted.org.uk/~mdw/become/blobdiff_plain/c327f3bc65730b2d3199b3d072785ef9df4dcf84..27fb3b270fc6d2b974e762fab36e7eacf32d5112:/src/parser.y diff --git a/src/parser.y b/src/parser.y index a3860b4..f7ed0e3 100644 --- a/src/parser.y +++ b/src/parser.y @@ -1,10 +1,10 @@ /* -*-c-*- * - * $Id: parser.y,v 1.4 1997/09/17 10:26:52 mdw Exp $ + * $Id$ * * Parser for `become.conf' files * - * (c) 1997 EBI + * (c) 1998 EBI */ /*----- Licensing notice --------------------------------------------------* @@ -26,24 +26,6 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: parser.y,v $ - * Revision 1.4 1997/09/17 10:26:52 mdw - * Use rewritten class handler. Makes the expression parsers considerably - * simpler. - * - * Revision 1.3 1997/09/09 18:17:06 mdw - * Allow default port to be given as a service name or port number. - * - * Revision 1.2 1997/08/04 10:24:24 mdw - * Sources placed under CVS control. - * - * Revision 1.1 1997/07/21 13:47:45 mdw - * Initial revision - * - */ - /*----- Header files ------------------------------------------------------*/ %{ @@ -66,6 +48,11 @@ #include #include +/* --- mLib headers --- */ + +#include +#include + /* --- Local headers --- */ #include "class.h" @@ -73,9 +60,10 @@ #include "lexer.h" #include "name.h" #include "rule.h" -#include "sym.h" #include "userdb.h" -#include "utils.h" + +#define YYDEBUG 1 +#define YYERROR_VERBOSE %} /*----- Stack type --------------------------------------------------------*/ @@ -117,9 +105,6 @@ /*----- Error reporting ---------------------------------------------------*/ %{ -#define YYDEBUG 1 -#define YYERROR_VERBOSE - /* --- @yyprint@ --- * * * Arguments: @FILE *fp@ = pointer to stream to write on @@ -203,18 +188,38 @@ host_spec : HOST name '=' host_class ';' { ; port_spec : PORT STRING ';' { +#ifndef NONETWORK struct servent *s = getservbyname($2, "udp"); if (!s) { moan("unknown service `%s' at line %i", $2, lex_line); - YYERROR; + yynerrs++; YYERROR; } daemon_usePort(s->s_port); +#else + yyerror("`port' command unsupported"); + yynerrs++; YYERROR; +#endif + } + | PORT INT ';' { +#ifndef NONETWORK + daemon_usePort(htons($2)); +#else + yyerror("`port' command unsupported"); + yynerrs++; YYERROR; +#endif } - | PORT INT ';' { daemon_usePort(htons($2)); } ; -key_spec : KEYFILE STRING ';' { daemon_readKey($2); } +key_spec : KEYFILE STRING ';' { +#ifndef NONETWORK + daemon_readKey($2); +#else + yyerror("`keyfile' command unsupported"); + yynerrs++; YYERROR; +#endif + } + ; /* --- Parsing allow specifications --- */ @@ -222,6 +227,7 @@ allow_spec : ALLOW host_class_opt user_class ARROW user_class_opt command_class_opt ';' { rule_add($2, $3, $5, $6); } + ; host_class_opt : /* empty */ { $$ = class_all; } | '[' host_class ']' { $$ = $2; } @@ -244,6 +250,7 @@ name : WORD { n->c = 0; $$ = n; } + ; /*----- Various class expression types ------------------------------------* * @@ -256,25 +263,25 @@ name : WORD { user_class : user_class ',' user_class { if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | user_class '-' user_class { if (($$ = class_diff($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | user_class '&' user_class { if (($$ = class_isect($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | user_class '|' user_class { if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | INT { $$ = class_fromUser(clType_user, $1); } @@ -283,7 +290,7 @@ user_class : user_class ',' user_class { if ((pw = userdb_userByName($1)) == 0) { moan("user `%s' not known at line %i", $1, lex_line); - YYERROR; + yynerrs++; YYERROR; } else $$ = class_fromUser(clType_user, pw->pw_uid); } @@ -292,10 +299,10 @@ user_class : user_class ',' user_class { if (!n || !n->c) { moan("class `%s' not found at line %i", $1, lex_line); - YYERROR; + yynerrs++; YYERROR; } else if (~n->c->type & clType_user) { - yyerror("type mismatch"); - YYERROR; + yynerrs++; yyerror("type mismatch"); + yynerrs++; YYERROR; } else { $$ = n->c; class_inc(n->c); @@ -309,25 +316,25 @@ user_class : user_class ',' user_class { command_class : command_class ',' command_class { if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | command_class '-' command_class { if (($$ = class_diff($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | command_class '&' command_class { if (($$ = class_isect($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | command_class '|' command_class { if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | STRING { $$ = class_fromString(clType_command, $1); } @@ -336,10 +343,10 @@ command_class : command_class ',' command_class { if (!n || !n->c) { moan("class `%s' not found at line %i", $1, lex_line); - YYERROR; + yynerrs++; YYERROR; } else if (~n->c->type & clType_command) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } else { $$ = n->c; class_inc(n->c); @@ -353,25 +360,25 @@ command_class : command_class ',' command_class { host_class : host_class ',' host_class { if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | host_class '-' host_class { if (($$ = class_diff($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | host_class '&' host_class { if (($$ = class_isect($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | host_class '|' host_class { if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } } | STRING { $$ = class_fromString(clType_host, $1); } @@ -380,10 +387,10 @@ host_class : host_class ',' host_class { if (!n || !n->c) { moan("class `%s' not found at line %i", $1, lex_line); - YYERROR; + yynerrs++; YYERROR; } else if (~n->c->type & clType_host) { yyerror("type mismatch"); - YYERROR; + yynerrs++; YYERROR; } else { $$ = n->c; class_inc(n->c); @@ -392,4 +399,21 @@ host_class : host_class ',' host_class { | '(' host_class ')' { $$ = $2; } ; +/*----- Helper functions --------------------------------------------------*/ +%% +/* --- @parse@ --- * + * + * Arguments: --- + * + * Returns: Zero if it worked, nonzero if it didn't. + * + * Use: Parses configuration files. + */ + +int parse(void) +{ + yynerrs = 0; + return (yyparse() || yynerrs); +} + /*----- That's all, folks -------------------------------------------------*/