3 * Copyright (c) 1996, 1998-2004, 2007
4 * Todd C. Miller <Todd.Miller@courtesan.com>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
18 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20 * Sponsored in part by the Defense Advanced Research Projects
21 * Agency (DARPA) and Air Force Research Laboratory, Air Force
22 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
26 * XXX - the whole opFOO naming thing is somewhat bogus.
28 * XXX - the way things are stored for printmatches is stupid,
29 * they should be stored as elements in an array and then
30 * list_matches() can format things the way it wants.
35 #include <sys/types.h>
36 #include <sys/param.h>
45 #endif /* STDC_HEADERS */
49 # ifdef HAVE_STRINGS_H
52 #endif /* HAVE_STRING_H */
55 #endif /* HAVE_UNISTD_H */
57 #if defined(YYBISON) && defined(HAVE_ALLOCA_H) && !defined(__GNUC__)
59 #endif /* YYBISON && HAVE_ALLOCA_H && !__GNUC__ */
62 #endif /* HAVE_LSEARCH */
69 #include "emul/search.h"
70 #endif /* HAVE_LSEARCH */
73 __unused static const char rcsid[] = "$Sudo: parse.yacc,v 1.204.2.10 2008/01/16 23:20:53 millert Exp $";
77 * We must define SIZE_MAX for yacc's skeleton.c.
78 * If there is no SIZE_MAX or SIZE_T_MAX we have to assume that size_t
79 * could be signed (as it is on SunOS 4.x).
83 # define SIZE_MAX SIZE_T_MAX
85 # define SIZE_MAX INT_MAX
86 # endif /* SIZE_T_MAX */
92 extern int sudolineno, parse_error;
94 int clearaliases = TRUE;
95 int printmatches = FALSE;
99 int used_runas = FALSE;
107 #define RUNAS_ALIAS 4
109 #define SETMATCH(_var, _val) do { \
110 if ((_var) == UNSPEC || (_val) != NOMATCH) \
114 #define SETNMATCH(_var, _val) do { \
115 if ((_val) != NOMATCH) \
117 else if ((_var) == UNSPEC) \
121 #define SETENV_RESET \
122 if (setenv_ok == IMPLIED) setenv_ok = def_setenv ? TRUE : UNSPEC
125 * The matching stack, initial space allocated in init_parser().
127 struct matchstack *match;
128 int top = 0, stacksize = 0;
132 if (top >= stacksize) { \
133 while ((stacksize += STACKINCREMENT) < top); \
134 match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \
136 match[top].user = UNSPEC; \
137 match[top].cmnd = UNSPEC; \
138 match[top].host = UNSPEC; \
139 match[top].runas = UNSPEC; \
140 match[top].nopass = def_authenticate ? UNSPEC : TRUE; \
141 match[top].noexec = def_noexec ? TRUE : UNSPEC; \
142 match[top].setenv = def_setenv ? TRUE : UNSPEC; \
148 if (top >= stacksize) { \
149 while ((stacksize += STACKINCREMENT) < top); \
150 match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \
152 match[top].user = match[top-1].user; \
153 match[top].cmnd = match[top-1].cmnd; \
154 match[top].host = match[top-1].host; \
155 match[top].runas = match[top-1].runas; \
156 match[top].nopass = match[top-1].nopass; \
157 match[top].noexec = match[top-1].noexec; \
158 match[top].setenv = match[top-1].setenv; \
165 yyerror("matching stack underflow"); \
172 * For testing if foo_matches variable was set to TRUE or FALSE
174 #define MATCHED(_v) ((_v) >= 0)
177 * Shortcuts for append()
179 #define append_cmnd(s, p) append(s, &cm_list[cm_list_len].cmnd, \
180 &cm_list[cm_list_len].cmnd_len, &cm_list[cm_list_len].cmnd_size, p)
182 #define append_runas(s, p) append(s, &cm_list[cm_list_len].runas, \
183 &cm_list[cm_list_len].runas_len, &cm_list[cm_list_len].runas_size, p)
185 #define append_entries(s, p) append(s, &ga_list[ga_list_len-1].entries, \
186 &ga_list[ga_list_len-1].entries_len, \
187 &ga_list[ga_list_len-1].entries_size, p)
190 * The stack for printmatches. A list of allowed commands for the user.
192 static struct command_match *cm_list = NULL;
193 static size_t cm_list_len = 0, cm_list_size = 0;
196 * List of Cmnd_Aliases and expansions for `sudo -l'
198 static int in_alias = FALSE;
199 static size_t ga_list_len = 0, ga_list_size = 0;
200 static struct generic_alias *ga_list = NULL;
203 * Does this Defaults list pertain to this user?
205 static int defaults_matches = FALSE;
210 static int add_alias __P((char *, int, int));
211 static void append __P((char *, char **, size_t *, size_t *, char *));
212 static void expand_ga_list __P((void));
213 static void expand_match_list __P((void));
214 static aliasinfo *find_alias __P((char *, int));
215 static void more_aliases __P((void));
216 void init_parser __P((void));
217 void yyerror __P((char *));
223 /* Save the line the first error occurred on. */
224 if (errorlineno == -1)
225 errorlineno = sudolineno ? sudolineno - 1 : 0;
228 (void) fprintf(stderr, ">>> sudoers file: %s, line %d <<<\n", s,
229 sudolineno ? sudolineno - 1 : 0);
231 (void) fprintf(stderr, "<*> ");
241 struct sudo_command command;
245 %start file /* special start symbol */
246 %token <command> COMMAND /* absolute pathname w/ optional args */
247 %token <string> ALIAS /* an UPPERCASE alias name */
248 %token <string> DEFVAR /* a Defaults variable name */
249 %token <string> NTWKADDR /* w.x.y.z or ipv6 address */
250 %token <string> NETGROUP /* a netgroup (+NAME) */
251 %token <string> USERGROUP /* a usergroup (%NAME) */
252 %token <string> WORD /* a word */
253 %token <tok> DEFAULTS /* Defaults entry */
254 %token <tok> DEFAULTS_HOST /* Host-specific defaults entry */
255 %token <tok> DEFAULTS_USER /* User-specific defaults entry */
256 %token <tok> DEFAULTS_RUNAS /* Runas-specific defaults entry */
257 %token <tok> RUNAS /* ( runas_list ) */
258 %token <tok> NOPASSWD /* no passwd req for command */
259 %token <tok> PASSWD /* passwd req for command (default) */
260 %token <tok> NOEXEC /* preload dummy execve() for cmnd */
261 %token <tok> EXEC /* don't preload dummy execve() */
262 %token <tok> SETENV /* user may set environment for cmnd */
263 %token <tok> NOSETENV /* user may not set environment */
264 %token <tok> ALL /* ALL keyword */
265 %token <tok> COMMENT /* comment and/or carriage return */
266 %token <tok> HOSTALIAS /* Host_Alias keyword */
267 %token <tok> CMNDALIAS /* Cmnd_Alias keyword */
268 %token <tok> USERALIAS /* User_Alias keyword */
269 %token <tok> RUNASALIAS /* Runas_Alias keyword */
270 %token <tok> ':' '=' ',' '!' '+' '-' /* union member tokens */
274 * NOTE: these are not true booleans as there are actually 4 possible values:
275 * 1) TRUE (positive match)
276 * 0) FALSE (negative match due to a '!' somewhere)
277 * -1) NOMATCH (don't change the value of *_matches)
278 * -2) UNSPEC (uninitialized value)
282 %type <BOOLEAN> runasuser
283 %type <BOOLEAN> oprunasuser
284 %type <BOOLEAN> runaslist
297 | { push; } userlist privileges {
298 while (top && user_matches != TRUE)
301 | USERALIAS useraliases
303 | HOSTALIAS hostaliases
305 | CMNDALIAS cmndaliases
307 | RUNASALIAS runasaliases
313 defaults_line : defaults_type defaults_list
316 defaults_type : DEFAULTS {
317 defaults_matches = TRUE;
319 | DEFAULTS_USER { push; } userlist {
320 defaults_matches = user_matches;
323 | DEFAULTS_RUNAS { push; } runaslist {
324 defaults_matches = $3 == TRUE;
327 | DEFAULTS_HOST { push; } hostlist {
328 defaults_matches = host_matches;
333 defaults_list : defaults_entry
334 | defaults_entry ',' defaults_list
337 defaults_entry : DEFVAR {
338 if (defaults_matches == TRUE &&
339 !set_default($1, NULL, TRUE)) {
346 if (defaults_matches == TRUE &&
347 !set_default($2, NULL, FALSE)) {
354 if (defaults_matches == TRUE &&
355 !set_default($1, $3, TRUE)) {
363 if (defaults_matches == TRUE &&
364 !set_default($1, $3, '+')) {
372 if (defaults_matches == TRUE &&
373 !set_default($1, $3, '-')) {
382 privileges : privilege
383 | privileges ':' privilege
386 privilege : hostlist '=' cmndspeclist {
388 * We already did a push if necessary in
389 * cmndspec so just reset some values so
390 * the next 'privilege' gets a clean slate.
392 host_matches = UNSPEC;
393 runas_matches = UNSPEC;
394 no_passwd = def_authenticate ? UNSPEC : TRUE;
395 no_execve = def_noexec ? TRUE : UNSPEC;
396 setenv_ok = def_setenv ? TRUE : UNSPEC;
401 SETMATCH(host_matches, $1);
404 SETNMATCH(host_matches, $2);
412 if (addr_matches($1))
419 if (netgr_matches($1, user_host, user_shost, NULL))
426 if (hostname_matches(user_shost, user_host, $1) == 0)
433 aliasinfo *aip = find_alias($1, HOST_ALIAS);
435 /* could be an all-caps hostname */
438 else if (strcasecmp(user_shost, $1) == 0)
442 (void) fprintf(stderr,
443 "%s: undeclared Host_Alias `%s' referenced near line %d\n",
444 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
456 cmndspeclist : cmndspec
457 | cmndspeclist ',' cmndspec
460 cmndspec : { SETENV_RESET; } runasspec cmndtag opcmnd {
462 * Push the entry onto the stack if it is worth
463 * saving and reset cmnd_matches for next cmnd.
465 * We need to save at least one entry on
466 * the stack so sudoers_lookup() can tell that
467 * the user was listed in sudoers. Also, we
468 * need to be able to tell whether or not a
469 * user was listed for this specific host.
471 * If keepall is set and the user matches then
472 * we need to keep entries around too...
474 if (MATCHED(user_matches) &&
475 MATCHED(host_matches) &&
476 MATCHED(cmnd_matches) &&
477 MATCHED(runas_matches))
479 else if (MATCHED(user_matches) && (top == 1 ||
480 (top == 2 && MATCHED(host_matches) &&
481 !MATCHED(match[0].host))))
483 else if (user_matches == TRUE && keepall)
485 cmnd_matches = UNSPEC;
490 SETMATCH(cmnd_matches, $1);
493 if (printmatches == TRUE) {
494 if (in_alias == TRUE)
495 append_entries("!", ", ");
496 else if (host_matches == TRUE &&
497 user_matches == TRUE)
498 append_cmnd("!", NULL);
501 SETNMATCH(cmnd_matches, $3);
505 runasspec : /* empty */ {
506 if (printmatches == TRUE && host_matches == TRUE &&
507 user_matches == TRUE) {
508 if (runas_matches == UNSPEC) {
509 cm_list[cm_list_len].runas_len = 0;
511 /* Inherit runas data. */
512 cm_list[cm_list_len].runas =
513 estrdup(cm_list[cm_list_len-1].runas);
514 cm_list[cm_list_len].runas_len =
515 cm_list[cm_list_len-1].runas_len;
516 cm_list[cm_list_len].runas_size =
517 cm_list[cm_list_len-1].runas_size;
521 * If this is the first entry in a command list
522 * then check against default runas user.
524 if (runas_matches == UNSPEC) {
525 runas_matches = userpw_matches(def_runas_default,
526 *user_runas, runas_pw) ? TRUE : NOMATCH;
534 runaslist : oprunasuser { ; }
535 | runaslist ',' oprunasuser {
536 /* Later entries override earlier ones. */
544 oprunasuser : runasuser { ; }
546 if (printmatches == TRUE) {
547 if (in_alias == TRUE)
548 append_entries("!", ", ");
549 else if (host_matches == TRUE &&
550 user_matches == TRUE)
551 append_runas("!", ", ");
554 /* Set $$ to the negation of runasuser */
555 $$ = ($3 == NOMATCH ? NOMATCH : ! $3);
560 if (printmatches == TRUE) {
561 if (in_alias == TRUE)
562 append_entries($1, ", ");
563 else if (host_matches == TRUE &&
564 user_matches == TRUE)
565 append_runas($1, ", ");
567 if (userpw_matches($1, *user_runas, runas_pw))
575 if (printmatches == TRUE) {
576 if (in_alias == TRUE)
577 append_entries($1, ", ");
578 else if (host_matches == TRUE &&
579 user_matches == TRUE)
580 append_runas($1, ", ");
582 if (usergr_matches($1, *user_runas, runas_pw))
590 if (printmatches == TRUE) {
591 if (in_alias == TRUE)
592 append_entries($1, ", ");
593 else if (host_matches == TRUE &&
594 user_matches == TRUE)
595 append_runas($1, ", ");
597 if (netgr_matches($1, NULL, NULL, *user_runas))
605 aliasinfo *aip = find_alias($1, RUNAS_ALIAS);
607 if (printmatches == TRUE) {
608 if (in_alias == TRUE)
609 append_entries($1, ", ");
610 else if (host_matches == TRUE &&
611 user_matches == TRUE)
612 append_runas($1, ", ");
614 /* could be an all-caps username */
617 else if (strcmp($1, *user_runas) == 0)
621 (void) fprintf(stderr,
622 "%s: undeclared Runas_Alias `%s' referenced near line %d\n",
623 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
635 if (printmatches == TRUE) {
636 if (in_alias == TRUE)
637 append_entries("ALL", ", ");
638 else if (host_matches == TRUE &&
639 user_matches == TRUE)
640 append_runas("ALL", ", ");
646 cmndtag : /* empty */ {
647 /* Inherit {NO,}{PASSWD,EXEC,SETENV} status. */
648 if (printmatches == TRUE && host_matches == TRUE &&
649 user_matches == TRUE) {
650 if (no_passwd == TRUE)
651 cm_list[cm_list_len].nopasswd = TRUE;
653 cm_list[cm_list_len].nopasswd = FALSE;
654 if (no_execve == TRUE)
655 cm_list[cm_list_len].noexecve = TRUE;
657 cm_list[cm_list_len].noexecve = FALSE;
658 if (setenv_ok == TRUE)
659 cm_list[cm_list_len].setenv = TRUE;
661 cm_list[cm_list_len].setenv = FALSE;
666 if (printmatches == TRUE && host_matches == TRUE &&
667 user_matches == TRUE)
668 cm_list[cm_list_len].nopasswd = TRUE;
672 if (printmatches == TRUE && host_matches == TRUE &&
673 user_matches == TRUE)
674 cm_list[cm_list_len].nopasswd = FALSE;
678 if (printmatches == TRUE && host_matches == TRUE &&
679 user_matches == TRUE)
680 cm_list[cm_list_len].noexecve = TRUE;
684 if (printmatches == TRUE && host_matches == TRUE &&
685 user_matches == TRUE)
686 cm_list[cm_list_len].noexecve = FALSE;
690 if (printmatches == TRUE && host_matches == TRUE &&
691 user_matches == TRUE)
692 cm_list[cm_list_len].setenv = TRUE;
696 if (printmatches == TRUE && host_matches == TRUE &&
697 user_matches == TRUE)
698 cm_list[cm_list_len].setenv = FALSE;
703 if (printmatches == TRUE) {
704 if (in_alias == TRUE)
705 append_entries("ALL", ", ");
706 else if (host_matches == TRUE &&
707 user_matches == TRUE) {
708 append_cmnd("ALL", NULL);
712 /* sudo "ALL" implies the SETENV tag */
713 if (setenv_ok == UNSPEC)
723 if (printmatches == TRUE) {
724 if (in_alias == TRUE)
725 append_entries($1, ", ");
726 else if (host_matches == TRUE &&
727 user_matches == TRUE) {
728 append_cmnd($1, NULL);
733 if ((aip = find_alias($1, CMND_ALIAS)))
737 (void) fprintf(stderr,
738 "%s: undeclared Cmnd_Alias `%s' referenced near line %d\n",
739 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
750 if (printmatches == TRUE) {
751 if (in_alias == TRUE) {
752 append_entries($1.cmnd, ", ");
754 append_entries($1.args, " ");
756 if (host_matches == TRUE &&
757 user_matches == TRUE) {
758 append_cmnd($1.cmnd, NULL);
760 append_cmnd($1.args, " ");
765 if (command_matches($1.cmnd, $1.args))
775 hostaliases : hostalias
776 | hostaliases ':' hostalias
779 hostalias : ALIAS { push; } '=' hostlist {
780 if ((MATCHED(host_matches) || pedantic) &&
781 !add_alias($1, HOST_ALIAS, host_matches)) {
790 | hostlist ',' ophost
793 cmndaliases : cmndalias
794 | cmndaliases ':' cmndalias
799 if (printmatches == TRUE) {
801 /* Allocate space for ga_list if necessary. */
803 ga_list[ga_list_len-1].type = CMND_ALIAS;
804 ga_list[ga_list_len-1].alias = estrdup($1);
807 if ((MATCHED(cmnd_matches) || pedantic) &&
808 !add_alias($1, CMND_ALIAS, cmnd_matches)) {
815 if (printmatches == TRUE)
820 cmndlist : opcmnd { ; }
821 | cmndlist ',' opcmnd
824 runasaliases : runasalias
825 | runasaliases ':' runasalias
829 if (printmatches == TRUE) {
831 /* Allocate space for ga_list if necessary. */
833 ga_list[ga_list_len-1].type = RUNAS_ALIAS;
834 ga_list[ga_list_len-1].alias = estrdup($1);
837 if (($4 != NOMATCH || pedantic) &&
838 !add_alias($1, RUNAS_ALIAS, $4)) {
844 if (printmatches == TRUE)
849 useraliases : useralias
850 | useraliases ':' useralias
853 useralias : ALIAS { push; } '=' userlist {
854 if ((MATCHED(user_matches) || pedantic) &&
855 !add_alias($1, USER_ALIAS, user_matches)) {
865 | userlist ',' opuser
869 SETMATCH(user_matches, $1);
872 SETNMATCH(user_matches, $2);
877 if (userpw_matches($1, user_name, sudo_user.pw))
884 if (usergr_matches($1, user_name, sudo_user.pw))
891 if (netgr_matches($1, NULL, NULL, user_name))
898 aliasinfo *aip = find_alias($1, USER_ALIAS);
900 /* could be an all-caps username */
903 else if (strcmp($1, user_name) == 0)
907 (void) fprintf(stderr,
908 "%s: undeclared User_Alias `%s' referenced near line %d\n",
909 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
926 #define MOREALIASES (32)
927 aliasinfo *aliases = NULL;
933 * Compare two aliasinfo structures, strcmp() style.
934 * Note that we do *not* compare their values.
941 aliasinfo *ai1, *ai2;
943 ai1 = (aliasinfo *) a1;
944 ai2 = (aliasinfo *) a2;
945 if ((r = strcmp(ai1->name, ai2->name)) == 0)
946 r = ai1->type - ai2->type;
952 * Compare two generic_alias structures, strcmp() style.
955 genaliascmp(entry, key)
956 const VOID *entry, *key;
959 struct generic_alias *ga1, *ga2;
961 ga1 = (struct generic_alias *) key;
962 ga2 = (struct generic_alias *) entry;
963 if ((r = strcmp(ga1->alias, ga2->alias)) == 0)
964 r = ga1->type - ga2->type;
971 * Adds the named alias of the specified type to the aliases list.
974 add_alias(alias, type, val)
983 if (naliases >= nslots)
988 ai.name = estrdup(alias);
989 onaliases = naliases;
991 aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases, &naliases,
992 sizeof(ai), aliascmp);
994 (void) snprintf(s, sizeof(s), "Aliases corrupted defining alias `%s'",
999 if (onaliases == naliases) {
1000 (void) snprintf(s, sizeof(s), "Alias `%s' already defined", alias);
1009 * Searches for the named alias of the specified type.
1012 find_alias(alias, type)
1021 return((aliasinfo *) lfind((VOID *)&ai, (VOID *)aliases, &naliases,
1022 sizeof(ai), aliascmp));
1026 * Allocates more space for the aliases list.
1032 nslots += MOREALIASES;
1033 aliases = (aliasinfo *) erealloc3(aliases, nslots, sizeof(aliasinfo));
1037 * Lists the contents of the aliases list.
1044 for (n = 0; n < naliases; n++) {
1045 if (aliases[n].val == -1)
1048 switch (aliases[n].type) {
1050 (void) puts("HOST_ALIAS");
1054 (void) puts("CMND_ALIAS");
1058 (void) puts("USER_ALIAS");
1062 (void) puts("RUNAS_ALIAS");
1065 (void) printf("\t%s: %d\n", aliases[n].name, aliases[n].val);
1070 * Lists the contents of cm_list and ga_list for `sudo -l'.
1077 struct generic_alias *ga, key;
1079 (void) printf("User %s may run the following commands on this host:\n",
1081 for (count = 0; count < cm_list_len; count++) {
1083 /* Print the runas list. */
1084 (void) fputs(" ", stdout);
1085 if (cm_list[count].runas) {
1086 (void) putchar('(');
1087 p = strtok(cm_list[count].runas, ", ");
1089 if (p != cm_list[count].runas)
1090 (void) fputs(", ", stdout);
1093 key.type = RUNAS_ALIAS;
1094 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
1095 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
1096 (void) fputs(ga->entries, stdout);
1098 (void) fputs(p, stdout);
1099 } while ((p = strtok(NULL, ", ")));
1100 (void) fputs(") ", stdout);
1102 (void) printf("(%s) ", def_runas_default);
1105 /* Is execve(2) disabled? */
1106 if (cm_list[count].noexecve == TRUE && !def_noexec)
1107 (void) fputs("NOEXEC: ", stdout);
1108 else if (cm_list[count].noexecve == FALSE && def_noexec)
1109 (void) fputs("EXEC: ", stdout);
1111 /* Is a password required? */
1112 if (cm_list[count].nopasswd == TRUE && def_authenticate)
1113 (void) fputs("NOPASSWD: ", stdout);
1114 else if (cm_list[count].nopasswd == FALSE && !def_authenticate)
1115 (void) fputs("PASSWD: ", stdout);
1117 /* Is setenv enabled? */
1118 if (cm_list[count].setenv == TRUE && !def_setenv)
1119 (void) fputs("SETENV: ", stdout);
1120 else if (cm_list[count].setenv == FALSE && def_setenv)
1121 (void) fputs("NOSETENV: ", stdout);
1123 /* Print the actual command or expanded Cmnd_Alias. */
1124 key.alias = cm_list[count].cmnd;
1125 key.type = CMND_ALIAS;
1126 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
1127 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
1128 (void) puts(ga->entries);
1130 (void) puts(cm_list[count].cmnd);
1133 /* Be nice and free up space now that we are done. */
1134 for (count = 0; count < ga_list_len; count++) {
1135 efree(ga_list[count].alias);
1136 efree(ga_list[count].entries);
1141 for (count = 0; count < cm_list_len; count++) {
1142 efree(cm_list[count].runas);
1143 efree(cm_list[count].cmnd);
1152 * Appends a source string to the destination, optionally prefixing a separator.
1155 append(src, dstp, dst_len, dst_size, separator)
1157 size_t *dst_len, *dst_size;
1160 size_t src_len = strlen(src);
1164 * Only add the separator if there is something to separate from.
1165 * If the last char is a '!', don't apply the separator (XXX).
1167 if (separator && dst && dst[*dst_len - 1] != '!')
1168 src_len += strlen(separator);
1172 /* Assumes dst will be NULL if not set. */
1174 dst = (char *) emalloc(BUFSIZ);
1181 /* Allocate more space if necessary. */
1182 if (*dst_size <= *dst_len + src_len) {
1183 while (*dst_size <= *dst_len + src_len)
1184 *dst_size += BUFSIZ;
1186 dst = (char *) erealloc(dst, *dst_size);
1190 /* Copy src -> dst adding a separator if appropriate and adjust len. */
1192 (void) strlcat(dst, separator, *dst_size);
1193 (void) strlcat(dst, src, *dst_size);
1194 *dst_len += src_len;
1198 * Frees up space used by the aliases list and resets the associated counters.
1206 for (n = 0; n < naliases; n++)
1207 efree(aliases[n].name);
1211 naliases = nslots = 0;
1215 * Increments ga_list_len, allocating more space as necessary.
1221 if (++ga_list_len >= ga_list_size) {
1222 while ((ga_list_size += STACKINCREMENT) < ga_list_len)
1224 ga_list = (struct generic_alias *)
1225 erealloc3(ga_list, ga_list_size, sizeof(struct generic_alias));
1228 ga_list[ga_list_len - 1].entries = NULL;
1232 * Increments cm_list_len, allocating more space as necessary.
1238 if (++cm_list_len >= cm_list_size) {
1239 while ((cm_list_size += STACKINCREMENT) < cm_list_len)
1241 if (cm_list == NULL)
1242 cm_list_len = 0; /* start at 0 since it is a subscript */
1243 cm_list = (struct command_match *)
1244 erealloc3(cm_list, cm_list_size, sizeof(struct command_match));
1247 cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL;
1248 cm_list[cm_list_len].nopasswd = FALSE;
1249 cm_list[cm_list_len].noexecve = FALSE;
1250 cm_list[cm_list_len].setenv = FALSE;
1254 * Frees up spaced used by a previous parser run and allocates new space
1255 * for various data structures.
1261 /* Free up old data structures if we run the parser more than once. */
1266 parse_error = FALSE;
1272 /* Allocate space for the matching stack. */
1273 stacksize = STACKINCREMENT;
1274 match = (struct matchstack *) emalloc2(stacksize, sizeof(struct matchstack));
1276 /* Allocate space for the match list (for `sudo -l'). */
1277 if (printmatches == TRUE)
1278 expand_match_list();