1 1.1 elric %{ 2 1.7 riastrad /* $NetBSD: cgdparse.y,v 1.7 2022/08/12 10:49:17 riastradh 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.7 riastrad __RCSID("$NetBSD: cgdparse.y,v 1.7 2022/08/12 10:49:17 riastradh Exp $"); 36 1.1 elric #endif 37 1.1 elric 38 1.1 elric #include <stdio.h> 39 1.5 drochner #include <stdlib.h> 40 1.1 elric 41 1.1 elric #include "params.h" 42 1.1 elric #include "utils.h" 43 1.2 christos #include "extern.h" 44 1.1 elric 45 1.2 christos static struct params *yy_global_params; 46 1.1 elric 47 1.1 elric %} 48 1.1 elric %union { 49 1.1 elric int integer; 50 1.1 elric struct { 51 1.1 elric char *text; 52 1.1 elric int length; 53 1.1 elric } token; 54 1.1 elric string_t *string; 55 1.1 elric bits_t *bits; 56 1.1 elric struct params *params; 57 1.1 elric struct keygen *keygen; 58 1.1 elric } 59 1.1 elric 60 1.1 elric %type <params> entry rules rule 61 1.1 elric %type <keygen> kgrule kgbody kgvars kgvar deprecated 62 1.1 elric %type <string> stringlit base64 intstr tokstr 63 1.1 elric %type <bits> bits 64 1.1 elric %type <token> token deptoken 65 1.1 elric 66 1.1 elric %token <integer> INTEGER 67 1.1 elric %token <string> STRINGLIT 68 1.1 elric 69 1.1 elric %token <token> ALGORITHM KEYLENGTH IVMETHOD VERIFY_METHOD 70 1.7 riastrad %token <token> KEYGEN SALT ITERATIONS MEMORY PARALLELISM VERSION KEY CMD SHARED 71 1.7 riastrad %token <token> SUBKEY 72 1.1 elric 73 1.1 elric %token EOL 74 1.1 elric 75 1.1 elric /* Deprecated tokens */ 76 1.1 elric %token <token> KEYGEN_METHOD KEYGEN_SALT KEYGEN_ITERATIONS XOR_KEY 77 1.1 elric 78 1.1 elric %% 79 1.1 elric 80 1.1 elric entry: rules { yy_global_params = $$; } 81 1.1 elric 82 1.1 elric rules: /* empty */ { $$ = NULL; } 83 1.1 elric | rules rule { $$ = params_combine($$, $2); } 84 1.1 elric 85 1.1 elric rule: ALGORITHM stringlit EOL { $$ = params_algorithm($2); } 86 1.1 elric | KEYLENGTH INTEGER EOL { $$ = params_keylen($2); } 87 1.1 elric | IVMETHOD stringlit EOL { $$ = params_ivmeth($2); } 88 1.1 elric | VERIFY_METHOD stringlit EOL { $$ = params_verify_method($2); } 89 1.1 elric | kgrule { $$ = params_keygen($1); } 90 1.1 elric | deprecated { $$ = params_dep_keygen($1); } 91 1.1 elric | EOL { $$ = NULL; } 92 1.1 elric 93 1.1 elric kgrule: KEYGEN stringlit kgbody EOL { $$ = keygen_set_method($3, $2); } 94 1.1 elric 95 1.1 elric kgbody: kgvar { $$ = $1; } 96 1.1 elric | '{' kgvars '}' { $$ = $2; } 97 1.1 elric 98 1.1 elric kgvars: /* empty */ { $$ = NULL; } 99 1.1 elric | kgvars kgvar { $$ = keygen_combine($$, $2); } 100 1.1 elric 101 1.1 elric kgvar: SALT bits EOL { $$ = keygen_salt($2); } 102 1.1 elric | ITERATIONS INTEGER EOL { $$ = keygen_iterations($2); } 103 1.6 nia | MEMORY INTEGER EOL { $$ = keygen_memory($2); } 104 1.6 nia | PARALLELISM INTEGER EOL { $$ = keygen_parallelism($2); } 105 1.6 nia | VERSION INTEGER EOL { $$ = keygen_version($2); } 106 1.1 elric | KEY bits EOL { $$ = keygen_key($2); } 107 1.4 elric | CMD stringlit EOL { $$ = keygen_cmd($2); } 108 1.7 riastrad | SHARED stringlit ALGORITHM stringlit SUBKEY bits EOL 109 1.7 riastrad { $$ = keygen_shared($2, $4, $6); } 110 1.1 elric | EOL { $$ = NULL; } 111 1.1 elric 112 1.1 elric stringlit: STRINGLIT | tokstr | intstr 113 1.1 elric 114 1.1 elric tokstr: token { $$ = string_new($1.text, $1.length); } 115 1.1 elric 116 1.1 elric token: ALGORITHM | KEYLENGTH 117 1.1 elric | IVMETHOD | VERIFY_METHOD 118 1.1 elric | KEYGEN | SALT | ITERATIONS 119 1.1 elric | KEY 120 1.1 elric | deptoken 121 1.1 elric 122 1.1 elric intstr: INTEGER { $$ = string_fromint($1); } 123 1.1 elric 124 1.1 elric bits: base64 { $$ = bits_decode_d($1); } 125 1.1 elric 126 1.1 elric base64: stringlit 127 1.1 elric | base64 stringlit { $$ = string_add_d($1, $2); } 128 1.1 elric 129 1.1 elric /* The following rules are deprecated */ 130 1.1 elric 131 1.1 elric deprecated: 132 1.1 elric KEYGEN_METHOD stringlit EOL { $$ = keygen_method($2); } 133 1.1 elric | KEYGEN_SALT bits EOL { $$ = keygen_salt($2); } 134 1.1 elric | KEYGEN_ITERATIONS INTEGER EOL { $$ = keygen_iterations($2); } 135 1.1 elric | XOR_KEY bits EOL { $$ = keygen_key($2); } 136 1.1 elric 137 1.1 elric deptoken: KEYGEN_METHOD | KEYGEN_SALT 138 1.1 elric | KEYGEN_ITERATIONS | XOR_KEY 139 1.1 elric 140 1.1 elric %% 141 1.1 elric 142 1.1 elric struct params * 143 1.1 elric cgdparsefile(FILE *f) 144 1.1 elric { 145 1.1 elric 146 1.1 elric yyin = f; 147 1.1 elric yy_global_params = NULL; 148 1.1 elric if (yyparse()) { 149 1.1 elric fprintf(stderr, "%s: failed to parse parameters file\n", 150 1.1 elric getprogname()); 151 1.1 elric params_free(yy_global_params); 152 1.1 elric return NULL; 153 1.1 elric } 154 1.1 elric return yy_global_params; 155 1.1 elric } 156