static RETSIGTYPE Exit __P((int));
static void setup_signals __P((void));
static int run_command __P((char *, char **));
+static int check_syntax __P((int, int));
int command_matches __P((char *, char *, char *, char *));
int addr_matches __P((char *));
int hostname_matches __P((char *, char *, char *));
extern FILE *yyin, *yyout;
extern int errorlineno;
extern int pedantic;
+extern int quiet;
/*
* Globals
char *UserEditor; /* editor user wants to use */
char *EditorPath; /* colon-separated list of editors */
char *av[4]; /* argument vector for run_command */
+ int checkonly; /* only check existing file? */
int sudoers_fd; /* sudoers file descriptor */
int stmp_fd; /* stmp file descriptor */
int n; /* length parameter */
/*
* Arg handling.
*/
+ checkonly = 0;
while (--argc) {
if (!strcmp(argv[argc], "-V")) {
(void) printf("visudo version %s\n", version);
exit(0);
} else if (!strcmp(argv[argc], "-s")) {
pedantic++; /* strict mode */
+ } else if (!strcmp(argv[argc], "-c")) {
+ checkonly++; /* check mode */
+ } else if (!strcmp(argv[argc], "-q")) {
+ quiet++; /* quiet mode */
} else {
usage();
}
strerror(errno));
exit(1);
}
+ if (checkonly)
+ exit(check_syntax(sudoers_fd, quiet));
if (!lock_file(sudoers_fd, SUDO_TLOCK)) {
(void) fprintf(stderr, "%s: sudoers file busy, try again later.\n",
Argv[0]);
return(TRUE);
}
+void
+init_envtables()
+{
+ return;
+}
+
/*
* Assuming a parse error occurred, prompt the user for what they want
* to do now. Returns the first letter of their choice.
return(pid == -1 ? -1 : (status >> 8));
}
+static int
+check_syntax(fd, quiet)
+ int fd;
+ int quiet;
+{
+ if ((yyin = fdopen(fd, "r")) == NULL) {
+ if (!quiet)
+ (void) fprintf(stderr, "%s: can't fdopen sudoers fd: %s", Argv[0],
+ strerror(errno));
+ exit(1);
+ }
+ yyout = stdout;
+ init_parser();
+ if (yyparse() && parse_error != TRUE) {
+ if (!quiet)
+ (void) printf("Failed to parse %s file, unknown error.\n",
+ sudoers);
+ parse_error = TRUE;
+ }
+ if (!quiet){
+ if (parse_error)
+ (void) printf("parse error in %s near line %d\n", sudoers,
+ errorlineno);
+ else
+ (void) printf("%s file parsed OK\n", sudoers);
+ }
+
+ return(parse_error == TRUE);
+}
+
/*
* Unlink the sudoers temp file (if it exists) and exit.
* Used in place of a normal exit() and as a signal handler.