now uses flat arg string

This commit is contained in:
Todd C. Miller
1996-07-22 19:30:42 +00:00
parent 27d484f3f0
commit 8a177073ef
2 changed files with 30 additions and 69 deletions

47
parse.c
View File

@@ -95,7 +95,6 @@ extern FILE *yyin, *yyout;
* Prototypes for static (local) functions
*/
static int has_meta __P((char *));
static int compare_args __P((char **, char **));
/*
* this routine is called from the sudo.c module and tries to validate
@@ -195,9 +194,9 @@ int validate(check_cmnd)
*/
int command_matches(cmnd, user_args, path, sudoers_args)
char *cmnd;
char **user_args;
char *user_args;
char *path;
char **sudoers_args;
char *sudoers_args;
{
int plen;
struct stat pst;
@@ -234,11 +233,10 @@ int command_matches(cmnd, user_args, path, sudoers_args)
return(FALSE);
if (!sudoers_args)
return(TRUE);
else if (user_args && sudoers_args)
return(compare_args(user_args, sudoers_args));
else if (!user_args && sudoers_args && sudoers_args[0][0] == '\0' &&
sudoers_args[1] == NULL)
else if (!user_args && sudoers_args && !strcmp("\"\"", sudoers_args))
return(TRUE);
else if (user_args && sudoers_args)
return((fnmatch(sudoers_args, user_args, FNM_PATHNAME) == 0));
else
return(FALSE);
} else {
@@ -268,11 +266,10 @@ int command_matches(cmnd, user_args, path, sudoers_args)
return(FALSE);
if (!sudoers_args)
return(TRUE);
else if (user_args && sudoers_args)
return(compare_args(user_args, sudoers_args));
else if (!user_args && sudoers_args && sudoers_args[0][0] == '\0' &&
sudoers_args[1] == NULL)
else if (!user_args && sudoers_args && !strcmp("\"\"", sudoers_args))
return(TRUE);
else if (user_args && sudoers_args)
return((fnmatch(sudoers_args, user_args, FNM_PATHNAME) == 0));
else
return(FALSE);
}
@@ -435,31 +432,3 @@ static int has_meta(s)
}
return(FALSE);
}
/*
* Compare two arguments lists and return TRUE if they are
* the same (inc. wildcard matches) or FALSE if they differ.
*/
static int compare_args(user_args, sudoers_args)
char **user_args;
char **sudoers_args;
{
char **ua, **sa;
for (ua=user_args, sa=sudoers_args; *ua && *sa; ua++, sa++) {
/* Match and honor wildcards */
if (fnmatch(*sa, *ua, FNM_PATHNAME) != 0)
return(FALSE);
}
/*
* Return false unless we got to the end of each or the
* last part of sudoers_args we looked at consists of '*'
*/
if (*sa-- || (*ua && **sa != '*' && *(*sa + 1) != '\0'))
return(FALSE);
else
return(TRUE);
}

View File

@@ -57,8 +57,8 @@ extern YYSTYPE yylval;
extern int clearaliases;
int sudolineno = 1;
static int sawspace = 0;
static int max_args;
static int num_args;
static int arg_len = 0;
static int arg_size = 0;
static void fill __P((char *, int));
static void fill_cmnd __P((char *, int));
@@ -122,13 +122,6 @@ WORD [[:alnum:]_-]+
return(COMMENT);
} /* return comments */
<GOTCMND>\"[^\n]*\" {
/* XXX - this should go away */
LEXTRACE("ARG ");
fill_args(yytext+1, yyleng-2, sawspace);
sawspace = FALSE;
} /* quoted command line arg */
<GOTCMND>[^:\,= \t\n]+ {
LEXTRACE("ARG ");
fill_args(yytext, yyleng, sawspace);
@@ -288,7 +281,7 @@ static void fill_cmnd(s, len)
char *s;
int len;
{
num_args = max_args = 0;
arg_len = arg_size = 0;
yylval.command.cmnd = (char *) malloc(len + 1);
if (yylval.command.cmnd == NULL)
@@ -302,34 +295,33 @@ static void fill_cmnd(s, len)
}
static void fill_args(s, len, startnew)
static void fill_args(s, len, addspace)
char *s;
int len;
int startnew;
int addspace;
{
num_args += startnew;
int new_len = arg_len + len + addspace;
char *p;
if (num_args >= max_args) {
max_args += COMMANDARGINC;
if (yylval.command.args == NULL)
yylval.command.args = (char **) malloc(max_args);
else
yylval.command.args = (char **) realloc(yylval.command.args,
max_args);
/*
* If we don't have enough space realloc() some more
*/
if (new_len >= arg_size) {
/* Allocate more space than we need for subsequent args */
while (new_len >= (arg_size += COMMANDARGINC))
;
yylval.command.args = (char *) realloc(yylval.command.args, arg_size);
if (yylval.command.args == NULL)
yyerror("unable to allocate memory");
}
yylval.command.args[num_args-1] = (char *) malloc(len + 1);
if (yylval.command.args[num_args-1] == NULL)
yyerror("unable to allocate memory");
/* copy the string and NULL-terminate it */
(void) strncpy(yylval.command.args[num_args-1], s, len);
yylval.command.args[num_args-1][len] = '\0';
/* NULL-terminate the argument vector */
yylval.command.args[num_args] = (char *)NULL;
/* Efficiently append the arg (with a leading space) */
p = yylval.command.args + arg_len;
if (addspace)
*p++ = ' ';
(void) strcpy(p, s);
arg_len = new_len;
}