Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / ipsec-tools / src / racoon / prsa_par.c
1 /* A Bison parser, made from ./prsa_par.y
2    by GNU bison 1.35.  */
3
4 #define YYBISON 1  /* Identify Bison output.  */
5
6 #define yyparse prsaparse
7 #define yylex prsalex
8 #define yyerror prsaerror
9 #define yylval prsalval
10 #define yychar prsachar
11 #define yydebug prsadebug
12 #define yynerrs prsanerrs
13 # define        COLON   257
14 # define        HEX     258
15 # define        OBRACE  259
16 # define        EBRACE  260
17 # define        TAG_RSA 261
18 # define        TAG_PUB 262
19 # define        TAG_PSK 263
20 # define        MODULUS 264
21 # define        PUBLIC_EXPONENT 265
22 # define        PRIVATE_EXPONENT        266
23 # define        PRIME1  267
24 # define        PRIME2  268
25 # define        EXPONENT1       269
26 # define        EXPONENT2       270
27 # define        COEFFICIENT     271
28 # define        ADDR4   272
29 # define        ADDR6   273
30 # define        ADDRANY 274
31 # define        SLASH   275
32 # define        NUMBER  276
33 # define        BASE64  277
34
35 #line 3 "./prsa_par.y"
36
37 /*
38  * Copyright (C) 2004 SuSE Linux AG, Nuernberg, Germany.
39  * Contributed by: Michal Ludvig <mludvig@suse.cz>, SUSE Labs
40  * All rights reserved.
41  *
42  * Redistribution and use in source and binary forms, with or without
43  * modification, are permitted provided that the following conditions
44  * are met:
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.
53  *
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
64  * SUCH DAMAGE.
65  */
66
67 /* This file contains a parser for FreeS/WAN-style ipsec.secrets RSA keys. */
68
69 #include "config.h"
70
71 #include <stdio.h>
72 #include <stdarg.h>
73 #include <string.h>
74 #include <errno.h>
75 #include <unistd.h>
76
77 #ifdef HAVE_STDARG_H
78 #include <stdarg.h>
79 #else
80 #include <varargs.h>
81 #endif
82
83 #include <netdb.h>
84 #include <netinet/in.h>
85 #include <sys/socket.h>
86 #include <arpa/inet.h>
87 #include <sys/types.h>
88
89 #include <sys/stat.h>
90 #include <unistd.h>
91
92 #include <openssl/bn.h>
93 #include <openssl/rsa.h>
94
95 #include "misc.h"
96 #include "vmbuf.h"
97 #include "plog.h"
98 #include "oakley.h"
99 #include "isakmp_var.h"
100 #include "handler.h"
101 #include "crypto_openssl.h"
102 #include "sockmisc.h"
103 #include "rsalist.h"
104
105 extern void prsaerror(const char *str, ...);
106 extern int prsawrap (void);
107 extern int prsalex (void);
108
109 extern char *prsatext;
110 extern int prsa_cur_lineno;
111 extern char *prsa_cur_fname;
112 extern FILE *prsain;
113
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;
118
119 static RSA *rsa_cur;
120
121 void
122 prsaerror(const char *s, ...)
123 {
124         char fmt[512];
125
126         va_list ap;
127 #ifdef HAVE_STDARG_H
128         va_start(ap, s);
129 #else
130         va_start(ap);
131 #endif
132         snprintf(fmt, sizeof(fmt), "%s:%d: %s",
133                 prsa_cur_fname, prsa_cur_lineno, s);
134         plogv(LLV_ERROR, LOCATION, NULL, fmt, ap);
135         va_end(ap);
136 }
137
138 void
139 prsawarning(const char *s, ...)
140 {
141         char fmt[512];
142
143         va_list ap;
144 #ifdef HAVE_STDARG_H
145         va_start(ap, s);
146 #else
147         va_start(ap);
148 #endif
149         snprintf(fmt, sizeof(fmt), "%s:%d: %s",
150                 prsa_cur_fname, prsa_cur_lineno, s);
151         plogv(LLV_WARNING, LOCATION, NULL, fmt, ap);
152         va_end(ap);
153 }
154
155 int
156 prsawrap()
157 {
158         return 1;
159
160
161 #line 128 "./prsa_par.y"
162 #ifndef YYSTYPE
163 typedef union {
164         BIGNUM *bn;
165         RSA *rsa;
166         char *chr;
167         long num;
168         struct netaddr *naddr;
169 } yystype;
170 # define YYSTYPE yystype
171 # define YYSTYPE_IS_TRIVIAL 1
172 #endif
173 #ifndef YYDEBUG
174 # define YYDEBUG 0
175 #endif
176
177
178
179 #define YYFINAL         55
180 #define YYFLAG          -32768
181 #define YYNTBASE        24
182
183 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
184 #define YYTRANSLATE(x) ((unsigned)(x) <= 277 ? yytranslate[x] : 33)
185
186 /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
187 static const char yytranslate[] =
188 {
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
217 };
218
219 #if YYDEBUG
220 static const short yyprhs[] =
221 {
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
225 };
226 static const short yyrhs[] =
227 {
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,
236        0
237 };
238
239 #endif
240
241 #if YYDEBUG
242 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
243 static const short yyrline[] =
244 {
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
248 };
249 #endif
250
251
252 #if (YYDEBUG) || defined YYERROR_VERBOSE
253
254 /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
255 static const char *const yytname[] =
256 {
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
263 };
264 #endif
265
266 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
267 static const short yyr1[] =
268 {
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
272 };
273
274 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
275 static const short yyr2[] =
276 {
277        0,     2,     1,     4,     3,     2,     4,     2,     2,     1,
278        1,     1,     2,     2,     0,     2,     2,     1,     3,     3,
279        3,     3,     3,     3,     3,     3
280 };
281
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
284    error. */
285 static const short yydefact[] =
286 {
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,
292       22,    23,    24,    25,     0,     0
293 };
294
295 static const short yydefgoto[] =
296 {
297        5,     6,    12,     7,     8,     9,    14,    33,    34
298 };
299
300 static const short yypact[] =
301 {
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
308 };
309
310 static const short yypgoto[] =
311 {
312   -32768,    52,   -16,    53,-32768,-32768,    55,-32768,    29
313 };
314
315
316 #define YYLAST          62
317
318
319 static const short yytable[] =
320 {
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,
327       18,     0,    45
328 };
329
330 static const short yycheck[] =
331 {
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,
338        7,    -1,    33
339 };
340 /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
341 #line 3 "/usr/share/bison/bison.simple"
342
343 /* Skeleton output parser for bison,
344
345    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software
346    Foundation, Inc.
347
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)
351    any later version.
352
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.
357
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.  */
362
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.  */
367
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.  */
372
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.  */
379
380 #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
381
382 /* The parser invokes alloca or malloc; define the necessary symbols.  */
383
384 # if YYSTACK_USE_ALLOCA
385 #  define YYSTACK_ALLOC alloca
386 # else
387 #  ifndef YYSTACK_USE_ALLOCA
388 #   if defined (alloca) || defined (_ALLOCA_H)
389 #    define YYSTACK_ALLOC alloca
390 #   else
391 #    ifdef __GNUC__
392 #     define YYSTACK_ALLOC __builtin_alloca
393 #    endif
394 #   endif
395 #  endif
396 # endif
397
398 # ifdef YYSTACK_ALLOC
399    /* Pacify GCC's `empty if-body' warning. */
400 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
401 # else
402 #  if defined (__STDC__) || defined (__cplusplus)
403 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
404 #   define YYSIZE_T size_t
405 #  endif
406 #  define YYSTACK_ALLOC malloc
407 #  define YYSTACK_FREE free
408 # endif
409 #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
410
411
412 #if (! defined (yyoverflow) \
413      && (! defined (__cplusplus) \
414          || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
415
416 /* A type that is properly aligned for any stack member.  */
417 union yyalloc
418 {
419   short yyss;
420   YYSTYPE yyvs;
421 # if YYLSP_NEEDED
422   YYLTYPE yyls;
423 # endif
424 };
425
426 /* The size of the maximum gap between one aligned stack and the next.  */
427 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
428
429 /* The size of an array large to enough to hold all stacks, each with
430    N elements.  */
431 # if YYLSP_NEEDED
432 #  define YYSTACK_BYTES(N) \
433      ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE))      \
434       + 2 * YYSTACK_GAP_MAX)
435 # else
436 #  define YYSTACK_BYTES(N) \
437      ((N) * (sizeof (short) + sizeof (YYSTYPE))                         \
438       + YYSTACK_GAP_MAX)
439 # endif
440
441 /* Copy COUNT objects from FROM to TO.  The source and destination do
442    not overlap.  */
443 # ifndef YYCOPY
444 #  if 1 < __GNUC__
445 #   define YYCOPY(To, From, Count) \
446       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
447 #  else
448 #   define YYCOPY(To, From, Count)              \
449       do                                        \
450         {                                       \
451           register YYSIZE_T yyi;                \
452           for (yyi = 0; yyi < (Count); yyi++)   \
453             (To)[yyi] = (From)[yyi];            \
454         }                                       \
455       while (0)
456 #  endif
457 # endif
458
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
463    stack.  */
464 # define YYSTACK_RELOCATE(Stack)                                        \
465     do                                                                  \
466       {                                                                 \
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);                          \
472       }                                                                 \
473     while (0)
474
475 #endif
476
477
478 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
479 # define YYSIZE_T __SIZE_TYPE__
480 #endif
481 #if ! defined (YYSIZE_T) && defined (size_t)
482 # define YYSIZE_T size_t
483 #endif
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
488 # endif
489 #endif
490 #if ! defined (YYSIZE_T)
491 # define YYSIZE_T unsigned int
492 #endif
493
494 #define yyerrok         (yyerrstatus = 0)
495 #define yyclearin       (yychar = YYEMPTY)
496 #define YYEMPTY         -2
497 #define YYEOF           0
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)                                  \
507 do                                                              \
508   if (yychar == YYEMPTY && yylen == 1)                          \
509     {                                                           \
510       yychar = (Token);                                         \
511       yylval = (Value);                                         \
512       yychar1 = YYTRANSLATE (yychar);                           \
513       YYPOPSTACK;                                               \
514       goto yybackup;                                            \
515     }                                                           \
516   else                                                          \
517     {                                                           \
518       yyerror ("syntax error: cannot back up");                 \
519       YYERROR;                                                  \
520     }                                                           \
521 while (0)
522
523 #define YYTERROR        1
524 #define YYERRCODE       256
525
526
527 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
528    are run).
529
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.  */
533
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;
538 #endif
539
540
541 /* YYLEX -- calling `yylex' with the right arguments.  */
542
543 #if YYPURE
544 # if YYLSP_NEEDED
545 #  ifdef YYLEX_PARAM
546 #   define YYLEX                yylex (&yylval, &yylloc, YYLEX_PARAM)
547 #  else
548 #   define YYLEX                yylex (&yylval, &yylloc)
549 #  endif
550 # else /* !YYLSP_NEEDED */
551 #  ifdef YYLEX_PARAM
552 #   define YYLEX                yylex (&yylval, YYLEX_PARAM)
553 #  else
554 #   define YYLEX                yylex (&yylval)
555 #  endif
556 # endif /* !YYLSP_NEEDED */
557 #else /* !YYPURE */
558 # define YYLEX                  yylex ()
559 #endif /* !YYPURE */
560
561
562 /* Enable debugging if requested.  */
563 #if YYDEBUG
564
565 # ifndef YYFPRINTF
566 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
567 #  define YYFPRINTF fprintf
568 # endif
569
570 # define YYDPRINTF(Args)                        \
571 do {                                            \
572   if (yydebug)                                  \
573     YYFPRINTF Args;                             \
574 } while (0)
575 /* Nonzero means print parse trace.  It is left uninitialized so that
576    multiple parsers can coexist.  */
577 int yydebug;
578 #else /* !YYDEBUG */
579 # define YYDPRINTF(Args)
580 #endif /* !YYDEBUG */
581
582 /* YYINITDEPTH -- initial size of the parser's stacks.  */
583 #ifndef YYINITDEPTH
584 # define YYINITDEPTH 200
585 #endif
586
587 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
588    if the built-in stack extension method is used).
589
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.  */
593
594 #if YYMAXDEPTH == 0
595 # undef YYMAXDEPTH
596 #endif
597
598 #ifndef YYMAXDEPTH
599 # define YYMAXDEPTH 10000
600 #endif
601 \f
602 #ifdef YYERROR_VERBOSE
603
604 # ifndef yystrlen
605 #  if defined (__GLIBC__) && defined (_STRING_H)
606 #   define yystrlen strlen
607 #  else
608 /* Return the length of YYSTR.  */
609 static YYSIZE_T
610 #   if defined (__STDC__) || defined (__cplusplus)
611 yystrlen (const char *yystr)
612 #   else
613 yystrlen (yystr)
614      const char *yystr;
615 #   endif
616 {
617   register const char *yys = yystr;
618
619   while (*yys++ != '\0')
620     continue;
621
622   return yys - yystr - 1;
623 }
624 #  endif
625 # endif
626
627 # ifndef yystpcpy
628 #  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
629 #   define yystpcpy stpcpy
630 #  else
631 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
632    YYDEST.  */
633 static char *
634 #   if defined (__STDC__) || defined (__cplusplus)
635 yystpcpy (char *yydest, const char *yysrc)
636 #   else
637 yystpcpy (yydest, yysrc)
638      char *yydest;
639      const char *yysrc;
640 #   endif
641 {
642   register char *yyd = yydest;
643   register const char *yys = yysrc;
644
645   while ((*yyd++ = *yys++) != '\0')
646     continue;
647
648   return yyd - 1;
649 }
650 #  endif
651 # endif
652 #endif
653 \f
654 #line 315 "/usr/share/bison/bison.simple"
655
656
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.  */
662
663 #ifdef YYPARSE_PARAM
664 # if defined (__STDC__) || defined (__cplusplus)
665 #  define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
666 #  define YYPARSE_PARAM_DECL
667 # else
668 #  define YYPARSE_PARAM_ARG YYPARSE_PARAM
669 #  define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
670 # endif
671 #else /* !YYPARSE_PARAM */
672 # define YYPARSE_PARAM_ARG
673 # define YYPARSE_PARAM_DECL
674 #endif /* !YYPARSE_PARAM */
675
676 /* Prevent warning if -Wstrict-prototypes.  */
677 #ifdef __GNUC__
678 # ifdef YYPARSE_PARAM
679 int yyparse (void *);
680 # else
681 int yyparse (void);
682 # endif
683 #endif
684
685 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
686    variables are global, or local to YYPARSE.  */
687
688 #define YY_DECL_NON_LSP_VARIABLES                       \
689 /* The lookahead symbol.  */                            \
690 int yychar;                                             \
691                                                         \
692 /* The semantic value of the lookahead symbol. */       \
693 YYSTYPE yylval;                                         \
694                                                         \
695 /* Number of parse errors so far.  */                   \
696 int yynerrs;
697
698 #if YYLSP_NEEDED
699 # define YY_DECL_VARIABLES                      \
700 YY_DECL_NON_LSP_VARIABLES                       \
701                                                 \
702 /* Location data for the lookahead symbol.  */  \
703 YYLTYPE yylloc;
704 #else
705 # define YY_DECL_VARIABLES                      \
706 YY_DECL_NON_LSP_VARIABLES
707 #endif
708
709
710 /* If nonreentrant, generate the variables here. */
711
712 #if !YYPURE
713 YY_DECL_VARIABLES
714 #endif  /* !YYPURE */
715
716 int
717 yyparse (YYPARSE_PARAM_ARG)
718      YYPARSE_PARAM_DECL
719 {
720   /* If reentrant, generate the variables here. */
721 #if YYPURE
722   YY_DECL_VARIABLES
723 #endif  /* !YYPURE */
724
725   register int yystate;
726   register int yyn;
727   int yyresult;
728   /* Number of tokens to shift before error messages enabled.  */
729   int yyerrstatus;
730   /* Lookahead token as an internal (translated) token number.  */
731   int yychar1 = 0;
732
733   /* Three stacks and their tools:
734      `yyss': related to states,
735      `yyvs': related to semantic values,
736      `yyls': related to locations.
737
738      Refer to the stacks thru separate pointers, to allow yyoverflow
739      to reallocate them elsewhere.  */
740
741   /* The state stack. */
742   short yyssa[YYINITDEPTH];
743   short *yyss = yyssa;
744   register short *yyssp;
745
746   /* The semantic value stack.  */
747   YYSTYPE yyvsa[YYINITDEPTH];
748   YYSTYPE *yyvs = yyvsa;
749   register YYSTYPE *yyvsp;
750
751 #if YYLSP_NEEDED
752   /* The location stack.  */
753   YYLTYPE yylsa[YYINITDEPTH];
754   YYLTYPE *yyls = yylsa;
755   YYLTYPE *yylsp;
756 #endif
757
758 #if YYLSP_NEEDED
759 # define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
760 #else
761 # define YYPOPSTACK   (yyvsp--, yyssp--)
762 #endif
763
764   YYSIZE_T yystacksize = YYINITDEPTH;
765
766
767   /* The variables used to return semantic value and location from the
768      action routines.  */
769   YYSTYPE yyval;
770 #if YYLSP_NEEDED
771   YYLTYPE yyloc;
772 #endif
773
774   /* When reducing, the number of symbols on the RHS of the reduced
775      rule. */
776   int yylen;
777
778   YYDPRINTF ((stderr, "Starting parse\n"));
779
780   yystate = 0;
781   yyerrstatus = 0;
782   yynerrs = 0;
783   yychar = YYEMPTY;             /* Cause a token to be read.  */
784
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.  */
789
790   yyssp = yyss;
791   yyvsp = yyvs;
792 #if YYLSP_NEEDED
793   yylsp = yyls;
794 #endif
795   goto yysetstate;
796
797 /*------------------------------------------------------------.
798 | yynewstate -- Push a new state, which is found in yystate.  |
799 `------------------------------------------------------------*/
800  yynewstate:
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.
803      */
804   yyssp++;
805
806  yysetstate:
807   *yyssp = yystate;
808
809   if (yyssp >= yyss + yystacksize - 1)
810     {
811       /* Get the current used size of the three stacks, in elements.  */
812       YYSIZE_T yysize = yyssp - yyss + 1;
813
814 #ifdef yyoverflow
815       {
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
818            memory.  */
819         YYSTYPE *yyvs1 = yyvs;
820         short *yyss1 = yyss;
821
822         /* Each stack pointer address is followed by the size of the
823            data in use in that stack, in bytes.  */
824 # if YYLSP_NEEDED
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),
832                     &yystacksize);
833         yyls = yyls1;
834 # else
835         yyoverflow ("parser stack overflow",
836                     &yyss1, yysize * sizeof (*yyssp),
837                     &yyvs1, yysize * sizeof (*yyvsp),
838                     &yystacksize);
839 # endif
840         yyss = yyss1;
841         yyvs = yyvs1;
842       }
843 #else /* no yyoverflow */
844 # ifndef YYSTACK_RELOCATE
845       goto yyoverflowlab;
846 # else
847       /* Extend the stack our own way.  */
848       if (yystacksize >= YYMAXDEPTH)
849         goto yyoverflowlab;
850       yystacksize *= 2;
851       if (yystacksize > YYMAXDEPTH)
852         yystacksize = YYMAXDEPTH;
853
854       {
855         short *yyss1 = yyss;
856         union yyalloc *yyptr =
857           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
858         if (! yyptr)
859           goto yyoverflowlab;
860         YYSTACK_RELOCATE (yyss);
861         YYSTACK_RELOCATE (yyvs);
862 # if YYLSP_NEEDED
863         YYSTACK_RELOCATE (yyls);
864 # endif
865 # undef YYSTACK_RELOCATE
866         if (yyss1 != yyssa)
867           YYSTACK_FREE (yyss1);
868       }
869 # endif
870 #endif /* no yyoverflow */
871
872       yyssp = yyss + yysize - 1;
873       yyvsp = yyvs + yysize - 1;
874 #if YYLSP_NEEDED
875       yylsp = yyls + yysize - 1;
876 #endif
877
878       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
879                   (unsigned long int) yystacksize));
880
881       if (yyssp >= yyss + yystacksize - 1)
882         YYABORT;
883     }
884
885   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
886
887   goto yybackup;
888
889
890 /*-----------.
891 | yybackup.  |
892 `-----------*/
893 yybackup:
894
895 /* Do appropriate processing given the current state.  */
896 /* Read a lookahead token if we need one and don't already have one.  */
897 /* yyresume: */
898
899   /* First try to decide what to do without reference to lookahead token.  */
900
901   yyn = yypact[yystate];
902   if (yyn == YYFLAG)
903     goto yydefault;
904
905   /* Not known => get a lookahead token if don't already have one.  */
906
907   /* yychar is either YYEMPTY or YYEOF
908      or a valid token in external form.  */
909
910   if (yychar == YYEMPTY)
911     {
912       YYDPRINTF ((stderr, "Reading a token: "));
913       yychar = YYLEX;
914     }
915
916   /* Convert token to internal form (in yychar1) for indexing tables with */
917
918   if (yychar <= 0)              /* This means end of input. */
919     {
920       yychar1 = 0;
921       yychar = YYEOF;           /* Don't call YYLEX any more */
922
923       YYDPRINTF ((stderr, "Now at end of input.\n"));
924     }
925   else
926     {
927       yychar1 = YYTRANSLATE (yychar);
928
929 #if YYDEBUG
930      /* We have to keep this `#if YYDEBUG', since we use variables
931         which are defined only if `YYDEBUG' is set.  */
932       if (yydebug)
933         {
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.  */
938 # ifdef YYPRINT
939           YYPRINT (stderr, yychar, yylval);
940 # endif
941           YYFPRINTF (stderr, ")\n");
942         }
943 #endif
944     }
945
946   yyn += yychar1;
947   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
948     goto yydefault;
949
950   yyn = yytable[yyn];
951
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,
956        just return success.
957      0, or most negative number => error.  */
958
959   if (yyn < 0)
960     {
961       if (yyn == YYFLAG)
962         goto yyerrlab;
963       yyn = -yyn;
964       goto yyreduce;
965     }
966   else if (yyn == 0)
967     goto yyerrlab;
968
969   if (yyn == YYFINAL)
970     YYACCEPT;
971
972   /* Shift the lookahead token.  */
973   YYDPRINTF ((stderr, "Shifting token %d (%s), ",
974               yychar, yytname[yychar1]));
975
976   /* Discard the token being shifted unless it is eof.  */
977   if (yychar != YYEOF)
978     yychar = YYEMPTY;
979
980   *++yyvsp = yylval;
981 #if YYLSP_NEEDED
982   *++yylsp = yylloc;
983 #endif
984
985   /* Count tokens shifted since error; after three, turn off error
986      status.  */
987   if (yyerrstatus)
988     yyerrstatus--;
989
990   yystate = yyn;
991   goto yynewstate;
992
993
994 /*-----------------------------------------------------------.
995 | yydefault -- do the default action for the current state.  |
996 `-----------------------------------------------------------*/
997 yydefault:
998   yyn = yydefact[yystate];
999   if (yyn == 0)
1000     goto yyerrlab;
1001   goto yyreduce;
1002
1003
1004 /*-----------------------------.
1005 | yyreduce -- Do a reduction.  |
1006 `-----------------------------*/
1007 yyreduce:
1008   /* yyn is the number of a rule to reduce with.  */
1009   yylen = yyr2[yyn];
1010
1011   /* If YYLEN is nonzero, implement the default value of the action:
1012      `$$ = $1'.
1013
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];
1020
1021 #if YYLSP_NEEDED
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);
1026 #endif
1027
1028 #if YYDEBUG
1029   /* We have to keep this `#if YYDEBUG', since we use variables which
1030      are defined only if `YYDEBUG' is set.  */
1031   if (yydebug)
1032     {
1033       int yyi;
1034
1035       YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
1036                  yyn, yyrline[yyn]);
1037
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]]);
1042     }
1043 #endif
1044
1045   switch (yyn) {
1046
1047 case 3:
1048 #line 159 "./prsa_par.y"
1049 {
1050                 rsa_key_insert(prsa_cur_list, yyvsp[-3].naddr, yyvsp[-2].naddr, yyvsp[0].rsa);
1051         }
1052     break;
1053 case 4:
1054 #line 163 "./prsa_par.y"
1055 {
1056                 rsa_key_insert(prsa_cur_list, NULL, yyvsp[-2].naddr, yyvsp[0].rsa);
1057         }
1058     break;
1059 case 5:
1060 #line 167 "./prsa_par.y"
1061 {
1062                 rsa_key_insert(prsa_cur_list, NULL, NULL, yyvsp[0].rsa);
1063         }
1064     break;
1065 case 6:
1066 #line 174 "./prsa_par.y"
1067 {
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");
1072                                 YYABORT;
1073                         }
1074                 }
1075                 else {
1076                         if (!rsa_cur->n || !rsa_cur->e || !rsa_cur->d) {
1077                                 prsaerror("Incomplete key. Mandatory parameters are missing!\n");
1078                                 YYABORT;
1079                         }
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);
1087
1088                                 rsa_cur->p = NULL;
1089                                 rsa_cur->q = NULL;
1090                                 rsa_cur->dmp1 = NULL;
1091                                 rsa_cur->dmq1 = NULL;
1092                                 rsa_cur->iqmp = NULL;
1093                         }
1094                 }
1095                 yyval.rsa = rsa_cur;
1096                 rsa_cur = RSA_new();
1097         }
1098     break;
1099 case 7:
1100 #line 206 "./prsa_par.y"
1101 {
1102                 if (prsa_cur_type == RSA_TYPE_PRIVATE) {
1103                         prsaerror("Public key in private-key file!\n");
1104                         YYABORT;
1105                 }
1106                 yyval.rsa = base64_pubkey2rsa(yyvsp[0].chr);
1107         }
1108     break;
1109 case 8:
1110 #line 214 "./prsa_par.y"
1111 {
1112                 if (prsa_cur_type == RSA_TYPE_PRIVATE) {
1113                         prsaerror("Public key in private-key file!\n");
1114                         YYABORT;
1115                 }
1116                 yyval.rsa = bignum_pubkey2rsa(yyvsp[0].bn);
1117         }
1118     break;
1119 case 11:
1120 #line 227 "./prsa_par.y"
1121 {
1122                 yyval.naddr = NULL;
1123         }
1124     break;
1125 case 12:
1126 #line 234 "./prsa_par.y"
1127 {
1128                 int err;
1129                 struct sockaddr_in *sap;
1130                 
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");
1134                         YYABORT;
1135                 }
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));
1141                 if (err <= 0) {
1142                         prsaerror("inet_pton(%s): %s\n", yyvsp[-1].chr, strerror(errno));
1143                         YYABORT;
1144                 }
1145         }
1146     break;
1147 case 13:
1148 #line 257 "./prsa_par.y"
1149 {
1150                 int err;
1151                 struct sockaddr_in6 *sap;
1152                 
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");
1156                         YYABORT;
1157                 }
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));
1163                 if (err <= 0) {
1164                         prsaerror("inet_pton(%s): %s\n", yyvsp[-1].chr, strerror(errno));
1165                         YYABORT;
1166                 }
1167         }
1168     break;
1169 case 14:
1170 #line 279 "./prsa_par.y"
1171 { yyval.num = -1; }
1172     break;
1173 case 15:
1174 #line 280 "./prsa_par.y"
1175 { yyval.num = yyvsp[0].num; }
1176     break;
1177 case 18:
1178 #line 289 "./prsa_par.y"
1179 { if (!rsa_cur->n) rsa_cur->n = yyvsp[0].bn; else { prsaerror ("Modulus already defined\n"); YYABORT; } }
1180     break;
1181 case 19:
1182 #line 291 "./prsa_par.y"
1183 { if (!rsa_cur->e) rsa_cur->e = yyvsp[0].bn; else { prsaerror ("PublicExponent already defined\n"); YYABORT; } }
1184     break;
1185 case 20:
1186 #line 293 "./prsa_par.y"
1187 { if (!rsa_cur->d) rsa_cur->d = yyvsp[0].bn; else { prsaerror ("PrivateExponent already defined\n"); YYABORT; } }
1188     break;
1189 case 21:
1190 #line 295 "./prsa_par.y"
1191 { if (!rsa_cur->p) rsa_cur->p = yyvsp[0].bn; else { prsaerror ("Prime1 already defined\n"); YYABORT; } }
1192     break;
1193 case 22:
1194 #line 297 "./prsa_par.y"
1195 { if (!rsa_cur->q) rsa_cur->q = yyvsp[0].bn; else { prsaerror ("Prime2 already defined\n"); YYABORT; } }
1196     break;
1197 case 23:
1198 #line 299 "./prsa_par.y"
1199 { if (!rsa_cur->dmp1) rsa_cur->dmp1 = yyvsp[0].bn; else { prsaerror ("Exponent1 already defined\n"); YYABORT; } }
1200     break;
1201 case 24:
1202 #line 301 "./prsa_par.y"
1203 { if (!rsa_cur->dmq1) rsa_cur->dmq1 = yyvsp[0].bn; else { prsaerror ("Exponent2 already defined\n"); YYABORT; } }
1204     break;
1205 case 25:
1206 #line 303 "./prsa_par.y"
1207 { if (!rsa_cur->iqmp) rsa_cur->iqmp = yyvsp[0].bn; else { prsaerror ("Coefficient already defined\n"); YYABORT; } }
1208     break;
1209 }
1210
1211 #line 705 "/usr/share/bison/bison.simple"
1212
1213 \f
1214   yyvsp -= yylen;
1215   yyssp -= yylen;
1216 #if YYLSP_NEEDED
1217   yylsp -= yylen;
1218 #endif
1219
1220 #if YYDEBUG
1221   if (yydebug)
1222     {
1223       short *yyssp1 = yyss - 1;
1224       YYFPRINTF (stderr, "state stack now");
1225       while (yyssp1 != yyssp)
1226         YYFPRINTF (stderr, " %d", *++yyssp1);
1227       YYFPRINTF (stderr, "\n");
1228     }
1229 #endif
1230
1231   *++yyvsp = yyval;
1232 #if YYLSP_NEEDED
1233   *++yylsp = yyloc;
1234 #endif
1235
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.  */
1239
1240   yyn = yyr1[yyn];
1241
1242   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1243   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1244     yystate = yytable[yystate];
1245   else
1246     yystate = yydefgoto[yyn - YYNTBASE];
1247
1248   goto yynewstate;
1249
1250
1251 /*------------------------------------.
1252 | yyerrlab -- here on detecting error |
1253 `------------------------------------*/
1254 yyerrlab:
1255   /* If not already recovering from an error, report this error.  */
1256   if (!yyerrstatus)
1257     {
1258       ++yynerrs;
1259
1260 #ifdef YYERROR_VERBOSE
1261       yyn = yypact[yystate];
1262
1263       if (yyn > YYFLAG && yyn < YYLAST)
1264         {
1265           YYSIZE_T yysize = 0;
1266           char *yymsg;
1267           int yyx, yycount;
1268
1269           yycount = 0;
1270           /* Start YYX at -YYN if negative to avoid negative indexes in
1271              YYCHECK.  */
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);
1279           if (yymsg != 0)
1280             {
1281               char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
1282               yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
1283
1284               if (yycount < 5)
1285                 {
1286                   yycount = 0;
1287                   for (yyx = yyn < 0 ? -yyn : 0;
1288                        yyx < (int) (sizeof (yytname) / sizeof (char *));
1289                        yyx++)
1290                     if (yycheck[yyx + yyn] == yyx)
1291                       {
1292                         const char *yyq = ! yycount ? ", expecting " : " or ";
1293                         yyp = yystpcpy (yyp, yyq);
1294                         yyp = yystpcpy (yyp, yytname[yyx]);
1295                         yycount++;
1296                       }
1297                 }
1298               yyerror (yymsg);
1299               YYSTACK_FREE (yymsg);
1300             }
1301           else
1302             yyerror ("parse error; also virtual memory exhausted");
1303         }
1304       else
1305 #endif /* defined (YYERROR_VERBOSE) */
1306         yyerror ("parse error");
1307     }
1308   goto yyerrlab1;
1309
1310
1311 /*--------------------------------------------------.
1312 | yyerrlab1 -- error raised explicitly by an action |
1313 `--------------------------------------------------*/
1314 yyerrlab1:
1315   if (yyerrstatus == 3)
1316     {
1317       /* If just tried and failed to reuse lookahead token after an
1318          error, discard it.  */
1319
1320       /* return failure if at end of input */
1321       if (yychar == YYEOF)
1322         YYABORT;
1323       YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
1324                   yychar, yytname[yychar1]));
1325       yychar = YYEMPTY;
1326     }
1327
1328   /* Else will try to reuse lookahead token after shifting the error
1329      token.  */
1330
1331   yyerrstatus = 3;              /* Each real token shifted decrements this */
1332
1333   goto yyerrhandle;
1334
1335
1336 /*-------------------------------------------------------------------.
1337 | yyerrdefault -- current state does not do anything special for the |
1338 | error token.                                                       |
1339 `-------------------------------------------------------------------*/
1340 yyerrdefault:
1341 #if 0
1342   /* This is wrong; only states that explicitly want error tokens
1343      should shift them.  */
1344
1345   /* If its default is to accept any token, ok.  Otherwise pop it.  */
1346   yyn = yydefact[yystate];
1347   if (yyn)
1348     goto yydefault;
1349 #endif
1350
1351
1352 /*---------------------------------------------------------------.
1353 | yyerrpop -- pop the current state because it cannot handle the |
1354 | error token                                                    |
1355 `---------------------------------------------------------------*/
1356 yyerrpop:
1357   if (yyssp == yyss)
1358     YYABORT;
1359   yyvsp--;
1360   yystate = *--yyssp;
1361 #if YYLSP_NEEDED
1362   yylsp--;
1363 #endif
1364
1365 #if YYDEBUG
1366   if (yydebug)
1367     {
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");
1373     }
1374 #endif
1375
1376 /*--------------.
1377 | yyerrhandle.  |
1378 `--------------*/
1379 yyerrhandle:
1380   yyn = yypact[yystate];
1381   if (yyn == YYFLAG)
1382     goto yyerrdefault;
1383
1384   yyn += YYTERROR;
1385   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
1386     goto yyerrdefault;
1387
1388   yyn = yytable[yyn];
1389   if (yyn < 0)
1390     {
1391       if (yyn == YYFLAG)
1392         goto yyerrpop;
1393       yyn = -yyn;
1394       goto yyreduce;
1395     }
1396   else if (yyn == 0)
1397     goto yyerrpop;
1398
1399   if (yyn == YYFINAL)
1400     YYACCEPT;
1401
1402   YYDPRINTF ((stderr, "Shifting error token, "));
1403
1404   *++yyvsp = yylval;
1405 #if YYLSP_NEEDED
1406   *++yylsp = yylloc;
1407 #endif
1408
1409   yystate = yyn;
1410   goto yynewstate;
1411
1412
1413 /*-------------------------------------.
1414 | yyacceptlab -- YYACCEPT comes here.  |
1415 `-------------------------------------*/
1416 yyacceptlab:
1417   yyresult = 0;
1418   goto yyreturn;
1419
1420 /*-----------------------------------.
1421 | yyabortlab -- YYABORT comes here.  |
1422 `-----------------------------------*/
1423 yyabortlab:
1424   yyresult = 1;
1425   goto yyreturn;
1426
1427 /*---------------------------------------------.
1428 | yyoverflowab -- parser overflow comes here.  |
1429 `---------------------------------------------*/
1430 yyoverflowlab:
1431   yyerror ("parser stack overflow");
1432   yyresult = 2;
1433   /* Fall through.  */
1434
1435 yyreturn:
1436 #ifndef yyoverflow
1437   if (yyss != yyssa)
1438     YYSTACK_FREE (yyss);
1439 #endif
1440   return yyresult;
1441 }
1442 #line 305 "./prsa_par.y"
1443
1444
1445 int prsaparse(void);
1446
1447 int
1448 prsa_parse_file(struct genlist *list, char *fname, enum rsa_key_type type)
1449 {
1450         FILE *fp = NULL;
1451         int ret;
1452         
1453         if (!fname)
1454                 return -1;
1455         if (type == RSA_TYPE_PRIVATE) {
1456                 struct stat st;
1457                 if (stat(fname, &st) < 0)
1458                         return -1;
1459                 if (st.st_mode & (S_IRWXG | S_IRWXO)) {
1460                         plog(LLV_ERROR, LOCATION, NULL,
1461                                 "Too slack permissions on private key '%s'\n", 
1462                                 fname);
1463                         plog(LLV_ERROR, LOCATION, NULL,
1464                                 "Should be at most 0600, now is 0%o\n",
1465                                 st.st_mode & 0777);
1466                         return -1;
1467                 }
1468         }
1469         fp = fopen(fname, "r");
1470         if (!fp)
1471                 return -1;
1472         prsain = fp;
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();
1478         ret = prsaparse();
1479         if (rsa_cur) {
1480                 RSA_free(rsa_cur);
1481                 rsa_cur = NULL;
1482         }
1483         fclose (fp);
1484         prsain = NULL;
1485         return ret;
1486 }