=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sudo/Attic/visudo.c,v retrieving revision 1.2 retrieving revision 1.3 diff -c -r1.2 -r1.3 *** src/usr.bin/sudo/Attic/visudo.c 1999/12/10 06:45:12 1.2 --- src/usr.bin/sudo/Attic/visudo.c 2000/01/24 04:22:54 1.3 *************** *** 1,5 **** /* ! * Copyright (c) 1996, 1998, 1999 Todd C. Miller * All rights reserved. * * Redistribution and use in source and binary forms, with or without --- 1,5 ---- /* ! * Copyright (c) 1996, 1998-2000 Todd C. Miller * All rights reserved. * * Redistribution and use in source and binary forms, with or without *************** *** 81,87 **** #endif /* POSIX_SIGNALS && !SA_RESETHAND */ #ifndef lint ! static const char rcsid[] = "$Sudo: visudo.c,v 1.117 1999/12/02 20:31:25 millert Exp $"; #endif /* lint */ /* --- 81,87 ---- #endif /* POSIX_SIGNALS && !SA_RESETHAND */ #ifndef lint ! static const char rcsid[] = "$Sudo: visudo.c,v 1.121 2000/01/19 19:07:24 millert Exp $"; #endif /* lint */ /* *************** *** 93,99 **** static void setup_signals __P((void)); int command_matches __P((char *, char *, char *, char *)); int addr_matches __P((char *)); ! int netgr_matches __P((char *, char *, char *)); int usergr_matches __P((char *, char *)); void init_parser __P((void)); void yyrestart __P((FILE *)); --- 93,99 ---- static void setup_signals __P((void)); int command_matches __P((char *, char *, char *, char *)); int addr_matches __P((char *)); ! int netgr_matches __P((char *, char *, char *, char *)); int usergr_matches __P((char *, char *)); void init_parser __P((void)); void yyrestart __P((FILE *)); *************** *** 169,212 **** #endif /* ENV_EDITOR */ /* ! * Open sudoers temp file and grab a lock. */ ! stmp_fd = open(stmp, O_WRONLY | O_CREAT, 0600); ! if (stmp_fd < 0) { ! (void) fprintf(stderr, "%s: %s\n", Argv[0], strerror(errno)); ! exit(1); } ! if (!lock_file(stmp_fd, SUDO_TLOCK)) { (void) fprintf(stderr, "%s: sudoers file busy, try again later.\n", Argv[0]); exit(1); } ! #ifdef HAVE_FTRUNCATE ! if (ftruncate(stmp_fd, 0) == -1) { #else ! if (truncate(stmp, 0) == -1) { #endif ! (void) fprintf(stderr, "%s: can't truncate %s: %s\n", Argv[0], ! stmp, strerror(errno)); Exit(-1); } /* Install signal handlers to clean up stmp if we are killed. */ setup_signals(); - (void) memset(&sudoers_sb, 0, sizeof(sudoers_sb)); - if (stat(sudoers, &sudoers_sb) == -1 && errno != ENOENT) { - (void) fprintf(stderr, "%s: %s\n", Argv[0], strerror(errno)); - Exit(-1); - } - sudoers_fd = open(sudoers, O_RDONLY); - if (sudoers_fd == -1 && errno != ENOENT) { - (void) fprintf(stderr, "%s: %s\n", Argv[0], strerror(errno)); - Exit(-1); - } - /* Copy sudoers -> stmp and reset the mtime */ ! if (sudoers_fd != -1) { while ((n = read(sudoers_fd, buf, sizeof(buf))) > 0) if (write(stmp_fd, buf, n) != n) { (void) fprintf(stderr, "%s: Write failed: %s\n", Argv[0], --- 169,212 ---- #endif /* ENV_EDITOR */ /* ! * Open sudoers, lock it and stat it. ! * sudoers_fd must remain open throughout in order to hold the lock. */ ! sudoers_fd = open(sudoers, O_RDWR | O_CREAT); ! if (sudoers_fd == -1) { ! (void) fprintf(stderr, "%s: %s: %s\n", Argv[0], sudoers, ! strerror(errno)); ! Exit(-1); } ! if (!lock_file(sudoers_fd, SUDO_TLOCK)) { (void) fprintf(stderr, "%s: sudoers file busy, try again later.\n", Argv[0]); exit(1); } ! #ifdef HAVE_FSTAT ! if (fstat(sudoers_fd, &sudoers_sb) == -1) { #else ! if (stat(sudoers, &sudoers_sb) == -1) { #endif ! (void) fprintf(stderr, "%s: can't stat %s: %s\n", ! Argv[0], sudoers, strerror(errno)); Exit(-1); } + /* + * Open sudoers temp file. + */ + stmp_fd = open(stmp, O_WRONLY | O_CREAT | O_TRUNC, 0600); + if (stmp_fd < 0) { + (void) fprintf(stderr, "%s: %s: %s\n", Argv[0], stmp, strerror(errno)); + exit(1); + } + /* Install signal handlers to clean up stmp if we are killed. */ setup_signals(); /* Copy sudoers -> stmp and reset the mtime */ ! if (sudoers_sb.st_size) { while ((n = read(sudoers_fd, buf, sizeof(buf))) > 0) if (write(stmp_fd, buf, n) != n) { (void) fprintf(stderr, "%s: Write failed: %s\n", Argv[0], *************** *** 214,223 **** Exit(-1); } ! (void) close(sudoers_fd); ! } ! (void) close(stmp_fd); ! (void) touch(stmp, sudoers_sb.st_mtime); /* * Edit the temp file and parse it (for sanity checking) --- 214,223 ---- Exit(-1); } ! (void) close(stmp_fd); ! (void) touch(stmp, sudoers_sb.st_mtime); ! } else ! (void) close(stmp_fd); /* * Edit the temp file and parse it (for sanity checking) *************** *** 369,375 **** } } ! return(0); } /* --- 369,375 ---- } } ! exit(0); } /* *************** *** 401,408 **** } int ! netgr_matches(n, h, u) ! char *n, *h, *u; { return(TRUE); } --- 401,408 ---- } int ! netgr_matches(n, h, sh, u) ! char *n, *h, *sh, *u; { return(TRUE); } *************** *** 428,444 **** for (c = choice; c != '\n' && c != EOF;) c = getchar(); ! if (choice == 'e' || choice == 'x' || choice == 'Q') ! break; ! else { ! (void) puts("Options are:"); ! (void) puts(" (e)dit sudoers file again"); ! (void) puts(" e(x)it without saving changes to sudoers file"); ! (void) puts(" (Q)uit and save changes to sudoers file (DANGER!)\n"); } } - - return(choice); } /* --- 428,448 ---- for (c = choice; c != '\n' && c != EOF;) c = getchar(); ! switch (choice) { ! case EOF: ! choice = 'x'; ! /* FALLTHROUGH */ ! case 'e': ! case 'x': ! case 'Q': ! return(choice); ! default: ! (void) puts("Options are:"); ! (void) puts(" (e)dit sudoers file again"); ! (void) puts(" e(x)it without saving changes to sudoers file"); ! (void) puts(" (Q)uit and save changes to sudoers file (DANGER!)\n"); } } } /*