Home | History | Annotate | Line # | Download | only in cgdconfig
cgdparse.y revision 1.3
      1 %{
      2 /* $NetBSD: cgdparse.y,v 1.3 2008/04/28 20:23:08 martin Exp $ */
      3 
      4 /*-
      5  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      6  * All rights reserved.
      7  *
      8  * This code is derived from software contributed to The NetBSD Foundation
      9  * by Roland C. Dowdeswell.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  * POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 #include <sys/cdefs.h>
     34 #ifndef lint
     35 __RCSID("$NetBSD: cgdparse.y,v 1.3 2008/04/28 20:23:08 martin Exp $");
     36 #endif
     37 
     38 #include <stdio.h>
     39 
     40 #include "params.h"
     41 #include "utils.h"
     42 #include "extern.h"
     43 
     44 static struct params *yy_global_params;
     45 
     46 %}
     47 %union {
     48 	int	 	 integer;
     49 	struct {
     50 		char	*text;
     51 		int	 length;
     52 	} token;
     53 	string_t	*string;
     54 	bits_t		*bits;
     55 	struct params	*params;
     56 	struct keygen	*keygen;
     57 }
     58 
     59 %type <params>	entry rules rule
     60 %type <keygen>	kgrule kgbody kgvars kgvar deprecated
     61 %type <string>	stringlit base64 intstr tokstr
     62 %type <bits>	bits
     63 %type <token>	token deptoken
     64 
     65 %token <integer> INTEGER
     66 %token <string> STRINGLIT
     67 
     68 %token <token> ALGORITHM KEYLENGTH IVMETHOD VERIFY_METHOD
     69 %token <token> KEYGEN SALT ITERATIONS KEY
     70 
     71 %token EOL
     72 
     73 /* Deprecated tokens */
     74 %token <token> KEYGEN_METHOD KEYGEN_SALT KEYGEN_ITERATIONS XOR_KEY
     75 
     76 %%
     77 
     78 entry:	  rules				{ yy_global_params = $$; }
     79 
     80 rules:	/* empty */			{ $$ = NULL; }
     81 	| rules rule			{ $$ = params_combine($$, $2); }
     82 
     83 rule:	  ALGORITHM stringlit EOL	{ $$ = params_algorithm($2); }
     84 	| KEYLENGTH INTEGER EOL		{ $$ = params_keylen($2); }
     85 	| IVMETHOD stringlit EOL	{ $$ = params_ivmeth($2); }
     86 	| VERIFY_METHOD stringlit EOL	{ $$ = params_verify_method($2); }
     87 	| kgrule			{ $$ = params_keygen($1); }
     88 	| deprecated			{ $$ = params_dep_keygen($1); }
     89 	| EOL				{ $$ = NULL; }
     90 
     91 kgrule:	  KEYGEN stringlit kgbody EOL	{ $$ = keygen_set_method($3, $2); }
     92 
     93 kgbody:	  kgvar				{ $$ = $1; }
     94 	| '{' kgvars '}'		{ $$ = $2; }
     95 
     96 kgvars: /* empty */			{ $$ = NULL; }
     97 	| kgvars kgvar			{ $$ = keygen_combine($$, $2); }
     98 
     99 kgvar:	  SALT bits EOL			{ $$ = keygen_salt($2); }
    100 	| ITERATIONS INTEGER EOL	{ $$ = keygen_iterations($2); }
    101 	| KEY bits EOL			{ $$ = keygen_key($2); }
    102 	| EOL				{ $$ = NULL; }
    103 
    104 stringlit:  STRINGLIT | tokstr | intstr
    105 
    106 tokstr:	  token				{ $$ = string_new($1.text, $1.length); }
    107 
    108 token:	  ALGORITHM | KEYLENGTH
    109 	| IVMETHOD | VERIFY_METHOD
    110 	| KEYGEN | SALT | ITERATIONS
    111 	| KEY
    112 	| deptoken
    113 
    114 intstr:   INTEGER			{ $$ = string_fromint($1); }
    115 
    116 bits:	  base64			{ $$ = bits_decode_d($1); }
    117 
    118 base64:   stringlit
    119 	| base64 stringlit		{ $$ = string_add_d($1, $2); }
    120 
    121 /* The following rules are deprecated */
    122 
    123 deprecated:
    124 	  KEYGEN_METHOD stringlit EOL	{ $$ = keygen_method($2); }
    125 	| KEYGEN_SALT bits EOL		{ $$ = keygen_salt($2); }
    126 	| KEYGEN_ITERATIONS INTEGER EOL	{ $$ = keygen_iterations($2); }
    127 	| XOR_KEY bits EOL		{ $$ = keygen_key($2); }
    128 
    129 deptoken: KEYGEN_METHOD | KEYGEN_SALT
    130 	| KEYGEN_ITERATIONS | XOR_KEY
    131 
    132 %%
    133 
    134 struct params *
    135 cgdparsefile(FILE *f)
    136 {
    137 
    138 	yyin = f;
    139 	yy_global_params = NULL;
    140 	if (yyparse()) {
    141 		fprintf(stderr, "%s: failed to parse parameters file\n",
    142 		    getprogname());
    143 		params_free(yy_global_params);
    144 		return NULL;
    145 	}
    146 	return yy_global_params;
    147 }
    148