command_alias -> generic_alias
This commit is contained in:
133
parse.yacc
133
parse.yacc
@@ -122,8 +122,8 @@ static size_t cm_list_len = 0, cm_list_size = 0;
|
|||||||
* List of Cmnd_Aliases and expansions for `sudo -l'
|
* List of Cmnd_Aliases and expansions for `sudo -l'
|
||||||
*/
|
*/
|
||||||
static int in_alias = FALSE;
|
static int in_alias = FALSE;
|
||||||
static size_t ca_list_len = 0, ca_list_size = 0;
|
static size_t ga_list_len = 0, ga_list_size = 0;
|
||||||
static struct command_alias *ca_list = NULL;
|
static struct generic_alias *ga_list = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Protoypes
|
* Protoypes
|
||||||
@@ -136,7 +136,7 @@ static int find_alias __P((char *, int));
|
|||||||
static int add_alias __P((char *, int));
|
static int add_alias __P((char *, int));
|
||||||
static int more_aliases __P((void));
|
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 *, int));
|
||||||
static void expand_ca_list __P((void));
|
static void expand_ga_list __P((void));
|
||||||
static void expand_match_list __P((void));
|
static void expand_match_list __P((void));
|
||||||
void init_parser __P((void));
|
void init_parser __P((void));
|
||||||
void yyerror __P((char *));
|
void yyerror __P((char *));
|
||||||
@@ -324,9 +324,9 @@ runaslist : runasuser {
|
|||||||
runasuser : NAME {
|
runasuser : NAME {
|
||||||
$$ = (strcmp($1, runas_user) == 0);
|
$$ = (strcmp($1, runas_user) == 0);
|
||||||
if (printmatches == TRUE && in_alias == TRUE)
|
if (printmatches == TRUE && in_alias == TRUE)
|
||||||
append($1, &ca_list[ca_list_len-1].entries,
|
append($1, &ga_list[ga_list_len-1].entries,
|
||||||
&ca_list[ca_list_len-1].entries_len,
|
&ga_list[ga_list_len-1].entries_len,
|
||||||
&ca_list[ca_list_len-1].entries_size, ',');
|
&ga_list[ga_list_len-1].entries_size, ',');
|
||||||
if (printmatches == TRUE && host_matches == TRUE &&
|
if (printmatches == TRUE && host_matches == TRUE &&
|
||||||
user_matches == TRUE)
|
user_matches == TRUE)
|
||||||
append($1, &cm_list[cm_list_len].runas,
|
append($1, &cm_list[cm_list_len].runas,
|
||||||
@@ -337,9 +337,9 @@ runasuser : NAME {
|
|||||||
| USERGROUP {
|
| USERGROUP {
|
||||||
$$ = usergr_matches($1, runas_user);
|
$$ = usergr_matches($1, runas_user);
|
||||||
if (printmatches == TRUE && in_alias == TRUE)
|
if (printmatches == TRUE && in_alias == TRUE)
|
||||||
append($1, &ca_list[ca_list_len-1].entries,
|
append($1, &ga_list[ga_list_len-1].entries,
|
||||||
&ca_list[ca_list_len-1].entries_len,
|
&ga_list[ga_list_len-1].entries_len,
|
||||||
&ca_list[ca_list_len-1].entries_size, ',');
|
&ga_list[ga_list_len-1].entries_size, ',');
|
||||||
if (printmatches == TRUE && host_matches == TRUE &&
|
if (printmatches == TRUE && host_matches == TRUE &&
|
||||||
user_matches == TRUE) {
|
user_matches == TRUE) {
|
||||||
append("%", &cm_list[cm_list_len].runas,
|
append("%", &cm_list[cm_list_len].runas,
|
||||||
@@ -354,9 +354,9 @@ runasuser : NAME {
|
|||||||
| NETGROUP {
|
| NETGROUP {
|
||||||
$$ = netgr_matches($1, NULL, runas_user);
|
$$ = netgr_matches($1, NULL, runas_user);
|
||||||
if (printmatches == TRUE && in_alias == TRUE)
|
if (printmatches == TRUE && in_alias == TRUE)
|
||||||
append($1, &ca_list[ca_list_len-1].entries,
|
append($1, &ga_list[ga_list_len-1].entries,
|
||||||
&ca_list[ca_list_len-1].entries_len,
|
&ga_list[ga_list_len-1].entries_len,
|
||||||
&ca_list[ca_list_len-1].entries_size, ',');
|
&ga_list[ga_list_len-1].entries_size, ',');
|
||||||
if (printmatches == TRUE && host_matches == TRUE &&
|
if (printmatches == TRUE && host_matches == TRUE &&
|
||||||
user_matches == TRUE) {
|
user_matches == TRUE) {
|
||||||
append("+", &cm_list[cm_list_len].runas,
|
append("+", &cm_list[cm_list_len].runas,
|
||||||
@@ -376,9 +376,9 @@ runasuser : NAME {
|
|||||||
else
|
else
|
||||||
$$ = FALSE;
|
$$ = FALSE;
|
||||||
if (printmatches == TRUE && in_alias == TRUE)
|
if (printmatches == TRUE && in_alias == TRUE)
|
||||||
append($1, &ca_list[ca_list_len-1].entries,
|
append($1, &ga_list[ga_list_len-1].entries,
|
||||||
&ca_list[ca_list_len-1].entries_len,
|
&ga_list[ga_list_len-1].entries_len,
|
||||||
&ca_list[ca_list_len-1].entries_size, ',');
|
&ga_list[ga_list_len-1].entries_size, ',');
|
||||||
if (printmatches == TRUE && host_matches == TRUE &&
|
if (printmatches == TRUE && host_matches == TRUE &&
|
||||||
user_matches == TRUE)
|
user_matches == TRUE)
|
||||||
append($1, &cm_list[cm_list_len].runas,
|
append($1, &cm_list[cm_list_len].runas,
|
||||||
@@ -389,9 +389,9 @@ runasuser : NAME {
|
|||||||
| ALL {
|
| ALL {
|
||||||
$$ = TRUE;
|
$$ = TRUE;
|
||||||
if (printmatches == TRUE && in_alias == TRUE)
|
if (printmatches == TRUE && in_alias == TRUE)
|
||||||
append("ALL", &ca_list[ca_list_len-1].entries,
|
append("ALL", &ga_list[ga_list_len-1].entries,
|
||||||
&ca_list[ca_list_len-1].entries_len,
|
&ga_list[ga_list_len-1].entries_len,
|
||||||
&ca_list[ca_list_len-1].entries_size, ',');
|
&ga_list[ga_list_len-1].entries_size, ',');
|
||||||
if (printmatches == TRUE && host_matches == TRUE &&
|
if (printmatches == TRUE && host_matches == TRUE &&
|
||||||
user_matches == TRUE)
|
user_matches == TRUE)
|
||||||
append("ALL", &cm_list[cm_list_len].runas,
|
append("ALL", &cm_list[cm_list_len].runas,
|
||||||
@@ -413,9 +413,9 @@ nopasswd : /* empty */ {
|
|||||||
|
|
||||||
cmnd : ALL {
|
cmnd : ALL {
|
||||||
if (printmatches == TRUE && in_alias == TRUE) {
|
if (printmatches == TRUE && in_alias == TRUE) {
|
||||||
append("ALL", &ca_list[ca_list_len-1].entries,
|
append("ALL", &ga_list[ga_list_len-1].entries,
|
||||||
&ca_list[ca_list_len-1].entries_len,
|
&ga_list[ga_list_len-1].entries_len,
|
||||||
&ca_list[ca_list_len-1].entries_size, ',');
|
&ga_list[ga_list_len-1].entries_size, ',');
|
||||||
}
|
}
|
||||||
if (printmatches == TRUE && host_matches == TRUE &&
|
if (printmatches == TRUE && host_matches == TRUE &&
|
||||||
user_matches == TRUE) {
|
user_matches == TRUE) {
|
||||||
@@ -430,9 +430,9 @@ cmnd : ALL {
|
|||||||
}
|
}
|
||||||
| ALIAS {
|
| ALIAS {
|
||||||
if (printmatches == TRUE && in_alias == TRUE) {
|
if (printmatches == TRUE && in_alias == TRUE) {
|
||||||
append($1, &ca_list[ca_list_len-1].entries,
|
append($1, &ga_list[ga_list_len-1].entries,
|
||||||
&ca_list[ca_list_len-1].entries_len,
|
&ga_list[ga_list_len-1].entries_len,
|
||||||
&ca_list[ca_list_len-1].entries_size, ',');
|
&ga_list[ga_list_len-1].entries_size, ',');
|
||||||
}
|
}
|
||||||
if (printmatches == TRUE && host_matches == TRUE &&
|
if (printmatches == TRUE && host_matches == TRUE &&
|
||||||
user_matches == TRUE) {
|
user_matches == TRUE) {
|
||||||
@@ -449,13 +449,13 @@ cmnd : ALL {
|
|||||||
}
|
}
|
||||||
| COMMAND {
|
| COMMAND {
|
||||||
if (printmatches == TRUE && in_alias == TRUE) {
|
if (printmatches == TRUE && in_alias == TRUE) {
|
||||||
append($1.cmnd, &ca_list[ca_list_len-1].entries,
|
append($1.cmnd, &ga_list[ga_list_len-1].entries,
|
||||||
&ca_list[ca_list_len-1].entries_len,
|
&ga_list[ga_list_len-1].entries_len,
|
||||||
&ca_list[ca_list_len-1].entries_size, ',');
|
&ga_list[ga_list_len-1].entries_size, ',');
|
||||||
if ($1.args)
|
if ($1.args)
|
||||||
append($1.args, &ca_list[ca_list_len-1].entries,
|
append($1.args, &ga_list[ga_list_len-1].entries,
|
||||||
&ca_list[ca_list_len-1].entries_len,
|
&ga_list[ga_list_len-1].entries_len,
|
||||||
&ca_list[ca_list_len-1].entries_size, ' ');
|
&ga_list[ga_list_len-1].entries_size, ' ');
|
||||||
}
|
}
|
||||||
if (printmatches == TRUE && host_matches == TRUE &&
|
if (printmatches == TRUE && host_matches == TRUE &&
|
||||||
user_matches == TRUE) {
|
user_matches == TRUE) {
|
||||||
@@ -506,9 +506,9 @@ cmndalias : ALIAS {
|
|||||||
push;
|
push;
|
||||||
if (printmatches == TRUE) {
|
if (printmatches == TRUE) {
|
||||||
in_alias = TRUE;
|
in_alias = TRUE;
|
||||||
/* Allocate space for ca_list if necesary. */
|
/* Allocate space for ga_list if necesary. */
|
||||||
expand_ca_list();
|
expand_ga_list();
|
||||||
if (!(ca_list[ca_list_len-1].alias = strdup($1))){
|
if (!(ga_list[ga_list_len-1].alias = strdup($1))){
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
(void) fprintf(stderr,
|
(void) fprintf(stderr,
|
||||||
"%s: cannot allocate memory!\n", Argv[0]);
|
"%s: cannot allocate memory!\n", Argv[0]);
|
||||||
@@ -540,9 +540,9 @@ runasalias : ALIAS {
|
|||||||
push;
|
push;
|
||||||
if (printmatches == TRUE) {
|
if (printmatches == TRUE) {
|
||||||
in_alias = TRUE;
|
in_alias = TRUE;
|
||||||
/* Allocate space for ca_list if necesary. */
|
/* Allocate space for ga_list if necesary. */
|
||||||
expand_ca_list();
|
expand_ga_list();
|
||||||
if (!(ca_list[ca_list_len-1].alias = strdup($1))){
|
if (!(ga_list[ga_list_len-1].alias = strdup($1))){
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
(void) fprintf(stderr,
|
(void) fprintf(stderr,
|
||||||
"%s: cannot allocate memory!\n", Argv[0]);
|
"%s: cannot allocate memory!\n", Argv[0]);
|
||||||
@@ -644,18 +644,18 @@ static int aliascmp(a1, a2)
|
|||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
*
|
*
|
||||||
* cmndaliascmp()
|
* genaliascmp()
|
||||||
*
|
*
|
||||||
* This function compares two command_alias structures.
|
* This function compares two generic_alias structures.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int cmndaliascmp(entry, key)
|
static int genaliascmp(entry, key)
|
||||||
const VOID *entry, *key;
|
const VOID *entry, *key;
|
||||||
{
|
{
|
||||||
struct command_alias *ca1 = (struct command_alias *) key;
|
struct generic_alias *ga1 = (struct generic_alias *) key;
|
||||||
struct command_alias *ca2 = (struct command_alias *) entry;
|
struct generic_alias *ga2 = (struct generic_alias *) entry;
|
||||||
|
|
||||||
return(strcmp(ca1->alias, ca2->alias));
|
return(strcmp(ga1->alias, ga2->alias));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -784,7 +784,7 @@ void dumpaliases()
|
|||||||
*
|
*
|
||||||
* list_matches()
|
* list_matches()
|
||||||
*
|
*
|
||||||
* This function lists the contents of cm_list and ca_list for
|
* This function lists the contents of cm_list and ga_list for
|
||||||
* `sudo -l'.
|
* `sudo -l'.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -792,7 +792,7 @@ void list_matches()
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *p;
|
char *p;
|
||||||
struct command_alias *ca, key;
|
struct generic_alias *ga, key;
|
||||||
|
|
||||||
(void) puts("You may run the following commands on this host:");
|
(void) puts("You may run the following commands on this host:");
|
||||||
for (i = 0; i < cm_list_len; i++) {
|
for (i = 0; i < cm_list_len; i++) {
|
||||||
@@ -806,11 +806,10 @@ void list_matches()
|
|||||||
if (p != cm_list[i].runas)
|
if (p != cm_list[i].runas)
|
||||||
(void) fputs(", ", stdout);
|
(void) fputs(", ", stdout);
|
||||||
|
|
||||||
/* XXX - this is disgusting! Make ca_list generic? */
|
|
||||||
key.alias = p;
|
key.alias = p;
|
||||||
if ((ca = (struct command_alias *) lfind((VOID *) &key,
|
if ((ga = (struct generic_alias *) lfind((VOID *) &key,
|
||||||
(VOID *) &ca_list[0], &ca_list_len, sizeof(key), cmndaliascmp)))
|
(VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
|
||||||
(void) fputs(ca->entries, stdout);
|
(void) fputs(ga->entries, stdout);
|
||||||
else
|
else
|
||||||
(void) fputs(p, stdout);
|
(void) fputs(p, stdout);
|
||||||
} while ((p = strtok(NULL, ":")));
|
} while ((p = strtok(NULL, ":")));
|
||||||
@@ -825,20 +824,20 @@ void list_matches()
|
|||||||
|
|
||||||
/* Print the actual command or expanded Cmnd_Alias. */
|
/* Print the actual command or expanded Cmnd_Alias. */
|
||||||
key.alias = cm_list[i].cmnd;
|
key.alias = cm_list[i].cmnd;
|
||||||
if ((ca = (struct command_alias *) lfind((VOID *) &key,
|
if ((ga = (struct generic_alias *) lfind((VOID *) &key,
|
||||||
(VOID *) &ca_list[0], &ca_list_len, sizeof(key), cmndaliascmp)))
|
(VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
|
||||||
(void) puts(ca->entries);
|
(void) puts(ga->entries);
|
||||||
else
|
else
|
||||||
(void) puts(cm_list[i].cmnd);
|
(void) puts(cm_list[i].cmnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Be nice and free up space now that we are done. */
|
/* Be nice and free up space now that we are done. */
|
||||||
for (i = 0; i < ca_list_len; i++) {
|
for (i = 0; i < ga_list_len; i++) {
|
||||||
(void) free(ca_list[i].alias);
|
(void) free(ga_list[i].alias);
|
||||||
(void) free(ca_list[i].entries);
|
(void) free(ga_list[i].entries);
|
||||||
}
|
}
|
||||||
(void) free(ca_list);
|
(void) free(ga_list);
|
||||||
ca_list = NULL;
|
ga_list = NULL;
|
||||||
|
|
||||||
for (i = 0; i < cm_list_len; i++) {
|
for (i = 0; i < cm_list_len; i++) {
|
||||||
(void) free(cm_list[i].runas);
|
(void) free(cm_list[i].runas);
|
||||||
@@ -919,25 +918,25 @@ void reset_aliases()
|
|||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
*
|
*
|
||||||
* expand_ca_list()
|
* expand_ga_list()
|
||||||
*
|
*
|
||||||
* This function increments ca_list_len, allocating more space as necesary.
|
* This function increments ga_list_len, allocating more space as necesary.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void expand_ca_list()
|
static void expand_ga_list()
|
||||||
{
|
{
|
||||||
if (++ca_list_len > ca_list_size) {
|
if (++ga_list_len > ga_list_size) {
|
||||||
while ((ca_list_size += STACKINCREMENT) < ca_list_len);
|
while ((ga_list_size += STACKINCREMENT) < ga_list_len);
|
||||||
if (ca_list == NULL) {
|
if (ga_list == NULL) {
|
||||||
if ((ca_list = (struct command_alias *)
|
if ((ga_list = (struct generic_alias *)
|
||||||
malloc(sizeof(struct command_alias) * ca_list_size)) == NULL) {
|
malloc(sizeof(struct generic_alias) * ga_list_size)) == NULL) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((ca_list = (struct command_alias *) realloc(ca_list,
|
if ((ga_list = (struct generic_alias *) realloc(ga_list,
|
||||||
sizeof(struct command_alias) * ca_list_size)) == NULL) {
|
sizeof(struct generic_alias) * ga_list_size)) == NULL) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
(void) fprintf(stderr, "%s: cannot allocate memory!\n", Argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
@@ -945,7 +944,7 @@ static void expand_ca_list()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ca_list[ca_list_len - 1].entries = NULL;
|
ga_list[ga_list_len - 1].entries = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
2
sudo.h
2
sudo.h
@@ -92,7 +92,7 @@ struct command_match {
|
|||||||
/*
|
/*
|
||||||
* Structure containing Cmnd_Alias's if "sudo -l" is used.
|
* Structure containing Cmnd_Alias's if "sudo -l" is used.
|
||||||
*/
|
*/
|
||||||
struct command_alias {
|
struct generic_alias {
|
||||||
char *alias;
|
char *alias;
|
||||||
char *entries;
|
char *entries;
|
||||||
size_t entries_size;
|
size_t entries_size;
|
||||||
|
Reference in New Issue
Block a user