now uses flat arg string
This commit is contained in:
47
parse.c
47
parse.c
@@ -95,7 +95,6 @@ extern FILE *yyin, *yyout;
|
|||||||
* Prototypes for static (local) functions
|
* Prototypes for static (local) functions
|
||||||
*/
|
*/
|
||||||
static int has_meta __P((char *));
|
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
|
* 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)
|
int command_matches(cmnd, user_args, path, sudoers_args)
|
||||||
char *cmnd;
|
char *cmnd;
|
||||||
char **user_args;
|
char *user_args;
|
||||||
char *path;
|
char *path;
|
||||||
char **sudoers_args;
|
char *sudoers_args;
|
||||||
{
|
{
|
||||||
int plen;
|
int plen;
|
||||||
struct stat pst;
|
struct stat pst;
|
||||||
@@ -234,11 +233,10 @@ int command_matches(cmnd, user_args, path, sudoers_args)
|
|||||||
return(FALSE);
|
return(FALSE);
|
||||||
if (!sudoers_args)
|
if (!sudoers_args)
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
else if (user_args && sudoers_args)
|
else if (!user_args && sudoers_args && !strcmp("\"\"", sudoers_args))
|
||||||
return(compare_args(user_args, sudoers_args));
|
|
||||||
else if (!user_args && sudoers_args && sudoers_args[0][0] == '\0' &&
|
|
||||||
sudoers_args[1] == NULL)
|
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
|
else if (user_args && sudoers_args)
|
||||||
|
return((fnmatch(sudoers_args, user_args, FNM_PATHNAME) == 0));
|
||||||
else
|
else
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
} else {
|
} else {
|
||||||
@@ -268,11 +266,10 @@ int command_matches(cmnd, user_args, path, sudoers_args)
|
|||||||
return(FALSE);
|
return(FALSE);
|
||||||
if (!sudoers_args)
|
if (!sudoers_args)
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
else if (user_args && sudoers_args)
|
else if (!user_args && sudoers_args && !strcmp("\"\"", sudoers_args))
|
||||||
return(compare_args(user_args, sudoers_args));
|
|
||||||
else if (!user_args && sudoers_args && sudoers_args[0][0] == '\0' &&
|
|
||||||
sudoers_args[1] == NULL)
|
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
|
else if (user_args && sudoers_args)
|
||||||
|
return((fnmatch(sudoers_args, user_args, FNM_PATHNAME) == 0));
|
||||||
else
|
else
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
@@ -435,31 +432,3 @@ static int has_meta(s)
|
|||||||
}
|
}
|
||||||
return(FALSE);
|
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);
|
|
||||||
}
|
|
||||||
|
52
parse.lex
52
parse.lex
@@ -57,8 +57,8 @@ extern YYSTYPE yylval;
|
|||||||
extern int clearaliases;
|
extern int clearaliases;
|
||||||
int sudolineno = 1;
|
int sudolineno = 1;
|
||||||
static int sawspace = 0;
|
static int sawspace = 0;
|
||||||
static int max_args;
|
static int arg_len = 0;
|
||||||
static int num_args;
|
static int arg_size = 0;
|
||||||
|
|
||||||
static void fill __P((char *, int));
|
static void fill __P((char *, int));
|
||||||
static void fill_cmnd __P((char *, int));
|
static void fill_cmnd __P((char *, int));
|
||||||
@@ -122,13 +122,6 @@ WORD [[:alnum:]_-]+
|
|||||||
return(COMMENT);
|
return(COMMENT);
|
||||||
} /* return comments */
|
} /* 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]+ {
|
<GOTCMND>[^:\,= \t\n]+ {
|
||||||
LEXTRACE("ARG ");
|
LEXTRACE("ARG ");
|
||||||
fill_args(yytext, yyleng, sawspace);
|
fill_args(yytext, yyleng, sawspace);
|
||||||
@@ -288,7 +281,7 @@ static void fill_cmnd(s, len)
|
|||||||
char *s;
|
char *s;
|
||||||
int len;
|
int len;
|
||||||
{
|
{
|
||||||
num_args = max_args = 0;
|
arg_len = arg_size = 0;
|
||||||
|
|
||||||
yylval.command.cmnd = (char *) malloc(len + 1);
|
yylval.command.cmnd = (char *) malloc(len + 1);
|
||||||
if (yylval.command.cmnd == NULL)
|
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;
|
char *s;
|
||||||
int len;
|
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 we don't have enough space realloc() some more
|
||||||
if (yylval.command.args == NULL)
|
*/
|
||||||
yylval.command.args = (char **) malloc(max_args);
|
if (new_len >= arg_size) {
|
||||||
else
|
/* Allocate more space than we need for subsequent args */
|
||||||
yylval.command.args = (char **) realloc(yylval.command.args,
|
while (new_len >= (arg_size += COMMANDARGINC))
|
||||||
max_args);
|
;
|
||||||
|
|
||||||
|
yylval.command.args = (char *) realloc(yylval.command.args, arg_size);
|
||||||
if (yylval.command.args == NULL)
|
if (yylval.command.args == NULL)
|
||||||
yyerror("unable to allocate memory");
|
yyerror("unable to allocate memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
yylval.command.args[num_args-1] = (char *) malloc(len + 1);
|
/* Efficiently append the arg (with a leading space) */
|
||||||
if (yylval.command.args[num_args-1] == NULL)
|
p = yylval.command.args + arg_len;
|
||||||
yyerror("unable to allocate memory");
|
if (addspace)
|
||||||
|
*p++ = ' ';
|
||||||
/* copy the string and NULL-terminate it */
|
(void) strcpy(p, s);
|
||||||
(void) strncpy(yylval.command.args[num_args-1], s, len);
|
arg_len = new_len;
|
||||||
yylval.command.args[num_args-1][len] = '\0';
|
|
||||||
|
|
||||||
/* NULL-terminate the argument vector */
|
|
||||||
yylval.command.args[num_args] = (char *)NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user