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.8 2007/11/02 19:09:01 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) {
508 runas_matches = userpw_matches(def_runas_default,
509 *user_runas, runas_pw) ? TRUE : NOMATCH;
517 runaslist : oprunasuser { ; }
518 | runaslist ',' oprunasuser {
519 /* Later entries override earlier ones. */
527 oprunasuser : runasuser { ; }
529 if (printmatches == TRUE) {
530 if (in_alias == TRUE)
531 append_entries("!", ", ");
532 else if (host_matches == TRUE &&
533 user_matches == TRUE)
534 append_runas("!", ", ");
537 /* Set $$ to the negation of runasuser */
538 $$ = ($3 == NOMATCH ? NOMATCH : ! $3);
543 if (printmatches == TRUE) {
544 if (in_alias == TRUE)
545 append_entries($1, ", ");
546 else if (host_matches == TRUE &&
547 user_matches == TRUE)
548 append_runas($1, ", ");
550 if (userpw_matches($1, *user_runas, runas_pw))
558 if (printmatches == TRUE) {
559 if (in_alias == TRUE)
560 append_entries($1, ", ");
561 else if (host_matches == TRUE &&
562 user_matches == TRUE)
563 append_runas($1, ", ");
565 if (usergr_matches($1, *user_runas, runas_pw))
573 if (printmatches == TRUE) {
574 if (in_alias == TRUE)
575 append_entries($1, ", ");
576 else if (host_matches == TRUE &&
577 user_matches == TRUE)
578 append_runas($1, ", ");
580 if (netgr_matches($1, NULL, NULL, *user_runas))
588 aliasinfo *aip = find_alias($1, RUNAS_ALIAS);
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 /* could be an all-caps username */
600 else if (strcmp($1, *user_runas) == 0)
604 (void) fprintf(stderr,
605 "%s: undeclared Runas_Alias `%s' referenced near line %d\n",
606 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
618 if (printmatches == TRUE) {
619 if (in_alias == TRUE)
620 append_entries("ALL", ", ");
621 else if (host_matches == TRUE &&
622 user_matches == TRUE)
623 append_runas("ALL", ", ");
629 cmndtag : /* empty */ {
630 /* Inherit {NO,}{PASSWD,EXEC,SETENV} status. */
631 if (printmatches == TRUE && host_matches == TRUE &&
632 user_matches == TRUE) {
633 if (no_passwd == TRUE)
634 cm_list[cm_list_len].nopasswd = TRUE;
636 cm_list[cm_list_len].nopasswd = FALSE;
637 if (no_execve == TRUE)
638 cm_list[cm_list_len].noexecve = TRUE;
640 cm_list[cm_list_len].noexecve = FALSE;
641 if (setenv_ok == TRUE)
642 cm_list[cm_list_len].setenv = TRUE;
644 cm_list[cm_list_len].setenv = FALSE;
649 if (printmatches == TRUE && host_matches == TRUE &&
650 user_matches == TRUE)
651 cm_list[cm_list_len].nopasswd = TRUE;
655 if (printmatches == TRUE && host_matches == TRUE &&
656 user_matches == TRUE)
657 cm_list[cm_list_len].nopasswd = FALSE;
661 if (printmatches == TRUE && host_matches == TRUE &&
662 user_matches == TRUE)
663 cm_list[cm_list_len].noexecve = TRUE;
667 if (printmatches == TRUE && host_matches == TRUE &&
668 user_matches == TRUE)
669 cm_list[cm_list_len].noexecve = FALSE;
673 if (printmatches == TRUE && host_matches == TRUE &&
674 user_matches == TRUE)
675 cm_list[cm_list_len].setenv = TRUE;
679 if (printmatches == TRUE && host_matches == TRUE &&
680 user_matches == TRUE)
681 cm_list[cm_list_len].setenv = FALSE;
686 if (printmatches == TRUE) {
687 if (in_alias == TRUE)
688 append_entries("ALL", ", ");
689 else if (host_matches == TRUE &&
690 user_matches == TRUE) {
691 append_cmnd("ALL", NULL);
703 if (printmatches == TRUE) {
704 if (in_alias == TRUE)
705 append_entries($1, ", ");
706 else if (host_matches == TRUE &&
707 user_matches == TRUE) {
708 append_cmnd($1, NULL);
713 if ((aip = find_alias($1, CMND_ALIAS)))
717 (void) fprintf(stderr,
718 "%s: undeclared Cmnd_Alias `%s' referenced near line %d\n",
719 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
730 if (printmatches == TRUE) {
731 if (in_alias == TRUE) {
732 append_entries($1.cmnd, ", ");
734 append_entries($1.args, " ");
736 if (host_matches == TRUE &&
737 user_matches == TRUE) {
738 append_cmnd($1.cmnd, NULL);
740 append_cmnd($1.args, " ");
745 if (command_matches($1.cmnd, $1.args))
755 hostaliases : hostalias
756 | hostaliases ':' hostalias
759 hostalias : ALIAS { push; } '=' hostlist {
760 if ((MATCHED(host_matches) || pedantic) &&
761 !add_alias($1, HOST_ALIAS, host_matches)) {
770 | hostlist ',' ophost
773 cmndaliases : cmndalias
774 | cmndaliases ':' cmndalias
779 if (printmatches == TRUE) {
781 /* Allocate space for ga_list if necessary. */
783 ga_list[ga_list_len-1].type = CMND_ALIAS;
784 ga_list[ga_list_len-1].alias = estrdup($1);
787 if ((MATCHED(cmnd_matches) || pedantic) &&
788 !add_alias($1, CMND_ALIAS, cmnd_matches)) {
795 if (printmatches == TRUE)
800 cmndlist : opcmnd { ; }
801 | cmndlist ',' opcmnd
804 runasaliases : runasalias
805 | runasaliases ':' runasalias
809 if (printmatches == TRUE) {
811 /* Allocate space for ga_list if necessary. */
813 ga_list[ga_list_len-1].type = RUNAS_ALIAS;
814 ga_list[ga_list_len-1].alias = estrdup($1);
817 if (($4 != NOMATCH || pedantic) &&
818 !add_alias($1, RUNAS_ALIAS, $4)) {
824 if (printmatches == TRUE)
829 useraliases : useralias
830 | useraliases ':' useralias
833 useralias : ALIAS { push; } '=' userlist {
834 if ((MATCHED(user_matches) || pedantic) &&
835 !add_alias($1, USER_ALIAS, user_matches)) {
845 | userlist ',' opuser
849 SETMATCH(user_matches, $1);
852 SETNMATCH(user_matches, $2);
857 if (userpw_matches($1, user_name, sudo_user.pw))
864 if (usergr_matches($1, user_name, sudo_user.pw))
871 if (netgr_matches($1, NULL, NULL, user_name))
878 aliasinfo *aip = find_alias($1, USER_ALIAS);
880 /* could be an all-caps username */
883 else if (strcmp($1, user_name) == 0)
887 (void) fprintf(stderr,
888 "%s: undeclared User_Alias `%s' referenced near line %d\n",
889 (pedantic == 1) ? "Warning" : "Error", $1, sudolineno);
906 #define MOREALIASES (32)
907 aliasinfo *aliases = NULL;
913 * Compare two aliasinfo structures, strcmp() style.
914 * Note that we do *not* compare their values.
921 aliasinfo *ai1, *ai2;
923 ai1 = (aliasinfo *) a1;
924 ai2 = (aliasinfo *) a2;
925 if ((r = strcmp(ai1->name, ai2->name)) == 0)
926 r = ai1->type - ai2->type;
932 * Compare two generic_alias structures, strcmp() style.
935 genaliascmp(entry, key)
936 const VOID *entry, *key;
939 struct generic_alias *ga1, *ga2;
941 ga1 = (struct generic_alias *) key;
942 ga2 = (struct generic_alias *) entry;
943 if ((r = strcmp(ga1->alias, ga2->alias)) == 0)
944 r = ga1->type - ga2->type;
951 * Adds the named alias of the specified type to the aliases list.
954 add_alias(alias, type, val)
963 if (naliases >= nslots)
968 ai.name = estrdup(alias);
969 onaliases = naliases;
971 aip = (aliasinfo *) lsearch((VOID *)&ai, (VOID *)aliases, &naliases,
972 sizeof(ai), aliascmp);
974 (void) snprintf(s, sizeof(s), "Aliases corrupted defining alias `%s'",
979 if (onaliases == naliases) {
980 (void) snprintf(s, sizeof(s), "Alias `%s' already defined", alias);
989 * Searches for the named alias of the specified type.
992 find_alias(alias, type)
1001 return((aliasinfo *) lfind((VOID *)&ai, (VOID *)aliases, &naliases,
1002 sizeof(ai), aliascmp));
1006 * Allocates more space for the aliases list.
1012 nslots += MOREALIASES;
1013 aliases = (aliasinfo *) erealloc3(aliases, nslots, sizeof(aliasinfo));
1017 * Lists the contents of the aliases list.
1024 for (n = 0; n < naliases; n++) {
1025 if (aliases[n].val == -1)
1028 switch (aliases[n].type) {
1030 (void) puts("HOST_ALIAS");
1034 (void) puts("CMND_ALIAS");
1038 (void) puts("USER_ALIAS");
1042 (void) puts("RUNAS_ALIAS");
1045 (void) printf("\t%s: %d\n", aliases[n].name, aliases[n].val);
1050 * Lists the contents of cm_list and ga_list for `sudo -l'.
1057 struct generic_alias *ga, key;
1059 (void) printf("User %s may run the following commands on this host:\n",
1061 for (count = 0; count < cm_list_len; count++) {
1063 /* Print the runas list. */
1064 (void) fputs(" ", stdout);
1065 if (cm_list[count].runas) {
1066 (void) putchar('(');
1067 p = strtok(cm_list[count].runas, ", ");
1069 if (p != cm_list[count].runas)
1070 (void) fputs(", ", stdout);
1073 key.type = RUNAS_ALIAS;
1074 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
1075 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
1076 (void) fputs(ga->entries, stdout);
1078 (void) fputs(p, stdout);
1079 } while ((p = strtok(NULL, ", ")));
1080 (void) fputs(") ", stdout);
1082 (void) printf("(%s) ", def_runas_default);
1085 /* Is execve(2) disabled? */
1086 if (cm_list[count].noexecve == TRUE && !def_noexec)
1087 (void) fputs("NOEXEC: ", stdout);
1088 else if (cm_list[count].noexecve == FALSE && def_noexec)
1089 (void) fputs("EXEC: ", stdout);
1091 /* Is a password required? */
1092 if (cm_list[count].nopasswd == TRUE && def_authenticate)
1093 (void) fputs("NOPASSWD: ", stdout);
1094 else if (cm_list[count].nopasswd == FALSE && !def_authenticate)
1095 (void) fputs("PASSWD: ", stdout);
1097 /* Is setenv enabled? */
1098 if (cm_list[count].setenv == TRUE && !def_setenv)
1099 (void) fputs("SETENV: ", stdout);
1100 else if (cm_list[count].setenv == FALSE && def_setenv)
1101 (void) fputs("NOSETENV: ", stdout);
1103 /* Print the actual command or expanded Cmnd_Alias. */
1104 key.alias = cm_list[count].cmnd;
1105 key.type = CMND_ALIAS;
1106 if ((ga = (struct generic_alias *) lfind((VOID *) &key,
1107 (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp)))
1108 (void) puts(ga->entries);
1110 (void) puts(cm_list[count].cmnd);
1113 /* Be nice and free up space now that we are done. */
1114 for (count = 0; count < ga_list_len; count++) {
1115 efree(ga_list[count].alias);
1116 efree(ga_list[count].entries);
1121 for (count = 0; count < cm_list_len; count++) {
1122 efree(cm_list[count].runas);
1123 efree(cm_list[count].cmnd);
1132 * Appends a source string to the destination, optionally prefixing a separator.
1135 append(src, dstp, dst_len, dst_size, separator)
1137 size_t *dst_len, *dst_size;
1140 size_t src_len = strlen(src);
1144 * Only add the separator if there is something to separate from.
1145 * If the last char is a '!', don't apply the separator (XXX).
1147 if (separator && dst && dst[*dst_len - 1] != '!')
1148 src_len += strlen(separator);
1152 /* Assumes dst will be NULL if not set. */
1154 dst = (char *) emalloc(BUFSIZ);
1161 /* Allocate more space if necessary. */
1162 if (*dst_size <= *dst_len + src_len) {
1163 while (*dst_size <= *dst_len + src_len)
1164 *dst_size += BUFSIZ;
1166 dst = (char *) erealloc(dst, *dst_size);
1170 /* Copy src -> dst adding a separator if appropriate and adjust len. */
1172 (void) strlcat(dst, separator, *dst_size);
1173 (void) strlcat(dst, src, *dst_size);
1174 *dst_len += src_len;
1178 * Frees up space used by the aliases list and resets the associated counters.
1186 for (n = 0; n < naliases; n++)
1187 efree(aliases[n].name);
1191 naliases = nslots = 0;
1195 * Increments ga_list_len, allocating more space as necessary.
1201 if (++ga_list_len >= ga_list_size) {
1202 while ((ga_list_size += STACKINCREMENT) < ga_list_len)
1204 ga_list = (struct generic_alias *)
1205 erealloc3(ga_list, ga_list_size, sizeof(struct generic_alias));
1208 ga_list[ga_list_len - 1].entries = NULL;
1212 * Increments cm_list_len, allocating more space as necessary.
1218 if (++cm_list_len >= cm_list_size) {
1219 while ((cm_list_size += STACKINCREMENT) < cm_list_len)
1221 if (cm_list == NULL)
1222 cm_list_len = 0; /* start at 0 since it is a subscript */
1223 cm_list = (struct command_match *)
1224 erealloc3(cm_list, cm_list_size, sizeof(struct command_match));
1227 cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL;
1228 cm_list[cm_list_len].nopasswd = FALSE;
1229 cm_list[cm_list_len].noexecve = FALSE;
1230 cm_list[cm_list_len].setenv = FALSE;
1234 * Frees up spaced used by a previous parser run and allocates new space
1235 * for various data structures.
1241 /* Free up old data structures if we run the parser more than once. */
1246 parse_error = FALSE;
1252 /* Allocate space for the matching stack. */
1253 stacksize = STACKINCREMENT;
1254 match = (struct matchstack *) emalloc2(stacksize, sizeof(struct matchstack));
1256 /* Allocate space for the match list (for `sudo -l'). */
1257 if (printmatches == TRUE)
1258 expand_match_list();