=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sudo/Attic/parse.yacc,v retrieving revision 1.7 retrieving revision 1.8 diff -c -r1.7 -r1.8 *** src/usr.bin/sudo/Attic/parse.yacc 2002/04/25 15:49:03 1.7 --- src/usr.bin/sudo/Attic/parse.yacc 2003/03/15 21:23:54 1.8 *************** *** 1,6 **** %{ /* ! * Copyright (c) 1996, 1998-2001 Todd C. Miller * All rights reserved. * * This code is derived from software contributed by Chris Jepeway. --- 1,6 ---- %{ /* ! * Copyright (c) 1996, 1998-2003 Todd C. Miller * All rights reserved. * * This code is derived from software contributed by Chris Jepeway. *************** *** 85,91 **** #endif /* HAVE_LSEARCH */ #ifndef lint ! static const char rcsid[] = "$Sudo: parse.yacc,v 1.180 2002/03/16 00:44:47 millert Exp $"; #endif /* lint */ /* --- 85,91 ---- #endif /* HAVE_LSEARCH */ #ifndef lint ! static const char rcsid[] = "$Sudo: parse.yacc,v 1.187 2003/03/15 20:31:02 millert Exp $"; #endif /* lint */ /* *************** *** 117,123 **** do { \ if (top >= stacksize) { \ while ((stacksize += STACKINCREMENT) < top); \ ! match = (struct matchstack *) erealloc(match, sizeof(struct matchstack) * stacksize); \ } \ match[top].user = -1; \ match[top].cmnd = -1; \ --- 117,123 ---- do { \ if (top >= stacksize) { \ while ((stacksize += STACKINCREMENT) < top); \ ! match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \ } \ match[top].user = -1; \ match[top].cmnd = -1; \ *************** *** 131,137 **** do { \ if (top >= stacksize) { \ while ((stacksize += STACKINCREMENT) < top); \ ! match = (struct matchstack *) erealloc(match, sizeof(struct matchstack) * stacksize); \ } \ match[top].user = match[top-1].user; \ match[top].cmnd = match[top-1].cmnd; \ --- 131,137 ---- do { \ if (top >= stacksize) { \ while ((stacksize += STACKINCREMENT) < top); \ ! match = (struct matchstack *) erealloc3(match, stacksize, sizeof(struct matchstack)); \ } \ match[top].user = match[top-1].user; \ match[top].cmnd = match[top-1].cmnd; \ *************** *** 229,234 **** --- 229,235 ---- %token DEFAULTS /* Defaults entry */ %token DEFAULTS_HOST /* Host-specific defaults entry */ %token DEFAULTS_USER /* User-specific defaults entry */ + %token DEFAULTS_RUNAS /* Runas-specific defaults entry */ %token RUNAS /* ( runas_list ) */ %token NOPASSWD /* no passwd req for command */ %token PASSWD /* passwd req for command (default) */ *************** *** 281,286 **** --- 282,288 ---- ; defaults_line : defaults_type defaults_list + ; defaults_type : DEFAULTS { defaults_matches = TRUE; *************** *** 289,294 **** --- 291,300 ---- defaults_matches = user_matches; pop; } + | DEFAULTS_RUNAS { push; } runaslist { + defaults_matches = $3 == TRUE; + pop; + } | DEFAULTS_HOST { push; } hostlist { defaults_matches = host_matches; pop; *************** *** 297,302 **** --- 303,309 ---- defaults_list : defaults_entry | defaults_entry ',' defaults_list + ; defaults_entry : DEFVAR { if (defaults_matches == TRUE && *************** *** 341,346 **** --- 348,354 ---- free($1); free($3); } + ; privileges : privilege | privileges ':' privilege *************** *** 369,374 **** --- 377,383 ---- if ($2 != -1) host_matches = ! $2; } + ; host : ALL { $$ = TRUE; *************** *** 518,523 **** --- 527,533 ---- /* Set $$ to the negation of runasuser */ $$ = ($3 == -1 ? -1 : ! $3); } + ; runasuser : WORD { if (printmatches == TRUE) { *************** *** 706,713 **** hostalias : ALIAS { push; } '=' hostlist { if ((host_matches != -1 || pedantic) && ! !add_alias($1, HOST_ALIAS, host_matches)) YYERROR; pop; } ; --- 716,725 ---- hostalias : ALIAS { push; } '=' hostlist { if ((host_matches != -1 || pedantic) && ! !add_alias($1, HOST_ALIAS, host_matches)) { ! yyerror(NULL); YYERROR; + } pop; } ; *************** *** 731,738 **** } } '=' cmndlist { if ((cmnd_matches != -1 || pedantic) && ! !add_alias($1, CMND_ALIAS, cmnd_matches)) YYERROR; pop; free($1); --- 743,752 ---- } } '=' cmndlist { if ((cmnd_matches != -1 || pedantic) && ! !add_alias($1, CMND_ALIAS, cmnd_matches)) { ! yyerror(NULL); YYERROR; + } pop; free($1); *************** *** 759,766 **** } } '=' runaslist { if (($4 != -1 || pedantic) && ! !add_alias($1, RUNAS_ALIAS, $4)) YYERROR; free($1); if (printmatches == TRUE) --- 773,782 ---- } } '=' runaslist { if (($4 != -1 || pedantic) && ! !add_alias($1, RUNAS_ALIAS, $4)) { ! yyerror(NULL); YYERROR; + } free($1); if (printmatches == TRUE) *************** *** 774,781 **** useralias : ALIAS { push; } '=' userlist { if ((user_matches != -1 || pedantic) && ! !add_alias($1, USER_ALIAS, user_matches)) YYERROR; pop; free($1); } --- 790,799 ---- useralias : ALIAS { push; } '=' userlist { if ((user_matches != -1 || pedantic) && ! !add_alias($1, USER_ALIAS, user_matches)) { ! yyerror(NULL); YYERROR; + } pop; free($1); } *************** *** 793,798 **** --- 811,817 ---- if ($2 != -1) user_matches = ! $2; } + ; user : WORD { if (strcmp($1, user_name) == 0) *************** *** 828,835 **** (void) fprintf(stderr, "%s: undeclared User_Alias `%s' referenced near line %d\n", (pedantic == 1) ? "Warning" : "Error", $1, sudolineno); ! if (pedantic > 1) YYERROR; } $$ = -1; } --- 847,856 ---- (void) fprintf(stderr, "%s: undeclared User_Alias `%s' referenced near line %d\n", (pedantic == 1) ? "Warning" : "Error", $1, sudolineno); ! if (pedantic > 1) { ! yyerror(NULL); YYERROR; + } } $$ = -1; } *************** *** 1000,1020 **** void list_matches() { ! int i; char *p; struct generic_alias *ga, key; (void) printf("User %s may run the following commands on this host:\n", user_name); ! for (i = 0; i < cm_list_len; i++) { /* Print the runas list. */ (void) fputs(" ", stdout); ! if (cm_list[i].runas) { (void) putchar('('); ! p = strtok(cm_list[i].runas, ", "); do { ! if (p != cm_list[i].runas) (void) fputs(", ", stdout); key.alias = p; --- 1021,1041 ---- void list_matches() { ! size_t count; char *p; struct generic_alias *ga, key; (void) printf("User %s may run the following commands on this host:\n", user_name); ! for (count = 0; count < cm_list_len; count++) { /* Print the runas list. */ (void) fputs(" ", stdout); ! if (cm_list[count].runas) { (void) putchar('('); ! p = strtok(cm_list[count].runas, ", "); do { ! if (p != cm_list[count].runas) (void) fputs(", ", stdout); key.alias = p; *************** *** 1031,1062 **** } /* Is a password required? */ ! if (cm_list[i].nopasswd == TRUE && def_flag(I_AUTHENTICATE)) (void) fputs("NOPASSWD: ", stdout); ! else if (cm_list[i].nopasswd == FALSE && !def_flag(I_AUTHENTICATE)) (void) fputs("PASSWD: ", stdout); /* Print the actual command or expanded Cmnd_Alias. */ ! key.alias = cm_list[i].cmnd; key.type = CMND_ALIAS; if ((ga = (struct generic_alias *) lfind((VOID *) &key, (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp))) (void) puts(ga->entries); else ! (void) puts(cm_list[i].cmnd); } /* Be nice and free up space now that we are done. */ ! for (i = 0; i < ga_list_len; i++) { ! free(ga_list[i].alias); ! free(ga_list[i].entries); } free(ga_list); ga_list = NULL; ! for (i = 0; i < cm_list_len; i++) { ! free(cm_list[i].runas); ! free(cm_list[i].cmnd); } free(cm_list); cm_list = NULL; --- 1052,1083 ---- } /* Is a password required? */ ! if (cm_list[count].nopasswd == TRUE && def_flag(I_AUTHENTICATE)) (void) fputs("NOPASSWD: ", stdout); ! else if (cm_list[count].nopasswd == FALSE && !def_flag(I_AUTHENTICATE)) (void) fputs("PASSWD: ", stdout); /* Print the actual command or expanded Cmnd_Alias. */ ! key.alias = cm_list[count].cmnd; key.type = CMND_ALIAS; if ((ga = (struct generic_alias *) lfind((VOID *) &key, (VOID *) &ga_list[0], &ga_list_len, sizeof(key), genaliascmp))) (void) puts(ga->entries); else ! (void) puts(cm_list[count].cmnd); } /* Be nice and free up space now that we are done. */ ! for (count = 0; count < ga_list_len; count++) { ! free(ga_list[count].alias); ! free(ga_list[count].entries); } free(ga_list); ga_list = NULL; ! for (count = 0; count < cm_list_len; count++) { ! free(cm_list[count].runas); ! free(cm_list[count].cmnd); } free(cm_list); cm_list = NULL; *************** *** 1088,1093 **** --- 1109,1115 ---- /* Assumes dst will be NULL if not set. */ if (dst == NULL) { dst = (char *) emalloc(BUFSIZ); + *dst = '\0'; *dst_size = BUFSIZ; *dst_len = 0; *dstp = dst; *************** *** 1103,1114 **** } /* Copy src -> dst adding a separator if appropriate and adjust len. */ - dst += *dst_len; - *dst_len += src_len; - *dst = '\0'; if (separator) ! (void) strcat(dst, separator); ! (void) strcat(dst, src); } /* --- 1125,1134 ---- } /* Copy src -> dst adding a separator if appropriate and adjust len. */ if (separator) ! (void) strlcat(dst, separator, *dst_size); ! (void) strlcat(dst, src, *dst_size); ! *dst_len += src_len; } /* *************** *** 1139,1145 **** while ((ga_list_size += STACKINCREMENT) < ga_list_len) ; ga_list = (struct generic_alias *) ! erealloc(ga_list, sizeof(struct generic_alias) * ga_list_size); } ga_list[ga_list_len - 1].entries = NULL; --- 1159,1165 ---- while ((ga_list_size += STACKINCREMENT) < ga_list_len) ; ga_list = (struct generic_alias *) ! erealloc3(ga_list, ga_list_size, sizeof(struct generic_alias)); } ga_list[ga_list_len - 1].entries = NULL; *************** *** 1158,1164 **** if (cm_list == NULL) cm_list_len = 0; /* start at 0 since it is a subscript */ cm_list = (struct command_match *) ! erealloc(cm_list, sizeof(struct command_match) * cm_list_size); } cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL; --- 1178,1184 ---- if (cm_list == NULL) cm_list_len = 0; /* start at 0 since it is a subscript */ cm_list = (struct command_match *) ! erealloc3(cm_list, cm_list_size, sizeof(struct command_match)); } cm_list[cm_list_len].runas = cm_list[cm_list_len].cmnd = NULL; *************** *** 1185,1191 **** /* Allocate space for the matching stack. */ stacksize = STACKINCREMENT; ! match = (struct matchstack *) emalloc(sizeof(struct matchstack) * stacksize); /* Allocate space for the match list (for `sudo -l'). */ if (printmatches == TRUE) --- 1205,1211 ---- /* Allocate space for the matching stack. */ stacksize = STACKINCREMENT; ! match = (struct matchstack *) emalloc2(stacksize, sizeof(struct matchstack)); /* Allocate space for the match list (for `sudo -l'). */ if (printmatches == TRUE)