cgdparse.y revision 1.1 1 1.1 elric %{
2 1.1 elric /* $NetBSD: cgdparse.y,v 1.1 2003/03/24 02:02:50 elric 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.1 elric __RCSID("$NetBSD: cgdparse.y,v 1.1 2003/03/24 02:02:50 elric 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.1 elric
50 1.1 elric extern char *yytext;
51 1.1 elric extern int yylineno;
52 1.1 elric
53 1.1 elric int yylex(void);
54 1.1 elric int yyerror(char *);
55 1.1 elric
56 1.1 elric struct params *cgdparsefile(FILE *);
57 1.1 elric
58 1.1 elric struct params *yy_global_params;
59 1.1 elric
60 1.1 elric %}
61 1.1 elric %union {
62 1.1 elric int integer;
63 1.1 elric struct {
64 1.1 elric char *text;
65 1.1 elric int length;
66 1.1 elric } token;
67 1.1 elric string_t *string;
68 1.1 elric bits_t *bits;
69 1.1 elric struct params *params;
70 1.1 elric struct keygen *keygen;
71 1.1 elric }
72 1.1 elric
73 1.1 elric %type <params> entry rules rule
74 1.1 elric %type <keygen> kgrule kgbody kgvars kgvar deprecated
75 1.1 elric %type <string> stringlit base64 intstr tokstr
76 1.1 elric %type <bits> bits
77 1.1 elric %type <token> token deptoken
78 1.1 elric
79 1.1 elric %token <integer> INTEGER
80 1.1 elric %token <string> STRINGLIT
81 1.1 elric
82 1.1 elric %token <token> ALGORITHM KEYLENGTH IVMETHOD VERIFY_METHOD
83 1.1 elric %token <token> KEYGEN SALT ITERATIONS KEY
84 1.1 elric
85 1.1 elric %token EOL
86 1.1 elric
87 1.1 elric /* Deprecated tokens */
88 1.1 elric %token <token> KEYGEN_METHOD KEYGEN_SALT KEYGEN_ITERATIONS XOR_KEY
89 1.1 elric
90 1.1 elric %%
91 1.1 elric
92 1.1 elric entry: rules { yy_global_params = $$; }
93 1.1 elric
94 1.1 elric rules: /* empty */ { $$ = NULL; }
95 1.1 elric | rules rule { $$ = params_combine($$, $2); }
96 1.1 elric
97 1.1 elric rule: ALGORITHM stringlit EOL { $$ = params_algorithm($2); }
98 1.1 elric | KEYLENGTH INTEGER EOL { $$ = params_keylen($2); }
99 1.1 elric | IVMETHOD stringlit EOL { $$ = params_ivmeth($2); }
100 1.1 elric | VERIFY_METHOD stringlit EOL { $$ = params_verify_method($2); }
101 1.1 elric | kgrule { $$ = params_keygen($1); }
102 1.1 elric | deprecated { $$ = params_dep_keygen($1); }
103 1.1 elric | EOL { $$ = NULL; }
104 1.1 elric
105 1.1 elric kgrule: KEYGEN stringlit kgbody EOL { $$ = keygen_set_method($3, $2); }
106 1.1 elric
107 1.1 elric kgbody: kgvar { $$ = $1; }
108 1.1 elric | '{' kgvars '}' { $$ = $2; }
109 1.1 elric
110 1.1 elric kgvars: /* empty */ { $$ = NULL; }
111 1.1 elric | kgvars kgvar { $$ = keygen_combine($$, $2); }
112 1.1 elric
113 1.1 elric kgvar: SALT bits EOL { $$ = keygen_salt($2); }
114 1.1 elric | ITERATIONS INTEGER EOL { $$ = keygen_iterations($2); }
115 1.1 elric | KEY bits EOL { $$ = keygen_key($2); }
116 1.1 elric | EOL { $$ = NULL; }
117 1.1 elric
118 1.1 elric stringlit: STRINGLIT | tokstr | intstr
119 1.1 elric
120 1.1 elric tokstr: token { $$ = string_new($1.text, $1.length); }
121 1.1 elric
122 1.1 elric token: ALGORITHM | KEYLENGTH
123 1.1 elric | IVMETHOD | VERIFY_METHOD
124 1.1 elric | KEYGEN | SALT | ITERATIONS
125 1.1 elric | KEY
126 1.1 elric | deptoken
127 1.1 elric
128 1.1 elric intstr: INTEGER { $$ = string_fromint($1); }
129 1.1 elric
130 1.1 elric bits: base64 { $$ = bits_decode_d($1); }
131 1.1 elric
132 1.1 elric base64: stringlit
133 1.1 elric | base64 stringlit { $$ = string_add_d($1, $2); }
134 1.1 elric
135 1.1 elric /* The following rules are deprecated */
136 1.1 elric
137 1.1 elric deprecated:
138 1.1 elric KEYGEN_METHOD stringlit EOL { $$ = keygen_method($2); }
139 1.1 elric | KEYGEN_SALT bits EOL { $$ = keygen_salt($2); }
140 1.1 elric | KEYGEN_ITERATIONS INTEGER EOL { $$ = keygen_iterations($2); }
141 1.1 elric | XOR_KEY bits EOL { $$ = keygen_key($2); }
142 1.1 elric
143 1.1 elric deptoken: KEYGEN_METHOD | KEYGEN_SALT
144 1.1 elric | KEYGEN_ITERATIONS | XOR_KEY
145 1.1 elric
146 1.1 elric %%
147 1.1 elric
148 1.1 elric extern FILE *yyin;
149 1.1 elric
150 1.1 elric struct params *
151 1.1 elric cgdparsefile(FILE *f)
152 1.1 elric {
153 1.1 elric
154 1.1 elric yyin = f;
155 1.1 elric yy_global_params = NULL;
156 1.1 elric if (yyparse()) {
157 1.1 elric fprintf(stderr, "%s: failed to parse parameters file\n",
158 1.1 elric getprogname());
159 1.1 elric params_free(yy_global_params);
160 1.1 elric return NULL;
161 1.1 elric }
162 1.1 elric return yy_global_params;
163 1.1 elric }
164