chiark / gitweb /
New `parse' interface to configuration file parser; informs caller
authormdw <mdw>
Thu, 23 Apr 1998 13:26:49 +0000 (13:26 +0000)
committermdw <mdw>
Thu, 23 Apr 1998 13:26:49 +0000 (13:26 +0000)
whether parsing encountered any errors.  Also support no-network
configuration.

src/parser.y

index 8b4527b9937f78c2aace7292ca86965abaaab2e8..d731389c12c43894b6caba0eee51a46e36ec50a2 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: parser.y,v 1.5 1998/01/12 16:46:22 mdw Exp $
+ * $Id: parser.y,v 1.6 1998/04/23 13:26:49 mdw Exp $
  *
  * Parser for `become.conf' files
  *
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: parser.y,v $
+ * Revision 1.6  1998/04/23 13:26:49  mdw
+ * New `parse' interface to configuration file parser; informs caller
+ * whether parsing encountered any errors.  Also support no-network
+ * configuration.
+ *
  * Revision 1.5  1998/01/12 16:46:22  mdw
  * Fix copyright date.
  *
@@ -206,18 +211,37 @@ 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 --- */
 
@@ -259,25 +283,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); }
@@ -286,7 +310,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);
                        }
@@ -295,10 +319,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);
@@ -312,25 +336,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); }
@@ -339,10 +363,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);
@@ -356,25 +380,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); }
@@ -383,10 +407,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);
@@ -395,4 +419,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 -------------------------------------------------*/