Imported Debian patch 1.6.6-1.3woody1
[debian/sudo] / sudo.tab.c
1 /* A Bison parser, made from parse.yacc
2    by GNU bison 1.35.  */
3
4 #define YYBISON 1  /* Identify Bison output.  */
5
6 # define        COMMAND 257
7 # define        ALIAS   258
8 # define        DEFVAR  259
9 # define        NTWKADDR        260
10 # define        NETGROUP        261
11 # define        USERGROUP       262
12 # define        WORD    263
13 # define        DEFAULTS        264
14 # define        DEFAULTS_HOST   265
15 # define        DEFAULTS_USER   266
16 # define        RUNAS   267
17 # define        NOPASSWD        268
18 # define        PASSWD  269
19 # define        ALL     270
20 # define        COMMENT 271
21 # define        HOSTALIAS       272
22 # define        CMNDALIAS       273
23 # define        USERALIAS       274
24 # define        RUNASALIAS      275
25 # define        ERROR   276
26
27 #line 1 "parse.yacc"
28
29 /*
30  * Copyright (c) 1996, 1998-2001 Todd C. Miller <Todd.Miller@courtesan.com>
31  * All rights reserved.
32  *
33  * This code is derived from software contributed by Chris Jepeway.
34  *
35  * Redistribution and use in source and binary forms, with or without
36  * modification, are permitted provided that the following conditions
37  * are met:
38  *
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  *
42  * 2. Redistributions in binary form must reproduce the above copyright
43  *    notice, this list of conditions and the following disclaimer in the
44  *    documentation and/or other materials provided with the distribution.
45  *
46  * 3. The name of the author may not be used to endorse or promote products
47  *    derived from this software without specific prior written permission.
48  *
49  * 4. Products derived from this software may not be called "Sudo" nor
50  *    may "Sudo" appear in their names without specific prior written
51  *    permission from the author.
52  *
53  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
54  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
55  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
56  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
57  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
58  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
59  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
60  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
61  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
62  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63  */
64
65 /*
66  * XXX - the whole opFOO naming thing is somewhat bogus.
67  *
68  * XXX - the way things are stored for printmatches is stupid,
69  *       they should be stored as elements in an array and then
70  *       list_matches() can format things the way it wants.
71  */
72
73 #include "config.h"
74
75 #include <sys/types.h>
76 #include <sys/param.h>
77 #include <stdio.h>
78 #ifdef STDC_HEADERS
79 # include <stdlib.h>
80 # include <stddef.h>
81 #else
82 # ifdef HAVE_STDLIB_H
83 #  include <stdlib.h>
84 # endif
85 #endif /* STDC_HEADERS */
86 #ifdef HAVE_STRING_H
87 # include <string.h>
88 #else
89 # ifdef HAVE_STRINGS_H
90 #  include <strings.h>
91 # endif
92 #endif /* HAVE_STRING_H */
93 #ifdef HAVE_UNISTD_H
94 # include <unistd.h>
95 #endif /* HAVE_UNISTD_H */
96 #include <pwd.h>
97 #if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
98 # include <malloc.h>
99 #endif /* HAVE_MALLOC_H && !STDC_HEADERS */
100 #if defined(YYBISON) && defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
101 # include <alloca.h>
102 #endif /* YYBISON && HAVE_ALLOCA_H && !__GNUC__ */
103 #ifdef HAVE_LSEARCH
104 # include <search.h>
105 #endif /* HAVE_LSEARCH */
106
107 #include "sudo.h"
108 #include "parse.h"
109
110 #ifndef HAVE_LSEARCH
111 #include "emul/search.h"
112 #endif /* HAVE_LSEARCH */
113
114 #ifndef lint
115 static const char rcsid[] = "$Sudo: parse.yacc,v 1.180 2002/03/16 00:44:47 millert Exp $";
116 #endif /* lint */
117
118 /*
119  * Globals
120  */
121 extern int sudolineno, parse_error;
122 int errorlineno = -1;
123 int clearaliases = TRUE;
124 int printmatches = FALSE;
125 int pedantic = FALSE;
126 int keepall = FALSE;
127 int quiet = FALSE;
128
129 /*
130  * Alias types
131  */
132 #define HOST_ALIAS               1
133 #define CMND_ALIAS               2
134 #define USER_ALIAS               3
135 #define RUNAS_ALIAS              4
136
137 /*
138  * The matching stack, initial space allocated in init_parser().
139  */
140 struct matchstack *match;
141 int top = 0, stacksize = 0;
142
143 #define push \
144     do { \
145         if (top >= stacksize) { \
146             while ((stacksize += STACKINCREMENT) < top); \
147             match = (struct matchstack *) erealloc(match, sizeof(struct matchstack) * stacksize); \
148         } \
149         match[top].user   = -1; \
150         match[top].cmnd   = -1; \
151         match[top].host   = -1; \
152         match[top].runas  = -1; \
153         match[top].nopass = def_flag(I_AUTHENTICATE) ? -1 : TRUE; \
154         top++; \
155     } while (0)
156
157 #define pushcp \
158     do { \
159         if (top >= stacksize) { \
160             while ((stacksize += STACKINCREMENT) < top); \
161             match = (struct matchstack *) erealloc(match, sizeof(struct matchstack) * stacksize); \
162         } \
163         match[top].user   = match[top-1].user; \
164         match[top].cmnd   = match[top-1].cmnd; \
165         match[top].host   = match[top-1].host; \
166         match[top].runas  = match[top-1].runas; \
167         match[top].nopass = match[top-1].nopass; \
168         top++; \
169     } while (0)
170
171 #define pop \
172     { \
173         if (top == 0) \
174             yyerror("matching stack underflow"); \
175         else \
176             top--; \
177     }
178
179 /*
180  * Shortcuts for append()
181  */
182 #define append_cmnd(s, p) append(s, &cm_list[cm_list_len].cmnd, \
183         &cm_list[cm_list_len].cmnd_len, &cm_list[cm_list_len].cmnd_size, p)
184
185 #define append_runas(s, p) append(s, &cm_list[cm_list_len].runas, \
186         &cm_list[cm_list_len].runas_len, &cm_list[cm_list_len].runas_size, p)
187
188 #define append_entries(s, p) append(s, &ga_list[ga_list_len-1].entries, \
189         &ga_list[ga_list_len-1].entries_len, \
190         &ga_list[ga_list_len-1].entries_size, p)
191
192 /*
193  * The stack for printmatches.  A list of allowed commands for the user.
194  */
195 static struct command_match *cm_list = NULL;
196 static size_t cm_list_len = 0, cm_list_size = 0;
197
198 /*
199  * List of Cmnd_Aliases and expansions for `sudo -l'
200  */
201 static int in_alias = FALSE;
202 static size_t ga_list_len = 0, ga_list_size = 0;
203 static struct generic_alias *ga_list = NULL;
204
205 /*
206  * Does this Defaults list pertain to this user?
207  */
208 static int defaults_matches = 0;
209
210 /*
211  * Local protoypes
212  */
213 static int  add_alias           __P((char *, int, int));
214 static void append              __P((char *, char **, size_t *, size_t *, char *));
215 static void expand_ga_list      __P((void));
216 static void expand_match_list   __P((void));
217 static aliasinfo *find_alias    __P((char *, int));
218 static int  more_aliases        __P((void));
219        void init_parser         __P((void));
220        void yyerror             __P((char *));
221
222 void
223 yyerror(s)
224     char *s;
225 {
226     /* Save the line the first error occurred on. */
227     if (errorlineno == -1)
228         errorlineno = sudolineno ? sudolineno - 1 : 0;
229     if (s && !quiet) {
230 #ifndef TRACELEXER
231         (void) fprintf(stderr, ">>> sudoers file: %s, line %d <<<\n", s,
232             sudolineno ? sudolineno - 1 : 0);
233 #else
234         (void) fprintf(stderr, "<*> ");
235 #endif
236     }
237     parse_error = TRUE;
238 }
239
240 #line 214 "parse.yacc"
241 #ifndef YYSTYPE
242 typedef union {
243     char *string;
244     int BOOLEAN;
245     struct sudo_command command;
246     int tok;
247 } yystype;
248 # define YYSTYPE yystype
249 # define YYSTYPE_IS_TRIVIAL 1
250 #endif
251 #ifndef YYDEBUG
252 # define YYDEBUG 0
253 #endif
254
255
256
257 #define YYFINAL         129
258 #define YYFLAG          -32768
259 #define YYNTBASE        29
260
261 /* YYTRANSLATE(YYLEX) -- Bison token number corresponding to YYLEX. */
262 #define YYTRANSLATE(x) ((unsigned)(x) <= 276 ? yytranslate[x] : 70)
263
264 /* YYTRANSLATE[YYLEX] -- Bison token number corresponding to YYLEX. */
265 static const char yytranslate[] =
266 {
267        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
268        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
269        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
270        2,     2,     2,    25,     2,     2,     2,     2,     2,     2,
271        2,     2,     2,    26,    24,    27,     2,     2,     2,     2,
272        2,     2,     2,     2,     2,     2,     2,     2,    22,     2,
273        2,    23,     2,     2,     2,     2,     2,     2,     2,     2,
274        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
275        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
276        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
277        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
278        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
279        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
280        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
281        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
282        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
283        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
284        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
285        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
286        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
287        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
288        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
289        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
290        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
291        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
292        2,     2,     2,     2,     2,     2,     1,     3,     4,     5,
293        6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
294       16,    17,    18,    19,    20,    21,    28
295 };
296
297 #if YYDEBUG
298 static const short yyprhs[] =
299 {
300        0,     0,     2,     5,     7,    10,    11,    15,    18,    21,
301       24,    27,    29,    32,    34,    35,    39,    40,    44,    46,
302       50,    52,    55,    59,    63,    67,    69,    73,    77,    79,
303       82,    84,    86,    88,    90,    92,    94,    98,   102,   104,
304      105,   109,   110,   113,   115,   119,   121,   122,   126,   128,
305      130,   132,   134,   136,   137,   139,   141,   143,   145,   147,
306      149,   153,   154,   159,   161,   165,   167,   171,   172,   177,
307      179,   183,   185,   189,   190,   195,   197,   201,   202,   207,
308      209,   213,   215,   218,   220,   222,   224,   226
309 };
310 static const short yyrhs[] =
311 {
312       30,     0,    29,    30,     0,    17,     0,     1,    17,     0,
313        0,    31,    67,    38,     0,    20,    64,     0,    18,    53,
314        0,    19,    57,     0,    21,    61,     0,    32,     0,    33,
315       36,     0,    10,     0,     0,    12,    34,    67,     0,     0,
316       11,    35,    56,     0,    37,     0,    37,    24,    36,     0,
317        5,     0,    25,     5,     0,     5,    23,     9,     0,     5,
318       26,     9,     0,     5,    27,     9,     0,    39,     0,    38,
319       22,    39,     0,    56,    23,    42,     0,    41,     0,    25,
320       41,     0,    16,     0,     6,     0,     7,     0,     9,     0,
321        4,     0,    43,     0,    42,    24,    43,     0,    46,    51,
322       44,     0,    52,     0,     0,    25,    45,    52,     0,     0,
323       13,    47,     0,    48,     0,    47,    24,    48,     0,    50,
324        0,     0,    25,    49,    50,     0,     9,     0,     8,     0,
325        7,     0,     4,     0,    16,     0,     0,    14,     0,    15,
326        0,    16,     0,     4,     0,     3,     0,    54,     0,    53,
327       22,    54,     0,     0,     4,    55,    23,    56,     0,    40,
328        0,    56,    24,    40,     0,    58,     0,    57,    22,    58,
329        0,     0,     4,    59,    23,    60,     0,    44,     0,    60,
330       24,    44,     0,    62,     0,    61,    22,    62,     0,     0,
331        4,    63,    23,    47,     0,    65,     0,    64,    22,    65,
332        0,     0,     4,    66,    23,    67,     0,    68,     0,    67,
333       24,    68,     0,    69,     0,    25,    69,     0,     9,     0,
334        8,     0,     7,     0,     4,     0,    16,     0
335 };
336
337 #endif
338
339 #if YYDEBUG
340 /* YYRLINE[YYN] -- source line where rule number YYN was defined. */
341 static const short yyrline[] =
342 {
343        0,   259,   260,   263,   265,   267,   267,   271,   273,   275,
344      277,   279,   283,   285,   288,   288,   292,   292,   298,   299,
345      301,   309,   317,   326,   335,   345,   346,   349,   364,   368,
346      373,   376,   383,   390,   397,   421,   422,   425,   452,   456,
347      456,   470,   493,   498,   499,   508,   509,   509,   522,   536,
348      550,   564,   593,   605,   615,   621,   629,   642,   671,   699,
349      700,   703,   703,   711,   712,   715,   716,   719,   719,   740,
350      741,   744,   745,   748,   748,   767,   768,   771,   771,   780,
351      781,   784,   788,   793,   800,   807,   814,   834
352 };
353 #endif
354
355
356 #if (YYDEBUG) || defined YYERROR_VERBOSE
357
358 /* YYTNAME[TOKEN_NUM] -- String name of the token TOKEN_NUM. */
359 static const char *const yytname[] =
360 {
361   "$", "error", "$undefined.", "COMMAND", "ALIAS", "DEFVAR", "NTWKADDR", 
362   "NETGROUP", "USERGROUP", "WORD", "DEFAULTS", "DEFAULTS_HOST", 
363   "DEFAULTS_USER", "RUNAS", "NOPASSWD", "PASSWD", "ALL", "COMMENT", 
364   "HOSTALIAS", "CMNDALIAS", "USERALIAS", "RUNASALIAS", "':'", "'='", 
365   "','", "'!'", "'+'", "'-'", "ERROR", "file", "entry", "@1", 
366   "defaults_line", "defaults_type", "@2", "@3", "defaults_list", 
367   "defaults_entry", "privileges", "privilege", "ophost", "host", 
368   "cmndspeclist", "cmndspec", "opcmnd", "@4", "runasspec", "runaslist", 
369   "oprunasuser", "@5", "runasuser", "nopasswd", "cmnd", "hostaliases", 
370   "hostalias", "@6", "hostlist", "cmndaliases", "cmndalias", "@7", 
371   "cmndlist", "runasaliases", "runasalias", "@8", "useraliases", 
372   "useralias", "@9", "userlist", "opuser", "user", 0
373 };
374 #endif
375
376 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
377 static const short yyr1[] =
378 {
379        0,    29,    29,    30,    30,    31,    30,    30,    30,    30,
380       30,    30,    32,    33,    34,    33,    35,    33,    36,    36,
381       37,    37,    37,    37,    37,    38,    38,    39,    40,    40,
382       41,    41,    41,    41,    41,    42,    42,    43,    44,    45,
383       44,    46,    46,    47,    47,    48,    49,    48,    50,    50,
384       50,    50,    50,    51,    51,    51,    52,    52,    52,    53,
385       53,    55,    54,    56,    56,    57,    57,    59,    58,    60,
386       60,    61,    61,    63,    62,    64,    64,    66,    65,    67,
387       67,    68,    68,    69,    69,    69,    69,    69
388 };
389
390 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
391 static const short yyr2[] =
392 {
393        0,     1,     2,     1,     2,     0,     3,     2,     2,     2,
394        2,     1,     2,     1,     0,     3,     0,     3,     1,     3,
395        1,     2,     3,     3,     3,     1,     3,     3,     1,     2,
396        1,     1,     1,     1,     1,     1,     3,     3,     1,     0,
397        3,     0,     2,     1,     3,     1,     0,     3,     1,     1,
398        1,     1,     1,     0,     1,     1,     1,     1,     1,     1,
399        3,     0,     4,     1,     3,     1,     3,     0,     4,     1,
400        3,     1,     3,     0,     4,     1,     3,     0,     4,     1,
401        3,     1,     2,     1,     1,     1,     1,     1
402 };
403
404 /* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
405    doesn't specify something else to do.  Zero means the default is an
406    error. */
407 static const short yydefact[] =
408 {
409        0,     0,    13,    16,    14,     3,     0,     0,     0,     0,
410        0,     1,     0,    11,     0,     4,     0,     0,    61,     8,
411       59,    67,     9,    65,    77,     7,    75,    73,    10,    71,
412        2,    86,    85,    84,    83,    87,     0,     0,    79,    81,
413       20,     0,    12,    18,    34,    31,    32,    33,    30,     0,
414       63,    28,    17,    15,     0,     0,     0,     0,     0,     0,
415        0,     0,    82,     0,     6,    25,     0,     0,     0,     0,
416       21,     0,    29,     0,     0,    60,     0,    66,     0,    76,
417        0,    72,    80,     0,    41,    22,    23,    24,    19,    64,
418       62,    58,    57,    56,    39,    69,    38,    68,    78,    51,
419       50,    49,    48,    52,    46,    74,    43,    45,    26,     0,
420       27,    35,    53,     0,     0,     0,     0,    42,    41,    54,
421       55,     0,    40,    70,    47,    44,    36,    37,     0,     0
422 };
423
424 static const short yydefgoto[] =
425 {
426       10,    11,    12,    13,    14,    17,    16,    42,    43,    64,
427       65,    50,    51,   110,   111,    95,   113,   112,   105,   106,
428      115,   107,   121,    96,    19,    20,    54,    66,    22,    23,
429       56,    97,    28,    29,    60,    25,    26,    58,    37,    38,
430       39
431 };
432
433 static const short yypact[] =
434 {
435       24,   -10,-32768,-32768,-32768,-32768,    12,    20,    35,    50,
436        2,-32768,    48,-32768,    33,-32768,    68,    48,-32768,    15,
437   -32768,-32768,    40,-32768,-32768,    41,-32768,-32768,    45,-32768,
438   -32768,-32768,-32768,-32768,-32768,-32768,    78,    44,-32768,-32768,
439       83,    65,-32768,    47,-32768,-32768,-32768,-32768,-32768,    92,
440   -32768,-32768,    59,    66,    69,    12,    79,    20,    84,    35,
441       88,    50,-32768,    48,    67,-32768,     6,    82,    86,   104,
442   -32768,    33,-32768,    68,    68,-32768,     1,-32768,    48,-32768,
443       72,-32768,-32768,    68,   101,-32768,-32768,-32768,-32768,-32768,
444       59,-32768,-32768,-32768,-32768,-32768,-32768,    91,    66,-32768,
445   -32768,-32768,-32768,-32768,-32768,    93,-32768,-32768,-32768,    72,
446       94,-32768,    32,    62,     1,    96,    72,    93,   101,-32768,
447   -32768,     1,-32768,-32768,-32768,-32768,-32768,-32768,   116,-32768
448 };
449
450 static const short yypgoto[] =
451 {
452   -32768,   109,-32768,-32768,-32768,-32768,-32768,    49,-32768,-32768,
453       38,    51,    73,-32768,     5,  -106,-32768,-32768,    16,    10,
454   -32768,    13,-32768,    14,-32768,    74,-32768,   -15,-32768,    75,
455   -32768,-32768,-32768,    70,-32768,-32768,    71,-32768,   -17,    76,
456       97
457 };
458
459
460 #define YYLAST          139
461
462
463 static const short yytable[] =
464 {
465       53,    52,   128,     1,    91,    92,    -5,    15,   123,    -5,
466       -5,    -5,     2,     3,     4,   127,    18,    93,    -5,     5,
467        6,     7,     8,     9,    21,     1,    94,    -5,    -5,    84,
468       73,    -5,    -5,    -5,     2,     3,     4,    55,    40,    24,
469       -5,     5,     6,     7,     8,     9,   119,   120,    44,    -5,
470       45,    46,    31,    47,    27,    32,    33,    34,    41,    90,
471       48,    98,    57,    59,    35,    91,    92,    61,    63,    49,
472       70,    71,    44,    36,    45,    46,    99,    47,    93,   100,
473      101,   102,    31,    73,    48,    32,    33,    34,   103,    83,
474       63,    85,    74,    49,    35,    86,    44,   104,    45,    46,
475       99,    47,    76,   100,   101,   102,    67,    78,    48,    68,
476       69,    80,   103,    87,   109,   114,   129,   116,   118,    30,
477       88,   108,    72,   126,    89,   117,   125,   122,   124,    75,
478       79,    81,    77,    62,     0,     0,     0,     0,     0,    82
479 };
480
481 static const short yycheck[] =
482 {
483       17,    16,     0,     1,     3,     4,     4,    17,   114,     7,
484        8,     9,    10,    11,    12,   121,     4,    16,    16,    17,
485       18,    19,    20,    21,     4,     1,    25,    25,     4,    23,
486       24,     7,     8,     9,    10,    11,    12,    22,     5,     4,
487       16,    17,    18,    19,    20,    21,    14,    15,     4,    25,
488        6,     7,     4,     9,     4,     7,     8,     9,    25,    74,
489       16,    78,    22,    22,    16,     3,     4,    22,    24,    25,
490        5,    24,     4,    25,     6,     7,     4,     9,    16,     7,
491        8,     9,     4,    24,    16,     7,     8,     9,    16,    22,
492       24,     9,    23,    25,    16,     9,     4,    25,     6,     7,
493        4,     9,    23,     7,     8,     9,    23,    23,    16,    26,
494       27,    23,    16,     9,    13,    24,     0,    24,    24,    10,
495       71,    83,    49,   118,    73,   109,   116,   113,   115,    55,
496       59,    61,    57,    36,    -1,    -1,    -1,    -1,    -1,    63
497 };
498 /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
499 #line 3 "/usr/share/bison/bison.simple"
500
501 /* Skeleton output parser for bison,
502
503    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002 Free Software
504    Foundation, Inc.
505
506    This program is free software; you can redistribute it and/or modify
507    it under the terms of the GNU General Public License as published by
508    the Free Software Foundation; either version 2, or (at your option)
509    any later version.
510
511    This program is distributed in the hope that it will be useful,
512    but WITHOUT ANY WARRANTY; without even the implied warranty of
513    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
514    GNU General Public License for more details.
515
516    You should have received a copy of the GNU General Public License
517    along with this program; if not, write to the Free Software
518    Foundation, Inc., 59 Temple Place - Suite 330,
519    Boston, MA 02111-1307, USA.  */
520
521 /* As a special exception, when this file is copied by Bison into a
522    Bison output file, you may use that output file without restriction.
523    This special exception was added by the Free Software Foundation
524    in version 1.24 of Bison.  */
525
526 /* This is the parser code that is written into each bison parser when
527    the %semantic_parser declaration is not specified in the grammar.
528    It was written by Richard Stallman by simplifying the hairy parser
529    used when %semantic_parser is specified.  */
530
531 /* All symbols defined below should begin with yy or YY, to avoid
532    infringing on user name space.  This should be done even for local
533    variables, as they might otherwise be expanded by user macros.
534    There are some unavoidable exceptions within include files to
535    define necessary library symbols; they are noted "INFRINGES ON
536    USER NAME SPACE" below.  */
537
538 #if ! defined (yyoverflow) || defined (YYERROR_VERBOSE)
539
540 /* The parser invokes alloca or malloc; define the necessary symbols.  */
541
542 # if YYSTACK_USE_ALLOCA
543 #  define YYSTACK_ALLOC alloca
544 # else
545 #  ifndef YYSTACK_USE_ALLOCA
546 #   if defined (alloca) || defined (_ALLOCA_H)
547 #    define YYSTACK_ALLOC alloca
548 #   else
549 #    ifdef __GNUC__
550 #     define YYSTACK_ALLOC __builtin_alloca
551 #    endif
552 #   endif
553 #  endif
554 # endif
555
556 # ifdef YYSTACK_ALLOC
557    /* Pacify GCC's `empty if-body' warning. */
558 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
559 # else
560 #  if defined (__STDC__) || defined (__cplusplus)
561 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
562 #   define YYSIZE_T size_t
563 #  endif
564 #  define YYSTACK_ALLOC malloc
565 #  define YYSTACK_FREE free
566 # endif
567 #endif /* ! defined (yyoverflow) || defined (YYERROR_VERBOSE) */
568
569
570 #if (! defined (yyoverflow) \
571      && (! defined (__cplusplus) \
572          || (YYLTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
573
574 /* A type that is properly aligned for any stack member.  */
575 union yyalloc
576 {
577   short yyss;
578   YYSTYPE yyvs;
579 # if YYLSP_NEEDED
580   YYLTYPE yyls;
581 # endif
582 };
583
584 /* The size of the maximum gap between one aligned stack and the next.  */
585 # define YYSTACK_GAP_MAX (sizeof (union yyalloc) - 1)
586
587 /* The size of an array large to enough to hold all stacks, each with
588    N elements.  */
589 # if YYLSP_NEEDED
590 #  define YYSTACK_BYTES(N) \
591      ((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE))      \
592       + 2 * YYSTACK_GAP_MAX)
593 # else
594 #  define YYSTACK_BYTES(N) \
595      ((N) * (sizeof (short) + sizeof (YYSTYPE))                         \
596       + YYSTACK_GAP_MAX)
597 # endif
598
599 /* Copy COUNT objects from FROM to TO.  The source and destination do
600    not overlap.  */
601 # ifndef YYCOPY
602 #  if 1 < __GNUC__
603 #   define YYCOPY(To, From, Count) \
604       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
605 #  else
606 #   define YYCOPY(To, From, Count)              \
607       do                                        \
608         {                                       \
609           register YYSIZE_T yyi;                \
610           for (yyi = 0; yyi < (Count); yyi++)   \
611             (To)[yyi] = (From)[yyi];            \
612         }                                       \
613       while (0)
614 #  endif
615 # endif
616
617 /* Relocate STACK from its old location to the new one.  The
618    local variables YYSIZE and YYSTACKSIZE give the old and new number of
619    elements in the stack, and YYPTR gives the new location of the
620    stack.  Advance YYPTR to a properly aligned location for the next
621    stack.  */
622 # define YYSTACK_RELOCATE(Stack)                                        \
623     do                                                                  \
624       {                                                                 \
625         YYSIZE_T yynewbytes;                                            \
626         YYCOPY (&yyptr->Stack, Stack, yysize);                          \
627         Stack = &yyptr->Stack;                                          \
628         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAX;   \
629         yyptr += yynewbytes / sizeof (*yyptr);                          \
630       }                                                                 \
631     while (0)
632
633 #endif
634
635
636 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
637 # define YYSIZE_T __SIZE_TYPE__
638 #endif
639 #if ! defined (YYSIZE_T) && defined (size_t)
640 # define YYSIZE_T size_t
641 #endif
642 #if ! defined (YYSIZE_T)
643 # if defined (__STDC__) || defined (__cplusplus)
644 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
645 #  define YYSIZE_T size_t
646 # endif
647 #endif
648 #if ! defined (YYSIZE_T)
649 # define YYSIZE_T unsigned int
650 #endif
651
652 #define yyerrok         (yyerrstatus = 0)
653 #define yyclearin       (yychar = YYEMPTY)
654 #define YYEMPTY         -2
655 #define YYEOF           0
656 #define YYACCEPT        goto yyacceptlab
657 #define YYABORT         goto yyabortlab
658 #define YYERROR         goto yyerrlab1
659 /* Like YYERROR except do call yyerror.  This remains here temporarily
660    to ease the transition to the new meaning of YYERROR, for GCC.
661    Once GCC version 2 has supplanted version 1, this can go.  */
662 #define YYFAIL          goto yyerrlab
663 #define YYRECOVERING()  (!!yyerrstatus)
664 #define YYBACKUP(Token, Value)                                  \
665 do                                                              \
666   if (yychar == YYEMPTY && yylen == 1)                          \
667     {                                                           \
668       yychar = (Token);                                         \
669       yylval = (Value);                                         \
670       yychar1 = YYTRANSLATE (yychar);                           \
671       YYPOPSTACK;                                               \
672       goto yybackup;                                            \
673     }                                                           \
674   else                                                          \
675     {                                                           \
676       yyerror ("syntax error: cannot back up");                 \
677       YYERROR;                                                  \
678     }                                                           \
679 while (0)
680
681 #define YYTERROR        1
682 #define YYERRCODE       256
683
684
685 /* YYLLOC_DEFAULT -- Compute the default location (before the actions
686    are run).
687
688    When YYLLOC_DEFAULT is run, CURRENT is set the location of the
689    first token.  By default, to implement support for ranges, extend
690    its range to the last symbol.  */
691
692 #ifndef YYLLOC_DEFAULT
693 # define YYLLOC_DEFAULT(Current, Rhs, N)        \
694    Current.last_line   = Rhs[N].last_line;      \
695    Current.last_column = Rhs[N].last_column;
696 #endif
697
698
699 /* YYLEX -- calling `yylex' with the right arguments.  */
700
701 #if YYPURE
702 # if YYLSP_NEEDED
703 #  ifdef YYLEX_PARAM
704 #   define YYLEX                yylex (&yylval, &yylloc, YYLEX_PARAM)
705 #  else
706 #   define YYLEX                yylex (&yylval, &yylloc)
707 #  endif
708 # else /* !YYLSP_NEEDED */
709 #  ifdef YYLEX_PARAM
710 #   define YYLEX                yylex (&yylval, YYLEX_PARAM)
711 #  else
712 #   define YYLEX                yylex (&yylval)
713 #  endif
714 # endif /* !YYLSP_NEEDED */
715 #else /* !YYPURE */
716 # define YYLEX                  yylex ()
717 #endif /* !YYPURE */
718
719
720 /* Enable debugging if requested.  */
721 #if YYDEBUG
722
723 # ifndef YYFPRINTF
724 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
725 #  define YYFPRINTF fprintf
726 # endif
727
728 # define YYDPRINTF(Args)                        \
729 do {                                            \
730   if (yydebug)                                  \
731     YYFPRINTF Args;                             \
732 } while (0)
733 /* Nonzero means print parse trace.  It is left uninitialized so that
734    multiple parsers can coexist.  */
735 int yydebug;
736 #else /* !YYDEBUG */
737 # define YYDPRINTF(Args)
738 #endif /* !YYDEBUG */
739
740 /* YYINITDEPTH -- initial size of the parser's stacks.  */
741 #ifndef YYINITDEPTH
742 # define YYINITDEPTH 200
743 #endif
744
745 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
746    if the built-in stack extension method is used).
747
748    Do not make this value too large; the results are undefined if
749    SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
750    evaluated with infinite-precision integer arithmetic.  */
751
752 #if YYMAXDEPTH == 0
753 # undef YYMAXDEPTH
754 #endif
755
756 #ifndef YYMAXDEPTH
757 # define YYMAXDEPTH 10000
758 #endif
759 \f
760 #ifdef YYERROR_VERBOSE
761
762 # ifndef yystrlen
763 #  if defined (__GLIBC__) && defined (_STRING_H)
764 #   define yystrlen strlen
765 #  else
766 /* Return the length of YYSTR.  */
767 static YYSIZE_T
768 #   if defined (__STDC__) || defined (__cplusplus)
769 yystrlen (const char *yystr)
770 #   else
771 yystrlen (yystr)
772      const char *yystr;
773 #   endif
774 {
775   register const char *yys = yystr;
776
777   while (*yys++ != '\0')
778     continue;
779
780   return yys - yystr - 1;
781 }
782 #  endif
783 # endif
784
785 # ifndef yystpcpy
786 #  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
787 #   define yystpcpy stpcpy
788 #  else
789 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
790    YYDEST.  */
791 static char *
792 #   if defined (__STDC__) || defined (__cplusplus)
793 yystpcpy (char *yydest, const char *yysrc)
794 #   else
795 yystpcpy (yydest, yysrc)
796      char *yydest;
797      const char *yysrc;
798 #   endif
799 {
800   register char *yyd = yydest;
801   register const char *yys = yysrc;
802
803   while ((*yyd++ = *yys++) != '\0')
804     continue;
805
806   return yyd - 1;
807 }
808 #  endif
809 # endif
810 #endif
811 \f
812 #line 315 "/usr/share/bison/bison.simple"
813
814
815 /* The user can define YYPARSE_PARAM as the name of an argument to be passed
816    into yyparse.  The argument should have type void *.
817    It should actually point to an object.
818    Grammar actions can access the variable by casting it
819    to the proper pointer type.  */
820
821 #ifdef YYPARSE_PARAM
822 # if defined (__STDC__) || defined (__cplusplus)
823 #  define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
824 #  define YYPARSE_PARAM_DECL
825 # else
826 #  define YYPARSE_PARAM_ARG YYPARSE_PARAM
827 #  define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
828 # endif
829 #else /* !YYPARSE_PARAM */
830 # define YYPARSE_PARAM_ARG
831 # define YYPARSE_PARAM_DECL
832 #endif /* !YYPARSE_PARAM */
833
834 /* Prevent warning if -Wstrict-prototypes.  */
835 #ifdef __GNUC__
836 # ifdef YYPARSE_PARAM
837 int yyparse (void *);
838 # else
839 int yyparse (void);
840 # endif
841 #endif
842
843 /* YY_DECL_VARIABLES -- depending whether we use a pure parser,
844    variables are global, or local to YYPARSE.  */
845
846 #define YY_DECL_NON_LSP_VARIABLES                       \
847 /* The lookahead symbol.  */                            \
848 int yychar;                                             \
849                                                         \
850 /* The semantic value of the lookahead symbol. */       \
851 YYSTYPE yylval;                                         \
852                                                         \
853 /* Number of parse errors so far.  */                   \
854 int yynerrs;
855
856 #if YYLSP_NEEDED
857 # define YY_DECL_VARIABLES                      \
858 YY_DECL_NON_LSP_VARIABLES                       \
859                                                 \
860 /* Location data for the lookahead symbol.  */  \
861 YYLTYPE yylloc;
862 #else
863 # define YY_DECL_VARIABLES                      \
864 YY_DECL_NON_LSP_VARIABLES
865 #endif
866
867
868 /* If nonreentrant, generate the variables here. */
869
870 #if !YYPURE
871 YY_DECL_VARIABLES
872 #endif  /* !YYPURE */
873
874 int
875 yyparse (YYPARSE_PARAM_ARG)
876      YYPARSE_PARAM_DECL
877 {
878   /* If reentrant, generate the variables here. */
879 #if YYPURE
880   YY_DECL_VARIABLES
881 #endif  /* !YYPURE */
882
883   register int yystate;
884   register int yyn;
885   int yyresult;
886   /* Number of tokens to shift before error messages enabled.  */
887   int yyerrstatus;
888   /* Lookahead token as an internal (translated) token number.  */
889   int yychar1 = 0;
890
891   /* Three stacks and their tools:
892      `yyss': related to states,
893      `yyvs': related to semantic values,
894      `yyls': related to locations.
895
896      Refer to the stacks thru separate pointers, to allow yyoverflow
897      to reallocate them elsewhere.  */
898
899   /* The state stack. */
900   short yyssa[YYINITDEPTH];
901   short *yyss = yyssa;
902   register short *yyssp;
903
904   /* The semantic value stack.  */
905   YYSTYPE yyvsa[YYINITDEPTH];
906   YYSTYPE *yyvs = yyvsa;
907   register YYSTYPE *yyvsp;
908
909 #if YYLSP_NEEDED
910   /* The location stack.  */
911   YYLTYPE yylsa[YYINITDEPTH];
912   YYLTYPE *yyls = yylsa;
913   YYLTYPE *yylsp;
914 #endif
915
916 #if YYLSP_NEEDED
917 # define YYPOPSTACK   (yyvsp--, yyssp--, yylsp--)
918 #else
919 # define YYPOPSTACK   (yyvsp--, yyssp--)
920 #endif
921
922   YYSIZE_T yystacksize = YYINITDEPTH;
923
924
925   /* The variables used to return semantic value and location from the
926      action routines.  */
927   YYSTYPE yyval;
928 #if YYLSP_NEEDED
929   YYLTYPE yyloc;
930 #endif
931
932   /* When reducing, the number of symbols on the RHS of the reduced
933      rule. */
934   int yylen;
935
936   YYDPRINTF ((stderr, "Starting parse\n"));
937
938   yystate = 0;
939   yyerrstatus = 0;
940   yynerrs = 0;
941   yychar = YYEMPTY;             /* Cause a token to be read.  */
942
943   /* Initialize stack pointers.
944      Waste one element of value and location stack
945      so that they stay on the same level as the state stack.
946      The wasted elements are never initialized.  */
947
948   yyssp = yyss;
949   yyvsp = yyvs;
950 #if YYLSP_NEEDED
951   yylsp = yyls;
952 #endif
953   goto yysetstate;
954
955 /*------------------------------------------------------------.
956 | yynewstate -- Push a new state, which is found in yystate.  |
957 `------------------------------------------------------------*/
958  yynewstate:
959   /* In all cases, when you get here, the value and location stacks
960      have just been pushed. so pushing a state here evens the stacks.
961      */
962   yyssp++;
963
964  yysetstate:
965   *yyssp = yystate;
966
967   if (yyssp >= yyss + yystacksize - 1)
968     {
969       /* Get the current used size of the three stacks, in elements.  */
970       YYSIZE_T yysize = yyssp - yyss + 1;
971
972 #ifdef yyoverflow
973       {
974         /* Give user a chance to reallocate the stack. Use copies of
975            these so that the &'s don't force the real ones into
976            memory.  */
977         YYSTYPE *yyvs1 = yyvs;
978         short *yyss1 = yyss;
979
980         /* Each stack pointer address is followed by the size of the
981            data in use in that stack, in bytes.  */
982 # if YYLSP_NEEDED
983         YYLTYPE *yyls1 = yyls;
984         /* This used to be a conditional around just the two extra args,
985            but that might be undefined if yyoverflow is a macro.  */
986         yyoverflow ("parser stack overflow",
987                     &yyss1, yysize * sizeof (*yyssp),
988                     &yyvs1, yysize * sizeof (*yyvsp),
989                     &yyls1, yysize * sizeof (*yylsp),
990                     &yystacksize);
991         yyls = yyls1;
992 # else
993         yyoverflow ("parser stack overflow",
994                     &yyss1, yysize * sizeof (*yyssp),
995                     &yyvs1, yysize * sizeof (*yyvsp),
996                     &yystacksize);
997 # endif
998         yyss = yyss1;
999         yyvs = yyvs1;
1000       }
1001 #else /* no yyoverflow */
1002 # ifndef YYSTACK_RELOCATE
1003       goto yyoverflowlab;
1004 # else
1005       /* Extend the stack our own way.  */
1006       if (yystacksize >= YYMAXDEPTH)
1007         goto yyoverflowlab;
1008       yystacksize *= 2;
1009       if (yystacksize > YYMAXDEPTH)
1010         yystacksize = YYMAXDEPTH;
1011
1012       {
1013         short *yyss1 = yyss;
1014         union yyalloc *yyptr =
1015           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1016         if (! yyptr)
1017           goto yyoverflowlab;
1018         YYSTACK_RELOCATE (yyss);
1019         YYSTACK_RELOCATE (yyvs);
1020 # if YYLSP_NEEDED
1021         YYSTACK_RELOCATE (yyls);
1022 # endif
1023 # undef YYSTACK_RELOCATE
1024         if (yyss1 != yyssa)
1025           YYSTACK_FREE (yyss1);
1026       }
1027 # endif
1028 #endif /* no yyoverflow */
1029
1030       yyssp = yyss + yysize - 1;
1031       yyvsp = yyvs + yysize - 1;
1032 #if YYLSP_NEEDED
1033       yylsp = yyls + yysize - 1;
1034 #endif
1035
1036       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1037                   (unsigned long int) yystacksize));
1038
1039       if (yyssp >= yyss + yystacksize - 1)
1040         YYABORT;
1041     }
1042
1043   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1044
1045   goto yybackup;
1046
1047
1048 /*-----------.
1049 | yybackup.  |
1050 `-----------*/
1051 yybackup:
1052
1053 /* Do appropriate processing given the current state.  */
1054 /* Read a lookahead token if we need one and don't already have one.  */
1055 /* yyresume: */
1056
1057   /* First try to decide what to do without reference to lookahead token.  */
1058
1059   yyn = yypact[yystate];
1060   if (yyn == YYFLAG)
1061     goto yydefault;
1062
1063   /* Not known => get a lookahead token if don't already have one.  */
1064
1065   /* yychar is either YYEMPTY or YYEOF
1066      or a valid token in external form.  */
1067
1068   if (yychar == YYEMPTY)
1069     {
1070       YYDPRINTF ((stderr, "Reading a token: "));
1071       yychar = YYLEX;
1072     }
1073
1074   /* Convert token to internal form (in yychar1) for indexing tables with */
1075
1076   if (yychar <= 0)              /* This means end of input. */
1077     {
1078       yychar1 = 0;
1079       yychar = YYEOF;           /* Don't call YYLEX any more */
1080
1081       YYDPRINTF ((stderr, "Now at end of input.\n"));
1082     }
1083   else
1084     {
1085       yychar1 = YYTRANSLATE (yychar);
1086
1087 #if YYDEBUG
1088      /* We have to keep this `#if YYDEBUG', since we use variables
1089         which are defined only if `YYDEBUG' is set.  */
1090       if (yydebug)
1091         {
1092           YYFPRINTF (stderr, "Next token is %d (%s",
1093                      yychar, yytname[yychar1]);
1094           /* Give the individual parser a way to print the precise
1095              meaning of a token, for further debugging info.  */
1096 # ifdef YYPRINT
1097           YYPRINT (stderr, yychar, yylval);
1098 # endif
1099           YYFPRINTF (stderr, ")\n");
1100         }
1101 #endif
1102     }
1103
1104   yyn += yychar1;
1105   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
1106     goto yydefault;
1107
1108   yyn = yytable[yyn];
1109
1110   /* yyn is what to do for this token type in this state.
1111      Negative => reduce, -yyn is rule number.
1112      Positive => shift, yyn is new state.
1113        New state is final state => don't bother to shift,
1114        just return success.
1115      0, or most negative number => error.  */
1116
1117   if (yyn < 0)
1118     {
1119       if (yyn == YYFLAG)
1120         goto yyerrlab;
1121       yyn = -yyn;
1122       goto yyreduce;
1123     }
1124   else if (yyn == 0)
1125     goto yyerrlab;
1126
1127   if (yyn == YYFINAL)
1128     YYACCEPT;
1129
1130   /* Shift the lookahead token.  */
1131   YYDPRINTF ((stderr, "Shifting token %d (%s), ",
1132               yychar, yytname[yychar1]));
1133
1134   /* Discard the token being shifted unless it is eof.  */
1135   if (yychar != YYEOF)
1136     yychar = YYEMPTY;
1137
1138   *++yyvsp = yylval;
1139 #if YYLSP_NEEDED
1140   *++yylsp = yylloc;
1141 #endif
1142
1143   /* Count tokens shifted since error; after three, turn off error
1144      status.  */
1145   if (yyerrstatus)
1146     yyerrstatus--;
1147
1148   yystate = yyn;
1149   goto yynewstate;
1150
1151
1152 /*-----------------------------------------------------------.
1153 | yydefault -- do the default action for the current state.  |
1154 `-----------------------------------------------------------*/
1155 yydefault:
1156   yyn = yydefact[yystate];
1157   if (yyn == 0)
1158     goto yyerrlab;
1159   goto yyreduce;
1160
1161
1162 /*-----------------------------.
1163 | yyreduce -- Do a reduction.  |
1164 `-----------------------------*/
1165 yyreduce:
1166   /* yyn is the number of a rule to reduce with.  */
1167   yylen = yyr2[yyn];
1168
1169   /* If YYLEN is nonzero, implement the default value of the action:
1170      `$$ = $1'.
1171
1172      Otherwise, the following line sets YYVAL to the semantic value of
1173      the lookahead token.  This behavior is undocumented and Bison
1174      users should not rely upon it.  Assigning to YYVAL
1175      unconditionally makes the parser a bit smaller, and it avoids a
1176      GCC warning that YYVAL may be used uninitialized.  */
1177   yyval = yyvsp[1-yylen];
1178
1179 #if YYLSP_NEEDED
1180   /* Similarly for the default location.  Let the user run additional
1181      commands if for instance locations are ranges.  */
1182   yyloc = yylsp[1-yylen];
1183   YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
1184 #endif
1185
1186 #if YYDEBUG
1187   /* We have to keep this `#if YYDEBUG', since we use variables which
1188      are defined only if `YYDEBUG' is set.  */
1189   if (yydebug)
1190     {
1191       int yyi;
1192
1193       YYFPRINTF (stderr, "Reducing via rule %d (line %d), ",
1194                  yyn, yyrline[yyn]);
1195
1196       /* Print the symbols being reduced, and their result.  */
1197       for (yyi = yyprhs[yyn]; yyrhs[yyi] > 0; yyi++)
1198         YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
1199       YYFPRINTF (stderr, " -> %s\n", yytname[yyr1[yyn]]);
1200     }
1201 #endif
1202
1203   switch (yyn) {
1204
1205 case 3:
1206 #line 264 "parse.yacc"
1207 { ; }
1208     break;
1209 case 4:
1210 #line 266 "parse.yacc"
1211 { yyerrok; }
1212     break;
1213 case 5:
1214 #line 267 "parse.yacc"
1215 { push; }
1216     break;
1217 case 6:
1218 #line 267 "parse.yacc"
1219 {
1220                             while (top && user_matches != TRUE)
1221                                 pop;
1222                         }
1223     break;
1224 case 7:
1225 #line 272 "parse.yacc"
1226 { ; }
1227     break;
1228 case 8:
1229 #line 274 "parse.yacc"
1230 { ; }
1231     break;
1232 case 9:
1233 #line 276 "parse.yacc"
1234 { ; }
1235     break;
1236 case 10:
1237 #line 278 "parse.yacc"
1238 { ; }
1239     break;
1240 case 11:
1241 #line 280 "parse.yacc"
1242 { ; }
1243     break;
1244 case 13:
1245 #line 285 "parse.yacc"
1246 {
1247                             defaults_matches = TRUE;
1248                         }
1249     break;
1250 case 14:
1251 #line 288 "parse.yacc"
1252 { push; }
1253     break;
1254 case 15:
1255 #line 288 "parse.yacc"
1256 {
1257                             defaults_matches = user_matches;
1258                             pop;
1259                         }
1260     break;
1261 case 16:
1262 #line 292 "parse.yacc"
1263 { push; }
1264     break;
1265 case 17:
1266 #line 292 "parse.yacc"
1267 {
1268                             defaults_matches = host_matches;
1269                             pop;
1270                         }
1271     break;
1272 case 20:
1273 #line 301 "parse.yacc"
1274 {
1275                             if (defaults_matches == TRUE &&
1276                                 !set_default(yyvsp[0].string, NULL, TRUE)) {
1277                                 yyerror(NULL);
1278                                 YYERROR;
1279                             }
1280                             free(yyvsp[0].string);
1281                         }
1282     break;
1283 case 21:
1284 #line 309 "parse.yacc"
1285 {
1286                             if (defaults_matches == TRUE &&
1287                                 !set_default(yyvsp[0].string, NULL, FALSE)) {
1288                                 yyerror(NULL);
1289                                 YYERROR;
1290                             }
1291                             free(yyvsp[0].string);
1292                         }
1293     break;
1294 case 22:
1295 #line 317 "parse.yacc"
1296 {
1297                             if (defaults_matches == TRUE &&
1298                                 !set_default(yyvsp[-2].string, yyvsp[0].string, TRUE)) {
1299                                 yyerror(NULL);
1300                                 YYERROR;
1301                             }
1302                             free(yyvsp[-2].string);
1303                             free(yyvsp[0].string);
1304                         }
1305     break;
1306 case 23:
1307 #line 326 "parse.yacc"
1308 {
1309                             if (defaults_matches == TRUE &&
1310                                 !set_default(yyvsp[-2].string, yyvsp[0].string, '+')) {
1311                                 yyerror(NULL);
1312                                 YYERROR;
1313                             }
1314                             free(yyvsp[-2].string);
1315                             free(yyvsp[0].string);
1316                         }
1317     break;
1318 case 24:
1319 #line 335 "parse.yacc"
1320 {
1321                             if (defaults_matches == TRUE &&
1322                                 !set_default(yyvsp[-2].string, yyvsp[0].string, '-')) {
1323                                 yyerror(NULL);
1324                                 YYERROR;
1325                             }
1326                             free(yyvsp[-2].string);
1327                             free(yyvsp[0].string);
1328                         }
1329     break;
1330 case 27:
1331 #line 349 "parse.yacc"
1332 {
1333                             /*
1334                              * We already did a push if necessary in
1335                              * cmndspec so just reset some values so
1336                              * the next 'privilege' gets a clean slate.
1337                              */
1338                             host_matches = -1;
1339                             runas_matches = -1;
1340                             if (def_flag(I_AUTHENTICATE))
1341                                 no_passwd = -1;
1342                             else
1343                                 no_passwd = TRUE;
1344                         }
1345     break;
1346 case 28:
1347 #line 364 "parse.yacc"
1348 {
1349                             if (yyvsp[0].BOOLEAN != -1)
1350                                 host_matches = yyvsp[0].BOOLEAN;
1351                         }
1352     break;
1353 case 29:
1354 #line 368 "parse.yacc"
1355 {
1356                             if (yyvsp[0].BOOLEAN != -1)
1357                                 host_matches = ! yyvsp[0].BOOLEAN;
1358                         }
1359     break;
1360 case 30:
1361 #line 373 "parse.yacc"
1362 {
1363                             yyval.BOOLEAN = TRUE;
1364                         }
1365     break;
1366 case 31:
1367 #line 376 "parse.yacc"
1368 {
1369                             if (addr_matches(yyvsp[0].string))
1370                                 yyval.BOOLEAN = TRUE;
1371                             else
1372                                 yyval.BOOLEAN = -1;
1373                             free(yyvsp[0].string);
1374                         }
1375     break;
1376 case 32:
1377 #line 383 "parse.yacc"
1378 {
1379                             if (netgr_matches(yyvsp[0].string, user_host, user_shost, NULL))
1380                                 yyval.BOOLEAN = TRUE;
1381                             else
1382                                 yyval.BOOLEAN = -1;
1383                             free(yyvsp[0].string);
1384                         }
1385     break;
1386 case 33:
1387 #line 390 "parse.yacc"
1388 {
1389                             if (hostname_matches(user_shost, user_host, yyvsp[0].string) == 0)
1390                                 yyval.BOOLEAN = TRUE;
1391                             else
1392                                 yyval.BOOLEAN = -1;
1393                             free(yyvsp[0].string);
1394                         }
1395     break;
1396 case 34:
1397 #line 397 "parse.yacc"
1398 {
1399                             aliasinfo *aip = find_alias(yyvsp[0].string, HOST_ALIAS);
1400
1401                             /* could be an all-caps hostname */
1402                             if (aip)
1403                                 yyval.BOOLEAN = aip->val;
1404                             else if (strcasecmp(user_shost, yyvsp[0].string) == 0)
1405                                 yyval.BOOLEAN = TRUE;
1406                             else {
1407                                 if (pedantic) {
1408                                     (void) fprintf(stderr,
1409                                         "%s: undeclared Host_Alias `%s' referenced near line %d\n",
1410                                         (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1411                                     if (pedantic > 1) {
1412                                         yyerror(NULL);
1413                                         YYERROR;
1414                                     }
1415                                 }
1416                                 yyval.BOOLEAN = -1;
1417                             }
1418                             free(yyvsp[0].string);
1419                         }
1420     break;
1421 case 37:
1422 #line 425 "parse.yacc"
1423 {
1424                             /*
1425                              * Push the entry onto the stack if it is worth
1426                              * saving and clear cmnd_matches for next cmnd.
1427                              *
1428                              * We need to save at least one entry on
1429                              * the stack so sudoers_lookup() can tell that
1430                              * the user was listed in sudoers.  Also, we
1431                              * need to be able to tell whether or not a
1432                              * user was listed for this specific host.
1433                              *
1434                              * If keepall is set and the user matches then
1435                              * we need to keep entries around too...
1436                              */
1437                             if (user_matches != -1 && host_matches != -1 &&
1438                                 cmnd_matches != -1 && runas_matches != -1)
1439                                 pushcp;
1440                             else if (user_matches != -1 && (top == 1 ||
1441                                 (top == 2 && host_matches != -1 &&
1442                                 match[0].host == -1)))
1443                                 pushcp;
1444                             else if (user_matches == TRUE && keepall)
1445                                 pushcp;
1446                             cmnd_matches = -1;
1447                         }
1448     break;
1449 case 38:
1450 #line 452 "parse.yacc"
1451 {
1452                             if (yyvsp[0].BOOLEAN != -1)
1453                                 cmnd_matches = yyvsp[0].BOOLEAN;
1454                         }
1455     break;
1456 case 39:
1457 #line 456 "parse.yacc"
1458 {
1459                             if (printmatches == TRUE) {
1460                                 if (in_alias == TRUE)
1461                                     append_entries("!", ", ");
1462                                 else if (host_matches == TRUE &&
1463                                     user_matches == TRUE)
1464                                     append_cmnd("!", NULL);
1465                             }
1466                         }
1467     break;
1468 case 40:
1469 #line 464 "parse.yacc"
1470 {
1471                             if (yyvsp[0].BOOLEAN != -1)
1472                                 cmnd_matches = ! yyvsp[0].BOOLEAN;
1473                         }
1474     break;
1475 case 41:
1476 #line 470 "parse.yacc"
1477 {
1478                             if (printmatches == TRUE && host_matches == TRUE &&
1479                                 user_matches == TRUE) {
1480                                 if (runas_matches == -1) {
1481                                     cm_list[cm_list_len].runas_len = 0;
1482                                 } else {
1483                                     /* Inherit runas data. */
1484                                     cm_list[cm_list_len].runas =
1485                                         estrdup(cm_list[cm_list_len-1].runas);
1486                                     cm_list[cm_list_len].runas_len =
1487                                         cm_list[cm_list_len-1].runas_len;
1488                                     cm_list[cm_list_len].runas_size =
1489                                         cm_list[cm_list_len-1].runas_size;
1490                                 }
1491                             }
1492                             /*
1493                              * If this is the first entry in a command list
1494                              * then check against default runas user.
1495                              */
1496                             if (runas_matches == -1)
1497                                 runas_matches = (strcmp(*user_runas,
1498                                     def_str(I_RUNAS_DEFAULT)) == 0);
1499                         }
1500     break;
1501 case 42:
1502 #line 493 "parse.yacc"
1503 {
1504                             runas_matches = (yyvsp[0].BOOLEAN == TRUE ? TRUE : FALSE);
1505                         }
1506     break;
1507 case 43:
1508 #line 498 "parse.yacc"
1509 { ; }
1510     break;
1511 case 44:
1512 #line 499 "parse.yacc"
1513 {
1514                             /* Later entries override earlier ones. */
1515                             if (yyvsp[0].BOOLEAN != -1)
1516                                 yyval.BOOLEAN = yyvsp[0].BOOLEAN;
1517                             else
1518                                 yyval.BOOLEAN = yyvsp[-2].BOOLEAN;
1519                         }
1520     break;
1521 case 45:
1522 #line 508 "parse.yacc"
1523 { ; }
1524     break;
1525 case 46:
1526 #line 509 "parse.yacc"
1527 {
1528                             if (printmatches == TRUE) {
1529                                 if (in_alias == TRUE)
1530                                     append_entries("!", ", ");
1531                                 else if (host_matches == TRUE &&
1532                                     user_matches == TRUE)
1533                                     append_runas("!", ", ");
1534                             }
1535                         }
1536     break;
1537 case 47:
1538 #line 517 "parse.yacc"
1539 {
1540                             /* Set $$ to the negation of runasuser */
1541                             yyval.BOOLEAN = (yyvsp[0].BOOLEAN == -1 ? -1 : ! yyvsp[0].BOOLEAN);
1542                         }
1543     break;
1544 case 48:
1545 #line 522 "parse.yacc"
1546 {
1547                             if (printmatches == TRUE) {
1548                                 if (in_alias == TRUE)
1549                                     append_entries(yyvsp[0].string, ", ");
1550                                 else if (host_matches == TRUE &&
1551                                     user_matches == TRUE)
1552                                     append_runas(yyvsp[0].string, ", ");
1553                             }
1554                             if (strcmp(yyvsp[0].string, *user_runas) == 0)
1555                                 yyval.BOOLEAN = TRUE;
1556                             else
1557                                 yyval.BOOLEAN = -1;
1558                             free(yyvsp[0].string);
1559                         }
1560     break;
1561 case 49:
1562 #line 536 "parse.yacc"
1563 {
1564                             if (printmatches == TRUE) {
1565                                 if (in_alias == TRUE)
1566                                     append_entries(yyvsp[0].string, ", ");
1567                                 else if (host_matches == TRUE &&
1568                                     user_matches == TRUE)
1569                                     append_runas(yyvsp[0].string, ", ");
1570                             }
1571                             if (usergr_matches(yyvsp[0].string, *user_runas))
1572                                 yyval.BOOLEAN = TRUE;
1573                             else
1574                                 yyval.BOOLEAN = -1;
1575                             free(yyvsp[0].string);
1576                         }
1577     break;
1578 case 50:
1579 #line 550 "parse.yacc"
1580 {
1581                             if (printmatches == TRUE) {
1582                                 if (in_alias == TRUE)
1583                                     append_entries(yyvsp[0].string, ", ");
1584                                 else if (host_matches == TRUE &&
1585                                     user_matches == TRUE)
1586                                     append_runas(yyvsp[0].string, ", ");
1587                             }
1588                             if (netgr_matches(yyvsp[0].string, NULL, NULL, *user_runas))
1589                                 yyval.BOOLEAN = TRUE;
1590                             else
1591                                 yyval.BOOLEAN = -1;
1592                             free(yyvsp[0].string);
1593                         }
1594     break;
1595 case 51:
1596 #line 564 "parse.yacc"
1597 {
1598                             aliasinfo *aip = find_alias(yyvsp[0].string, RUNAS_ALIAS);
1599
1600                             if (printmatches == TRUE) {
1601                                 if (in_alias == TRUE)
1602                                     append_entries(yyvsp[0].string, ", ");
1603                                 else if (host_matches == TRUE &&
1604                                     user_matches == TRUE)
1605                                     append_runas(yyvsp[0].string, ", ");
1606                             }
1607                             /* could be an all-caps username */
1608                             if (aip)
1609                                 yyval.BOOLEAN = aip->val;
1610                             else if (strcmp(yyvsp[0].string, *user_runas) == 0)
1611                                 yyval.BOOLEAN = TRUE;
1612                             else {
1613                                 if (pedantic) {
1614                                     (void) fprintf(stderr,
1615                                         "%s: undeclared Runas_Alias `%s' referenced near line %d\n",
1616                                         (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1617                                     if (pedantic > 1) {
1618                                         yyerror(NULL);
1619                                         YYERROR;
1620                                     }
1621                                 }
1622                                 yyval.BOOLEAN = -1;
1623                             }
1624                             free(yyvsp[0].string);
1625                         }
1626     break;
1627 case 52:
1628 #line 593 "parse.yacc"
1629 {
1630                             if (printmatches == TRUE) {
1631                                 if (in_alias == TRUE)
1632                                     append_entries("ALL", ", ");
1633                                 else if (host_matches == TRUE &&
1634                                     user_matches == TRUE)
1635                                     append_runas("ALL", ", ");
1636                             }
1637                             yyval.BOOLEAN = TRUE;
1638                         }
1639     break;
1640 case 53:
1641 #line 605 "parse.yacc"
1642 {
1643                             /* Inherit NOPASSWD/PASSWD status. */
1644                             if (printmatches == TRUE && host_matches == TRUE &&
1645                                 user_matches == TRUE) {
1646                                 if (no_passwd == TRUE)
1647                                     cm_list[cm_list_len].nopasswd = TRUE;
1648                                 else
1649                                     cm_list[cm_list_len].nopasswd = FALSE;
1650                             }
1651                         }
1652     break;
1653 case 54:
1654 #line 615 "parse.yacc"
1655 {
1656                             no_passwd = TRUE;
1657                             if (printmatches == TRUE && host_matches == TRUE &&
1658                                 user_matches == TRUE)
1659                                 cm_list[cm_list_len].nopasswd = TRUE;
1660                         }
1661     break;
1662 case 55:
1663 #line 621 "parse.yacc"
1664 {
1665                             no_passwd = FALSE;
1666                             if (printmatches == TRUE && host_matches == TRUE &&
1667                                 user_matches == TRUE)
1668                                 cm_list[cm_list_len].nopasswd = FALSE;
1669                         }
1670     break;
1671 case 56:
1672 #line 629 "parse.yacc"
1673 {
1674                             if (printmatches == TRUE) {
1675                                 if (in_alias == TRUE)
1676                                     append_entries("ALL", ", ");
1677                                 else if (host_matches == TRUE &&
1678                                     user_matches == TRUE) {
1679                                     append_cmnd("ALL", NULL);
1680                                     expand_match_list();
1681                                 }
1682                             }
1683
1684                             yyval.BOOLEAN = TRUE;
1685                         }
1686     break;
1687 case 57:
1688 #line 642 "parse.yacc"
1689 {
1690                             aliasinfo *aip;
1691
1692                             if (printmatches == TRUE) {
1693                                 if (in_alias == TRUE)
1694                                     append_entries(yyvsp[0].string, ", ");
1695                                 else if (host_matches == TRUE &&
1696                                     user_matches == TRUE) {
1697                                     append_cmnd(yyvsp[0].string, NULL);
1698                                     expand_match_list();
1699                                 }
1700                             }
1701
1702                             if ((aip = find_alias(yyvsp[0].string, CMND_ALIAS)))
1703                                 yyval.BOOLEAN = aip->val;
1704                             else {
1705                                 if (pedantic) {
1706                                     (void) fprintf(stderr,
1707                                         "%s: undeclared Cmnd_Alias `%s' referenced near line %d\n",
1708                                         (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1709                                     if (pedantic > 1) {
1710                                         yyerror(NULL);
1711                                         YYERROR;
1712                                     }
1713                                 }
1714                                 yyval.BOOLEAN = -1;
1715                             }
1716                             free(yyvsp[0].string);
1717                         }
1718     break;
1719 case 58:
1720 #line 671 "parse.yacc"
1721 {
1722                             if (printmatches == TRUE) {
1723                                 if (in_alias == TRUE) {
1724                                     append_entries(yyvsp[0].command.cmnd, ", ");
1725                                     if (yyvsp[0].command.args)
1726                                         append_entries(yyvsp[0].command.args, " ");
1727                                 }
1728                                 if (host_matches == TRUE &&
1729                                     user_matches == TRUE)  {
1730                                     append_cmnd(yyvsp[0].command.cmnd, NULL);
1731                                     if (yyvsp[0].command.args)
1732                                         append_cmnd(yyvsp[0].command.args, " ");
1733                                     expand_match_list();
1734                                 }
1735                             }
1736
1737                             if (command_matches(user_cmnd, user_args,
1738                                 yyvsp[0].command.cmnd, yyvsp[0].command.args))
1739                                 yyval.BOOLEAN = TRUE;
1740                             else
1741                                 yyval.BOOLEAN = -1;
1742
1743                             free(yyvsp[0].command.cmnd);
1744                             if (yyvsp[0].command.args)
1745                                 free(yyvsp[0].command.args);
1746                         }
1747     break;
1748 case 61:
1749 #line 703 "parse.yacc"
1750 { push; }
1751     break;
1752 case 62:
1753 #line 703 "parse.yacc"
1754 {
1755                             if ((host_matches != -1 || pedantic) &&
1756                                 !add_alias(yyvsp[-3].string, HOST_ALIAS, host_matches))
1757                                 YYERROR;
1758                             pop;
1759                         }
1760     break;
1761 case 67:
1762 #line 719 "parse.yacc"
1763 {
1764                             push;
1765                             if (printmatches == TRUE) {
1766                                 in_alias = TRUE;
1767                                 /* Allocate space for ga_list if necessary. */
1768                                 expand_ga_list();
1769                                 ga_list[ga_list_len-1].type = CMND_ALIAS;
1770                                 ga_list[ga_list_len-1].alias = estrdup(yyvsp[0].string);
1771                              }
1772                         }
1773     break;
1774 case 68:
1775 #line 728 "parse.yacc"
1776 {
1777                             if ((cmnd_matches != -1 || pedantic) &&
1778                                 !add_alias(yyvsp[-3].string, CMND_ALIAS, cmnd_matches))
1779                                 YYERROR;
1780                             pop;
1781                             free(yyvsp[-3].string);
1782
1783                             if (printmatches == TRUE)
1784                                 in_alias = FALSE;
1785                         }
1786     break;
1787 case 69:
1788 #line 740 "parse.yacc"
1789 { ; }
1790     break;
1791 case 73:
1792 #line 748 "parse.yacc"
1793 {
1794                             if (printmatches == TRUE) {
1795                                 in_alias = TRUE;
1796                                 /* Allocate space for ga_list if necessary. */
1797                                 expand_ga_list();
1798                                 ga_list[ga_list_len-1].type = RUNAS_ALIAS;
1799                                 ga_list[ga_list_len-1].alias = estrdup(yyvsp[0].string);
1800                             }
1801                         }
1802     break;
1803 case 74:
1804 #line 756 "parse.yacc"
1805 {
1806                             if ((yyvsp[0].BOOLEAN != -1 || pedantic) &&
1807                                 !add_alias(yyvsp[-3].string, RUNAS_ALIAS, yyvsp[0].BOOLEAN))
1808                                 YYERROR;
1809                             free(yyvsp[-3].string);
1810
1811                             if (printmatches == TRUE)
1812                                 in_alias = FALSE;
1813                         }
1814     break;
1815 case 77:
1816 #line 771 "parse.yacc"
1817 { push; }
1818     break;
1819 case 78:
1820 #line 771 "parse.yacc"
1821 {
1822                             if ((user_matches != -1 || pedantic) &&
1823                                 !add_alias(yyvsp[-3].string, USER_ALIAS, user_matches))
1824                                 YYERROR;
1825                             pop;
1826                             free(yyvsp[-3].string);
1827                         }
1828     break;
1829 case 81:
1830 #line 784 "parse.yacc"
1831 {
1832                             if (yyvsp[0].BOOLEAN != -1)
1833                                 user_matches = yyvsp[0].BOOLEAN;
1834                         }
1835     break;
1836 case 82:
1837 #line 788 "parse.yacc"
1838 {
1839                             if (yyvsp[0].BOOLEAN != -1)
1840                                 user_matches = ! yyvsp[0].BOOLEAN;
1841                         }
1842     break;
1843 case 83:
1844 #line 793 "parse.yacc"
1845 {
1846                             if (strcmp(yyvsp[0].string, user_name) == 0)
1847                                 yyval.BOOLEAN = TRUE;
1848                             else
1849                                 yyval.BOOLEAN = -1;
1850                             free(yyvsp[0].string);
1851                         }
1852     break;
1853 case 84:
1854 #line 800 "parse.yacc"
1855 {
1856                             if (usergr_matches(yyvsp[0].string, user_name))
1857                                 yyval.BOOLEAN = TRUE;
1858                             else
1859                                 yyval.BOOLEAN = -1;
1860                             free(yyvsp[0].string);
1861                         }
1862     break;
1863 case 85:
1864 #line 807 "parse.yacc"
1865 {
1866                             if (netgr_matches(yyvsp[0].string, NULL, NULL, user_name))
1867                                 yyval.BOOLEAN = TRUE;
1868                             else
1869                                 yyval.BOOLEAN = -1;
1870                             free(yyvsp[0].string);
1871                         }
1872     break;
1873 case 86:
1874 #line 814 "parse.yacc"
1875 {
1876                             aliasinfo *aip = find_alias(yyvsp[0].string, USER_ALIAS);
1877
1878                             /* could be an all-caps username */
1879                             if (aip)
1880                                 yyval.BOOLEAN = aip->val;
1881                             else if (strcmp(yyvsp[0].string, user_name) == 0)
1882                                 yyval.BOOLEAN = TRUE;
1883                             else {
1884                                 if (pedantic) {
1885                                     (void) fprintf(stderr,
1886                                         "%s: undeclared User_Alias `%s' referenced near line %d\n",
1887                                         (pedantic == 1) ? "Warning" : "Error", yyvsp[0].string, sudolineno);
1888                                     if (pedantic > 1)
1889                                         YYERROR;
1890                                 }
1891                                 yyval.BOOLEAN = -1;
1892                             }
1893                             free(yyvsp[0].string);
1894                         }
1895     break;
1896 case 87:
1897 #line 834 "parse.yacc"
1898 {
1899                             yyval.BOOLEAN = TRUE;
1900                         }
1901     break;
1902 }
1903
1904 #line 705 "/usr/share/bison/bison.simple"
1905
1906 \f
1907   yyvsp -= yylen;
1908   yyssp -= yylen;
1909 #if YYLSP_NEEDED
1910   yylsp -= yylen;
1911 #endif
1912
1913 #if YYDEBUG
1914   if (yydebug)
1915     {
1916       short *yyssp1 = yyss - 1;
1917       YYFPRINTF (stderr, "state stack now");
1918       while (yyssp1 != yyssp)
1919         YYFPRINTF (stderr, " %d", *++yyssp1);
1920       YYFPRINTF (stderr, "\n");
1921     }
1922 #endif
1923
1924   *++yyvsp = yyval;
1925 #if YYLSP_NEEDED
1926   *++yylsp = yyloc;
1927 #endif
1928
1929   /* Now `shift' the result of the reduction.  Determine what state
1930      that goes to, based on the state we popped back to and the rule
1931      number reduced by.  */
1932
1933   yyn = yyr1[yyn];
1934
1935   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
1936   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1937     yystate = yytable[yystate];
1938   else
1939     yystate = yydefgoto[yyn - YYNTBASE];
1940
1941   goto yynewstate;
1942
1943
1944 /*------------------------------------.
1945 | yyerrlab -- here on detecting error |
1946 `------------------------------------*/
1947 yyerrlab:
1948   /* If not already recovering from an error, report this error.  */
1949   if (!yyerrstatus)
1950     {
1951       ++yynerrs;
1952
1953 #ifdef YYERROR_VERBOSE
1954       yyn = yypact[yystate];
1955
1956       if (yyn > YYFLAG && yyn < YYLAST)
1957         {
1958           YYSIZE_T yysize = 0;
1959           char *yymsg;
1960           int yyx, yycount;
1961
1962           yycount = 0;
1963           /* Start YYX at -YYN if negative to avoid negative indexes in
1964              YYCHECK.  */
1965           for (yyx = yyn < 0 ? -yyn : 0;
1966                yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)
1967             if (yycheck[yyx + yyn] == yyx)
1968               yysize += yystrlen (yytname[yyx]) + 15, yycount++;
1969           yysize += yystrlen ("parse error, unexpected ") + 1;
1970           yysize += yystrlen (yytname[YYTRANSLATE (yychar)]);
1971           yymsg = (char *) YYSTACK_ALLOC (yysize);
1972           if (yymsg != 0)
1973             {
1974               char *yyp = yystpcpy (yymsg, "parse error, unexpected ");
1975               yyp = yystpcpy (yyp, yytname[YYTRANSLATE (yychar)]);
1976
1977               if (yycount < 5)
1978                 {
1979                   yycount = 0;
1980                   for (yyx = yyn < 0 ? -yyn : 0;
1981                        yyx < (int) (sizeof (yytname) / sizeof (char *));
1982                        yyx++)
1983                     if (yycheck[yyx + yyn] == yyx)
1984                       {
1985                         const char *yyq = ! yycount ? ", expecting " : " or ";
1986                         yyp = yystpcpy (yyp, yyq);
1987                         yyp = yystpcpy (yyp, yytname[yyx]);
1988                         yycount++;
1989                       }
1990                 }
1991               yyerror (yymsg);
1992               YYSTACK_FREE (yymsg);
1993             }
1994           else
1995             yyerror ("parse error; also virtual memory exhausted");
1996         }
1997       else
1998 #endif /* defined (YYERROR_VERBOSE) */
1999         yyerror ("parse error");
2000     }
2001   goto yyerrlab1;
2002
2003
2004 /*--------------------------------------------------.
2005 | yyerrlab1 -- error raised explicitly by an action |
2006 `--------------------------------------------------*/
2007 yyerrlab1:
2008   if (yyerrstatus == 3)
2009     {
2010       /* If just tried and failed to reuse lookahead token after an
2011          error, discard it.  */
2012
2013       /* return failure if at end of input */
2014       if (yychar == YYEOF)
2015         YYABORT;
2016       YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
2017                   yychar, yytname[yychar1]));
2018       yychar = YYEMPTY;
2019     }
2020
2021   /* Else will try to reuse lookahead token after shifting the error
2022      token.  */
2023
2024   yyerrstatus = 3;              /* Each real token shifted decrements this */
2025
2026   goto yyerrhandle;
2027
2028
2029 /*-------------------------------------------------------------------.
2030 | yyerrdefault -- current state does not do anything special for the |
2031 | error token.                                                       |
2032 `-------------------------------------------------------------------*/
2033 yyerrdefault:
2034 #if 0
2035   /* This is wrong; only states that explicitly want error tokens
2036      should shift them.  */
2037
2038   /* If its default is to accept any token, ok.  Otherwise pop it.  */
2039   yyn = yydefact[yystate];
2040   if (yyn)
2041     goto yydefault;
2042 #endif
2043
2044
2045 /*---------------------------------------------------------------.
2046 | yyerrpop -- pop the current state because it cannot handle the |
2047 | error token                                                    |
2048 `---------------------------------------------------------------*/
2049 yyerrpop:
2050   if (yyssp == yyss)
2051     YYABORT;
2052   yyvsp--;
2053   yystate = *--yyssp;
2054 #if YYLSP_NEEDED
2055   yylsp--;
2056 #endif
2057
2058 #if YYDEBUG
2059   if (yydebug)
2060     {
2061       short *yyssp1 = yyss - 1;
2062       YYFPRINTF (stderr, "Error: state stack now");
2063       while (yyssp1 != yyssp)
2064         YYFPRINTF (stderr, " %d", *++yyssp1);
2065       YYFPRINTF (stderr, "\n");
2066     }
2067 #endif
2068
2069 /*--------------.
2070 | yyerrhandle.  |
2071 `--------------*/
2072 yyerrhandle:
2073   yyn = yypact[yystate];
2074   if (yyn == YYFLAG)
2075     goto yyerrdefault;
2076
2077   yyn += YYTERROR;
2078   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
2079     goto yyerrdefault;
2080
2081   yyn = yytable[yyn];
2082   if (yyn < 0)
2083     {
2084       if (yyn == YYFLAG)
2085         goto yyerrpop;
2086       yyn = -yyn;
2087       goto yyreduce;
2088     }
2089   else if (yyn == 0)
2090     goto yyerrpop;
2091
2092   if (yyn == YYFINAL)
2093     YYACCEPT;
2094
2095   YYDPRINTF ((stderr, "Shifting error token, "));
2096
2097   *++yyvsp = yylval;
2098 #if YYLSP_NEEDED
2099   *++yylsp = yylloc;
2100 #endif
2101
2102   yystate = yyn;
2103   goto yynewstate;
2104
2105
2106 /*-------------------------------------.
2107 | yyacceptlab -- YYACCEPT comes here.  |
2108 `-------------------------------------*/
2109 yyacceptlab:
2110   yyresult = 0;
2111   goto yyreturn;
2112
2113 /*-----------------------------------.
2114 | yyabortlab -- YYABORT comes here.  |
2115 `-----------------------------------*/
2116 yyabortlab:
2117   yyresult = 1;
2118   goto yyreturn;
2119
2120 /*---------------------------------------------.
2121 | yyoverflowab -- parser overflow comes here.  |
2122 `---------------------------------------------*/
2123 yyoverflowlab:
2124   yyerror ("parser stack overflow");
2125   yyresult = 2;
2126   /* Fall through.  */
2127
2128 yyreturn:
2129 #ifndef yyoverflow
2130   if (yyss != yyssa)
2131     YYSTACK_FREE (yyss);
2132 #endif
2133   return yyresult;
2134 }
2135 #line 839 "parse.yacc"
2136
2137
2138 #define MOREALIASES (32)
2139 aliasinfo *aliases = NULL;
2140 size_t naliases = 0;
2141 size_t nslots = 0;
2142
2143
2144 /*
2145  * Compare two aliasinfo structures, strcmp() style.
2146  * Note that we do *not* compare their values.
2147  */
2148 static int
2149 aliascmp(a1, a2)
2150     const VOID *a1, *a2;
2151 {
2152     int r;
2153     aliasinfo *ai1, *ai2;
2154
2155     ai1 = (aliasinfo *) a1;
2156     ai2 = (aliasinfo *) a2;
2157     if ((r = strcmp(ai1->name, ai2->name)) == 0)
2158         r = ai1->type - ai2->type;
2159
2160     return(r);
2161 }
2162
2163 /*
2164  * Compare two generic_alias structures, strcmp() style.
2165  */
2166 static int
2167 genaliascmp(entry, key)
2168     const VOID *entry, *key;
2169 {
2170     int r;
2171     struct generic_alias *ga1, *ga2;
2172
2173     ga1 = (struct generic_alias *) key;
2174     ga2 = (struct generic_alias *) entry;
2175     if ((r = strcmp(ga1->alias, ga2->alias)) == 0)
2176         r = ga1->type - ga2->type;
2177
2178     return(r);
2179 }
2180
2181
2182 /*
2183  * Adds the named alias of the specified type to the aliases list.
2184  */
2185 static int
2186 add_alias(alias, type, val)
2187     char *alias;
2188     int type;
2189     int val;
2190 {
2191     aliasinfo ai, *aip;
2192     size_t onaliases;
2193     char s[512];
2194
2195     if (naliases >= nslots && !more_aliases()) {
2196         (void) snprintf(s, sizeof(s), "Out of memory defining alias `%s'",
2197                         alias);
2198         yyerror(s);
2199         return(FALSE);
2200     }
2201
2202     ai.type = type;
2203     ai.val = val;
2204     ai.name = estrdup(alias);
2205     onaliases = naliases;
2206
2207     aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases, &naliases,
2208                                 sizeof(ai), aliascmp);
2209     if (aip == NULL) {
2210         (void) snprintf(s, sizeof(s), "Aliases corrupted defining alias `%s'",
2211                         alias);
2212         yyerror(s);
2213         return(FALSE);
2214     }
2215     if (onaliases == naliases) {
2216         (void) snprintf(s, sizeof(s), "Alias `%s' already defined", alias);
2217         yyerror(s);
2218         return(FALSE);
2219     }
2220
2221     return(TRUE);
2222 }
2223
2224 /*
2225  * Searches for the named alias of the specified type.
2226  */
2227 static aliasinfo *
2228 find_alias(alias, type)
2229     char *alias;
2230     int type;
2231 {
2232     aliasinfo ai;
2233
2234     ai.name = alias;
2235     ai.type = type;
2236
2237     return((aliasinfo *) lfind((VOID *)&ai, (VOID *)aliases, &naliases,
2238                  sizeof(ai), aliascmp));
2239 }
2240
2241 /*
2242  * Allocates more space for the aliases list.
2243  */
2244 static int
2245 more_aliases()
2246 {
2247
2248     nslots += MOREALIASES;
2249     if (nslots == MOREALIASES)
2250         aliases = (aliasinfo *) malloc(nslots * sizeof(aliasinfo));
2251     else
2252         aliases = (aliasinfo *) realloc(aliases, nslots * sizeof(aliasinfo));
2253
2254     return(aliases != NULL);
2255 }
2256
2257 /*
2258  * Lists the contents of the aliases list.
2259  */
2260 void
2261 dumpaliases()
2262 {
2263     size_t n;
2264
2265     for (n = 0; n < naliases; n++) {
2266         if (aliases[n].val == -1)
2267             continue;
2268
2269         switch (aliases[n].type) {
2270         case HOST_ALIAS:
2271             (void) puts("HOST_ALIAS");
2272             break;
2273
2274         case CMND_ALIAS:
2275             (void) puts("CMND_ALIAS");
2276             break;
2277
2278         case USER_ALIAS:
2279             (void) puts("USER_ALIAS");
2280             break;
2281
2282         case RUNAS_ALIAS:
2283             (void) puts("RUNAS_ALIAS");
2284             break;
2285         }
2286         (void) printf("\t%s: %d\n", aliases[n].name, aliases[n].val);
2287     }
2288 }
2289
2290 /*
2291  * Lists the contents of cm_list and ga_list for `sudo -l'.
2292  */
2293 void
2294 list_matches()
2295 {
2296     int i; 
2297     char *p;
2298     struct generic_alias *ga, key;
2299
2300     (void) printf("User %s may run the following commands on this host:\n",
2301         user_name);
2302     for (i = 0; i < cm_list_len; i++) {
2303
2304         /* Print the runas list. */
2305         (void) fputs("    ", stdout);
2306         if (cm_list[i].runas) {
2307             (void) putchar('(');
2308             p = strtok(cm_list[i].runas, ", ");
2309             do {
2310                 if (p != cm_list[i].runas)
2311                     (void) fputs(", ", stdout);
2312
2313                 key.alias = p;
2314                 key.type = RUNAS_ALIAS;
2315                 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
2316                     (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
2317                     (void) fputs(ga->entries, stdout);
2318                 else
2319                     (void) fputs(p, stdout);
2320             } while ((p = strtok(NULL, ", ")));
2321             (void) fputs(") ", stdout);
2322         } else {
2323             (void) printf("(%s) ", def_str(I_RUNAS_DEFAULT));
2324         }
2325
2326         /* Is a password required? */
2327         if (cm_list[i].nopasswd == TRUE && def_flag(I_AUTHENTICATE))
2328             (void) fputs("NOPASSWD: ", stdout);
2329         else if (cm_list[i].nopasswd == FALSE && !def_flag(I_AUTHENTICATE))
2330             (void) fputs("PASSWD: ", stdout);
2331
2332         /* Print the actual command or expanded Cmnd_Alias. */
2333         key.alias = cm_list[i].cmnd;
2334         key.type = CMND_ALIAS;
2335         if ((ga = (struct generic_alias *) lfind((VOID *) &key,
2336             (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
2337             (void) puts(ga->entries);
2338         else
2339             (void) puts(cm_list[i].cmnd);
2340     }
2341
2342     /* Be nice and free up space now that we are done. */
2343     for (i = 0; i < ga_list_len; i++) {
2344         free(ga_list[i].alias);
2345         free(ga_list[i].entries);
2346     }
2347     free(ga_list);
2348     ga_list = NULL;
2349
2350     for (i = 0; i < cm_list_len; i++) {
2351         free(cm_list[i].runas);
2352         free(cm_list[i].cmnd);
2353     }
2354     free(cm_list);
2355     cm_list = NULL;
2356     cm_list_len = 0;
2357     cm_list_size = 0;
2358 }
2359
2360 /*
2361  * Appends a source string to the destination, optionally prefixing a separator.
2362  */
2363 static void
2364 append(src, dstp, dst_len, dst_size, separator)
2365     char *src, **dstp;
2366     size_t *dst_len, *dst_size;
2367     char *separator;
2368 {
2369     size_t src_len = strlen(src);
2370     char *dst = *dstp;
2371
2372     /*
2373      * Only add the separator if there is something to separate from.
2374      * If the last char is a '!', don't apply the separator (XXX).
2375      */
2376     if (separator && dst && dst[*dst_len - 1] != '!')
2377         src_len += strlen(separator);
2378     else
2379         separator = NULL;
2380
2381     /* Assumes dst will be NULL if not set. */
2382     if (dst == NULL) {
2383         dst = (char *) emalloc(BUFSIZ);
2384         *dst_size = BUFSIZ;
2385         *dst_len = 0;
2386         *dstp = dst;
2387     }
2388
2389     /* Allocate more space if necessary. */
2390     if (*dst_size <= *dst_len + src_len) {
2391         while (*dst_size <= *dst_len + src_len)
2392             *dst_size += BUFSIZ;
2393
2394         dst = (char *) erealloc(dst, *dst_size);
2395         *dstp = dst;
2396     }
2397
2398     /* Copy src -> dst adding a separator if appropriate and adjust len. */
2399     dst += *dst_len;
2400     *dst_len += src_len;
2401     *dst = '\0';
2402     if (separator)
2403         (void) strcat(dst, separator);
2404     (void) strcat(dst, src);
2405 }
2406
2407 /*
2408  * Frees up space used by the aliases list and resets the associated counters.
2409  */
2410 void
2411 reset_aliases()
2412 {
2413     size_t n;
2414
2415     if (aliases) {
2416         for (n = 0; n < naliases; n++)
2417             free(aliases[n].name);
2418         free(aliases);
2419         aliases = NULL;
2420     }
2421     naliases = nslots = 0;
2422 }
2423
2424 /*
2425  * Increments ga_list_len, allocating more space as necessary.
2426  */
2427 static void
2428 expand_ga_list()
2429 {
2430
2431     if (++ga_list_len >= ga_list_size) {
2432         while ((ga_list_size += STACKINCREMENT) < ga_list_len)
2433             ;
2434         ga_list = (struct generic_alias *)
2435             erealloc(ga_list, sizeof(struct generic_alias) * ga_list_size);
2436     }
2437
2438     ga_list[ga_list_len - 1].entries = NULL;
2439 }
2440
2441 /*
2442  * Increments cm_list_len, allocating more space as necessary.
2443  */
2444 static void
2445 expand_match_list()
2446 {
2447
2448     if (++cm_list_len >= cm_list_size) {
2449         while ((cm_list_size += STACKINCREMENT) < cm_list_len)
2450             ;
2451         if (cm_list == NULL)
2452             cm_list_len = 0;            /* start at 0 since it is a subscript */
2453         cm_list = (struct command_match *)
2454             erealloc(cm_list, sizeof(struct command_match) * cm_list_size);
2455     }
2456
2457     cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL;
2458     cm_list[cm_list_len].nopasswd = FALSE;
2459 }
2460
2461 /*
2462  * Frees up spaced used by a previous parser run and allocates new space
2463  * for various data structures.
2464  */
2465 void
2466 init_parser()
2467 {
2468
2469     /* Free up old data structures if we run the parser more than once. */
2470     if (match) {
2471         free(match);
2472         match = NULL;
2473         top = 0;
2474         parse_error = FALSE;
2475         errorlineno = -1;   
2476         sudolineno = 1;     
2477     }
2478
2479     /* Allocate space for the matching stack. */
2480     stacksize = STACKINCREMENT;
2481     match = (struct matchstack *) emalloc(sizeof(struct matchstack) * stacksize);
2482
2483     /* Allocate space for the match list (for `sudo -l'). */
2484     if (printmatches == TRUE)
2485         expand_match_list();
2486 }