This commit is contained in:
Todd C. Miller
1999-07-22 13:12:27 +00:00
parent 4c7239fd97
commit 7126759483
2 changed files with 190 additions and 243 deletions

114
lex.yy.c
View File

@@ -528,30 +528,34 @@ char *yytext;
#define INITIAL 0 #define INITIAL 0
#line 2 "parse.lex" #line 2 "parse.lex"
/* /*
* CU sudo version 1.6
* Copyright (c) 1996, 1998, 1999 Todd C. Miller <Todd.Miller@courtesan.com> * Copyright (c) 1996, 1998, 1999 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
* *
* This program is free software; you can redistribute it and/or modify * This code is derived from software contributed by Chris Jepeway
* it under the terms of the GNU General Public License as published by * <jepeway@cs.utk.edu>
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
* *
* This program is distributed in the hope that it will be useful, * This code is derived from software contributed by Chris Jepeway
* but WITHOUT ANY WARRANTY; without even the implied warranty of * Redistribution and use in source and binary forms, with or without
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * modification, are permitted provided that the following conditions
* GNU General Public License for more details. * are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* *
* You should have received a copy of the GNU General Public License * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* along with this program; if not, write to the Free Software * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* Please send bugs, changes, problems to sudo-bugs@courtesan.com * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
******************************************************************* * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* parse.lex -- lexigraphical analyzer for sudo. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Chris Jepeway <jepeway@cs.utk.edu>
*/ */
#include "config.h" #include "config.h"
@@ -572,6 +576,7 @@ char *yytext;
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
#include "sudo.h" #include "sudo.h"
#include "parse.h"
#include "sudo.tab.h" #include "sudo.tab.h"
#ifndef lint #ifndef lint
@@ -605,7 +610,7 @@ extern void yyerror __P((char *));
#define GOTRUNAS 2 #define GOTRUNAS 2
#line 610 "lex.yy.c" #line 614 "lex.yy.c"
/* Macros after this point can all be overridden by user definitions in /* Macros after this point can all be overridden by user definitions in
* section 1. * section 1.
@@ -756,9 +761,9 @@ YY_DECL
register char *yy_cp, *yy_bp; register char *yy_cp, *yy_bp;
register int yy_act; register int yy_act;
#line 90 "parse.lex" #line 94 "parse.lex"
#line 763 "lex.yy.c" #line 767 "lex.yy.c"
if ( yy_init ) if ( yy_init )
{ {
@@ -843,14 +848,14 @@ do_action: /* This label is used only to access EOF actions. */
case 1: case 1:
YY_RULE_SETUP YY_RULE_SETUP
#line 91 "parse.lex" #line 95 "parse.lex"
{ /* throw away space/tabs */ { /* throw away space/tabs */
sawspace = TRUE; /* but remember for fill_args */ sawspace = TRUE; /* but remember for fill_args */
} }
YY_BREAK YY_BREAK
case 2: case 2:
YY_RULE_SETUP YY_RULE_SETUP
#line 95 "parse.lex" #line 99 "parse.lex"
{ {
sawspace = TRUE; /* remember for fill_args */ sawspace = TRUE; /* remember for fill_args */
++sudolineno; ++sudolineno;
@@ -859,7 +864,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 3: case 3:
YY_RULE_SETUP YY_RULE_SETUP
#line 101 "parse.lex" #line 105 "parse.lex"
{ {
LEXTRACE("QUOTEDCHAR "); LEXTRACE("QUOTEDCHAR ");
fill_args(yytext + 1, 1, sawspace); fill_args(yytext + 1, 1, sawspace);
@@ -868,7 +873,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 4: case 4:
YY_RULE_SETUP YY_RULE_SETUP
#line 107 "parse.lex" #line 111 "parse.lex"
{ {
BEGIN INITIAL; BEGIN INITIAL;
unput(*yytext); unput(*yytext);
@@ -877,7 +882,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 5: case 5:
YY_RULE_SETUP YY_RULE_SETUP
#line 113 "parse.lex" #line 117 "parse.lex"
{ {
++sudolineno; ++sudolineno;
LEXTRACE("\n"); LEXTRACE("\n");
@@ -886,7 +891,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 6: case 6:
YY_RULE_SETUP YY_RULE_SETUP
#line 119 "parse.lex" #line 123 "parse.lex"
{ {
++sudolineno; ++sudolineno;
LEXTRACE("\n"); LEXTRACE("\n");
@@ -895,7 +900,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 7: case 7:
YY_RULE_SETUP YY_RULE_SETUP
#line 125 "parse.lex" #line 129 "parse.lex"
{ {
LEXTRACE("ARG "); LEXTRACE("ARG ");
fill_args(yytext, yyleng, sawspace); fill_args(yytext, yyleng, sawspace);
@@ -904,7 +909,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 8: case 8:
YY_RULE_SETUP YY_RULE_SETUP
#line 131 "parse.lex" #line 135 "parse.lex"
{ {
LEXTRACE(", "); LEXTRACE(", ");
return(','); return(',');
@@ -912,14 +917,14 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 9: case 9:
YY_RULE_SETUP YY_RULE_SETUP
#line 136 "parse.lex" #line 140 "parse.lex"
{ {
return('!'); /* return '!' */ return('!'); /* return '!' */
} }
YY_BREAK YY_BREAK
case 10: case 10:
YY_RULE_SETUP YY_RULE_SETUP
#line 140 "parse.lex" #line 144 "parse.lex"
{ {
LEXTRACE("= "); LEXTRACE("= ");
return('='); return('=');
@@ -927,7 +932,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 11: case 11:
YY_RULE_SETUP YY_RULE_SETUP
#line 145 "parse.lex" #line 149 "parse.lex"
{ {
LEXTRACE(": "); LEXTRACE(": ");
return(':'); return(':');
@@ -935,14 +940,14 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 12: case 12:
YY_RULE_SETUP YY_RULE_SETUP
#line 150 "parse.lex" #line 154 "parse.lex"
{ {
return('.'); return('.');
} }
YY_BREAK YY_BREAK
case 13: case 13:
YY_RULE_SETUP YY_RULE_SETUP
#line 154 "parse.lex" #line 158 "parse.lex"
{ {
/* cmnd does not require passwd for this user */ /* cmnd does not require passwd for this user */
LEXTRACE("NOPASSWD "); LEXTRACE("NOPASSWD ");
@@ -951,7 +956,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 14: case 14:
YY_RULE_SETUP YY_RULE_SETUP
#line 160 "parse.lex" #line 164 "parse.lex"
{ {
/* cmnd requires passwd for this user */ /* cmnd requires passwd for this user */
LEXTRACE("PASSWD "); LEXTRACE("PASSWD ");
@@ -960,7 +965,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 15: case 15:
YY_RULE_SETUP YY_RULE_SETUP
#line 166 "parse.lex" #line 170 "parse.lex"
{ {
/* netgroup */ /* netgroup */
fill(yytext, yyleng); fill(yytext, yyleng);
@@ -969,7 +974,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 16: case 16:
YY_RULE_SETUP YY_RULE_SETUP
#line 172 "parse.lex" #line 176 "parse.lex"
{ {
/* UN*X group */ /* UN*X group */
fill(yytext, yyleng); fill(yytext, yyleng);
@@ -978,7 +983,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 17: case 17:
YY_RULE_SETUP YY_RULE_SETUP
#line 178 "parse.lex" #line 182 "parse.lex"
{ {
fill(yytext, yyleng); fill(yytext, yyleng);
LEXTRACE("NTWKADDR "); LEXTRACE("NTWKADDR ");
@@ -987,7 +992,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 18: case 18:
YY_RULE_SETUP YY_RULE_SETUP
#line 184 "parse.lex" #line 188 "parse.lex"
{ {
fill(yytext, yyleng); fill(yytext, yyleng);
LEXTRACE("FQHOST "); LEXTRACE("FQHOST ");
@@ -996,7 +1001,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 19: case 19:
YY_RULE_SETUP YY_RULE_SETUP
#line 190 "parse.lex" #line 194 "parse.lex"
{ {
BEGIN GOTRUNAS; BEGIN GOTRUNAS;
LEXTRACE("RUNAS "); LEXTRACE("RUNAS ");
@@ -1005,7 +1010,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 20: case 20:
YY_RULE_SETUP YY_RULE_SETUP
#line 196 "parse.lex" #line 200 "parse.lex"
{ {
/* Runas_Alias that user can run command as or ALL */ /* Runas_Alias that user can run command as or ALL */
fill(yytext, yyleng); fill(yytext, yyleng);
@@ -1020,7 +1025,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 21: case 21:
YY_RULE_SETUP YY_RULE_SETUP
#line 208 "parse.lex" #line 212 "parse.lex"
{ {
/* username/uid that user can run command as */ /* username/uid that user can run command as */
fill(yytext, yyleng); fill(yytext, yyleng);
@@ -1030,12 +1035,12 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 22: case 22:
YY_RULE_SETUP YY_RULE_SETUP
#line 215 "parse.lex" #line 219 "parse.lex"
BEGIN INITIAL; BEGIN INITIAL;
YY_BREAK YY_BREAK
case 23: case 23:
YY_RULE_SETUP YY_RULE_SETUP
#line 218 "parse.lex" #line 222 "parse.lex"
{ {
/* directories can't have args... */ /* directories can't have args... */
if (yytext[yyleng - 1] == '/') { if (yytext[yyleng - 1] == '/') {
@@ -1051,7 +1056,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 24: case 24:
YY_RULE_SETUP YY_RULE_SETUP
#line 231 "parse.lex" #line 235 "parse.lex"
{ {
fill(yytext, yyleng); fill(yytext, yyleng);
if (strcmp(yytext, "ALL") == 0) { if (strcmp(yytext, "ALL") == 0) {
@@ -1064,7 +1069,7 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 25: case 25:
YY_RULE_SETUP YY_RULE_SETUP
#line 241 "parse.lex" #line 245 "parse.lex"
{ {
fill(yytext, yyleng); fill(yytext, yyleng);
if (strcmp(yytext, "Host_Alias") == 0) { if (strcmp(yytext, "Host_Alias") == 0) {
@@ -1091,17 +1096,17 @@ YY_RULE_SETUP
YY_BREAK YY_BREAK
case 26: case 26:
YY_RULE_SETUP YY_RULE_SETUP
#line 265 "parse.lex" #line 269 "parse.lex"
{ {
return(ERROR); return(ERROR);
} /* parse error */ } /* parse error */
YY_BREAK YY_BREAK
case 27: case 27:
YY_RULE_SETUP YY_RULE_SETUP
#line 269 "parse.lex" #line 273 "parse.lex"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 1106 "lex.yy.c" #line 1110 "lex.yy.c"
case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(GOTCMND): case YY_STATE_EOF(GOTCMND):
case YY_STATE_EOF(GOTRUNAS): case YY_STATE_EOF(GOTRUNAS):
@@ -1989,7 +1994,7 @@ int main()
return 0; return 0;
} }
#endif #endif
#line 269 "parse.lex" #line 273 "parse.lex"
static void static void
fill(s, len) fill(s, len)
@@ -2005,7 +2010,6 @@ fill(s, len)
yylval.string[len] = '\0'; yylval.string[len] = '\0';
} }
static void static void
fill_cmnd(s, len) fill_cmnd(s, len)
char *s; char *s;
@@ -2024,7 +2028,6 @@ fill_cmnd(s, len)
yylval.command.args = NULL; yylval.command.args = NULL;
} }
static void static void
fill_args(s, len, addspace) fill_args(s, len, addspace)
char *s; char *s;
@@ -2072,7 +2075,6 @@ fill_args(s, len, addspace)
arg_len = new_len; arg_len = new_len;
} }
int int
yywrap() yywrap()
{ {
@@ -2080,7 +2082,7 @@ yywrap()
YY_NEW_FILE; YY_NEW_FILE;
#endif /* YY_NEW_FILE */ #endif /* YY_NEW_FILE */
/* don't reset the aliases if called by testsudoers */ /* Don't reset the aliases if called by testsudoers. */
if (clearaliases) if (clearaliases)
reset_aliases(); reset_aliases();

View File

@@ -17,32 +17,34 @@ static char yyrcsid[]
#define YYRECOVERING() (yyerrflag!=0) #define YYRECOVERING() (yyerrflag!=0)
#define YYPREFIX "yy" #define YYPREFIX "yy"
#line 2 "parse.yacc" #line 2 "parse.yacc"
/* /*
* CU sudo version 1.6
* Copyright (c) 1996, 1998, 1999 Todd C. Miller <Todd.Miller@courtesan.com> * Copyright (c) 1996, 1998, 1999 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
* *
* This program is free software; you can redistribute it and/or modify * This code is derived from software contributed by Chris Jepeway
* it under the terms of the GNU General Public License as published by * <jepeway@cs.utk.edu>
* the Free Software Foundation; either version 1, or (at your option)
* any later version.
* *
* This program is distributed in the hope that it will be useful, * Redistribution and use in source and binary forms, with or without
* but WITHOUT ANY WARRANTY; without even the implied warranty of * modification, are permitted provided that the following conditions
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * are met:
* GNU General Public License for more details. * 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* *
* You should have received a copy of the GNU General Public License * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* along with this program; if not, write to the Free Software * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* Please send bugs, changes, problems to sudo-bugs@courtesan.com * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
******************************************************************* * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* parse.yacc -- yacc parser and alias manipulation routines for sudo. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Chris Jepeway <jepeway@cs.utk.edu>
*/ */
#include "config.h" #include "config.h"
@@ -70,6 +72,7 @@ static char yyrcsid[]
#endif /* HAVE_LSEARCH */ #endif /* HAVE_LSEARCH */
#include "sudo.h" #include "sudo.h"
#include "parse.h"
#ifndef HAVE_LSEARCH #ifndef HAVE_LSEARCH
#include "emul/search.h" #include "emul/search.h"
@@ -174,7 +177,7 @@ void
yyerror(s) yyerror(s)
char *s; char *s;
{ {
/* save the line the first error occured on */ /* Save the line the first error occured on. */
if (errorlineno == -1) if (errorlineno == -1)
errorlineno = sudolineno ? sudolineno - 1 : 0; errorlineno = sudolineno ? sudolineno - 1 : 0;
#ifndef TRACELEXER #ifndef TRACELEXER
@@ -185,14 +188,14 @@ yyerror(s)
#endif #endif
parse_error = TRUE; parse_error = TRUE;
} }
#line 172 "parse.yacc" #line 175 "parse.yacc"
typedef union { typedef union {
char *string; char *string;
int BOOLEAN; int BOOLEAN;
struct sudo_command command; struct sudo_command command;
int tok; int tok;
} YYSTYPE; } YYSTYPE;
#line 196 "sudo.tab.c" #line 199 "sudo.tab.c"
#define ALIAS 257 #define ALIAS 257
#define NTWKADDR 258 #define NTWKADDR 258
#define FQHOST 259 #define FQHOST 259
@@ -497,8 +500,7 @@ short *yyss;
short *yysslim; short *yysslim;
YYSTYPE *yyvs; YYSTYPE *yyvs;
int yystacksize; int yystacksize;
#line 666 "parse.yacc" #line 668 "parse.yacc"
typedef struct { typedef struct {
int type; int type;
@@ -511,13 +513,9 @@ size_t naliases = 0;
size_t nslots = 0; size_t nslots = 0;
/********************************************************************** /*
* * Compare two aliasinfo structures, strcmp() style.
* aliascmp()
*
* This function compares two aliasinfo structures.
*/ */
static int static int
aliascmp(a1, a2) aliascmp(a1, a2)
const VOID *a1, *a2; const VOID *a1, *a2;
@@ -534,14 +532,9 @@ aliascmp(a1, a2)
return(r); return(r);
} }
/*
/********************************************************************** * Compare two generic_alias structures, strcmp() style.
*
* genaliascmp()
*
* This function compares two generic_alias structures.
*/ */
static int static int
genaliascmp(entry, key) genaliascmp(entry, key)
const VOID *entry, *key; const VOID *entry, *key;
@@ -553,14 +546,9 @@ genaliascmp(entry, key)
} }
/********************************************************************** /*
* * Adds the named alias of the specified type to the aliases list.
* add_alias()
*
* This function adds the named alias of the specified type to the
* aliases list.
*/ */
static int static int
add_alias(alias, type) add_alias(alias, type)
char *alias; char *alias;
@@ -600,14 +588,9 @@ add_alias(alias, type)
return(ok); return(ok);
} }
/*
/********************************************************************** * Searches for the named alias of the specified type.
*
* find_alias()
*
* This function searches for the named alias of the specified type.
*/ */
static int static int
find_alias(alias, type) find_alias(alias, type)
char *alias; char *alias;
@@ -622,17 +605,13 @@ find_alias(alias, type)
sizeof(ai), aliascmp) != NULL); sizeof(ai), aliascmp) != NULL);
} }
/*
/********************************************************************** * Allocates more space for the aliases list.
*
* more_aliases()
*
* This function allocates more space for the aliases list.
*/ */
static int static int
more_aliases() more_aliases()
{ {
nslots += MOREALIASES; nslots += MOREALIASES;
if (nslots == MOREALIASES) if (nslots == MOREALIASES)
aliases = (aliasinfo *) malloc(nslots * sizeof(aliasinfo)); aliases = (aliasinfo *) malloc(nslots * sizeof(aliasinfo));
@@ -642,14 +621,9 @@ more_aliases()
return(aliases != NULL); return(aliases != NULL);
} }
/*
/********************************************************************** * Lists the contents of the aliases list.
*
* dumpaliases()
*
* This function lists the contents of the aliases list.
*/ */
void void
dumpaliases() dumpaliases()
{ {
@@ -677,15 +651,9 @@ dumpaliases()
} }
} }
/*
/********************************************************************** * Lists the contents of cm_list and ga_list for `sudo -l'.
*
* list_matches()
*
* This function lists the contents of cm_list and ga_list for
* `sudo -l'.
*/ */
void void
list_matches() list_matches()
{ {
@@ -748,15 +716,9 @@ list_matches()
cm_list_size = 0; cm_list_size = 0;
} }
/*
/********************************************************************** * Appends a source string to the destination, optionally prefixing a separator.
*
* append()
*
* This function appends a source string to the destination prefixing
* a separator if one is given.
*/ */
static void static void
append(src, dstp, dst_len, dst_size, separator) append(src, dstp, dst_len, dst_size, separator)
char *src, **dstp; char *src, **dstp;
@@ -792,18 +754,13 @@ append(src, dstp, dst_len, dst_size, separator)
*dst_len += src_len; *dst_len += src_len;
} }
/*
/********************************************************************** * Frees up space used by the aliases list and resets the associated counters.
*
* reset_aliases()
*
* This function frees up space used by the aliases list and resets
* the associated counters.
*/ */
void void
reset_aliases() reset_aliases()
{ {
if (aliases) { if (aliases) {
free(aliases); free(aliases);
aliases = NULL; aliases = NULL;
@@ -811,17 +768,13 @@ reset_aliases()
naliases = nslots = 0; naliases = nslots = 0;
} }
/*
/********************************************************************** * Increments ga_list_len, allocating more space as necessary.
*
* expand_ga_list()
*
* This function increments ga_list_len, allocating more space as necessary.
*/ */
static void static void
expand_ga_list() expand_ga_list()
{ {
if (++ga_list_len >= ga_list_size) { if (++ga_list_len >= ga_list_size) {
while ((ga_list_size += STACKINCREMENT) < ga_list_len) while ((ga_list_size += STACKINCREMENT) < ga_list_len)
; ;
@@ -832,17 +785,13 @@ expand_ga_list()
ga_list[ga_list_len - 1].entries = NULL; ga_list[ga_list_len - 1].entries = NULL;
} }
/*
/********************************************************************** * Increments cm_list_len, allocating more space as necessary.
*
* expand_match_list()
*
* This function increments cm_list_len, allocating more space as necessary.
*/ */
static void static void
expand_match_list() expand_match_list()
{ {
if (++cm_list_len >= cm_list_size) { if (++cm_list_len >= cm_list_size) {
while ((cm_list_size += STACKINCREMENT) < cm_list_len) while ((cm_list_size += STACKINCREMENT) < cm_list_len)
; ;
@@ -856,18 +805,14 @@ expand_match_list()
cm_list[cm_list_len].nopasswd = FALSE; cm_list[cm_list_len].nopasswd = FALSE;
} }
/*
/********************************************************************** * Frees up spaced used by a previous parser run and allocates new space
* * for various data structures.
* init_parser()
*
* This function frees up spaced used by a previous parse and
* allocates new space for various data structures.
*/ */
void void
init_parser() init_parser()
{ {
/* Free up old data structures if we run the parser more than once. */ /* Free up old data structures if we run the parser more than once. */
if (match) { if (match) {
free(match); free(match);
@@ -886,7 +831,7 @@ init_parser()
if (printmatches == TRUE) if (printmatches == TRUE)
expand_match_list(); expand_match_list();
} }
#line 890 "sudo.tab.c" #line 835 "sudo.tab.c"
/* allocate initial stack or double stack size, up to YYMAXDEPTH */ /* allocate initial stack or double stack size, up to YYMAXDEPTH */
#if defined(__cplusplus) || __STDC__ #if defined(__cplusplus) || __STDC__
static int yygrowstack(void) static int yygrowstack(void)
@@ -1067,19 +1012,19 @@ yyreduce:
switch (yyn) switch (yyn)
{ {
case 3: case 3:
#line 210 "parse.yacc" #line 212 "parse.yacc"
{ ; } { ; }
break; break;
case 4: case 4:
#line 212 "parse.yacc" #line 214 "parse.yacc"
{ yyerrok; } { yyerrok; }
break; break;
case 5: case 5:
#line 213 "parse.yacc" #line 215 "parse.yacc"
{ push; } { push; }
break; break;
case 6: case 6:
#line 213 "parse.yacc" #line 215 "parse.yacc"
{ {
while (top && user_matches != TRUE) { while (top && user_matches != TRUE) {
pop; pop;
@@ -1087,23 +1032,23 @@ case 6:
} }
break; break;
case 7: case 7:
#line 219 "parse.yacc"
{ ; }
break;
case 8:
#line 221 "parse.yacc" #line 221 "parse.yacc"
{ ; } { ; }
break; break;
case 9: case 8:
#line 223 "parse.yacc" #line 223 "parse.yacc"
{ ; } { ; }
break; break;
case 10: case 9:
#line 225 "parse.yacc" #line 225 "parse.yacc"
{ ; } { ; }
break; break;
case 10:
#line 227 "parse.yacc"
{ ; }
break;
case 13: case 13:
#line 233 "parse.yacc" #line 235 "parse.yacc"
{ {
/* /*
* We already did a push if necessary in * We already did a push if necessary in
@@ -1116,13 +1061,13 @@ case 13:
} }
break; break;
case 15: case 15:
#line 246 "parse.yacc" #line 248 "parse.yacc"
{ {
push; push;
} }
break; break;
case 16: case 16:
#line 248 "parse.yacc" #line 250 "parse.yacc"
{ {
pop; pop;
if (host_matched == TRUE) if (host_matched == TRUE)
@@ -1132,13 +1077,13 @@ case 16:
} }
break; break;
case 17: case 17:
#line 256 "parse.yacc" #line 258 "parse.yacc"
{ {
host_matches = TRUE; host_matches = TRUE;
} }
break; break;
case 18: case 18:
#line 259 "parse.yacc" #line 261 "parse.yacc"
{ {
if (addr_matches(yyvsp[0].string)) if (addr_matches(yyvsp[0].string))
host_matches = TRUE; host_matches = TRUE;
@@ -1146,41 +1091,41 @@ case 18:
} }
break; break;
case 19: case 19:
#line 264 "parse.yacc" #line 266 "parse.yacc"
{ {
if (netgr_matches(yyvsp[0].string, host, NULL)) if (netgr_matches(yyvsp[0].string, user_host, NULL))
host_matches = TRUE; host_matches = TRUE;
free(yyvsp[0].string); free(yyvsp[0].string);
} }
break; break;
case 20: case 20:
#line 269 "parse.yacc" #line 271 "parse.yacc"
{ {
if (strcasecmp(shost, yyvsp[0].string) == 0) if (strcasecmp(user_shost, yyvsp[0].string) == 0)
host_matches = TRUE; host_matches = TRUE;
free(yyvsp[0].string); free(yyvsp[0].string);
} }
break; break;
case 21: case 21:
#line 274 "parse.yacc" #line 276 "parse.yacc"
{ {
if (strcasecmp(host, yyvsp[0].string) == 0) if (strcasecmp(user_host, yyvsp[0].string) == 0)
host_matches = TRUE; host_matches = TRUE;
free(yyvsp[0].string); free(yyvsp[0].string);
} }
break; break;
case 22: case 22:
#line 279 "parse.yacc" #line 281 "parse.yacc"
{ {
/* could be an all-caps hostname */ /* could be an all-caps hostname */
if (find_alias(yyvsp[0].string, HOST_ALIAS) == TRUE || if (find_alias(yyvsp[0].string, HOST_ALIAS) == TRUE ||
strcasecmp(shost, yyvsp[0].string) == 0) strcasecmp(user_shost, yyvsp[0].string) == 0)
host_matches = TRUE; host_matches = TRUE;
free(yyvsp[0].string); free(yyvsp[0].string);
} }
break; break;
case 25: case 25:
#line 292 "parse.yacc" #line 294 "parse.yacc"
{ {
if (printmatches == TRUE && if (printmatches == TRUE &&
(runas_matches == -1 || cmnd_matches == -1)) { (runas_matches == -1 || cmnd_matches == -1)) {
@@ -1201,11 +1146,11 @@ case 25:
} }
break; break;
case 26: case 26:
#line 312 "parse.yacc" #line 314 "parse.yacc"
{ ; } { ; }
break; break;
case 27: case 27:
#line 313 "parse.yacc" #line 315 "parse.yacc"
{ {
if (printmatches == TRUE && host_matches == TRUE && if (printmatches == TRUE && host_matches == TRUE &&
user_matches == TRUE) { user_matches == TRUE) {
@@ -1221,7 +1166,7 @@ case 27:
} }
break; break;
case 28: case 28:
#line 325 "parse.yacc" #line 327 "parse.yacc"
{ {
pop; pop;
if (cmnd_matched == TRUE) if (cmnd_matched == TRUE)
@@ -1232,7 +1177,7 @@ case 28:
} }
break; break;
case 29: case 29:
#line 335 "parse.yacc" #line 337 "parse.yacc"
{ {
/* /*
* If this is the first entry in a command list * If this is the first entry in a command list
@@ -1240,15 +1185,15 @@ case 29:
*/ */
if (runas_matches == -1) if (runas_matches == -1)
runas_matches = runas_matches =
(strcmp(RUNAS_DEFAULT, runas_user) == 0); (strcmp(RUNAS_DEFAULT, user_runas) == 0);
} }
break; break;
case 30: case 30:
#line 344 "parse.yacc" #line 346 "parse.yacc"
{ ; } { ; }
break; break;
case 33: case 33:
#line 351 "parse.yacc" #line 353 "parse.yacc"
{ {
if (printmatches == TRUE && host_matches == TRUE && if (printmatches == TRUE && host_matches == TRUE &&
user_matches == TRUE) user_matches == TRUE)
@@ -1258,7 +1203,7 @@ case 33:
} }
break; break;
case 34: case 34:
#line 358 "parse.yacc" #line 360 "parse.yacc"
{ {
if (printmatches == TRUE && host_matches == TRUE && if (printmatches == TRUE && host_matches == TRUE &&
user_matches == TRUE) { user_matches == TRUE) {
@@ -1272,7 +1217,7 @@ case 34:
} }
break; break;
case 35: case 35:
#line 368 "parse.yacc" #line 370 "parse.yacc"
{ {
pop; pop;
/* /*
@@ -1285,9 +1230,9 @@ case 35:
} }
break; break;
case 36: case 36:
#line 379 "parse.yacc" #line 381 "parse.yacc"
{ {
runas_matches = (strcmp(yyvsp[0].string, runas_user) == 0); runas_matches = (strcmp(yyvsp[0].string, user_runas) == 0);
if (printmatches == TRUE && in_alias == TRUE) if (printmatches == TRUE && in_alias == TRUE)
append(yyvsp[0].string, &ga_list[ga_list_len-1].entries, append(yyvsp[0].string, &ga_list[ga_list_len-1].entries,
&ga_list[ga_list_len-1].entries_len, &ga_list[ga_list_len-1].entries_len,
@@ -1301,9 +1246,9 @@ case 36:
} }
break; break;
case 37: case 37:
#line 392 "parse.yacc" #line 394 "parse.yacc"
{ {
runas_matches = usergr_matches(yyvsp[0].string, runas_user); runas_matches = usergr_matches(yyvsp[0].string, user_runas);
if (printmatches == TRUE && in_alias == TRUE) if (printmatches == TRUE && in_alias == TRUE)
append(yyvsp[0].string, &ga_list[ga_list_len-1].entries, append(yyvsp[0].string, &ga_list[ga_list_len-1].entries,
&ga_list[ga_list_len-1].entries_len, &ga_list[ga_list_len-1].entries_len,
@@ -1318,9 +1263,9 @@ case 37:
} }
break; break;
case 38: case 38:
#line 406 "parse.yacc" #line 408 "parse.yacc"
{ {
runas_matches = netgr_matches(yyvsp[0].string, NULL, runas_user); runas_matches = netgr_matches(yyvsp[0].string, NULL, user_runas);
if (printmatches == TRUE && in_alias == TRUE) if (printmatches == TRUE && in_alias == TRUE)
append(yyvsp[0].string, &ga_list[ga_list_len-1].entries, append(yyvsp[0].string, &ga_list[ga_list_len-1].entries,
&ga_list[ga_list_len-1].entries_len, &ga_list[ga_list_len-1].entries_len,
@@ -1335,11 +1280,11 @@ case 38:
} }
break; break;
case 39: case 39:
#line 420 "parse.yacc" #line 422 "parse.yacc"
{ {
/* could be an all-caps username */ /* could be an all-caps username */
if (find_alias(yyvsp[0].string, RUNAS_ALIAS) == TRUE || if (find_alias(yyvsp[0].string, RUNAS_ALIAS) == TRUE ||
strcmp(yyvsp[0].string, runas_user) == 0) strcmp(yyvsp[0].string, user_runas) == 0)
runas_matches = TRUE; runas_matches = TRUE;
else else
runas_matches = FALSE; runas_matches = FALSE;
@@ -1356,7 +1301,7 @@ case 39:
} }
break; break;
case 40: case 40:
#line 438 "parse.yacc" #line 440 "parse.yacc"
{ {
runas_matches = TRUE; runas_matches = TRUE;
if (printmatches == TRUE && in_alias == TRUE) if (printmatches == TRUE && in_alias == TRUE)
@@ -1371,13 +1316,13 @@ case 40:
} }
break; break;
case 41: case 41:
#line 452 "parse.yacc" #line 454 "parse.yacc"
{ {
; ;
} }
break; break;
case 42: case 42:
#line 455 "parse.yacc" #line 457 "parse.yacc"
{ {
no_passwd = TRUE; no_passwd = TRUE;
if (printmatches == TRUE && host_matches == TRUE && if (printmatches == TRUE && host_matches == TRUE &&
@@ -1386,7 +1331,7 @@ case 42:
} }
break; break;
case 43: case 43:
#line 461 "parse.yacc" #line 463 "parse.yacc"
{ {
no_passwd = FALSE; no_passwd = FALSE;
if (printmatches == TRUE && host_matches == TRUE && if (printmatches == TRUE && host_matches == TRUE &&
@@ -1395,7 +1340,7 @@ case 43:
} }
break; break;
case 44: case 44:
#line 469 "parse.yacc" #line 471 "parse.yacc"
{ {
if (printmatches == TRUE && in_alias == TRUE) { if (printmatches == TRUE && in_alias == TRUE) {
append("ALL", &ga_list[ga_list_len-1].entries, append("ALL", &ga_list[ga_list_len-1].entries,
@@ -1411,13 +1356,13 @@ case 44:
} }
yyval.BOOLEAN = cmnd_matches = TRUE; yyval.BOOLEAN = cmnd_matches = TRUE;
if (cmnd_safe) if (safe_cmnd)
free(cmnd_safe); free(safe_cmnd);
cmnd_safe = estrdup(cmnd); safe_cmnd = estrdup(user_cmnd);
} }
break; break;
case 45: case 45:
#line 488 "parse.yacc" #line 490 "parse.yacc"
{ {
if (printmatches == TRUE && in_alias == TRUE) { if (printmatches == TRUE && in_alias == TRUE) {
append(yyvsp[0].string, &ga_list[ga_list_len-1].entries, append(yyvsp[0].string, &ga_list[ga_list_len-1].entries,
@@ -1439,7 +1384,7 @@ case 45:
} }
break; break;
case 46: case 46:
#line 507 "parse.yacc" #line 509 "parse.yacc"
{ {
if (printmatches == TRUE && in_alias == TRUE) { if (printmatches == TRUE && in_alias == TRUE) {
append(yyvsp[0].command.cmnd, &ga_list[ga_list_len-1].entries, append(yyvsp[0].command.cmnd, &ga_list[ga_list_len-1].entries,
@@ -1463,8 +1408,8 @@ case 46:
} }
/* if NewArgc > 1 pass ptr to 1st arg, else NULL */ /* if NewArgc > 1 pass ptr to 1st arg, else NULL */
if (command_matches(cmnd, (NewArgc > 1) ? if (command_matches(user_cmnd, (NewArgc > 1) ?
cmnd_args : NULL, yyvsp[0].command.cmnd, yyvsp[0].command.args)) { user_args : NULL, yyvsp[0].command.cmnd, yyvsp[0].command.args)) {
cmnd_matches = TRUE; cmnd_matches = TRUE;
yyval.BOOLEAN = TRUE; yyval.BOOLEAN = TRUE;
} }
@@ -1475,11 +1420,11 @@ case 46:
} }
break; break;
case 49: case 49:
#line 546 "parse.yacc" #line 548 "parse.yacc"
{ push; } { push; }
break; break;
case 50: case 50:
#line 546 "parse.yacc" #line 548 "parse.yacc"
{ {
if (host_matches == TRUE && if (host_matches == TRUE &&
add_alias(yyvsp[-3].string, HOST_ALIAS) == FALSE) add_alias(yyvsp[-3].string, HOST_ALIAS) == FALSE)
@@ -1488,7 +1433,7 @@ case 50:
} }
break; break;
case 55: case 55:
#line 562 "parse.yacc" #line 564 "parse.yacc"
{ {
push; push;
if (printmatches == TRUE) { if (printmatches == TRUE) {
@@ -1500,7 +1445,7 @@ case 55:
} }
break; break;
case 56: case 56:
#line 570 "parse.yacc" #line 572 "parse.yacc"
{ {
if (cmnd_matches == TRUE && if (cmnd_matches == TRUE &&
add_alias(yyvsp[-3].string, CMND_ALIAS) == FALSE) add_alias(yyvsp[-3].string, CMND_ALIAS) == FALSE)
@@ -1513,11 +1458,11 @@ case 56:
} }
break; break;
case 57: case 57:
#line 582 "parse.yacc" #line 584 "parse.yacc"
{ ; } { ; }
break; break;
case 61: case 61:
#line 590 "parse.yacc" #line 592 "parse.yacc"
{ {
push; push;
if (printmatches == TRUE) { if (printmatches == TRUE) {
@@ -1529,7 +1474,7 @@ case 61:
} }
break; break;
case 62: case 62:
#line 598 "parse.yacc" #line 600 "parse.yacc"
{ {
if (runas_matches > 0 && if (runas_matches > 0 &&
add_alias(yyvsp[-3].string, RUNAS_ALIAS) == FALSE) add_alias(yyvsp[-3].string, RUNAS_ALIAS) == FALSE)
@@ -1542,11 +1487,11 @@ case 62:
} }
break; break;
case 65: case 65:
#line 614 "parse.yacc" #line 616 "parse.yacc"
{ push; } { push; }
break; break;
case 66: case 66:
#line 614 "parse.yacc" #line 616 "parse.yacc"
{ {
if (user_matches == TRUE && if (user_matches == TRUE &&
add_alias(yyvsp[-3].string, USER_ALIAS) == FALSE) add_alias(yyvsp[-3].string, USER_ALIAS) == FALSE)
@@ -1556,17 +1501,17 @@ case 66:
} }
break; break;
case 67: case 67:
#line 623 "parse.yacc" #line 625 "parse.yacc"
{ ; } { ; }
break; break;
case 70: case 70:
#line 628 "parse.yacc" #line 630 "parse.yacc"
{ {
push; push;
} }
break; break;
case 71: case 71:
#line 630 "parse.yacc" #line 632 "parse.yacc"
{ {
pop; pop;
if (user_matched == TRUE) if (user_matched == TRUE)
@@ -1576,7 +1521,7 @@ case 71:
} }
break; break;
case 72: case 72:
#line 638 "parse.yacc" #line 640 "parse.yacc"
{ {
if (strcmp(yyvsp[0].string, user_name) == 0) if (strcmp(yyvsp[0].string, user_name) == 0)
user_matches = TRUE; user_matches = TRUE;
@@ -1584,7 +1529,7 @@ case 72:
} }
break; break;
case 73: case 73:
#line 643 "parse.yacc" #line 645 "parse.yacc"
{ {
if (usergr_matches(yyvsp[0].string, user_name)) if (usergr_matches(yyvsp[0].string, user_name))
user_matches = TRUE; user_matches = TRUE;
@@ -1592,7 +1537,7 @@ case 73:
} }
break; break;
case 74: case 74:
#line 648 "parse.yacc" #line 650 "parse.yacc"
{ {
if (netgr_matches(yyvsp[0].string, NULL, user_name)) if (netgr_matches(yyvsp[0].string, NULL, user_name))
user_matches = TRUE; user_matches = TRUE;
@@ -1600,7 +1545,7 @@ case 74:
} }
break; break;
case 75: case 75:
#line 653 "parse.yacc" #line 655 "parse.yacc"
{ {
/* could be an all-caps username */ /* could be an all-caps username */
if (find_alias(yyvsp[0].string, USER_ALIAS) == TRUE || if (find_alias(yyvsp[0].string, USER_ALIAS) == TRUE ||
@@ -1610,12 +1555,12 @@ case 75:
} }
break; break;
case 76: case 76:
#line 660 "parse.yacc" #line 662 "parse.yacc"
{ {
user_matches = TRUE; user_matches = TRUE;
} }
break; break;
#line 1619 "sudo.tab.c" #line 1564 "sudo.tab.c"
} }
yyssp -= yym; yyssp -= yym;
yystate = *yyssp; yystate = *yyssp;