1 /* A Bison parser, made from ./prsa_par.y
4 #define YYBISON 1 /* Identify Bison output. */
6 #define yyparse prsaparse
8 #define yyerror prsaerror
9 #define yylval prsalval
10 #define yychar prsachar
11 #define yydebug prsadebug
12 #define yynerrs prsanerrs
21 # define PUBLIC_EXPONENT 265
22 # define PRIVATE_EXPONENT 266
25 # define EXPONENT1 269
26 # define EXPONENT2 270
27 # define COEFFICIENT 271
35 #line 3 "./prsa_par.y"
38 * Copyright (C) 2004 SuSE Linux AG, Nuernberg, Germany.
39 * Contributed by: Michal Ludvig <mludvig@suse.cz>, SUSE Labs
40 * All rights reserved.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. Neither the name of the project nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67 /* This file contains a parser for FreeS/WAN-style ipsec.secrets RSA keys. */
84 #include <netinet/in.h>
85 #include <sys/socket.h>
86 #include <arpa/inet.h>
87 #include <sys/types.h>
92 #include <openssl/bn.h>
93 #include <openssl/rsa.h>
99 #include "isakmp_var.h"
101 #include "crypto_openssl.h"
102 #include "sockmisc.h"
105 extern void prsaerror(const char *str, ...);
106 extern int prsawrap (void);
107 extern int prsalex (void);
109 extern char *prsatext;
110 extern int prsa_cur_lineno;
111 extern char *prsa_cur_fname;
114 int prsa_cur_lineno = 0;
115 char *prsa_cur_fname = NULL;
116 struct genlist *prsa_cur_list = NULL;
117 enum rsa_key_type prsa_cur_type = RSA_TYPE_ANY;
122 prsaerror(const char *s, ...)
132 snprintf(fmt, sizeof(fmt), "%s:%d: %s",
133 prsa_cur_fname, prsa_cur_lineno, s);
134 plogv(LLV_ERROR, LOCATION, NULL, fmt, ap);
139 prsawarning(const char *s, ...)
149 snprintf(fmt, sizeof(fmt), "%s:%d: %s",
150 prsa_cur_fname, prsa_cur_lineno, s);
151 plogv(LLV_WARNING, LOCATION, NULL, fmt, ap);
161 #line 128 "./prsa_par.y"
168 struct netaddr *naddr;
170 # define YYSTYPE yystype
171 # define YYSTYPE_IS_TRIVIAL 1
180 #define YYFLAG -32768
183 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
184 #define YYTRANSLATE(x) ((unsigned)(x) <= 277 ? yytranslate[x] : 33)
186 /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
187 static const char yytranslate[] =
189 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
190 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
191 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
192 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
193 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
194 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
195 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
196 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
197 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
198 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
199 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
200 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
201 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
202 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
203 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
204 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
205 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
206 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
207 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
208 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
209 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
210 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
211 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
212 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
213 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
214 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
215 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
216 16, 17, 18, 19, 20, 21, 22, 23
220 static const short yyprhs[] =
222 0, 0, 3, 5, 10, 14, 17, 22, 25, 28,
223 30, 32, 34, 37, 40, 41, 44, 47, 49, 53,
224 57, 61, 65, 69, 73, 77
226 static const short yyrhs[] =
228 24, 25, 0, 25, 0, 27, 27, 3, 26, 0,
229 27, 3, 26, 0, 3, 26, 0, 7, 5, 31,
230 6, 0, 8, 23, 0, 8, 4, 0, 28, 0,
231 29, 0, 20, 0, 18, 30, 0, 19, 30, 0,
232 0, 21, 22, 0, 31, 32, 0, 32, 0, 10,
233 3, 4, 0, 11, 3, 4, 0, 12, 3, 4,
234 0, 13, 3, 4, 0, 14, 3, 4, 0, 15,
235 3, 4, 0, 16, 3, 4, 0, 17, 3, 4,
242 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
243 static const short yyrline[] =
245 0, 152, 154, 157, 162, 166, 172, 205, 213, 223,
246 225, 226, 232, 255, 278, 280, 282, 284, 287, 290,
247 292, 294, 296, 298, 300, 302
252 #if (YYDEBUG) || defined YYERROR_VERBOSE
254 /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
255 static const char *const yytname[] =
257 "$", "error", "$undefined.", "COLON", "HEX", "OBRACE", "EBRACE",
258 "TAG_RSA", "TAG_PUB", "TAG_PSK", "MODULUS", "PUBLIC_EXPONENT",
259 "PRIVATE_EXPONENT", "PRIME1", "PRIME2", "EXPONENT1", "EXPONENT2",
260 "COEFFICIENT", "ADDR4", "ADDR6", "ADDRANY", "SLASH", "NUMBER", "BASE64",
261 "statements", "statement", "rsa_statement", "addr", "addr4", "addr6",
262 "prefix", "params", "param", 0
266 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
267 static const short yyr1[] =
269 0, 24, 24, 25, 25, 25, 26, 26, 26, 27,
270 27, 27, 28, 29, 30, 30, 31, 31, 32, 32,
271 32, 32, 32, 32, 32, 32
274 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
275 static const short yyr2[] =
277 0, 2, 1, 4, 3, 2, 4, 2, 2, 1,
278 1, 1, 2, 2, 0, 2, 2, 1, 3, 3,
282 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
283 doesn't specify something else to do. Zero means the default is an
285 static const short yydefact[] =
287 0, 0, 14, 14, 11, 0, 2, 0, 9, 10,
288 0, 0, 5, 0, 12, 13, 1, 0, 0, 0,
289 8, 7, 15, 4, 0, 0, 0, 0, 0, 0,
290 0, 0, 0, 0, 17, 3, 0, 0, 0, 0,
291 0, 0, 0, 0, 6, 16, 18, 19, 20, 21,
295 static const short yydefgoto[] =
297 5, 6, 12, 7, 8, 9, 14, 33, 34
300 static const short yypact[] =
302 4, -3, -15, -15,-32768, 0,-32768, 7,-32768,-32768,
303 6, -2,-32768, -13,-32768,-32768,-32768, -3, 9, 30,
304 -32768,-32768,-32768,-32768, -3, 10, 11, 12, 13, 14,
305 26, 27, 28, 22,-32768,-32768, 44, 45, 46, 47,
306 48, 49, 50, 51,-32768,-32768,-32768,-32768,-32768,-32768,
307 -32768,-32768,-32768,-32768, 56,-32768
310 static const short yypgoto[] =
312 -32768, 52, -16, 53,-32768,-32768, 55,-32768, 29
319 static const short yytable[] =
321 54, 23, 20, 1, 10, 11, 13, 1, 35, 22,
322 17, 19, 24, 36, 37, 38, 39, 40, 2, 3,
323 4, 21, 2, 3, 4, 2, 3, 4, 44, 41,
324 42, 43, 25, 26, 27, 28, 29, 30, 31, 32,
325 25, 26, 27, 28, 29, 30, 31, 32, 46, 47,
326 48, 49, 50, 51, 52, 53, 55, 16, 15, 0,
330 static const short yycheck[] =
332 0, 17, 4, 3, 7, 8, 21, 3, 24, 22,
333 3, 5, 3, 3, 3, 3, 3, 3, 18, 19,
334 20, 23, 18, 19, 20, 18, 19, 20, 6, 3,
335 3, 3, 10, 11, 12, 13, 14, 15, 16, 17,
336 10, 11, 12, 13, 14, 15, 16, 17, 4, 4,
337 4, 4, 4, 4, 4, 4, 0, 5, 3, -1,
340 /* -*-C-*- Note some compilers choke on comments on `#line' lines. */
341 #line 3 "/usr/share/bison/bison.simple"
343 /* Skeleton output parser for bison,
345 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software
348 This program is free software; you can redistribute it and/or modify
349 it under the terms of the GNU General Public License as published by
350 the Free Software Foundation; either version 2, or (at your option)
353 This program is distributed in the hope that it will be useful,
354 but WITHOUT ANY WARRANTY; without even the implied warranty of
355 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
356 GNU General Public License for more details.
358 You should have received a copy of the GNU General Public License
359 along with this program; if not, write to the Free Software
360 Foundation, Inc., 59 Temple Place - Suite 330,
361 Boston, MA 02111-1307, USA. */
363 /* As a special exception, when this file is copied by Bison into a
364 Bison output file, you may use that output file without restriction.
365 This special exception was added by the Free Software Foundation
366 in version 1.24 of Bison. */
368 /* This is the parser code that is written into each bison parser when
369 the %semantic_parser declaration is not specified in the grammar.
370 It was written by Richard Stallman by simplifying the hairy parser
371 used when %semantic_parser is specified. */
373 /* All symbols defined below should begin with yy or YY, to avoid
374 infringing on user name space. This should be done even for local
375 variables, as they might otherwise be expanded by user macros.
376 There are some unavoidable exceptions within include files to
377 define necessary library symbols; they are noted "INFRINGES ON
378 USER NAME SPACE" below. */
380 #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
382 /* The parser invokes alloca or malloc; define the necessary symbols. */
384 # if YYSTACK_USE_ALLOCA
385 # define YYSTACK_ALLOC alloca
387 # ifndef YYSTACK_USE_ALLOCA
388 # if defined (alloca) || defined (_ALLOCA_H)
389 # define YYSTACK_ALLOC alloca
392 # define YYSTACK_ALLOC __builtin_alloca
398 # ifdef YYSTACK_ALLOC
399 /* Pacify GCC's `empty if-body' warning. */
400 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
402 # if defined (__STDC__) || defined (__cplusplus)
403 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
404 # define YYSIZE_T size_t
406 # define YYSTACK_ALLOC malloc
407 # define YYSTACK_FREE free
409 #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
412 #if (! defined (yyoverflow) \
413 && (! defined (__cplusplus) \
414 || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
416 /* A type that is properly aligned for any stack member. */
426 /* The size of the maximum gap between one aligned stack and the next. */
427 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
429 /* The size of an array large to enough to hold all stacks, each with
432 # define YYSTACK_BYTES(N) \
433 ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
434 + 2 * YYSTACK_GAP_MAX)
436 # define YYSTACK_BYTES(N) \
437 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
441 /* Copy COUNT objects from FROM to TO. The source and destination do
445 # define YYCOPY(To, From, Count) \
446 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
448 # define YYCOPY(To, From, Count) \
451 register YYSIZE_T yyi; \
452 for (yyi = 0; yyi < (Count); yyi++) \
453 (To)[yyi] = (From)[yyi]; \
459 /* Relocate STACK from its old location to the new one. The
460 local variables YYSIZE and YYSTACKSIZE give the old and new number of
461 elements in the stack, and YYPTR gives the new location of the
462 stack. Advance YYPTR to a properly aligned location for the next
464 # define YYSTACK_RELOCATE(Stack) \
467 YYSIZE_T yynewbytes; \
468 YYCOPY (&yyptr->Stack, Stack, yysize); \
469 Stack = &yyptr->Stack; \
470 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX; \
471 yyptr += yynewbytes / sizeof (*yyptr); \
478 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
479 # define YYSIZE_T __SIZE_TYPE__
481 #if ! defined (YYSIZE_T) && defined (size_t)
482 # define YYSIZE_T size_t
484 #if ! defined (YYSIZE_T)
485 # if defined (__STDC__) || defined (__cplusplus)
486 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
487 # define YYSIZE_T size_t
490 #if ! defined (YYSIZE_T)
491 # define YYSIZE_T unsigned int
494 #define yyerrok (yyerrstatus = 0)
495 #define yyclearin (yychar = YYEMPTY)
498 #define YYACCEPT goto yyacceptlab
499 #define YYABORT goto yyabortlab
500 #define YYERROR goto yyerrlab1
501 /* Like YYERROR except do call yyerror. This remains here temporarily
502 to ease the transition to the new meaning of YYERROR, for GCC.
503 Once GCC version 2 has supplanted version 1, this can go. */
504 #define YYFAIL goto yyerrlab
505 #define YYRECOVERING() (!!yyerrstatus)
506 #define YYBACKUP(Token, Value) \
508 if (yychar == YYEMPTY && yylen == 1) \
512 yychar1 = YYTRANSLATE (yychar); \
518 yyerror ("syntax error: cannot back up"); \
524 #define YYERRCODE 256
527 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
530 When YYLLOC_DEFAULT is run, CURRENT is set the location of the
531 first token. By default, to implement support for ranges, extend
532 its range to the last symbol. */
534 #ifndef YYLLOC_DEFAULT
535 # define YYLLOC_DEFAULT(Current, Rhs, N) \
536 Current.last_line = Rhs[N].last_line; \
537 Current.last_column = Rhs[N].last_column;
541 /* YYLEX -- calling `yylex' with the right arguments. */
546 # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
548 # define YYLEX yylex (&yylval, &yylloc)
550 # else /* !YYLSP_NEEDED */
552 # define YYLEX yylex (&yylval, YYLEX_PARAM)
554 # define YYLEX yylex (&yylval)
556 # endif /* !YYLSP_NEEDED */
558 # define YYLEX yylex ()
562 /* Enable debugging if requested. */
566 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
567 # define YYFPRINTF fprintf
570 # define YYDPRINTF(Args) \
575 /* Nonzero means print parse trace. It is left uninitialized so that
576 multiple parsers can coexist. */
579 # define YYDPRINTF(Args)
580 #endif /* !YYDEBUG */
582 /* YYINITDEPTH -- initial size of the parser's stacks. */
584 # define YYINITDEPTH 200
587 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
588 if the built-in stack extension method is used).
590 Do not make this value too large; the results are undefined if
591 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
592 evaluated with infinite-precision integer arithmetic. */
599 # define YYMAXDEPTH 10000
602 #ifdef YYERROR_VERBOSE
605 # if defined (__GLIBC__) && defined (_STRING_H)
606 # define yystrlen strlen
608 /* Return the length of YYSTR. */
610 # if defined (__STDC__) || defined (__cplusplus)
611 yystrlen (const char *yystr)
617 register const char *yys = yystr;
619 while (*yys++ != '\0')
622 return yys - yystr - 1;
628 # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
629 # define yystpcpy stpcpy
631 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
634 # if defined (__STDC__) || defined (__cplusplus)
635 yystpcpy (char *yydest, const char *yysrc)
637 yystpcpy (yydest, yysrc)
642 register char *yyd = yydest;
643 register const char *yys = yysrc;
645 while ((*yyd++ = *yys++) != '\0')
654 #line 315 "/usr/share/bison/bison.simple"
657 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
658 into yyparse. The argument should have type void *.
659 It should actually point to an object.
660 Grammar actions can access the variable by casting it
661 to the proper pointer type. */
664 # if defined (__STDC__) || defined (__cplusplus)
665 # define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
666 # define YYPARSE_PARAM_DECL
668 # define YYPARSE_PARAM_ARG YYPARSE_PARAM
669 # define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
671 #else /* !YYPARSE_PARAM */
672 # define YYPARSE_PARAM_ARG
673 # define YYPARSE_PARAM_DECL
674 #endif /* !YYPARSE_PARAM */
676 /* Prevent warning if -Wstrict-prototypes. */
678 # ifdef YYPARSE_PARAM
679 int yyparse (void *);
685 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
686 variables are global, or local to YYPARSE. */
688 #define YY_DECL_NON_LSP_VARIABLES \
689 /* The lookahead symbol. */ \
692 /* The semantic value of the lookahead symbol. */ \
695 /* Number of parse errors so far. */ \
699 # define YY_DECL_VARIABLES \
700 YY_DECL_NON_LSP_VARIABLES \
702 /* Location data for the lookahead symbol. */ \
705 # define YY_DECL_VARIABLES \
706 YY_DECL_NON_LSP_VARIABLES
710 /* If nonreentrant, generate the variables here. */
717 yyparse (YYPARSE_PARAM_ARG)
720 /* If reentrant, generate the variables here. */
725 register int yystate;
728 /* Number of tokens to shift before error messages enabled. */
730 /* Lookahead token as an internal (translated) token number. */
733 /* Three stacks and their tools:
734 `yyss': related to states,
735 `yyvs': related to semantic values,
736 `yyls': related to locations.
738 Refer to the stacks thru separate pointers, to allow yyoverflow
739 to reallocate them elsewhere. */
741 /* The state stack. */
742 short yyssa[YYINITDEPTH];
744 register short *yyssp;
746 /* The semantic value stack. */
747 YYSTYPE yyvsa[YYINITDEPTH];
748 YYSTYPE *yyvs = yyvsa;
749 register YYSTYPE *yyvsp;
752 /* The location stack. */
753 YYLTYPE yylsa[YYINITDEPTH];
754 YYLTYPE *yyls = yylsa;
759 # define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
761 # define YYPOPSTACK (yyvsp--, yyssp--)
764 YYSIZE_T yystacksize = YYINITDEPTH;
767 /* The variables used to return semantic value and location from the
774 /* When reducing, the number of symbols on the RHS of the reduced
778 YYDPRINTF ((stderr, "Starting parse\n"));
783 yychar = YYEMPTY; /* Cause a token to be read. */
785 /* Initialize stack pointers.
786 Waste one element of value and location stack
787 so that they stay on the same level as the state stack.
788 The wasted elements are never initialized. */
797 /*------------------------------------------------------------.
798 | yynewstate -- Push a new state, which is found in yystate. |
799 `------------------------------------------------------------*/
801 /* In all cases, when you get here, the value and location stacks
802 have just been pushed. so pushing a state here evens the stacks.
809 if (yyssp >= yyss + yystacksize - 1)
811 /* Get the current used size of the three stacks, in elements. */
812 YYSIZE_T yysize = yyssp - yyss + 1;
816 /* Give user a chance to reallocate the stack. Use copies of
817 these so that the &'s don't force the real ones into
819 YYSTYPE *yyvs1 = yyvs;
822 /* Each stack pointer address is followed by the size of the
823 data in use in that stack, in bytes. */
825 YYLTYPE *yyls1 = yyls;
826 /* This used to be a conditional around just the two extra args,
827 but that might be undefined if yyoverflow is a macro. */
828 yyoverflow ("parser stack overflow",
829 &yyss1, yysize * sizeof (*yyssp),
830 &yyvs1, yysize * sizeof (*yyvsp),
831 &yyls1, yysize * sizeof (*yylsp),
835 yyoverflow ("parser stack overflow",
836 &yyss1, yysize * sizeof (*yyssp),
837 &yyvs1, yysize * sizeof (*yyvsp),
843 #else /* no yyoverflow */
844 # ifndef YYSTACK_RELOCATE
847 /* Extend the stack our own way. */
848 if (yystacksize >= YYMAXDEPTH)
851 if (yystacksize > YYMAXDEPTH)
852 yystacksize = YYMAXDEPTH;
856 union yyalloc *yyptr =
857 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
860 YYSTACK_RELOCATE (yyss);
861 YYSTACK_RELOCATE (yyvs);
863 YYSTACK_RELOCATE (yyls);
865 # undef YYSTACK_RELOCATE
867 YYSTACK_FREE (yyss1);
870 #endif /* no yyoverflow */
872 yyssp = yyss + yysize - 1;
873 yyvsp = yyvs + yysize - 1;
875 yylsp = yyls + yysize - 1;
878 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
879 (unsigned long int) yystacksize));
881 if (yyssp >= yyss + yystacksize - 1)
885 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
895 /* Do appropriate processing given the current state. */
896 /* Read a lookahead token if we need one and don't already have one. */
899 /* First try to decide what to do without reference to lookahead token. */
901 yyn = yypact[yystate];
905 /* Not known => get a lookahead token if don't already have one. */
907 /* yychar is either YYEMPTY or YYEOF
908 or a valid token in external form. */
910 if (yychar == YYEMPTY)
912 YYDPRINTF ((stderr, "Reading a token: "));
916 /* Convert token to internal form (in yychar1) for indexing tables with */
918 if (yychar <= 0) /* This means end of input. */
921 yychar = YYEOF; /* Don't call YYLEX any more */
923 YYDPRINTF ((stderr, "Now at end of input.\n"));
927 yychar1 = YYTRANSLATE (yychar);
930 /* We have to keep this `#if YYDEBUG', since we use variables
931 which are defined only if `YYDEBUG' is set. */
934 YYFPRINTF (stderr, "Next token is %d (%s",
935 yychar, yytname[yychar1]);
936 /* Give the individual parser a way to print the precise
937 meaning of a token, for further debugging info. */
939 YYPRINT (stderr, yychar, yylval);
941 YYFPRINTF (stderr, ")\n");
947 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
952 /* yyn is what to do for this token type in this state.
953 Negative => reduce, -yyn is rule number.
954 Positive => shift, yyn is new state.
955 New state is final state => don't bother to shift,
957 0, or most negative number => error. */
972 /* Shift the lookahead token. */
973 YYDPRINTF ((stderr, "Shifting token %d (%s), ",
974 yychar, yytname[yychar1]));
976 /* Discard the token being shifted unless it is eof. */
985 /* Count tokens shifted since error; after three, turn off error
994 /*-----------------------------------------------------------.
995 | yydefault -- do the default action for the current state. |
996 `-----------------------------------------------------------*/
998 yyn = yydefact[yystate];
1004 /*-----------------------------.
1005 | yyreduce -- Do a reduction. |
1006 `-----------------------------*/
1008 /* yyn is the number of a rule to reduce with. */
1011 /* If YYLEN is nonzero, implement the default value of the action:
1014 Otherwise, the following line sets YYVAL to the semantic value of
1015 the lookahead token. This behavior is undocumented and Bison
1016 users should not rely upon it. Assigning to YYVAL
1017 unconditionally makes the parser a bit smaller, and it avoids a
1018 GCC warning that YYVAL may be used uninitialized. */
1019 yyval = yyvsp[1-yylen];
1022 /* Similarly for the default location. Let the user run additional
1023 commands if for instance locations are ranges. */
1024 yyloc = yylsp[1-yylen];
1025 YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1029 /* We have to keep this `#if YYDEBUG', since we use variables which
1030 are defined only if `YYDEBUG' is set. */
1035 YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
1038 /* Print the symbols being reduced, and their result. */
1039 for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
1040 YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
1041 YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
1048 #line 159 "./prsa_par.y"
1050 rsa_key_insert(prsa_cur_list, yyvsp[-3].naddr, yyvsp[-2].naddr, yyvsp[0].rsa);
1054 #line 163 "./prsa_par.y"
1056 rsa_key_insert(prsa_cur_list, NULL, yyvsp[-2].naddr, yyvsp[0].rsa);
1060 #line 167 "./prsa_par.y"
1062 rsa_key_insert(prsa_cur_list, NULL, NULL, yyvsp[0].rsa);
1066 #line 174 "./prsa_par.y"
1068 if (prsa_cur_type == RSA_TYPE_PUBLIC) {
1069 prsawarning("Using private key for public key purpose.\n");
1070 if (!rsa_cur->n || !rsa_cur->e) {
1071 prsaerror("Incomplete key. Mandatory parameters are missing!\n");
1076 if (!rsa_cur->n || !rsa_cur->e || !rsa_cur->d) {
1077 prsaerror("Incomplete key. Mandatory parameters are missing!\n");
1080 if (!rsa_cur->p || !rsa_cur->q || !rsa_cur->dmp1
1081 || !rsa_cur->dmq1 || !rsa_cur->iqmp) {
1082 if (rsa_cur->p) BN_clear_free(rsa_cur->p);
1083 if (rsa_cur->q) BN_clear_free(rsa_cur->q);
1084 if (rsa_cur->dmp1) BN_clear_free(rsa_cur->dmp1);
1085 if (rsa_cur->dmq1) BN_clear_free(rsa_cur->dmq1);
1086 if (rsa_cur->iqmp) BN_clear_free(rsa_cur->iqmp);
1090 rsa_cur->dmp1 = NULL;
1091 rsa_cur->dmq1 = NULL;
1092 rsa_cur->iqmp = NULL;
1095 yyval.rsa = rsa_cur;
1096 rsa_cur = RSA_new();
1100 #line 206 "./prsa_par.y"
1102 if (prsa_cur_type == RSA_TYPE_PRIVATE) {
1103 prsaerror("Public key in private-key file!\n");
1106 yyval.rsa = base64_pubkey2rsa(yyvsp[0].chr);
1110 #line 214 "./prsa_par.y"
1112 if (prsa_cur_type == RSA_TYPE_PRIVATE) {
1113 prsaerror("Public key in private-key file!\n");
1116 yyval.rsa = bignum_pubkey2rsa(yyvsp[0].bn);
1120 #line 227 "./prsa_par.y"
1126 #line 234 "./prsa_par.y"
1129 struct sockaddr_in *sap;
1131 if (yyvsp[0].num == -1) yyvsp[0].num = 32;
1132 if (yyvsp[0].num < 0 || yyvsp[0].num > 32) {
1133 prsaerror ("Invalid IPv4 prefix\n");
1136 yyval.naddr = calloc (sizeof(struct netaddr), 1);
1137 yyval.naddr->prefix = yyvsp[0].num;
1138 sap = (struct sockaddr_in *)(&yyval.naddr->sa);
1139 sap->sin_family = AF_INET;
1140 err = inet_pton(AF_INET, yyvsp[-1].chr, (struct in_addr*)(&sap->sin_addr));
1142 prsaerror("inet_pton(%s): %s\n", yyvsp[-1].chr, strerror(errno));
1148 #line 257 "./prsa_par.y"
1151 struct sockaddr_in6 *sap;
1153 if (yyvsp[0].num == -1) yyvsp[0].num = 128;
1154 if (yyvsp[0].num < 0 || yyvsp[0].num > 128) {
1155 prsaerror ("Invalid IPv6 prefix\n");
1158 yyval.naddr = calloc (sizeof(struct netaddr), 1);
1159 yyval.naddr->prefix = yyvsp[0].num;
1160 sap = (struct sockaddr_in6 *)(&yyval.naddr->sa);
1161 sap->sin6_family = AF_INET6;
1162 err = inet_pton(AF_INET6, yyvsp[-1].chr, (struct in6_addr*)(&sap->sin6_addr));
1164 prsaerror("inet_pton(%s): %s\n", yyvsp[-1].chr, strerror(errno));
1170 #line 279 "./prsa_par.y"
1174 #line 280 "./prsa_par.y"
1175 { yyval.num = yyvsp[0].num; }
1178 #line 289 "./prsa_par.y"
1179 { if (!rsa_cur->n) rsa_cur->n = yyvsp[0].bn; else { prsaerror ("Modulus already defined\n"); YYABORT; } }
1182 #line 291 "./prsa_par.y"
1183 { if (!rsa_cur->e) rsa_cur->e = yyvsp[0].bn; else { prsaerror ("PublicExponent already defined\n"); YYABORT; } }
1186 #line 293 "./prsa_par.y"
1187 { if (!rsa_cur->d) rsa_cur->d = yyvsp[0].bn; else { prsaerror ("PrivateExponent already defined\n"); YYABORT; } }
1190 #line 295 "./prsa_par.y"
1191 { if (!rsa_cur->p) rsa_cur->p = yyvsp[0].bn; else { prsaerror ("Prime1 already defined\n"); YYABORT; } }
1194 #line 297 "./prsa_par.y"
1195 { if (!rsa_cur->q) rsa_cur->q = yyvsp[0].bn; else { prsaerror ("Prime2 already defined\n"); YYABORT; } }
1198 #line 299 "./prsa_par.y"
1199 { if (!rsa_cur->dmp1) rsa_cur->dmp1 = yyvsp[0].bn; else { prsaerror ("Exponent1 already defined\n"); YYABORT; } }
1202 #line 301 "./prsa_par.y"
1203 { if (!rsa_cur->dmq1) rsa_cur->dmq1 = yyvsp[0].bn; else { prsaerror ("Exponent2 already defined\n"); YYABORT; } }
1206 #line 303 "./prsa_par.y"
1207 { if (!rsa_cur->iqmp) rsa_cur->iqmp = yyvsp[0].bn; else { prsaerror ("Coefficient already defined\n"); YYABORT; } }
1211 #line 705 "/usr/share/bison/bison.simple"
1223 short *yyssp1 = yyss - 1;
1224 YYFPRINTF (stderr, "state stack now");
1225 while (yyssp1 != yyssp)
1226 YYFPRINTF (stderr, " %d", *++yyssp1);
1227 YYFPRINTF (stderr, "\n");
1236 /* Now `shift' the result of the reduction. Determine what state
1237 that goes to, based on the state we popped back to and the rule
1238 number reduced by. */
1242 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1243 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1244 yystate = yytable[yystate];
1246 yystate = yydefgoto[yyn - YYNTBASE];
1251 /*------------------------------------.
1252 | yyerrlab -- here on detecting error |
1253 `------------------------------------*/
1255 /* If not already recovering from an error, report this error. */
1260 #ifdef YYERROR_VERBOSE
1261 yyn = yypact[yystate];
1263 if (yyn > YYFLAG && yyn < YYLAST)
1265 YYSIZE_T yysize = 0;
1270 /* Start YYX at -YYN if negative to avoid negative indexes in
1272 for (yyx = yyn < 0 ? -yyn : 0;
1273 yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
1274 if (yycheck[yyx + yyn] == yyx)
1275 yysize += yystrlen (yytname[yyx]) + 15, yycount++;
1276 yysize += yystrlen ("parse error, unexpected ") + 1;
1277 yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
1278 yymsg = (char *) YYSTACK_ALLOC (yysize);
1281 char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
1282 yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
1287 for (yyx = yyn < 0 ? -yyn : 0;
1288 yyx < (int) (sizeof (yytname) / sizeof (char *));
1290 if (yycheck[yyx + yyn] == yyx)
1292 const char *yyq = ! yycount ? ", expecting " : " or ";
1293 yyp = yystpcpy (yyp, yyq);
1294 yyp = yystpcpy (yyp, yytname[yyx]);
1299 YYSTACK_FREE (yymsg);
1302 yyerror ("parse error; also virtual memory exhausted");
1305 #endif /* defined (YYERROR_VERBOSE) */
1306 yyerror ("parse error");
1311 /*--------------------------------------------------.
1312 | yyerrlab1 -- error raised explicitly by an action |
1313 `--------------------------------------------------*/
1315 if (yyerrstatus == 3)
1317 /* If just tried and failed to reuse lookahead token after an
1318 error, discard it. */
1320 /* return failure if at end of input */
1321 if (yychar == YYEOF)
1323 YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
1324 yychar, yytname[yychar1]));
1328 /* Else will try to reuse lookahead token after shifting the error
1331 yyerrstatus = 3; /* Each real token shifted decrements this */
1336 /*-------------------------------------------------------------------.
1337 | yyerrdefault -- current state does not do anything special for the |
1339 `-------------------------------------------------------------------*/
1342 /* This is wrong; only states that explicitly want error tokens
1343 should shift them. */
1345 /* If its default is to accept any token, ok. Otherwise pop it. */
1346 yyn = yydefact[yystate];
1352 /*---------------------------------------------------------------.
1353 | yyerrpop -- pop the current state because it cannot handle the |
1355 `---------------------------------------------------------------*/
1368 short *yyssp1 = yyss - 1;
1369 YYFPRINTF (stderr, "Error: state stack now");
1370 while (yyssp1 != yyssp)
1371 YYFPRINTF (stderr, " %d", *++yyssp1);
1372 YYFPRINTF (stderr, "\n");
1380 yyn = yypact[yystate];
1385 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1402 YYDPRINTF ((stderr, "Shifting error token, "));
1413 /*-------------------------------------.
1414 | yyacceptlab -- YYACCEPT comes here. |
1415 `-------------------------------------*/
1420 /*-----------------------------------.
1421 | yyabortlab -- YYABORT comes here. |
1422 `-----------------------------------*/
1427 /*---------------------------------------------.
1428 | yyoverflowab -- parser overflow comes here. |
1429 `---------------------------------------------*/
1431 yyerror ("parser stack overflow");
1438 YYSTACK_FREE (yyss);
1442 #line 305 "./prsa_par.y"
1445 int prsaparse(void);
1448 prsa_parse_file(struct genlist *list, char *fname, enum rsa_key_type type)
1455 if (type == RSA_TYPE_PRIVATE) {
1457 if (stat(fname, &st) < 0)
1459 if (st.st_mode & (S_IRWXG | S_IRWXO)) {
1460 plog(LLV_ERROR, LOCATION, NULL,
1461 "Too slack permissions on private key '%s'\n",
1463 plog(LLV_ERROR, LOCATION, NULL,
1464 "Should be at most 0600, now is 0%o\n",
1469 fp = fopen(fname, "r");
1473 prsa_cur_lineno = 1;
1474 prsa_cur_fname = fname;
1475 prsa_cur_list = list;
1476 prsa_cur_type = type;
1477 rsa_cur = RSA_new();