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.7 2007/09/13 23:06:51 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) \
108 * The matching stack, initial space allocated in init_parser().
110 struct matchstack *match;
111 int top = 0, stacksize = 0;
115 if (top >= stacksize) { \
116 while ((stacksize += STACKINCREMENT) < top); \
117 match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \
119 match[top].user = UNSPEC; \
120 match[top].cmnd = UNSPEC; \
121 match[top].host = UNSPEC; \
122 match[top].runas = UNSPEC; \
123 match[top].nopass = def_authenticate ? UNSPEC : TRUE; \
124 match[top].noexec = def_noexec ? TRUE : UNSPEC; \
125 match[top].setenv = def_setenv ? TRUE : UNSPEC; \
131 if (top >= stacksize) { \
132 while ((stacksize += STACKINCREMENT) < top); \
133 match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \
135 match[top].user = match[top-1].user; \
136 match[top].cmnd = match[top-1].cmnd; \
137 match[top].host = match[top-1].host; \
138 match[top].runas = match[top-1].runas; \
139 match[top].nopass = match[top-1].nopass; \
140 match[top].noexec = match[top-1].noexec; \
141 match[top].setenv = match[top-1].setenv; \
148 yyerror("matching stack underflow"); \
155 * For testing if foo_matches variable was set to TRUE or FALSE
157 #define MATCHED(_v) ((_v) >= 0)
160 * Shortcuts for append()
162 #define append_cmnd(s, p) append(s, &cm_list[cm_list_len].cmnd, \
163 &cm_list[cm_list_len].cmnd_len, &cm_list[cm_list_len].cmnd_size, p)
165 #define append_runas(s, p) append(s, &cm_list[cm_list_len].runas, \
166 &cm_list[cm_list_len].runas_len, &cm_list[cm_list_len].runas_size, p)
168 #define append_entries(s, p) append(s, &ga_list[ga_list_len-1].entries, \
169 &ga_list[ga_list_len-1].entries_len, \
170 &ga_list[ga_list_len-1].entries_size, p)
173 * The stack for printmatches. A list of allowed commands for the user.
175 static struct command_match *cm_list = NULL;
176 static size_t cm_list_len = 0, cm_list_size = 0;
179 * List of Cmnd_Aliases and expansions for `sudo -l'
181 static int in_alias = FALSE;
182 static size_t ga_list_len = 0, ga_list_size = 0;
183 static struct generic_alias *ga_list = NULL;
186 * Does this Defaults list pertain to this user?
188 static int defaults_matches = FALSE;
193 static int add_alias __P((char *, int, int));
194 static void append __P((char *, char **, size_t *, size_t *, char *));
195 static void expand_ga_list __P((void));
196 static void expand_match_list __P((void));
197 static aliasinfo *find_alias __P((char *, int));
198 static void more_aliases __P((void));
199 void init_parser __P((void));
200 void yyerror __P((char *));
206 /* Save the line the first error occurred on. */
207 if (errorlineno == -1)
208 errorlineno = sudolineno ? sudolineno - 1 : 0;
211 (void) fprintf(stderr, ">>> sudoers file: %s, line %d <<<\n", s,
212 sudolineno ? sudolineno - 1 : 0);
214 (void) fprintf(stderr, "<*> ");
224 struct sudo_command command;
228 %start file /* special start symbol */
229 %token <command> COMMAND /* absolute pathname w/ optional args */
230 %token <string> ALIAS /* an UPPERCASE alias name */
231 %token <string> DEFVAR /* a Defaults variable name */
232 %token <string> NTWKADDR /* w.x.y.z or ipv6 address */
233 %token <string> NETGROUP /* a netgroup (+NAME) */
234 %token <string> USERGROUP /* a usergroup (%NAME) */
235 %token <string> WORD /* a word */
236 %token <tok> DEFAULTS /* Defaults entry */
237 %token <tok> DEFAULTS_HOST /* Host-specific defaults entry */
238 %token <tok> DEFAULTS_USER /* User-specific defaults entry */
239 %token <tok> DEFAULTS_RUNAS /* Runas-specific defaults entry */
240 %token <tok> RUNAS /* ( runas_list ) */
241 %token <tok> NOPASSWD /* no passwd req for command */
242 %token <tok> PASSWD /* passwd req for command (default) */
243 %token <tok> NOEXEC /* preload dummy execve() for cmnd */
244 %token <tok> EXEC /* don't preload dummy execve() */
245 %token <tok> SETENV /* user may set environment for cmnd */
246 %token <tok> NOSETENV /* user may not set environment */
247 %token <tok> ALL /* ALL keyword */
248 %token <tok> COMMENT /* comment and/or carriage return */
249 %token <tok> HOSTALIAS /* Host_Alias keyword */
250 %token <tok> CMNDALIAS /* Cmnd_Alias keyword */
251 %token <tok> USERALIAS /* User_Alias keyword */
252 %token <tok> RUNASALIAS /* Runas_Alias keyword */
253 %token <tok> ':' '=' ',' '!' '+' '-' /* union member tokens */
257 * NOTE: these are not true booleans as there are actually 4 possible values:
258 * 1) TRUE (positive match)
259 * 0) FALSE (negative match due to a '!' somewhere)
260 * -1) NOMATCH (don't change the value of *_matches)
261 * -2) UNSPEC (uninitialized value)
265 %type <BOOLEAN> runasuser
266 %type <BOOLEAN> oprunasuser
267 %type <BOOLEAN> runaslist
280 | { push; } userlist privileges {
281 while (top && user_matches != TRUE)
284 | USERALIAS useraliases
286 | HOSTALIAS hostaliases
288 | CMNDALIAS cmndaliases
290 | RUNASALIAS runasaliases
296 defaults_line : defaults_type defaults_list
299 defaults_type : DEFAULTS {
300 defaults_matches = TRUE;
302 | DEFAULTS_USER { push; } userlist {
303 defaults_matches = user_matches;
306 | DEFAULTS_RUNAS { push; } runaslist {
307 defaults_matches = $3 == TRUE;
310 | DEFAULTS_HOST { push; } hostlist {
311 defaults_matches = host_matches;
316 defaults_list : defaults_entry
317 | defaults_entry ',' defaults_list
320 defaults_entry : DEFVAR {
321 if (defaults_matches == TRUE &&
322 !set_default($1, NULL, TRUE)) {
329 if (defaults_matches == TRUE &&
330 !set_default($2, NULL, FALSE)) {
337 if (defaults_matches == TRUE &&
338 !set_default($1, $3, TRUE)) {
346 if (defaults_matches == TRUE &&
347 !set_default($1, $3, '+')) {
355 if (defaults_matches == TRUE &&
356 !set_default($1, $3, '-')) {
365 privileges : privilege
366 | privileges ':' privilege
369 privilege : hostlist '=' cmndspeclist {
371 * We already did a push if necessary in
372 * cmndspec so just reset some values so
373 * the next 'privilege' gets a clean slate.
375 host_matches = UNSPEC;
376 runas_matches = UNSPEC;
377 no_passwd = def_authenticate ? UNSPEC : TRUE;
378 no_execve = def_noexec ? TRUE : UNSPEC;
379 setenv_ok = def_setenv ? TRUE : UNSPEC;
384 SETMATCH(host_matches, $1);
387 SETNMATCH(host_matches, $2);
395 if (addr_matches($1))
402 if (netgr_matches($1, user_host, user_shost, NULL))
409 if (hostname_matches(user_shost, user_host, $1) == 0)
416 aliasinfo *aip = find_alias($1, HOST_ALIAS);
418 /* could be an all-caps hostname */
421 else if (strcasecmp(user_shost, $1) == 0)
425 (void) fprintf(stderr,
426 "%s: undeclared Host_Alias `%s' referenced near line %d\n",
427 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
439 cmndspeclist : cmndspec
440 | cmndspeclist ',' cmndspec
443 cmndspec : runasspec cmndtag opcmnd {
445 * Push the entry onto the stack if it is worth
446 * saving and reset cmnd_matches for next cmnd.
448 * We need to save at least one entry on
449 * the stack so sudoers_lookup() can tell that
450 * the user was listed in sudoers. Also, we
451 * need to be able to tell whether or not a
452 * user was listed for this specific host.
454 * If keepall is set and the user matches then
455 * we need to keep entries around too...
457 if (MATCHED(user_matches) &&
458 MATCHED(host_matches) &&
459 MATCHED(cmnd_matches) &&
460 MATCHED(runas_matches))
462 else if (MATCHED(user_matches) && (top == 1 ||
463 (top == 2 && MATCHED(host_matches) &&
464 !MATCHED(match[0].host))))
466 else if (user_matches == TRUE && keepall)
468 cmnd_matches = UNSPEC;
473 SETMATCH(cmnd_matches, $1);
476 if (printmatches == TRUE) {
477 if (in_alias == TRUE)
478 append_entries("!", ", ");
479 else if (host_matches == TRUE &&
480 user_matches == TRUE)
481 append_cmnd("!", NULL);
484 SETNMATCH(cmnd_matches, $3);
488 runasspec : /* empty */ {
489 if (printmatches == TRUE && host_matches == TRUE &&
490 user_matches == TRUE) {
491 if (runas_matches == UNSPEC) {
492 cm_list[cm_list_len].runas_len = 0;
494 /* Inherit runas data. */
495 cm_list[cm_list_len].runas =
496 estrdup(cm_list[cm_list_len-1].runas);
497 cm_list[cm_list_len].runas_len =
498 cm_list[cm_list_len-1].runas_len;
499 cm_list[cm_list_len].runas_size =
500 cm_list[cm_list_len-1].runas_size;
504 * If this is the first entry in a command list
505 * then check against default runas user.
507 if (runas_matches == UNSPEC) {
509 userpw_matches(def_runas_default,
510 *user_runas, runas_pw);
518 runaslist : oprunasuser { ; }
519 | runaslist ',' oprunasuser {
520 /* Later entries override earlier ones. */
528 oprunasuser : runasuser { ; }
530 if (printmatches == TRUE) {
531 if (in_alias == TRUE)
532 append_entries("!", ", ");
533 else if (host_matches == TRUE &&
534 user_matches == TRUE)
535 append_runas("!", ", ");
538 /* Set $$ to the negation of runasuser */
539 $$ = ($3 == NOMATCH ? NOMATCH : ! $3);
544 if (printmatches == TRUE) {
545 if (in_alias == TRUE)
546 append_entries($1, ", ");
547 else if (host_matches == TRUE &&
548 user_matches == TRUE)
549 append_runas($1, ", ");
551 if (userpw_matches($1, *user_runas, runas_pw))
559 if (printmatches == TRUE) {
560 if (in_alias == TRUE)
561 append_entries($1, ", ");
562 else if (host_matches == TRUE &&
563 user_matches == TRUE)
564 append_runas($1, ", ");
566 if (usergr_matches($1, *user_runas, runas_pw))
574 if (printmatches == TRUE) {
575 if (in_alias == TRUE)
576 append_entries($1, ", ");
577 else if (host_matches == TRUE &&
578 user_matches == TRUE)
579 append_runas($1, ", ");
581 if (netgr_matches($1, NULL, NULL, *user_runas))
589 aliasinfo *aip = find_alias($1, RUNAS_ALIAS);
591 if (printmatches == TRUE) {
592 if (in_alias == TRUE)
593 append_entries($1, ", ");
594 else if (host_matches == TRUE &&
595 user_matches == TRUE)
596 append_runas($1, ", ");
598 /* could be an all-caps username */
601 else if (strcmp($1, *user_runas) == 0)
605 (void) fprintf(stderr,
606 "%s: undeclared Runas_Alias `%s' referenced near line %d\n",
607 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
619 if (printmatches == TRUE) {
620 if (in_alias == TRUE)
621 append_entries("ALL", ", ");
622 else if (host_matches == TRUE &&
623 user_matches == TRUE)
624 append_runas("ALL", ", ");
630 cmndtag : /* empty */ {
631 /* Inherit {NO,}{PASSWD,EXEC,SETENV} status. */
632 if (printmatches == TRUE && host_matches == TRUE &&
633 user_matches == TRUE) {
634 if (no_passwd == TRUE)
635 cm_list[cm_list_len].nopasswd = TRUE;
637 cm_list[cm_list_len].nopasswd = FALSE;
638 if (no_execve == TRUE)
639 cm_list[cm_list_len].noexecve = TRUE;
641 cm_list[cm_list_len].noexecve = FALSE;
642 if (setenv_ok == TRUE)
643 cm_list[cm_list_len].setenv = TRUE;
645 cm_list[cm_list_len].setenv = FALSE;
650 if (printmatches == TRUE && host_matches == TRUE &&
651 user_matches == TRUE)
652 cm_list[cm_list_len].nopasswd = TRUE;
656 if (printmatches == TRUE && host_matches == TRUE &&
657 user_matches == TRUE)
658 cm_list[cm_list_len].nopasswd = FALSE;
662 if (printmatches == TRUE && host_matches == TRUE &&
663 user_matches == TRUE)
664 cm_list[cm_list_len].noexecve = TRUE;
668 if (printmatches == TRUE && host_matches == TRUE &&
669 user_matches == TRUE)
670 cm_list[cm_list_len].noexecve = FALSE;
674 if (printmatches == TRUE && host_matches == TRUE &&
675 user_matches == TRUE)
676 cm_list[cm_list_len].setenv = TRUE;
680 if (printmatches == TRUE && host_matches == TRUE &&
681 user_matches == TRUE)
682 cm_list[cm_list_len].setenv = FALSE;
687 if (printmatches == TRUE) {
688 if (in_alias == TRUE)
689 append_entries("ALL", ", ");
690 else if (host_matches == TRUE &&
691 user_matches == TRUE) {
692 append_cmnd("ALL", NULL);
704 if (printmatches == TRUE) {
705 if (in_alias == TRUE)
706 append_entries($1, ", ");
707 else if (host_matches == TRUE &&
708 user_matches == TRUE) {
709 append_cmnd($1, NULL);
714 if ((aip = find_alias($1, CMND_ALIAS)))
718 (void) fprintf(stderr,
719 "%s: undeclared Cmnd_Alias `%s' referenced near line %d\n",
720 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
731 if (printmatches == TRUE) {
732 if (in_alias == TRUE) {
733 append_entries($1.cmnd, ", ");
735 append_entries($1.args, " ");
737 if (host_matches == TRUE &&
738 user_matches == TRUE) {
739 append_cmnd($1.cmnd, NULL);
741 append_cmnd($1.args, " ");
746 if (command_matches($1.cmnd, $1.args))
756 hostaliases : hostalias
757 | hostaliases ':' hostalias
760 hostalias : ALIAS { push; } '=' hostlist {
761 if ((MATCHED(host_matches) || pedantic) &&
762 !add_alias($1, HOST_ALIAS, host_matches)) {
771 | hostlist ',' ophost
774 cmndaliases : cmndalias
775 | cmndaliases ':' cmndalias
780 if (printmatches == TRUE) {
782 /* Allocate space for ga_list if necessary. */
784 ga_list[ga_list_len-1].type = CMND_ALIAS;
785 ga_list[ga_list_len-1].alias = estrdup($1);
788 if ((MATCHED(cmnd_matches) || pedantic) &&
789 !add_alias($1, CMND_ALIAS, cmnd_matches)) {
796 if (printmatches == TRUE)
801 cmndlist : opcmnd { ; }
802 | cmndlist ',' opcmnd
805 runasaliases : runasalias
806 | runasaliases ':' runasalias
810 if (printmatches == TRUE) {
812 /* Allocate space for ga_list if necessary. */
814 ga_list[ga_list_len-1].type = RUNAS_ALIAS;
815 ga_list[ga_list_len-1].alias = estrdup($1);
818 if (($4 != NOMATCH || pedantic) &&
819 !add_alias($1, RUNAS_ALIAS, $4)) {
825 if (printmatches == TRUE)
830 useraliases : useralias
831 | useraliases ':' useralias
834 useralias : ALIAS { push; } '=' userlist {
835 if ((MATCHED(user_matches) || pedantic) &&
836 !add_alias($1, USER_ALIAS, user_matches)) {
846 | userlist ',' opuser
850 SETMATCH(user_matches, $1);
853 SETNMATCH(user_matches, $2);
858 if (userpw_matches($1, user_name, sudo_user.pw))
865 if (usergr_matches($1, user_name, sudo_user.pw))
872 if (netgr_matches($1, NULL, NULL, user_name))
879 aliasinfo *aip = find_alias($1, USER_ALIAS);
881 /* could be an all-caps username */
884 else if (strcmp($1, user_name) == 0)
888 (void) fprintf(stderr,
889 "%s: undeclared User_Alias `%s' referenced near line %d\n",
890 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
907 #define MOREALIASES (32)
908 aliasinfo *aliases = NULL;
914 * Compare two aliasinfo structures, strcmp() style.
915 * Note that we do *not* compare their values.
922 aliasinfo *ai1, *ai2;
924 ai1 = (aliasinfo *) a1;
925 ai2 = (aliasinfo *) a2;
926 if ((r = strcmp(ai1->name, ai2->name)) == 0)
927 r = ai1->type - ai2->type;
933 * Compare two generic_alias structures, strcmp() style.
936 genaliascmp(entry, key)
937 const VOID *entry, *key;
940 struct generic_alias *ga1, *ga2;
942 ga1 = (struct generic_alias *) key;
943 ga2 = (struct generic_alias *) entry;
944 if ((r = strcmp(ga1->alias, ga2->alias)) == 0)
945 r = ga1->type - ga2->type;
952 * Adds the named alias of the specified type to the aliases list.
955 add_alias(alias, type, val)
964 if (naliases >= nslots)
969 ai.name = estrdup(alias);
970 onaliases = naliases;
972 aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases, &naliases,
973 sizeof(ai), aliascmp);
975 (void) snprintf(s, sizeof(s), "Aliases corrupted defining alias `%s'",
980 if (onaliases == naliases) {
981 (void) snprintf(s, sizeof(s), "Alias `%s' already defined", alias);
990 * Searches for the named alias of the specified type.
993 find_alias(alias, type)
1002 return((aliasinfo *) lfind((VOID *)&ai, (VOID *)aliases, &naliases,
1003 sizeof(ai), aliascmp));
1007 * Allocates more space for the aliases list.
1013 nslots += MOREALIASES;
1014 aliases = (aliasinfo *) erealloc3(aliases, nslots, sizeof(aliasinfo));
1018 * Lists the contents of the aliases list.
1025 for (n = 0; n < naliases; n++) {
1026 if (aliases[n].val == -1)
1029 switch (aliases[n].type) {
1031 (void) puts("HOST_ALIAS");
1035 (void) puts("CMND_ALIAS");
1039 (void) puts("USER_ALIAS");
1043 (void) puts("RUNAS_ALIAS");
1046 (void) printf("\t%s: %d\n", aliases[n].name, aliases[n].val);
1051 * Lists the contents of cm_list and ga_list for `sudo -l'.
1058 struct generic_alias *ga, key;
1060 (void) printf("User %s may run the following commands on this host:\n",
1062 for (count = 0; count < cm_list_len; count++) {
1064 /* Print the runas list. */
1065 (void) fputs(" ", stdout);
1066 if (cm_list[count].runas) {
1067 (void) putchar('(');
1068 p = strtok(cm_list[count].runas, ", ");
1070 if (p != cm_list[count].runas)
1071 (void) fputs(", ", stdout);
1074 key.type = RUNAS_ALIAS;
1075 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
1076 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
1077 (void) fputs(ga->entries, stdout);
1079 (void) fputs(p, stdout);
1080 } while ((p = strtok(NULL, ", ")));
1081 (void) fputs(") ", stdout);
1083 (void) printf("(%s) ", def_runas_default);
1086 /* Is execve(2) disabled? */
1087 if (cm_list[count].noexecve == TRUE && !def_noexec)
1088 (void) fputs("NOEXEC: ", stdout);
1089 else if (cm_list[count].noexecve == FALSE && def_noexec)
1090 (void) fputs("EXEC: ", stdout);
1092 /* Is a password required? */
1093 if (cm_list[count].nopasswd == TRUE && def_authenticate)
1094 (void) fputs("NOPASSWD: ", stdout);
1095 else if (cm_list[count].nopasswd == FALSE && !def_authenticate)
1096 (void) fputs("PASSWD: ", stdout);
1098 /* Is setenv enabled? */
1099 if (cm_list[count].setenv == TRUE && !def_setenv)
1100 (void) fputs("SETENV: ", stdout);
1101 else if (cm_list[count].setenv == FALSE && def_setenv)
1102 (void) fputs("NOSETENV: ", stdout);
1104 /* Print the actual command or expanded Cmnd_Alias. */
1105 key.alias = cm_list[count].cmnd;
1106 key.type = CMND_ALIAS;
1107 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
1108 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
1109 (void) puts(ga->entries);
1111 (void) puts(cm_list[count].cmnd);
1114 /* Be nice and free up space now that we are done. */
1115 for (count = 0; count < ga_list_len; count++) {
1116 efree(ga_list[count].alias);
1117 efree(ga_list[count].entries);
1122 for (count = 0; count < cm_list_len; count++) {
1123 efree(cm_list[count].runas);
1124 efree(cm_list[count].cmnd);
1133 * Appends a source string to the destination, optionally prefixing a separator.
1136 append(src, dstp, dst_len, dst_size, separator)
1138 size_t *dst_len, *dst_size;
1141 size_t src_len = strlen(src);
1145 * Only add the separator if there is something to separate from.
1146 * If the last char is a '!', don't apply the separator (XXX).
1148 if (separator && dst && dst[*dst_len - 1] != '!')
1149 src_len += strlen(separator);
1153 /* Assumes dst will be NULL if not set. */
1155 dst = (char *) emalloc(BUFSIZ);
1162 /* Allocate more space if necessary. */
1163 if (*dst_size <= *dst_len + src_len) {
1164 while (*dst_size <= *dst_len + src_len)
1165 *dst_size += BUFSIZ;
1167 dst = (char *) erealloc(dst, *dst_size);
1171 /* Copy src -> dst adding a separator if appropriate and adjust len. */
1173 (void) strlcat(dst, separator, *dst_size);
1174 (void) strlcat(dst, src, *dst_size);
1175 *dst_len += src_len;
1179 * Frees up space used by the aliases list and resets the associated counters.
1187 for (n = 0; n < naliases; n++)
1188 efree(aliases[n].name);
1192 naliases = nslots = 0;
1196 * Increments ga_list_len, allocating more space as necessary.
1202 if (++ga_list_len >= ga_list_size) {
1203 while ((ga_list_size += STACKINCREMENT) < ga_list_len)
1205 ga_list = (struct generic_alias *)
1206 erealloc3(ga_list, ga_list_size, sizeof(struct generic_alias));
1209 ga_list[ga_list_len - 1].entries = NULL;
1213 * Increments cm_list_len, allocating more space as necessary.
1219 if (++cm_list_len >= cm_list_size) {
1220 while ((cm_list_size += STACKINCREMENT) < cm_list_len)
1222 if (cm_list == NULL)
1223 cm_list_len = 0; /* start at 0 since it is a subscript */
1224 cm_list = (struct command_match *)
1225 erealloc3(cm_list, cm_list_size, sizeof(struct command_match));
1228 cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL;
1229 cm_list[cm_list_len].nopasswd = FALSE;
1230 cm_list[cm_list_len].noexecve = FALSE;
1231 cm_list[cm_list_len].setenv = FALSE;
1235 * Frees up spaced used by a previous parser run and allocates new space
1236 * for various data structures.
1242 /* Free up old data structures if we run the parser more than once. */
1247 parse_error = FALSE;
1253 /* Allocate space for the matching stack. */
1254 stacksize = STACKINCREMENT;
1255 match = (struct matchstack *) emalloc2(stacksize, sizeof(struct matchstack));
1257 /* Allocate space for the match list (for `sudo -l'). */
1258 if (printmatches == TRUE)
1259 expand_match_list();