3 * $Id: parser.y,v 1.2 1997/08/04 10:24:24 mdw Exp $
5 * Parser for `become.conf' files
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of `become'
14 * `Become' is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * `Become' is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with `become'; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
32 * Revision 1.2 1997/08/04 10:24:24 mdw
33 * Sources placed under CVS control.
35 * Revision 1.1 1997/07/21 13:47:45 mdw
40 /*----- Header files ------------------------------------------------------*/
43 /* --- ANSI headers --- */
49 /* --- Unix headers --- */
51 #include <sys/types.h>
56 /* --- Local headers --- */
69 /*----- Stack type --------------------------------------------------------*/
78 /*----- Token and rule declarations ---------------------------------------*/
101 %type <c> user_class command_class host_class
102 %type <c> user_class_opt command_class_opt host_class_opt
105 /*----- Error reporting ---------------------------------------------------*/
109 #define YYERROR_VERBOSE
111 /* --- @yyprint@ --- *
113 * Arguments: @FILE *fp@ = pointer to stream to write on
114 * @int type@ = pointer to token type
115 * @YYSTYPE v@ = token value
119 * Use: Displays the semantic value of a token.
122 #define YYPRINT(fp, type, value) yyprint(fp, type, value)
124 static void yyprint(FILE *fp, int type, YYSTYPE v)
128 fprintf(fp, " %li", v.i);
132 fprintf(fp, " `%s'", v.s);
137 /* --- @yyerror@ --- *
139 * Arguments: @const char *msg@ = pointer to error message
143 * Use: Reports parse errors.
146 static void yyerror(const char *msg)
148 moan("%s at line %i", msg, lex_line);
153 /*----- The actual grammar ------------------------------------------------*/
155 /* --- Simple driver things --- */
161 statement : user_spec
170 /* --- Main statement types --- */
172 user_spec : USER name '=' user_class ';' {
179 command_spec : COMMAND name '=' command_class ';' {
186 host_spec : HOST name '=' host_class ';' {
193 port_spec : PORT INT ';' { daemon_usePort($2); }
196 key_spec : KEYFILE STRING ';' { daemon_readKey($2); }
198 /* --- Parsing allow specifications --- */
200 allow_spec : ALLOW host_class_opt user_class ARROW
201 user_class_opt command_class_opt ';' {
202 rule_add($2, $3, $5, $6);
205 host_class_opt : /* empty */ { $$ = class_all; }
206 | '[' host_class ']' { $$ = $2; }
209 user_class_opt : /* empty */ { $$ = class_all; }
210 | user_class { $$ = $1; }
213 command_class_opt : /* empty */ { $$ = class_all; }
214 | ':' command_class { $$ = $2; }
217 /* --- Names get translated into symbols quickly --- */
221 name *n = name_find($1, 1, &f);
227 /*----- Various class expression types ------------------------------------*
229 * Unfortunately, all these need to handle token types slightly differently
230 * and I can't be bothered to remember the current state.
233 /* --- User class expressions --- */
235 user_class : user_class ',' user_class {
236 if ($1->type != $3->type) {
237 yyerror("type mismatch");
245 $$ = class_create($1->type,
246 set_union($1->t, $3->t));
251 | user_class '-' user_class {
252 if ($1->type != $3->type) {
253 yyerror("type mismatch");
258 $$ = class_create($1->type,
259 set_subtract($1->t, $3->t));
264 | user_class '&' user_class {
265 if ($1->type != $3->type) {
266 yyerror("type mismatch");
274 $$ = class_create($1->type,
275 set_intersect($1->t, $3->t));
280 | user_class '|' user_class {
281 if ($1->type != $3->type) {
282 yyerror("type mismatch");
290 $$ = class_create($1->type,
291 set_union($1->t, $3->t));
297 sym_table *t = xmalloc(sizeof(*t));
300 sym_find(t, (char *)&u, sizeof(u),
301 sizeof(sym_base), 0);
302 $$ = class_create(clType_user, t);
308 if ((pw = userdb_userByName($1)) == 0) {
309 moan("user `%s' not known at line %i",
313 t = xmalloc(sizeof(*t));
316 sym_find(t, (char *)&u, sizeof(u),
317 sizeof(sym_base), 0);
318 $$ = class_create(clType_user, t);
322 name *n = name_find($1, 0, 0);
324 moan("class `%s' not found at line %i",
327 } else if (~n->c->type & clType_user) {
328 yyerror("type mismatch");
335 | '(' user_class ')' { $$ = $2; }
338 /* --- Command class expressions --- */
340 command_class : command_class ',' command_class {
341 if ($1->type != $3->type) {
342 yyerror("type mismatch");
350 $$ = class_create($1->type,
351 set_union($1->t, $3->t));
356 | command_class '-' command_class {
357 if ($1->type != $3->type) {
358 yyerror("type mismatch");
363 $$ = class_create($1->type,
364 set_subtract($1->t, $3->t));
369 | command_class '&' command_class {
370 if ($1->type != $3->type) {
371 yyerror("type mismatch");
379 $$ = class_create($1->type,
380 set_intersect($1->t, $3->t));
385 | command_class '|' command_class {
386 if ($1->type != $3->type) {
387 yyerror("type mismatch");
395 $$ = class_create($1->type,
396 set_union($1->t, $3->t));
402 sym_table *t = xmalloc(sizeof(*t));
404 sym_find(t, $1, -1, sizeof(sym_base), 0);
405 $$ = class_create(clType_command, t);
408 name *n = name_find($1, 0, 0);
410 moan("class `%s' not found at line %i",
413 } else if (~n->c->type & clType_command) {
414 yyerror("type mismatch");
421 | '(' command_class ')' { $$ = $2; }
424 /* --- Host class expressions --- */
426 host_class : host_class ',' host_class {
427 if ($1->type != $3->type) {
428 yyerror("type mismatch");
436 $$ = class_create($1->type,
437 set_union($1->t, $3->t));
442 | host_class '-' host_class {
443 if ($1->type != $3->type) {
444 yyerror("type mismatch");
449 $$ = class_create($1->type,
450 set_subtract($1->t, $3->t));
455 | host_class '&' host_class {
456 if ($1->type != $3->type) {
457 yyerror("type mismatch");
465 $$ = class_create($1->type,
466 set_intersect($1->t, $3->t));
471 | host_class '|' host_class {
472 if ($1->type != $3->type) {
473 yyerror("type mismatch");
481 $$ = class_create($1->type,
482 set_union($1->t, $3->t));
488 sym_table *t = xmalloc(sizeof(*t));
490 sym_find(t, $1, -1, sizeof(sym_base), 0);
491 $$ = class_create(clType_host, t);
494 name *n = name_find($1, 0, 0);
496 moan("class `%s' not found at line %i",
499 } else if (~n->c->type & clType_host) {
500 yyerror("type mismatch");
507 | '(' host_class ')' { $$ = $2; }
510 /*----- That's all, folks -------------------------------------------------*/