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