Home | History | Annotate | Line # | Download | only in veriexecctl
veriexecctl_conf.l revision 1.10
      1 %{
      2 /*	$NetBSD: veriexecctl_conf.l,v 1.10 2006/11/29 14:28:30 elad Exp $	*/
      3 
      4 /*-
      5  * Copyright 2005 Elad Efrat <elad (at) NetBSD.org>
      6  * Copyright 2005 Brett Lymn <blymn (at) netbsd.org>
      7  *
      8  * All rights reserved.
      9  *
     10  * This code has been donated to The NetBSD Foundation by the Author.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. The name of the author may not be used to endorse or promote products
     18  *    derived from this software withough specific prior written permission
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  *
     31  *
     32  */
     33 
     34 #include <sys/param.h>
     35 #include <sys/types.h>
     36 #include <sys/queue.h>
     37 #include <sys/verified_exec.h>
     38 
     39 #include <stdio.h>
     40 #include <stdlib.h>
     41 #include <string.h>
     42 #include <unistd.h>
     43 #include <err.h>
     44 
     45 #include <prop/proplib.h>
     46 
     47 #include "veriexecctl_parse.h"
     48 #include "veriexecctl.h"
     49 
     50 u_int64_t entries;
     51 char *filename;
     52 
     53 static char *dequote(const char *s)
     54 {
     55 	size_t len;
     56 	const char *p;
     57 	char *buf, *q;
     58 
     59 	len = 0;
     60 	p = s;
     61 	while (*p) {
     62 		if (*p == '\\' && *(p+1))
     63 			++p;
     64 		++len;
     65 		++p;
     66 	}
     67 
     68 	buf = malloc(len + 1);
     69 	if (buf == NULL)
     70 		return NULL;
     71 
     72 	p = s;
     73 	q = buf;
     74 	while (*p) {
     75 		if (*p == '\\' && *(p+1))
     76 			++p;
     77 		*q++ = *p++;
     78 	}
     79 	*q++ = '\0';
     80 
     81 	return buf;
     82 }
     83 %}
     84 
     85 STRING		[0-9a-zA-Z]+
     86 PCHAR           (\\.|[^ \t])
     87 
     88 %%
     89 
     90 	/* path */
     91 \/{PCHAR}+	{
     92 			if ((yylval.string = dequote(yytext)) == NULL)
     93 				err(1, "Cannot allocate string");
     94 			return PATH;
     95 		}
     96 
     97 	/* string (fingerprint, type, options) */
     98 {STRING} 	{
     99 			if ((yylval.string = strdup(yytext)) == NULL)
    100 				err(1, "Cannot allocate string");
    101 			return STRING;
    102 		}
    103 
    104 	/* comments, white-outs */
    105 [ \t\r]		|
    106 #.*		;
    107 #.*\n		|
    108 \\\n		|
    109 ^\n		{ line++; }
    110 
    111 	/* eol on a line with data. need a call to ioctl, return eol */
    112 \n		{
    113 			line++;
    114 			return EOL;
    115 		}
    116 
    117 ","		{
    118 			return TOKEN_COMMA;
    119 		}
    120 
    121 .		{ yyerror("Invalid character"); }
    122 
    123 %%
    124 
    125 int
    126 yywrap(void)
    127 {
    128 	return 1;
    129 }
    130 
    131 void
    132 yyerror(const char *string)
    133 {
    134 	(void)fprintf(stderr, "%s: %s at \"%s\", line %zu\n", getprogname(),
    135 	    string, yytext, line);
    136 }
    137