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