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 */
68 #include "emul/search.h"
69 #endif /* HAVE_LSEARCH */
72 __unused static const char rcsid[] = "$Sudo: parse.yacc,v 1.204.2.9 2007/11/21 18:15:49 millert Exp $";
78 extern int sudolineno, parse_error;
80 int clearaliases = TRUE;
81 int printmatches = FALSE;
85 int used_runas = FALSE;
95 #define SETMATCH(_var, _val) do { \
96 if ((_var) == UNSPEC || (_val) != NOMATCH) \
100 #define SETNMATCH(_var, _val) do { \
101 if ((_val) != NOMATCH) \
103 else if ((_var) == UNSPEC) \
107 #define SETENV_RESET \
108 if (setenv_ok == IMPLIED) setenv_ok = def_setenv ? TRUE : UNSPEC
111 * The matching stack, initial space allocated in init_parser().
113 struct matchstack *match;
114 int top = 0, stacksize = 0;
118 if (top >= stacksize) { \
119 while ((stacksize += STACKINCREMENT) < top); \
120 match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \
122 match[top].user = UNSPEC; \
123 match[top].cmnd = UNSPEC; \
124 match[top].host = UNSPEC; \
125 match[top].runas = UNSPEC; \
126 match[top].nopass = def_authenticate ? UNSPEC : TRUE; \
127 match[top].noexec = def_noexec ? TRUE : UNSPEC; \
128 match[top].setenv = def_setenv ? TRUE : UNSPEC; \
134 if (top >= stacksize) { \
135 while ((stacksize += STACKINCREMENT) < top); \
136 match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \
138 match[top].user = match[top-1].user; \
139 match[top].cmnd = match[top-1].cmnd; \
140 match[top].host = match[top-1].host; \
141 match[top].runas = match[top-1].runas; \
142 match[top].nopass = match[top-1].nopass; \
143 match[top].noexec = match[top-1].noexec; \
144 match[top].setenv = match[top-1].setenv; \
151 yyerror("matching stack underflow"); \
158 * For testing if foo_matches variable was set to TRUE or FALSE
160 #define MATCHED(_v) ((_v) >= 0)
163 * Shortcuts for append()
165 #define append_cmnd(s, p) append(s, &cm_list[cm_list_len].cmnd, \
166 &cm_list[cm_list_len].cmnd_len, &cm_list[cm_list_len].cmnd_size, p)
168 #define append_runas(s, p) append(s, &cm_list[cm_list_len].runas, \
169 &cm_list[cm_list_len].runas_len, &cm_list[cm_list_len].runas_size, p)
171 #define append_entries(s, p) append(s, &ga_list[ga_list_len-1].entries, \
172 &ga_list[ga_list_len-1].entries_len, \
173 &ga_list[ga_list_len-1].entries_size, p)
176 * The stack for printmatches. A list of allowed commands for the user.
178 static struct command_match *cm_list = NULL;
179 static size_t cm_list_len = 0, cm_list_size = 0;
182 * List of Cmnd_Aliases and expansions for `sudo -l'
184 static int in_alias = FALSE;
185 static size_t ga_list_len = 0, ga_list_size = 0;
186 static struct generic_alias *ga_list = NULL;
189 * Does this Defaults list pertain to this user?
191 static int defaults_matches = FALSE;
196 static int add_alias __P((char *, int, int));
197 static void append __P((char *, char **, size_t *, size_t *, char *));
198 static void expand_ga_list __P((void));
199 static void expand_match_list __P((void));
200 static aliasinfo *find_alias __P((char *, int));
201 static void more_aliases __P((void));
202 void init_parser __P((void));
203 void yyerror __P((char *));
209 /* Save the line the first error occurred on. */
210 if (errorlineno == -1)
211 errorlineno = sudolineno ? sudolineno - 1 : 0;
214 (void) fprintf(stderr, ">>> sudoers file: %s, line %d <<<\n", s,
215 sudolineno ? sudolineno - 1 : 0);
217 (void) fprintf(stderr, "<*> ");
227 struct sudo_command command;
231 %start file /* special start symbol */
232 %token <command> COMMAND /* absolute pathname w/ optional args */
233 %token <string> ALIAS /* an UPPERCASE alias name */
234 %token <string> DEFVAR /* a Defaults variable name */
235 %token <string> NTWKADDR /* w.x.y.z or ipv6 address */
236 %token <string> NETGROUP /* a netgroup (+NAME) */
237 %token <string> USERGROUP /* a usergroup (%NAME) */
238 %token <string> WORD /* a word */
239 %token <tok> DEFAULTS /* Defaults entry */
240 %token <tok> DEFAULTS_HOST /* Host-specific defaults entry */
241 %token <tok> DEFAULTS_USER /* User-specific defaults entry */
242 %token <tok> DEFAULTS_RUNAS /* Runas-specific defaults entry */
243 %token <tok> RUNAS /* ( runas_list ) */
244 %token <tok> NOPASSWD /* no passwd req for command */
245 %token <tok> PASSWD /* passwd req for command (default) */
246 %token <tok> NOEXEC /* preload dummy execve() for cmnd */
247 %token <tok> EXEC /* don't preload dummy execve() */
248 %token <tok> SETENV /* user may set environment for cmnd */
249 %token <tok> NOSETENV /* user may not set environment */
250 %token <tok> ALL /* ALL keyword */
251 %token <tok> COMMENT /* comment and/or carriage return */
252 %token <tok> HOSTALIAS /* Host_Alias keyword */
253 %token <tok> CMNDALIAS /* Cmnd_Alias keyword */
254 %token <tok> USERALIAS /* User_Alias keyword */
255 %token <tok> RUNASALIAS /* Runas_Alias keyword */
256 %token <tok> ':' '=' ',' '!' '+' '-' /* union member tokens */
260 * NOTE: these are not true booleans as there are actually 4 possible values:
261 * 1) TRUE (positive match)
262 * 0) FALSE (negative match due to a '!' somewhere)
263 * -1) NOMATCH (don't change the value of *_matches)
264 * -2) UNSPEC (uninitialized value)
268 %type <BOOLEAN> runasuser
269 %type <BOOLEAN> oprunasuser
270 %type <BOOLEAN> runaslist
283 | { push; } userlist privileges {
284 while (top && user_matches != TRUE)
287 | USERALIAS useraliases
289 | HOSTALIAS hostaliases
291 | CMNDALIAS cmndaliases
293 | RUNASALIAS runasaliases
299 defaults_line : defaults_type defaults_list
302 defaults_type : DEFAULTS {
303 defaults_matches = TRUE;
305 | DEFAULTS_USER { push; } userlist {
306 defaults_matches = user_matches;
309 | DEFAULTS_RUNAS { push; } runaslist {
310 defaults_matches = $3 == TRUE;
313 | DEFAULTS_HOST { push; } hostlist {
314 defaults_matches = host_matches;
319 defaults_list : defaults_entry
320 | defaults_entry ',' defaults_list
323 defaults_entry : DEFVAR {
324 if (defaults_matches == TRUE &&
325 !set_default($1, NULL, TRUE)) {
332 if (defaults_matches == TRUE &&
333 !set_default($2, NULL, FALSE)) {
340 if (defaults_matches == TRUE &&
341 !set_default($1, $3, TRUE)) {
349 if (defaults_matches == TRUE &&
350 !set_default($1, $3, '+')) {
358 if (defaults_matches == TRUE &&
359 !set_default($1, $3, '-')) {
368 privileges : privilege
369 | privileges ':' privilege
372 privilege : hostlist '=' cmndspeclist {
374 * We already did a push if necessary in
375 * cmndspec so just reset some values so
376 * the next 'privilege' gets a clean slate.
378 host_matches = UNSPEC;
379 runas_matches = UNSPEC;
380 no_passwd = def_authenticate ? UNSPEC : TRUE;
381 no_execve = def_noexec ? TRUE : UNSPEC;
382 setenv_ok = def_setenv ? TRUE : UNSPEC;
387 SETMATCH(host_matches, $1);
390 SETNMATCH(host_matches, $2);
398 if (addr_matches($1))
405 if (netgr_matches($1, user_host, user_shost, NULL))
412 if (hostname_matches(user_shost, user_host, $1) == 0)
419 aliasinfo *aip = find_alias($1, HOST_ALIAS);
421 /* could be an all-caps hostname */
424 else if (strcasecmp(user_shost, $1) == 0)
428 (void) fprintf(stderr,
429 "%s: undeclared Host_Alias `%s' referenced near line %d\n",
430 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
442 cmndspeclist : cmndspec
443 | cmndspeclist ',' cmndspec
446 cmndspec : { SETENV_RESET; } runasspec cmndtag opcmnd {
448 * Push the entry onto the stack if it is worth
449 * saving and reset cmnd_matches for next cmnd.
451 * We need to save at least one entry on
452 * the stack so sudoers_lookup() can tell that
453 * the user was listed in sudoers. Also, we
454 * need to be able to tell whether or not a
455 * user was listed for this specific host.
457 * If keepall is set and the user matches then
458 * we need to keep entries around too...
460 if (MATCHED(user_matches) &&
461 MATCHED(host_matches) &&
462 MATCHED(cmnd_matches) &&
463 MATCHED(runas_matches))
465 else if (MATCHED(user_matches) && (top == 1 ||
466 (top == 2 && MATCHED(host_matches) &&
467 !MATCHED(match[0].host))))
469 else if (user_matches == TRUE && keepall)
471 cmnd_matches = UNSPEC;
476 SETMATCH(cmnd_matches, $1);
479 if (printmatches == TRUE) {
480 if (in_alias == TRUE)
481 append_entries("!", ", ");
482 else if (host_matches == TRUE &&
483 user_matches == TRUE)
484 append_cmnd("!", NULL);
487 SETNMATCH(cmnd_matches, $3);
491 runasspec : /* empty */ {
492 if (printmatches == TRUE && host_matches == TRUE &&
493 user_matches == TRUE) {
494 if (runas_matches == UNSPEC) {
495 cm_list[cm_list_len].runas_len = 0;
497 /* Inherit runas data. */
498 cm_list[cm_list_len].runas =
499 estrdup(cm_list[cm_list_len-1].runas);
500 cm_list[cm_list_len].runas_len =
501 cm_list[cm_list_len-1].runas_len;
502 cm_list[cm_list_len].runas_size =
503 cm_list[cm_list_len-1].runas_size;
507 * If this is the first entry in a command list
508 * then check against default runas user.
510 if (runas_matches == UNSPEC) {
511 runas_matches = userpw_matches(def_runas_default,
512 *user_runas, runas_pw) ? TRUE : NOMATCH;
520 runaslist : oprunasuser { ; }
521 | runaslist ',' oprunasuser {
522 /* Later entries override earlier ones. */
530 oprunasuser : runasuser { ; }
532 if (printmatches == TRUE) {
533 if (in_alias == TRUE)
534 append_entries("!", ", ");
535 else if (host_matches == TRUE &&
536 user_matches == TRUE)
537 append_runas("!", ", ");
540 /* Set $$ to the negation of runasuser */
541 $$ = ($3 == NOMATCH ? NOMATCH : ! $3);
546 if (printmatches == TRUE) {
547 if (in_alias == TRUE)
548 append_entries($1, ", ");
549 else if (host_matches == TRUE &&
550 user_matches == TRUE)
551 append_runas($1, ", ");
553 if (userpw_matches($1, *user_runas, runas_pw))
561 if (printmatches == TRUE) {
562 if (in_alias == TRUE)
563 append_entries($1, ", ");
564 else if (host_matches == TRUE &&
565 user_matches == TRUE)
566 append_runas($1, ", ");
568 if (usergr_matches($1, *user_runas, runas_pw))
576 if (printmatches == TRUE) {
577 if (in_alias == TRUE)
578 append_entries($1, ", ");
579 else if (host_matches == TRUE &&
580 user_matches == TRUE)
581 append_runas($1, ", ");
583 if (netgr_matches($1, NULL, NULL, *user_runas))
591 aliasinfo *aip = find_alias($1, RUNAS_ALIAS);
593 if (printmatches == TRUE) {
594 if (in_alias == TRUE)
595 append_entries($1, ", ");
596 else if (host_matches == TRUE &&
597 user_matches == TRUE)
598 append_runas($1, ", ");
600 /* could be an all-caps username */
603 else if (strcmp($1, *user_runas) == 0)
607 (void) fprintf(stderr,
608 "%s: undeclared Runas_Alias `%s' referenced near line %d\n",
609 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
621 if (printmatches == TRUE) {
622 if (in_alias == TRUE)
623 append_entries("ALL", ", ");
624 else if (host_matches == TRUE &&
625 user_matches == TRUE)
626 append_runas("ALL", ", ");
632 cmndtag : /* empty */ {
633 /* Inherit {NO,}{PASSWD,EXEC,SETENV} status. */
634 if (printmatches == TRUE && host_matches == TRUE &&
635 user_matches == TRUE) {
636 if (no_passwd == TRUE)
637 cm_list[cm_list_len].nopasswd = TRUE;
639 cm_list[cm_list_len].nopasswd = FALSE;
640 if (no_execve == TRUE)
641 cm_list[cm_list_len].noexecve = TRUE;
643 cm_list[cm_list_len].noexecve = FALSE;
644 if (setenv_ok == TRUE)
645 cm_list[cm_list_len].setenv = TRUE;
647 cm_list[cm_list_len].setenv = FALSE;
652 if (printmatches == TRUE && host_matches == TRUE &&
653 user_matches == TRUE)
654 cm_list[cm_list_len].nopasswd = TRUE;
658 if (printmatches == TRUE && host_matches == TRUE &&
659 user_matches == TRUE)
660 cm_list[cm_list_len].nopasswd = FALSE;
664 if (printmatches == TRUE && host_matches == TRUE &&
665 user_matches == TRUE)
666 cm_list[cm_list_len].noexecve = TRUE;
670 if (printmatches == TRUE && host_matches == TRUE &&
671 user_matches == TRUE)
672 cm_list[cm_list_len].noexecve = FALSE;
676 if (printmatches == TRUE && host_matches == TRUE &&
677 user_matches == TRUE)
678 cm_list[cm_list_len].setenv = TRUE;
682 if (printmatches == TRUE && host_matches == TRUE &&
683 user_matches == TRUE)
684 cm_list[cm_list_len].setenv = FALSE;
689 if (printmatches == TRUE) {
690 if (in_alias == TRUE)
691 append_entries("ALL", ", ");
692 else if (host_matches == TRUE &&
693 user_matches == TRUE) {
694 append_cmnd("ALL", NULL);
698 /* sudo "ALL" implies the SETENV tag */
699 if (setenv_ok == UNSPEC)
709 if (printmatches == TRUE) {
710 if (in_alias == TRUE)
711 append_entries($1, ", ");
712 else if (host_matches == TRUE &&
713 user_matches == TRUE) {
714 append_cmnd($1, NULL);
719 if ((aip = find_alias($1, CMND_ALIAS)))
723 (void) fprintf(stderr,
724 "%s: undeclared Cmnd_Alias `%s' referenced near line %d\n",
725 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
736 if (printmatches == TRUE) {
737 if (in_alias == TRUE) {
738 append_entries($1.cmnd, ", ");
740 append_entries($1.args, " ");
742 if (host_matches == TRUE &&
743 user_matches == TRUE) {
744 append_cmnd($1.cmnd, NULL);
746 append_cmnd($1.args, " ");
751 if (command_matches($1.cmnd, $1.args))
761 hostaliases : hostalias
762 | hostaliases ':' hostalias
765 hostalias : ALIAS { push; } '=' hostlist {
766 if ((MATCHED(host_matches) || pedantic) &&
767 !add_alias($1, HOST_ALIAS, host_matches)) {
776 | hostlist ',' ophost
779 cmndaliases : cmndalias
780 | cmndaliases ':' cmndalias
785 if (printmatches == TRUE) {
787 /* Allocate space for ga_list if necessary. */
789 ga_list[ga_list_len-1].type = CMND_ALIAS;
790 ga_list[ga_list_len-1].alias = estrdup($1);
793 if ((MATCHED(cmnd_matches) || pedantic) &&
794 !add_alias($1, CMND_ALIAS, cmnd_matches)) {
801 if (printmatches == TRUE)
806 cmndlist : opcmnd { ; }
807 | cmndlist ',' opcmnd
810 runasaliases : runasalias
811 | runasaliases ':' runasalias
815 if (printmatches == TRUE) {
817 /* Allocate space for ga_list if necessary. */
819 ga_list[ga_list_len-1].type = RUNAS_ALIAS;
820 ga_list[ga_list_len-1].alias = estrdup($1);
823 if (($4 != NOMATCH || pedantic) &&
824 !add_alias($1, RUNAS_ALIAS, $4)) {
830 if (printmatches == TRUE)
835 useraliases : useralias
836 | useraliases ':' useralias
839 useralias : ALIAS { push; } '=' userlist {
840 if ((MATCHED(user_matches) || pedantic) &&
841 !add_alias($1, USER_ALIAS, user_matches)) {
851 | userlist ',' opuser
855 SETMATCH(user_matches, $1);
858 SETNMATCH(user_matches, $2);
863 if (userpw_matches($1, user_name, sudo_user.pw))
870 if (usergr_matches($1, user_name, sudo_user.pw))
877 if (netgr_matches($1, NULL, NULL, user_name))
884 aliasinfo *aip = find_alias($1, USER_ALIAS);
886 /* could be an all-caps username */
889 else if (strcmp($1, user_name) == 0)
893 (void) fprintf(stderr,
894 "%s: undeclared User_Alias `%s' referenced near line %d\n",
895 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
912 #define MOREALIASES (32)
913 aliasinfo *aliases = NULL;
919 * Compare two aliasinfo structures, strcmp() style.
920 * Note that we do *not* compare their values.
927 aliasinfo *ai1, *ai2;
929 ai1 = (aliasinfo *) a1;
930 ai2 = (aliasinfo *) a2;
931 if ((r = strcmp(ai1->name, ai2->name)) == 0)
932 r = ai1->type - ai2->type;
938 * Compare two generic_alias structures, strcmp() style.
941 genaliascmp(entry, key)
942 const VOID *entry, *key;
945 struct generic_alias *ga1, *ga2;
947 ga1 = (struct generic_alias *) key;
948 ga2 = (struct generic_alias *) entry;
949 if ((r = strcmp(ga1->alias, ga2->alias)) == 0)
950 r = ga1->type - ga2->type;
957 * Adds the named alias of the specified type to the aliases list.
960 add_alias(alias, type, val)
969 if (naliases >= nslots)
974 ai.name = estrdup(alias);
975 onaliases = naliases;
977 aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases, &naliases,
978 sizeof(ai), aliascmp);
980 (void) snprintf(s, sizeof(s), "Aliases corrupted defining alias `%s'",
985 if (onaliases == naliases) {
986 (void) snprintf(s, sizeof(s), "Alias `%s' already defined", alias);
995 * Searches for the named alias of the specified type.
998 find_alias(alias, type)
1007 return((aliasinfo *) lfind((VOID *)&ai, (VOID *)aliases, &naliases,
1008 sizeof(ai), aliascmp));
1012 * Allocates more space for the aliases list.
1018 nslots += MOREALIASES;
1019 aliases = (aliasinfo *) erealloc3(aliases, nslots, sizeof(aliasinfo));
1023 * Lists the contents of the aliases list.
1030 for (n = 0; n < naliases; n++) {
1031 if (aliases[n].val == -1)
1034 switch (aliases[n].type) {
1036 (void) puts("HOST_ALIAS");
1040 (void) puts("CMND_ALIAS");
1044 (void) puts("USER_ALIAS");
1048 (void) puts("RUNAS_ALIAS");
1051 (void) printf("\t%s: %d\n", aliases[n].name, aliases[n].val);
1056 * Lists the contents of cm_list and ga_list for `sudo -l'.
1063 struct generic_alias *ga, key;
1065 (void) printf("User %s may run the following commands on this host:\n",
1067 for (count = 0; count < cm_list_len; count++) {
1069 /* Print the runas list. */
1070 (void) fputs(" ", stdout);
1071 if (cm_list[count].runas) {
1072 (void) putchar('(');
1073 p = strtok(cm_list[count].runas, ", ");
1075 if (p != cm_list[count].runas)
1076 (void) fputs(", ", stdout);
1079 key.type = RUNAS_ALIAS;
1080 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
1081 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
1082 (void) fputs(ga->entries, stdout);
1084 (void) fputs(p, stdout);
1085 } while ((p = strtok(NULL, ", ")));
1086 (void) fputs(") ", stdout);
1088 (void) printf("(%s) ", def_runas_default);
1091 /* Is execve(2) disabled? */
1092 if (cm_list[count].noexecve == TRUE && !def_noexec)
1093 (void) fputs("NOEXEC: ", stdout);
1094 else if (cm_list[count].noexecve == FALSE && def_noexec)
1095 (void) fputs("EXEC: ", stdout);
1097 /* Is a password required? */
1098 if (cm_list[count].nopasswd == TRUE && def_authenticate)
1099 (void) fputs("NOPASSWD: ", stdout);
1100 else if (cm_list[count].nopasswd == FALSE && !def_authenticate)
1101 (void) fputs("PASSWD: ", stdout);
1103 /* Is setenv enabled? */
1104 if (cm_list[count].setenv == TRUE && !def_setenv)
1105 (void) fputs("SETENV: ", stdout);
1106 else if (cm_list[count].setenv == FALSE && def_setenv)
1107 (void) fputs("NOSETENV: ", stdout);
1109 /* Print the actual command or expanded Cmnd_Alias. */
1110 key.alias = cm_list[count].cmnd;
1111 key.type = CMND_ALIAS;
1112 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
1113 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
1114 (void) puts(ga->entries);
1116 (void) puts(cm_list[count].cmnd);
1119 /* Be nice and free up space now that we are done. */
1120 for (count = 0; count < ga_list_len; count++) {
1121 efree(ga_list[count].alias);
1122 efree(ga_list[count].entries);
1127 for (count = 0; count < cm_list_len; count++) {
1128 efree(cm_list[count].runas);
1129 efree(cm_list[count].cmnd);
1138 * Appends a source string to the destination, optionally prefixing a separator.
1141 append(src, dstp, dst_len, dst_size, separator)
1143 size_t *dst_len, *dst_size;
1146 size_t src_len = strlen(src);
1150 * Only add the separator if there is something to separate from.
1151 * If the last char is a '!', don't apply the separator (XXX).
1153 if (separator && dst && dst[*dst_len - 1] != '!')
1154 src_len += strlen(separator);
1158 /* Assumes dst will be NULL if not set. */
1160 dst = (char *) emalloc(BUFSIZ);
1167 /* Allocate more space if necessary. */
1168 if (*dst_size <= *dst_len + src_len) {
1169 while (*dst_size <= *dst_len + src_len)
1170 *dst_size += BUFSIZ;
1172 dst = (char *) erealloc(dst, *dst_size);
1176 /* Copy src -> dst adding a separator if appropriate and adjust len. */
1178 (void) strlcat(dst, separator, *dst_size);
1179 (void) strlcat(dst, src, *dst_size);
1180 *dst_len += src_len;
1184 * Frees up space used by the aliases list and resets the associated counters.
1192 for (n = 0; n < naliases; n++)
1193 efree(aliases[n].name);
1197 naliases = nslots = 0;
1201 * Increments ga_list_len, allocating more space as necessary.
1207 if (++ga_list_len >= ga_list_size) {
1208 while ((ga_list_size += STACKINCREMENT) < ga_list_len)
1210 ga_list = (struct generic_alias *)
1211 erealloc3(ga_list, ga_list_size, sizeof(struct generic_alias));
1214 ga_list[ga_list_len - 1].entries = NULL;
1218 * Increments cm_list_len, allocating more space as necessary.
1224 if (++cm_list_len >= cm_list_size) {
1225 while ((cm_list_size += STACKINCREMENT) < cm_list_len)
1227 if (cm_list == NULL)
1228 cm_list_len = 0; /* start at 0 since it is a subscript */
1229 cm_list = (struct command_match *)
1230 erealloc3(cm_list, cm_list_size, sizeof(struct command_match));
1233 cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL;
1234 cm_list[cm_list_len].nopasswd = FALSE;
1235 cm_list[cm_list_len].noexecve = FALSE;
1236 cm_list[cm_list_len].setenv = FALSE;
1240 * Frees up spaced used by a previous parser run and allocates new space
1241 * for various data structures.
1247 /* Free up old data structures if we run the parser more than once. */
1252 parse_error = FALSE;
1258 /* Allocate space for the matching stack. */
1259 stacksize = STACKINCREMENT;
1260 match = (struct matchstack *) emalloc2(stacksize, sizeof(struct matchstack));
1262 /* Allocate space for the match list (for `sudo -l'). */
1263 if (printmatches == TRUE)
1264 expand_match_list();