Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/veriexecctl Some refactoring and bugfixes:



details:   https://anonhg.NetBSD.org/src/rev/e92f10cf22ff
branches:  trunk
changeset: 582009:e92f10cf22ff
user:      elad <elad%NetBSD.org@localhost>
date:      Mon Jun 13 15:18:44 2005 +0000

description:
Some refactoring and bugfixes:

  - Report line numbers correctly.
  - Don't perform a 2nd pass when there are were errors during 1st.
  - Support multiple, comma-separated flags. This is mostly a reworking of
    some parser internals preparing for planned features.

diffstat:

 sbin/veriexecctl/veriexecctl.c       |  10 ++++-
 sbin/veriexecctl/veriexecctl_conf.l  |   6 +++-
 sbin/veriexecctl/veriexecctl_parse.y |  59 +++++++++++++++++++++++++++--------
 3 files changed, 57 insertions(+), 18 deletions(-)

diffs (195 lines):

diff -r 901b3a00b220 -r e92f10cf22ff sbin/veriexecctl/veriexecctl.c
--- a/sbin/veriexecctl/veriexecctl.c    Mon Jun 13 13:07:56 2005 +0000
+++ b/sbin/veriexecctl/veriexecctl.c    Mon Jun 13 15:18:44 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: veriexecctl.c,v 1.15 2005/06/03 16:12:07 elad Exp $    */
+/*     $NetBSD: veriexecctl.c,v 1.16 2005/06/13 15:18:44 elad Exp $    */
 
 /*-
  * Copyright 2005 Elad Efrat <elad%bsd.org.il@localhost>
@@ -49,6 +49,7 @@
 
 extern struct veriexec_params params; /* in veriexecctl_parse.y */
 extern char *filename; /* in veriexecctl_conf.l */
+extern int yynerrs;
 int gfd, verbose = 0, phase;
 size_t line;
 
@@ -60,7 +61,6 @@
 static int fingerprint_load(char*);
 static void usage(void) __attribute__((__noreturn__));
 
-
 static FILE *
 openlock(const char *path)
 {
@@ -149,6 +149,7 @@
 fingerprint_load(char *ifile)
 {
        CIRCLEQ_INIT(&params_list);
+       memset(&params, 0, sizeof(params));
 
        if ((yyin = openlock(ifile)) == NULL)
                err(1, "Cannot open `%s'", ifile);
@@ -165,7 +166,10 @@
                (void)printf("=> Parsing \"%s\"\n", ifile);
        }
 
+       line = 1;
        yyparse();
+       if (yynerrs)
+               return -1;
 
        phase1_preload();
 
@@ -182,6 +186,7 @@
                (void)printf("=> Parsing \"%s\"\n", ifile);
        }
 
+       line = 1;
        yyparse();
 
        (void)fclose(yyin);
@@ -224,7 +229,6 @@
         * Handle the different commands we can do.
         */
        if (argc == 2 && strcasecmp(argv[0], "load") == 0) {
-               line = 0;
                filename = argv[1];
                fingerprint_load(argv[1]);
        } else
diff -r 901b3a00b220 -r e92f10cf22ff sbin/veriexecctl/veriexecctl_conf.l
--- a/sbin/veriexecctl/veriexecctl_conf.l       Mon Jun 13 13:07:56 2005 +0000
+++ b/sbin/veriexecctl/veriexecctl_conf.l       Mon Jun 13 15:18:44 2005 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: veriexecctl_conf.l,v 1.5 2005/04/21 13:37:44 blymn Exp $       */
+/*     $NetBSD: veriexecctl_conf.l,v 1.6 2005/06/13 15:18:44 elad Exp $        */
 
 /*-
  * Copyright 2005 Elad Efrat <elad%bsd.org.il@localhost>
@@ -80,6 +80,10 @@
                        return EOL;
                }
 
+","            {
+                       return TOKEN_COMMA;
+               }
+
 .              { yyerror("Invalid character"); }
 
 %%
diff -r 901b3a00b220 -r e92f10cf22ff sbin/veriexecctl/veriexecctl_parse.y
--- a/sbin/veriexecctl/veriexecctl_parse.y      Mon Jun 13 13:07:56 2005 +0000
+++ b/sbin/veriexecctl/veriexecctl_parse.y      Mon Jun 13 15:18:44 2005 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: veriexecctl_parse.y,v 1.9 2005/05/27 15:46:23 elad Exp $       */
+/*     $NetBSD: veriexecctl_parse.y,v 1.10 2005/06/13 15:18:44 elad Exp $      */
 
 /*-
  * Copyright 2005 Elad Efrat <elad%bsd.org.il@localhost>
@@ -48,6 +48,9 @@
 struct veriexec_params params;
 static int convert(u_char *, u_char *);
 
+int have_type = 0;
+
+#define        FIELD_TYPE      1
 %}
 
 %union {
@@ -57,7 +60,7 @@
 
 %token <string> PATH
 %token <string> STRING
-%token EOL
+%token EOL TOKEN_COMMA
 
 %%
 
@@ -100,6 +103,7 @@
        dev_add(sb.st_dev);
 phase_2_end:
        (void)memset(&params, 0, sizeof(params));
+       have_type = 0;
 }
                |       statement eol
                |       statement error eol {
@@ -113,7 +117,7 @@
                ;
 
 type           :       STRING {
-       if (phase != 1) {
+       if (phase == 2) {
                if (strlen($1) >= sizeof(params.fp_type)) {
                        yyerror("Fingerprint type too long");
                        YYERROR;
@@ -126,7 +130,7 @@
 
 
 fingerprint    :       STRING {
-       if (phase != 1) {
+       if (phase == 2) {
                params.fingerprint = malloc(strlen($1) / 2);
                if (params.fingerprint == NULL)
                        err(1, "Fingerprint mem alloc failed");
@@ -145,21 +149,48 @@
        if (phase == 2)
                params.type = VERIEXEC_DIRECT;
 }
-               |       flags flag_spec
+               |       flags_spec
+               ;
+
+flags_spec     :       flag_spec
+               |       flags_spec TOKEN_COMMA flag_spec
                ;
 
 flag_spec      :       STRING {
-       if (phase != 1) {
-               if (strcasecmp($1, "direct") == 0)
-                       params.type = VERIEXEC_DIRECT;
-               else if (strcasecmp($1, "indirect") == 0)
-                       params.type = VERIEXEC_INDIRECT;
-               else if (strcasecmp($1, "file") == 0)
-                       params.type = VERIEXEC_FILE;
-               else {
-                       yyerror("Bad option");
+       if (phase == 2) {
+               int field;
+               int value;
+
+               /*
+                * XXXEE: It might be a good idea to change this into
+                * XXXEE: something less hard-coded. Perhaps loop on
+                * XXXEE: tuples of (name, field, value)?
+                */
+               if (strcasecmp($1, "direct") == 0) {
+                       field = FIELD_TYPE;
+                       value = VERIEXEC_DIRECT;
+               } else if (strcasecmp($1, "indirect") == 0) {
+                       field = FIELD_TYPE;
+                       value = VERIEXEC_INDIRECT;
+               } else if (strcasecmp($1, "file") == 0) {
+                       field = FIELD_TYPE;
+                       value = VERIEXEC_FILE;
+               } else {
+                       yyerror("Bad flag");
                        YYERROR;
                }
+
+               switch (field) {
+               case FIELD_TYPE:
+                       if (have_type) {
+                               yyerror("Mulitple type definitions");
+                               YYERROR;
+                       }
+
+                       params.type = value;
+                       have_type = 1;
+                       break;
+               }
        }
 
 }



Home | Main Index | Thread Index | Old Index