X-Git-Url: https://git.distorted.org.uk/~mdw/become/blobdiff_plain/c4f2d992e4a0fc068281376d89ec38de56dc2f58..af4f4d6a77aceba8e2d6f58d15e894df320e7c24:/src/parser.y diff --git a/src/parser.y b/src/parser.y index 0a8462f..860ed7e 100644 --- a/src/parser.y +++ b/src/parser.y @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: parser.y,v 1.1 1997/07/21 13:47:45 mdw Exp $ + * $Id: parser.y,v 1.9 2004/04/08 01:36:20 mdw Exp $ * * Parser for `become.conf' files * - * (c) 1997 EBI + * (c) 1998 EBI */ -/*----- Licencing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of `become' * @@ -22,16 +22,8 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with `become'; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -/*----- Revision history --------------------------------------------------* - * - * $Log: parser.y,v $ - * Revision 1.1 1997/07/21 13:47:45 mdw - * Initial revision - * + * along with `become'; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /*----- Header files ------------------------------------------------------*/ @@ -46,10 +38,21 @@ /* --- Unix headers --- */ #include +#include + +#include + +#include +#include #include #include +/* --- mLib headers --- */ + +#include +#include + /* --- Local headers --- */ #include "class.h" @@ -57,10 +60,7 @@ #include "lexer.h" #include "name.h" #include "rule.h" -#include "set.h" -#include "sym.h" #include "userdb.h" -#include "utils.h" %} /*----- Stack type --------------------------------------------------------*/ @@ -69,7 +69,7 @@ long i; char *s; name *n; - classdef *c; + class_node *c; } /*----- Token and rule declarations ---------------------------------------*/ @@ -187,10 +187,39 @@ host_spec : HOST name '=' host_class ';' { } ; -port_spec : PORT INT ';' { daemon_usePort($2); } +port_spec : PORT STRING ';' { +#ifndef NONETWORK + struct servent *s = getservbyname($2, "udp"); + if (!s) { + moan("unknown service `%s' at line %i", + $2, lex_line); + 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 + } ; -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 --- */ @@ -198,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; } @@ -220,6 +250,7 @@ name : WORD { n->c = 0; $$ = n; } + ; /*----- Various class expression types ------------------------------------* * @@ -230,100 +261,48 @@ name : WORD { /* --- User class expressions --- */ user_class : user_class ',' user_class { - if ($1->type != $3->type) { + if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - if ($1 == class_all) - $$ = class_all; - else - $$ = class_create($1->type, - set_union($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } | user_class '-' user_class { - if ($1->type != $3->type) { + if (($$ = class_diff($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - $$ = class_create($1->type, - set_subtract($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } | user_class '&' user_class { - if ($1->type != $3->type) { + if (($$ = class_isect($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - if ($1 == class_all) - $$ = class_all; - else - $$ = class_create($1->type, - set_intersect($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } | user_class '|' user_class { - if ($1->type != $3->type) { + if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - if ($1 == class_all) - $$ = class_all; - else - $$ = class_create($1->type, - set_union($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } - | INT { - sym_table *t = xmalloc(sizeof(*t)); - int u = $1; - sym_createTable(t); - sym_find(t, (char *)&u, sizeof(u), - sizeof(sym_base), 0); - $$ = class_create(clType_user, t); - } + | INT { $$ = class_fromUser(clType_user, $1); } | STRING { struct passwd *pw; - sym_table *t; - int u; if ((pw = userdb_userByName($1)) == 0) { moan("user `%s' not known at line %i", $1, lex_line); - YYERROR; - } else { - t = xmalloc(sizeof(*t)); - u = pw->pw_uid; - sym_createTable(t); - sym_find(t, (char *)&u, sizeof(u), - sizeof(sym_base), 0); - $$ = class_create(clType_user, t); - } + yynerrs++; YYERROR; + } else + $$ = class_fromUser(clType_user, pw->pw_uid); } | WORD { name *n = name_find($1, 0, 0); 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); @@ -335,81 +314,39 @@ user_class : user_class ',' user_class { /* --- Command class expressions --- */ command_class : command_class ',' command_class { - if ($1->type != $3->type) { + if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - if ($1 == class_all) - $$ = class_all; - else - $$ = class_create($1->type, - set_union($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } | command_class '-' command_class { - if ($1->type != $3->type) { + if (($$ = class_diff($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - $$ = class_create($1->type, - set_subtract($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } | command_class '&' command_class { - if ($1->type != $3->type) { + if (($$ = class_isect($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - if ($1 == class_all) - $$ = class_all; - else - $$ = class_create($1->type, - set_intersect($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } | command_class '|' command_class { - if ($1->type != $3->type) { + if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - if ($1 == class_all) - $$ = class_all; - else - $$ = class_create($1->type, - set_union($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } - | STRING { - sym_table *t = xmalloc(sizeof(*t)); - sym_createTable(t); - sym_find(t, $1, -1, sizeof(sym_base), 0); - $$ = class_create(clType_command, t); - } + | STRING { $$ = class_fromString(clType_command, $1); } | WORD { name *n = name_find($1, 0, 0); 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); @@ -420,82 +357,40 @@ command_class : command_class ',' command_class { /* --- Host class expressions --- */ -host_class : host_class ',' host_class { - if ($1->type != $3->type) { +host_class : host_class ',' host_class { + if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - if ($1 == class_all) - $$ = class_all; - else - $$ = class_create($1->type, - set_union($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } | host_class '-' host_class { - if ($1->type != $3->type) { + if (($$ = class_diff($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - $$ = class_create($1->type, - set_subtract($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } | host_class '&' host_class { - if ($1->type != $3->type) { + if (($$ = class_isect($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - if ($1 == class_all) - $$ = class_all; - else - $$ = class_create($1->type, - set_intersect($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } | host_class '|' host_class { - if ($1->type != $3->type) { + if (($$ = class_union($1, $3)) == 0) { yyerror("type mismatch"); - class_dec($1); - class_dec($3); - YYERROR; - } else { - if ($1 == class_all) - $$ = class_all; - else - $$ = class_create($1->type, - set_union($1->t, $3->t)); - class_dec($1); - class_dec($3); + yynerrs++; YYERROR; } } - | STRING { - sym_table *t = xmalloc(sizeof(*t)); - sym_createTable(t); - sym_find(t, $1, -1, sizeof(sym_base), 0); - $$ = class_create(clType_host, t); - } + | STRING { $$ = class_fromString(clType_host, $1); } | WORD { name *n = name_find($1, 0, 0); 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); @@ -504,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 -------------------------------------------------*/