In check-only mode, don't create sudoers if it does not already exist.

This commit is contained in:
Todd C. Miller
2001-12-11 23:22:54 +00:00
parent 5486390782
commit 8f896ec2e2

View File

@@ -89,7 +89,7 @@ static char whatnow __P((void));
static RETSIGTYPE Exit __P((int)); static RETSIGTYPE Exit __P((int));
static void setup_signals __P((void)); static void setup_signals __P((void));
static int run_command __P((char *, char **)); static int run_command __P((char *, char **));
static int check_syntax __P((int, int)); static int check_syntax __P((int));
int command_matches __P((char *, char *, char *, char *)); int command_matches __P((char *, char *, char *, char *));
int addr_matches __P((char *)); int addr_matches __P((char *));
int hostname_matches __P((char *, char *, char *)); int hostname_matches __P((char *, char *, char *));
@@ -171,6 +171,9 @@ main(argc, argv)
/* Setup defaults data structures. */ /* Setup defaults data structures. */
init_defaults(); init_defaults();
if (checkonly)
exit(check_syntax(quiet));
/* /*
* Open sudoers, lock it and stat it. * Open sudoers, lock it and stat it.
* sudoers_fd must remain open throughout in order to hold the lock. * sudoers_fd must remain open throughout in order to hold the lock.
@@ -181,8 +184,6 @@ main(argc, argv)
strerror(errno)); strerror(errno));
exit(1); exit(1);
} }
if (checkonly)
exit(check_syntax(sudoers_fd, quiet));
if (!lock_file(sudoers_fd, SUDO_TLOCK)) { if (!lock_file(sudoers_fd, SUDO_TLOCK)) {
(void) fprintf(stderr, "%s: sudoers file busy, try again later.\n", (void) fprintf(stderr, "%s: sudoers file busy, try again later.\n",
Argv[0]); Argv[0]);
@@ -639,22 +640,23 @@ run_command(path, argv)
} }
static int static int
check_syntax(fd, quiet) check_syntax(quiet)
int fd;
int quiet; int quiet;
{ {
if ((yyin = fdopen(fd, "r")) == NULL) {
if ((yyin = fopen(sudoers, "r")) == NULL) {
if (!quiet) if (!quiet)
(void) fprintf(stderr, "%s: can't fdopen sudoers fd: %s", Argv[0], (void) fprintf(stderr, "%s: unable to open %s: %s\n", Argv[0],
strerror(errno)); sudoers, strerror(errno));
exit(1); exit(1);
} }
yyout = stdout; yyout = stdout;
init_parser(); init_parser();
if (yyparse() && parse_error != TRUE) { if (yyparse() && parse_error != TRUE) {
if (!quiet) if (!quiet)
(void) printf("Failed to parse %s file, unknown error.\n", (void) fprintf(stderr,
sudoers); "%s: failed to parse %s file, unknown error.\n",
Argv[0], sudoers);
parse_error = TRUE; parse_error = TRUE;
} }
if (!quiet){ if (!quiet){