* XXX - the way things are stored for printmatches is stupid,
* they should be stored as elements in an array and then
* list_matches() can format things the way it wants.
- *
- * XXX - '!' chars are not preserved when expanding Aliases
*/
#include "config.h"
top--; \
}
+/*
+ * Shortcuts for append()
+ */
+#define append_cmnd(s, p) append(s, &cm_list[cm_list_len].cmnd, \
+ &cm_list[cm_list_len].cmnd_len, &cm_list[cm_list_len].cmnd_size, p)
+
+#define append_runas(s, p) append(s, &cm_list[cm_list_len].runas, \
+ &cm_list[cm_list_len].runas_len, &cm_list[cm_list_len].runas_size, p)
+
+#define append_entries(s, p) append(s, &ga_list[ga_list_len-1].entries, \
+ &ga_list[ga_list_len-1].entries_len, \
+ &ga_list[ga_list_len-1].entries_size, p)
+
/*
* The stack for printmatches. A list of allowed commands for the user.
*/
static int find_alias __P((char *, int));
static int add_alias __P((char *, int));
static int more_aliases __P((void));
-static void append __P((char *, char **, size_t *, size_t *, int));
+static void append __P((char *, char **, size_t *, size_t *, char *));
static void expand_ga_list __P((void));
static void expand_match_list __P((void));
void init_parser __P((void));
;
cmndspec : runasspec nopasswd opcmnd {
- if (printmatches == TRUE &&
- (runas_matches == -1 || cmnd_matches == -1)) {
- cm_list[cm_list_len].runas_len = 0;
- cm_list[cm_list_len].cmnd_len = 0;
- cm_list[cm_list_len].nopasswd = FALSE;
- }
/*
* Push the entry onto the stack if it is worth
* saving (or if nothing else is on the stack)
cmnd_matches = TRUE;
}
| '!' {
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append("!", &cm_list[cm_list_len].cmnd,
- &cm_list[cm_list_len].cmnd_len,
- &cm_list[cm_list_len].cmnd_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries("!", ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_cmnd("!", NULL);
}
} cmnd {
if ($3 == TRUE)
;
runasspec : /* empty */ {
+ if (printmatches == TRUE && host_matches == TRUE &&
+ user_matches == TRUE) {
+ if (runas_matches == -1) {
+ cm_list[cm_list_len].runas_len = 0;
+ } else {
+ /* Inherit runas data. */
+ cm_list[cm_list_len].runas =
+ estrdup(cm_list[cm_list_len-1].runas);
+ cm_list[cm_list_len].runas_len =
+ cm_list[cm_list_len-1].runas_len;
+ cm_list[cm_list_len].runas_size =
+ cm_list[cm_list_len-1].runas_size;
+ }
+ }
/*
* If this is the first entry in a command list
* then check against RUNAS_DEFAULT.
;
oprunasuser : runasuser {
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE)
- append("", &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, ':');
if ($1 == TRUE)
runas_matches = TRUE;
}
| '!' {
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE)
- append("!", &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, ':');
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries("!", ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas("!", ", ");
+ }
} runasuser {
if ($3 == TRUE)
runas_matches = FALSE;
}
runasuser : NAME {
- if (printmatches == TRUE && in_alias == TRUE)
- append($1, &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ',');
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE)
- append($1, &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries($1, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas($1, ", ");
+ }
if (strcmp($1, user_runas) == 0)
$$ = TRUE;
free($1);
}
| USERGROUP {
- if (printmatches == TRUE && in_alias == TRUE)
- append($1, &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ',');
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append($1, &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries($1, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas($1, ", ");
}
if (usergr_matches($1, user_runas))
$$ = TRUE;
free($1);
}
| NETGROUP {
- if (printmatches == TRUE && in_alias == TRUE)
- append($1, &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ',');
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append($1, &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries($1, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas($1, ", ");
}
if (netgr_matches($1, NULL, user_runas))
$$ = TRUE;
free($1);
}
| ALIAS {
- if (printmatches == TRUE && in_alias == TRUE)
- append($1, &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ',');
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE)
- append($1, &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries($1, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas($1, ", ");
+ }
/* could be an all-caps username */
if (find_alias($1, RUNAS_ALIAS) == TRUE ||
strcmp($1, user_runas) == 0)
free($1);
}
| ALL {
- if (printmatches == TRUE && in_alias == TRUE)
- append("ALL", &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ',');
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE)
- append("ALL", &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries($1, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas($1, ", ");
+ }
$$ = TRUE;
free($1);
}
;
nopasswd : /* empty */ {
- ;
+ /* Inherit NOPASSWD/PASSWD status. */
+ if (printmatches == TRUE && host_matches == TRUE &&
+ user_matches == TRUE) {
+ if (no_passwd == TRUE)
+ cm_list[cm_list_len].nopasswd = TRUE;
+ else
+ cm_list[cm_list_len].nopasswd = FALSE;
+ }
}
| NOPASSWD {
no_passwd = TRUE;
;
cmnd : ALL {
- if (printmatches == TRUE && in_alias == TRUE) {
- append("ALL", &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ',');
- }
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append("ALL", &cm_list[cm_list_len].cmnd,
- &cm_list[cm_list_len].cmnd_len,
- &cm_list[cm_list_len].cmnd_size, 0);
- expand_match_list();
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries($1, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE) {
+ append_cmnd($1, NULL);
+ expand_match_list();
+ }
}
$$ = TRUE;
safe_cmnd = estrdup(user_cmnd);
}
| ALIAS {
- if (printmatches == TRUE && in_alias == TRUE) {
- append($1, &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ',');
- }
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append($1, &cm_list[cm_list_len].cmnd,
- &cm_list[cm_list_len].cmnd_len,
- &cm_list[cm_list_len].cmnd_size, 0);
- expand_match_list();
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries($1, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE) {
+ append_cmnd($1, NULL);
+ expand_match_list();
+ }
}
+
if (find_alias($1, CMND_ALIAS) == TRUE)
$$ = TRUE;
free($1);
}
| COMMAND {
- if (printmatches == TRUE && in_alias == TRUE) {
- append($1.cmnd, &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ',');
- if ($1.args)
- append($1.args, &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ' ');
- }
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append($1.cmnd, &cm_list[cm_list_len].cmnd,
- &cm_list[cm_list_len].cmnd_len,
- &cm_list[cm_list_len].cmnd_size, 0);
- if ($1.args)
- append($1.args, &cm_list[cm_list_len].cmnd,
- &cm_list[cm_list_len].cmnd_len,
- &cm_list[cm_list_len].cmnd_size, ' ');
- expand_match_list();
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE) {
+ append_entries($1.cmnd, ", ");
+ if ($1.args)
+ append_entries($1.args, " ");
+ }
+ if (host_matches == TRUE &&
+ user_matches == TRUE) {
+ append_cmnd($1.cmnd, NULL);
+ if ($1.args)
+ append_cmnd($1.args, " ");
+ expand_match_list();
+ }
}
if (command_matches(user_cmnd, user_args,
typedef struct {
int type;
- char name[BUFSIZ];
+ char *name;
} aliasinfo;
#define MOREALIASES (32)
int type;
{
aliasinfo ai, *aip;
+ size_t onaliases;
char s[512];
- int ok;
- ok = FALSE; /* assume failure */
- ai.type = type;
- (void) strcpy(ai.name, alias);
- if (lfind((VOID *)&ai, (VOID *)aliases, &naliases, sizeof(ai),
- aliascmp) != NULL) {
- (void) sprintf(s, "Alias `%.*s' already defined", (int) sizeof(s) - 25,
- alias);
+ if (naliases >= nslots && !more_aliases()) {
+ (void) snprintf(s, sizeof(s), "Out of memory defining alias `%s'",
+ alias);
yyerror(s);
- } else {
- if (naliases >= nslots && !more_aliases()) {
- (void) sprintf(s, "Out of memory defining alias `%.*s'",
- (int) sizeof(s) - 32, alias);
- yyerror(s);
- }
-
- aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases,
- &naliases, sizeof(ai), aliascmp);
+ return(FALSE);
+ }
- if (aip != NULL) {
- ok = TRUE;
- } else {
- (void) sprintf(s, "Aliases corrupted defining alias `%.*s'",
- (int) sizeof(s) - 36, alias);
- yyerror(s);
- }
+ ai.type = type;
+ ai.name = estrdup(alias);
+ onaliases = naliases;
+
+ aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases, &naliases,
+ sizeof(ai), aliascmp);
+ if (aip == NULL) {
+ (void) snprintf(s, sizeof(s), "Aliases corrupted defining alias `%s'",
+ alias);
+ yyerror(s);
+ return(FALSE);
+ }
+ if (onaliases == naliases) {
+ (void) snprintf(s, sizeof(s), "Alias `%s' already defined", alias);
+ yyerror(s);
+ return(FALSE);
}
- return(ok);
+ return(TRUE);
}
/*
{
aliasinfo ai;
- (void) strcpy(ai.name, alias);
+ ai.name = alias;
ai.type = type;
return(lfind((VOID *)&ai, (VOID *)aliases, &naliases,
(void) fputs(" ", stdout);
if (cm_list[i].runas) {
(void) putchar('(');
- p = strtok(cm_list[i].runas, ":");
+ p = strtok(cm_list[i].runas, ", ");
do {
if (p != cm_list[i].runas)
(void) fputs(", ", stdout);
(void) fputs(ga->entries, stdout);
else
(void) fputs(p, stdout);
- } while ((p = strtok(NULL, ":")));
+ } while ((p = strtok(NULL, ", ")));
(void) fputs(") ", stdout);
} else {
- (void) fputs("(root) ", stdout);
+ (void) printf("(%s) ", RUNAS_DEFAULT);
}
/* Is a password required? */
append(src, dstp, dst_len, dst_size, separator)
char *src, **dstp;
size_t *dst_len, *dst_size;
- int separator;
+ char *separator;
{
- /* Only add the separator if *dstp is non-NULL. */
- size_t src_len = strlen(src) + ((separator && *dstp) ? 1 : 0);
+ size_t src_len = strlen(src);
char *dst = *dstp;
+ /*
+ * Only add the separator if there is something to separate from.
+ * If the last char is a '!', don't apply the separator (XXX).
+ */
+ if (separator && dst && dst[*dst_len - 1] != '!')
+ src_len += strlen(separator);
+ else
+ separator = NULL;
+
/* Assumes dst will be NULL if not set. */
if (dst == NULL) {
dst = (char *) emalloc(BUFSIZ);
*dstp = dst;
}
- /* Copy src -> dst adding a separator char if appropriate and adjust len. */
+ /* Copy src -> dst adding a separator if appropriate and adjust len. */
dst += *dst_len;
- if (separator && *dst_len)
- *dst++ = (char) separator;
- (void) strcpy(dst, src);
*dst_len += src_len;
+ *dst = '\0';
+ if (separator)
+ (void) strcat(dst, separator);
+ (void) strcat(dst, src);
}
/*
void
reset_aliases()
{
+ size_t n;
if (aliases) {
+ for (n = 0; n < naliases; n++)
+ free(aliases[n].name);
free(aliases);
aliases = NULL;
}
* XXX - the way things are stored for printmatches is stupid,
* they should be stored as elements in an array and then
* list_matches() can format things the way it wants.
- *
- * XXX - '!' chars are not preserved when expanding Aliases
*/
#include "config.h"
top--; \
}
+/*
+ * Shortcuts for append()
+ */
+#define append_cmnd(s, p) append(s, &cm_list[cm_list_len].cmnd, \
+ &cm_list[cm_list_len].cmnd_len, &cm_list[cm_list_len].cmnd_size, p)
+
+#define append_runas(s, p) append(s, &cm_list[cm_list_len].runas, \
+ &cm_list[cm_list_len].runas_len, &cm_list[cm_list_len].runas_size, p)
+
+#define append_entries(s, p) append(s, &ga_list[ga_list_len-1].entries, \
+ &ga_list[ga_list_len-1].entries_len, \
+ &ga_list[ga_list_len-1].entries_size, p)
+
/*
* The stack for printmatches. A list of allowed commands for the user.
*/
static int find_alias __P((char *, int));
static int add_alias __P((char *, int));
static int more_aliases __P((void));
-static void append __P((char *, char **, size_t *, size_t *, int));
+static void append __P((char *, char **, size_t *, size_t *, char *));
static void expand_ga_list __P((void));
static void expand_match_list __P((void));
void init_parser __P((void));
#endif
parse_error = TRUE;
}
-#line 192 "parse.yacc"
+#line 203 "parse.yacc"
typedef union {
char *string;
int BOOLEAN;
struct sudo_command command;
int tok;
} YYSTYPE;
-#line 216 "sudo.tab.c"
+#line 227 "sudo.tab.c"
#define ALIAS 257
#define NTWKADDR 258
#define FQHOST 259
short *yysslim;
YYSTYPE *yyvs;
int yystacksize;
-#line 672 "parse.yacc"
+#line 673 "parse.yacc"
typedef struct {
int type;
- char name[BUFSIZ];
+ char *name;
} aliasinfo;
#define MOREALIASES (32)
int type;
{
aliasinfo ai, *aip;
+ size_t onaliases;
char s[512];
- int ok;
- ok = FALSE; /* assume failure */
- ai.type = type;
- (void) strcpy(ai.name, alias);
- if (lfind((VOID *)&ai, (VOID *)aliases, &naliases, sizeof(ai),
- aliascmp) != NULL) {
- (void) sprintf(s, "Alias `%.*s' already defined", (int) sizeof(s) - 25,
- alias);
+ if (naliases >= nslots && !more_aliases()) {
+ (void) snprintf(s, sizeof(s), "Out of memory defining alias `%s'",
+ alias);
yyerror(s);
- } else {
- if (naliases >= nslots && !more_aliases()) {
- (void) sprintf(s, "Out of memory defining alias `%.*s'",
- (int) sizeof(s) - 32, alias);
- yyerror(s);
- }
-
- aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases,
- &naliases, sizeof(ai), aliascmp);
+ return(FALSE);
+ }
- if (aip != NULL) {
- ok = TRUE;
- } else {
- (void) sprintf(s, "Aliases corrupted defining alias `%.*s'",
- (int) sizeof(s) - 36, alias);
- yyerror(s);
- }
+ ai.type = type;
+ ai.name = estrdup(alias);
+ onaliases = naliases;
+
+ aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases, &naliases,
+ sizeof(ai), aliascmp);
+ if (aip == NULL) {
+ (void) snprintf(s, sizeof(s), "Aliases corrupted defining alias `%s'",
+ alias);
+ yyerror(s);
+ return(FALSE);
+ }
+ if (onaliases == naliases) {
+ (void) snprintf(s, sizeof(s), "Alias `%s' already defined", alias);
+ yyerror(s);
+ return(FALSE);
}
- return(ok);
+ return(TRUE);
}
/*
{
aliasinfo ai;
- (void) strcpy(ai.name, alias);
+ ai.name = alias;
ai.type = type;
return(lfind((VOID *)&ai, (VOID *)aliases, &naliases,
(void) fputs(" ", stdout);
if (cm_list[i].runas) {
(void) putchar('(');
- p = strtok(cm_list[i].runas, ":");
+ p = strtok(cm_list[i].runas, ", ");
do {
if (p != cm_list[i].runas)
(void) fputs(", ", stdout);
(void) fputs(ga->entries, stdout);
else
(void) fputs(p, stdout);
- } while ((p = strtok(NULL, ":")));
+ } while ((p = strtok(NULL, ", ")));
(void) fputs(") ", stdout);
} else {
- (void) fputs("(root) ", stdout);
+ (void) printf("(%s) ", RUNAS_DEFAULT);
}
/* Is a password required? */
append(src, dstp, dst_len, dst_size, separator)
char *src, **dstp;
size_t *dst_len, *dst_size;
- int separator;
+ char *separator;
{
- /* Only add the separator if *dstp is non-NULL. */
- size_t src_len = strlen(src) + ((separator && *dstp) ? 1 : 0);
+ size_t src_len = strlen(src);
char *dst = *dstp;
+ /*
+ * Only add the separator if there is something to separate from.
+ * If the last char is a '!', don't apply the separator (XXX).
+ */
+ if (separator && dst && dst[*dst_len - 1] != '!')
+ src_len += strlen(separator);
+ else
+ separator = NULL;
+
/* Assumes dst will be NULL if not set. */
if (dst == NULL) {
dst = (char *) emalloc(BUFSIZ);
*dstp = dst;
}
- /* Copy src -> dst adding a separator char if appropriate and adjust len. */
+ /* Copy src -> dst adding a separator if appropriate and adjust len. */
dst += *dst_len;
- if (separator && *dst_len)
- *dst++ = (char) separator;
- (void) strcpy(dst, src);
*dst_len += src_len;
+ *dst = '\0';
+ if (separator)
+ (void) strcat(dst, separator);
+ (void) strcat(dst, src);
}
/*
void
reset_aliases()
{
+ size_t n;
if (aliases) {
+ for (n = 0; n < naliases; n++)
+ free(aliases[n].name);
free(aliases);
aliases = NULL;
}
if (printmatches == TRUE)
expand_match_list();
}
-#line 852 "sudo.tab.c"
+#line 873 "sudo.tab.c"
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
#if defined(__cplusplus) || __STDC__
static int yygrowstack(void)
switch (yyn)
{
case 3:
-#line 233 "parse.yacc"
+#line 244 "parse.yacc"
{ ; }
break;
case 4:
-#line 235 "parse.yacc"
+#line 246 "parse.yacc"
{ yyerrok; }
break;
case 5:
-#line 236 "parse.yacc"
+#line 247 "parse.yacc"
{ push; }
break;
case 6:
-#line 236 "parse.yacc"
+#line 247 "parse.yacc"
{
while (top && user_matches != TRUE) {
pop;
}
break;
case 7:
-#line 242 "parse.yacc"
+#line 253 "parse.yacc"
{ ; }
break;
case 8:
-#line 244 "parse.yacc"
+#line 255 "parse.yacc"
{ ; }
break;
case 9:
-#line 246 "parse.yacc"
+#line 257 "parse.yacc"
{ ; }
break;
case 10:
-#line 248 "parse.yacc"
+#line 259 "parse.yacc"
{ ; }
break;
case 13:
-#line 256 "parse.yacc"
+#line 267 "parse.yacc"
{
/*
* We already did a push if necessary in
}
break;
case 14:
-#line 268 "parse.yacc"
+#line 279 "parse.yacc"
{
if (yyvsp[0].BOOLEAN == TRUE)
host_matches = TRUE;
}
break;
case 15:
-#line 272 "parse.yacc"
+#line 283 "parse.yacc"
{
if (yyvsp[0].BOOLEAN == TRUE)
host_matches = FALSE;
}
break;
case 16:
-#line 277 "parse.yacc"
+#line 288 "parse.yacc"
{
yyval.BOOLEAN = TRUE;
free(yyvsp[0].string);
}
break;
case 17:
-#line 281 "parse.yacc"
+#line 292 "parse.yacc"
{
if (addr_matches(yyvsp[0].string))
yyval.BOOLEAN = TRUE;
}
break;
case 18:
-#line 286 "parse.yacc"
+#line 297 "parse.yacc"
{
if (netgr_matches(yyvsp[0].string, user_host, NULL))
yyval.BOOLEAN = TRUE;
}
break;
case 19:
-#line 291 "parse.yacc"
+#line 302 "parse.yacc"
{
if (strcasecmp(user_shost, yyvsp[0].string) == 0)
yyval.BOOLEAN = TRUE;
}
break;
case 20:
-#line 296 "parse.yacc"
+#line 307 "parse.yacc"
{
if (strcasecmp(user_host, yyvsp[0].string) == 0)
yyval.BOOLEAN = TRUE;
}
break;
case 21:
-#line 301 "parse.yacc"
+#line 312 "parse.yacc"
{
/* could be an all-caps hostname */
if (find_alias(yyvsp[0].string, HOST_ALIAS) == TRUE ||
}
break;
case 24:
-#line 314 "parse.yacc"
+#line 325 "parse.yacc"
{
- if (printmatches == TRUE &&
- (runas_matches == -1 || cmnd_matches == -1)) {
- cm_list[cm_list_len].runas_len = 0;
- cm_list[cm_list_len].cmnd_len = 0;
- cm_list[cm_list_len].nopasswd = FALSE;
- }
/*
* Push the entry onto the stack if it is worth
* saving (or if nothing else is on the stack)
}
break;
case 25:
-#line 334 "parse.yacc"
+#line 339 "parse.yacc"
{
if (yyvsp[0].BOOLEAN == TRUE)
cmnd_matches = TRUE;
}
break;
case 26:
-#line 338 "parse.yacc"
+#line 343 "parse.yacc"
{
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append("!", &cm_list[cm_list_len].cmnd,
- &cm_list[cm_list_len].cmnd_len,
- &cm_list[cm_list_len].cmnd_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries("!", ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_cmnd("!", NULL);
}
}
break;
case 27:
-#line 345 "parse.yacc"
+#line 351 "parse.yacc"
{
if (yyvsp[0].BOOLEAN == TRUE)
cmnd_matches = FALSE;
}
break;
case 28:
-#line 351 "parse.yacc"
+#line 357 "parse.yacc"
{
+ if (printmatches == TRUE && host_matches == TRUE &&
+ user_matches == TRUE) {
+ if (runas_matches == -1) {
+ cm_list[cm_list_len].runas_len = 0;
+ } else {
+ /* Inherit runas data. */
+ cm_list[cm_list_len].runas =
+ estrdup(cm_list[cm_list_len-1].runas);
+ cm_list[cm_list_len].runas_len =
+ cm_list[cm_list_len-1].runas_len;
+ cm_list[cm_list_len].runas_size =
+ cm_list[cm_list_len-1].runas_size;
+ }
+ }
/*
* If this is the first entry in a command list
* then check against RUNAS_DEFAULT.
}
break;
case 29:
-#line 360 "parse.yacc"
+#line 380 "parse.yacc"
{ ; }
break;
case 32:
-#line 367 "parse.yacc"
+#line 387 "parse.yacc"
{
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE)
- append("", &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, ':');
if (yyvsp[0].BOOLEAN == TRUE)
runas_matches = TRUE;
}
break;
case 33:
-#line 376 "parse.yacc"
+#line 391 "parse.yacc"
{
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE)
- append("!", &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, ':');
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries("!", ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas("!", ", ");
+ }
}
break;
case 34:
-#line 382 "parse.yacc"
+#line 399 "parse.yacc"
{
if (yyvsp[0].BOOLEAN == TRUE)
runas_matches = FALSE;
}
break;
case 35:
-#line 387 "parse.yacc"
+#line 404 "parse.yacc"
{
- if (printmatches == TRUE && in_alias == TRUE)
- 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_size, ',');
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE)
- append(yyvsp[0].string, &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries(yyvsp[0].string, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas(yyvsp[0].string, ", ");
+ }
if (strcmp(yyvsp[0].string, user_runas) == 0)
yyval.BOOLEAN = TRUE;
free(yyvsp[0].string);
}
break;
case 36:
-#line 401 "parse.yacc"
+#line 416 "parse.yacc"
{
- if (printmatches == TRUE && in_alias == TRUE)
- 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_size, ',');
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append(yyvsp[0].string, &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries(yyvsp[0].string, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas(yyvsp[0].string, ", ");
}
if (usergr_matches(yyvsp[0].string, user_runas))
yyval.BOOLEAN = TRUE;
}
break;
case 37:
-#line 416 "parse.yacc"
+#line 428 "parse.yacc"
{
- if (printmatches == TRUE && in_alias == TRUE)
- 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_size, ',');
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append(yyvsp[0].string, &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries(yyvsp[0].string, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas(yyvsp[0].string, ", ");
}
if (netgr_matches(yyvsp[0].string, NULL, user_runas))
yyval.BOOLEAN = TRUE;
}
break;
case 38:
-#line 431 "parse.yacc"
+#line 440 "parse.yacc"
{
- if (printmatches == TRUE && in_alias == TRUE)
- 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_size, ',');
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE)
- append(yyvsp[0].string, &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries(yyvsp[0].string, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas(yyvsp[0].string, ", ");
+ }
/* could be an all-caps username */
if (find_alias(yyvsp[0].string, RUNAS_ALIAS) == TRUE ||
strcmp(yyvsp[0].string, user_runas) == 0)
}
break;
case 39:
-#line 447 "parse.yacc"
+#line 454 "parse.yacc"
{
- if (printmatches == TRUE && in_alias == TRUE)
- append("ALL", &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ',');
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE)
- append("ALL", &cm_list[cm_list_len].runas,
- &cm_list[cm_list_len].runas_len,
- &cm_list[cm_list_len].runas_size, 0);
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries(yyvsp[0].string, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE)
+ append_runas(yyvsp[0].string, ", ");
+ }
yyval.BOOLEAN = TRUE;
free(yyvsp[0].string);
}
break;
case 40:
-#line 462 "parse.yacc"
+#line 467 "parse.yacc"
{
- ;
+ /* Inherit NOPASSWD/PASSWD status. */
+ if (printmatches == TRUE && host_matches == TRUE &&
+ user_matches == TRUE) {
+ if (no_passwd == TRUE)
+ cm_list[cm_list_len].nopasswd = TRUE;
+ else
+ cm_list[cm_list_len].nopasswd = FALSE;
+ }
}
break;
case 41:
-#line 465 "parse.yacc"
+#line 477 "parse.yacc"
{
no_passwd = TRUE;
if (printmatches == TRUE && host_matches == TRUE &&
}
break;
case 42:
-#line 471 "parse.yacc"
+#line 483 "parse.yacc"
{
no_passwd = FALSE;
if (printmatches == TRUE && host_matches == TRUE &&
}
break;
case 43:
-#line 479 "parse.yacc"
+#line 491 "parse.yacc"
{
- if (printmatches == TRUE && in_alias == TRUE) {
- append("ALL", &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ',');
- }
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append("ALL", &cm_list[cm_list_len].cmnd,
- &cm_list[cm_list_len].cmnd_len,
- &cm_list[cm_list_len].cmnd_size, 0);
- expand_match_list();
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries(yyvsp[0].string, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE) {
+ append_cmnd(yyvsp[0].string, NULL);
+ expand_match_list();
+ }
}
yyval.BOOLEAN = TRUE;
}
break;
case 44:
-#line 500 "parse.yacc"
+#line 509 "parse.yacc"
{
- if (printmatches == TRUE && in_alias == TRUE) {
- 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_size, ',');
- }
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append(yyvsp[0].string, &cm_list[cm_list_len].cmnd,
- &cm_list[cm_list_len].cmnd_len,
- &cm_list[cm_list_len].cmnd_size, 0);
- expand_match_list();
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE)
+ append_entries(yyvsp[0].string, ", ");
+ else if (host_matches == TRUE &&
+ user_matches == TRUE) {
+ append_cmnd(yyvsp[0].string, NULL);
+ expand_match_list();
+ }
}
+
if (find_alias(yyvsp[0].string, CMND_ALIAS) == TRUE)
yyval.BOOLEAN = TRUE;
free(yyvsp[0].string);
}
break;
case 45:
-#line 517 "parse.yacc"
+#line 524 "parse.yacc"
{
- if (printmatches == TRUE && in_alias == TRUE) {
- append(yyvsp[0].command.cmnd, &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ',');
- if (yyvsp[0].command.args)
- append(yyvsp[0].command.args, &ga_list[ga_list_len-1].entries,
- &ga_list[ga_list_len-1].entries_len,
- &ga_list[ga_list_len-1].entries_size, ' ');
- }
- if (printmatches == TRUE && host_matches == TRUE &&
- user_matches == TRUE) {
- append(yyvsp[0].command.cmnd, &cm_list[cm_list_len].cmnd,
- &cm_list[cm_list_len].cmnd_len,
- &cm_list[cm_list_len].cmnd_size, 0);
- if (yyvsp[0].command.args)
- append(yyvsp[0].command.args, &cm_list[cm_list_len].cmnd,
- &cm_list[cm_list_len].cmnd_len,
- &cm_list[cm_list_len].cmnd_size, ' ');
- expand_match_list();
+ if (printmatches == TRUE) {
+ if (in_alias == TRUE) {
+ append_entries(yyvsp[0].command.cmnd, ", ");
+ if (yyvsp[0].command.args)
+ append_entries(yyvsp[0].command.args, " ");
+ }
+ if (host_matches == TRUE &&
+ user_matches == TRUE) {
+ append_cmnd(yyvsp[0].command.cmnd, NULL);
+ if (yyvsp[0].command.args)
+ append_cmnd(yyvsp[0].command.args, " ");
+ expand_match_list();
+ }
}
if (command_matches(user_cmnd, user_args,
}
break;
case 48:
-#line 553 "parse.yacc"
+#line 554 "parse.yacc"
{ push; }
break;
case 49:
-#line 553 "parse.yacc"
+#line 554 "parse.yacc"
{
if (host_matches == TRUE &&
add_alias(yyvsp[-3].string, HOST_ALIAS) == FALSE)
}
break;
case 54:
-#line 569 "parse.yacc"
+#line 570 "parse.yacc"
{
push;
if (printmatches == TRUE) {
}
break;
case 55:
-#line 577 "parse.yacc"
+#line 578 "parse.yacc"
{
if (cmnd_matches == TRUE &&
add_alias(yyvsp[-3].string, CMND_ALIAS) == FALSE)
}
break;
case 56:
-#line 589 "parse.yacc"
+#line 590 "parse.yacc"
{ ; }
break;
case 60:
-#line 597 "parse.yacc"
+#line 598 "parse.yacc"
{
push;
if (printmatches == TRUE) {
}
break;
case 61:
-#line 605 "parse.yacc"
+#line 606 "parse.yacc"
{
if (runas_matches > 0 &&
add_alias(yyvsp[-3].string, RUNAS_ALIAS) == FALSE)
}
break;
case 64:
-#line 621 "parse.yacc"
+#line 622 "parse.yacc"
{ push; }
break;
case 65:
-#line 621 "parse.yacc"
+#line 622 "parse.yacc"
{
if (user_matches == TRUE &&
add_alias(yyvsp[-3].string, USER_ALIAS) == FALSE)
}
break;
case 66:
-#line 630 "parse.yacc"
+#line 631 "parse.yacc"
{ ; }
break;
case 68:
-#line 634 "parse.yacc"
+#line 635 "parse.yacc"
{
if (yyvsp[0].BOOLEAN == TRUE)
user_matches = TRUE;
}
break;
case 69:
-#line 638 "parse.yacc"
+#line 639 "parse.yacc"
{
if (yyvsp[0].BOOLEAN == TRUE)
user_matches = FALSE;
}
break;
case 70:
-#line 643 "parse.yacc"
+#line 644 "parse.yacc"
{
if (strcmp(yyvsp[0].string, user_name) == 0)
yyval.BOOLEAN = TRUE;
}
break;
case 71:
-#line 648 "parse.yacc"
+#line 649 "parse.yacc"
{
if (usergr_matches(yyvsp[0].string, user_name))
yyval.BOOLEAN = TRUE;
}
break;
case 72:
-#line 653 "parse.yacc"
+#line 654 "parse.yacc"
{
if (netgr_matches(yyvsp[0].string, NULL, user_name))
yyval.BOOLEAN = TRUE;
}
break;
case 73:
-#line 658 "parse.yacc"
+#line 659 "parse.yacc"
{
/* could be an all-caps username */
if (find_alias(yyvsp[0].string, USER_ALIAS) == TRUE ||
}
break;
case 74:
-#line 665 "parse.yacc"
+#line 666 "parse.yacc"
{
yyval.BOOLEAN = TRUE;
free(yyvsp[0].string);
}
break;
-#line 1564 "sudo.tab.c"
+#line 1575 "sudo.tab.c"
}
yyssp -= yym;
yystate = *yyssp;