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