1993-11-27 23:46:33 +00:00
|
|
|
/*
|
1999-07-12 10:53:09 +00:00
|
|
|
* CU sudo version 1.6
|
|
|
|
* Copyright (c) 1996, 1998, 1999 Todd C. Miller <Todd.Miller@courtesan.com>
|
1993-03-02 16:35:47 +00:00
|
|
|
*
|
1999-07-12 10:53:09 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 1, or (at your option)
|
|
|
|
* any later version.
|
1993-03-02 16:35:47 +00:00
|
|
|
*
|
1999-07-12 10:53:09 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
1993-03-02 16:35:47 +00:00
|
|
|
*
|
1999-07-12 10:53:09 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
1993-03-02 16:35:47 +00:00
|
|
|
*
|
1999-07-12 10:53:09 +00:00
|
|
|
* Please send bugs, changes, problems to sudo-bugs@courtesan.com
|
1995-03-27 18:26:36 +00:00
|
|
|
*
|
|
|
|
*******************************************************************
|
|
|
|
*
|
1999-07-12 10:53:09 +00:00
|
|
|
* visudo.c -- locks the sudoers file for safe editing (ala vipw)
|
|
|
|
* and checks for parse errors.
|
1993-10-04 19:23:33 +00:00
|
|
|
*/
|
|
|
|
|
1994-03-12 18:39:35 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
1993-03-02 16:35:47 +00:00
|
|
|
#include <stdio.h>
|
1994-03-09 22:36:55 +00:00
|
|
|
#ifdef STDC_HEADERS
|
1993-12-03 02:35:54 +00:00
|
|
|
#include <stdlib.h>
|
1994-03-09 22:36:55 +00:00
|
|
|
#endif /* STDC_HEADERS */
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif /* HAVE_UNISTD_H */
|
1995-03-27 18:26:36 +00:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
#include <string.h>
|
|
|
|
#endif /* HAVE_STRING_H */
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif /* HAVE_STRINGS_H */
|
1995-09-13 21:17:06 +00:00
|
|
|
#if defined(HAVE_MALLOC_H) && !defined(STDC_HEADERS)
|
1995-03-27 18:26:36 +00:00
|
|
|
#include <malloc.h>
|
1995-09-13 21:17:06 +00:00
|
|
|
#endif /* HAVE_MALLOC_H && !STDC_HEADERS */
|
1995-03-28 05:49:00 +00:00
|
|
|
#include <ctype.h>
|
1994-11-10 00:46:21 +00:00
|
|
|
#include <pwd.h>
|
1995-03-27 22:04:19 +00:00
|
|
|
#include <signal.h>
|
1993-03-02 16:35:47 +00:00
|
|
|
#include <errno.h>
|
1995-03-31 22:27:59 +00:00
|
|
|
#include <fcntl.h>
|
1994-05-24 16:02:23 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/file.h>
|
1993-03-02 16:35:47 +00:00
|
|
|
|
|
|
|
#include "sudo.h"
|
1994-05-25 03:08:45 +00:00
|
|
|
#include "version.h"
|
1993-03-02 16:35:47 +00:00
|
|
|
|
1994-03-09 22:36:55 +00:00
|
|
|
#ifndef STDC_HEADERS
|
1995-03-27 18:26:36 +00:00
|
|
|
#ifndef __GNUC__ /* gcc has its own malloc */
|
|
|
|
extern char *malloc __P((size_t));
|
|
|
|
#endif /* __GNUC__ */
|
1994-08-08 17:05:35 +00:00
|
|
|
extern char *getenv __P((const char *));
|
1995-03-27 18:26:36 +00:00
|
|
|
extern int stat __P((const char *, struct stat *));
|
1994-03-09 22:36:55 +00:00
|
|
|
#endif /* !STDC_HEADERS */
|
1993-12-03 02:35:54 +00:00
|
|
|
|
1995-03-27 18:26:36 +00:00
|
|
|
#if defined(POSIX_SIGNALS) && !defined(SA_RESETHAND)
|
|
|
|
#define SA_RESETHAND 0
|
|
|
|
#endif /* POSIX_SIGNALS && !SA_RESETHAND */
|
|
|
|
|
1998-11-18 04:16:13 +00:00
|
|
|
#ifndef lint
|
1999-01-17 23:16:20 +00:00
|
|
|
static const char rcsid[] = "$Sudo$";
|
1998-11-18 04:16:13 +00:00
|
|
|
#endif /* lint */
|
|
|
|
|
1995-03-27 18:26:36 +00:00
|
|
|
/*
|
|
|
|
* Function prototypes
|
|
|
|
*/
|
1995-03-27 19:54:53 +00:00
|
|
|
static void usage __P((void));
|
|
|
|
static char whatnow __P((void));
|
|
|
|
static RETSIGTYPE Exit __P((int));
|
1995-05-02 03:34:07 +00:00
|
|
|
static void setup_signals __P((void));
|
1996-07-22 19:50:59 +00:00
|
|
|
int command_matches __P((char *, char *, char *, char *));
|
1995-04-07 23:48:23 +00:00
|
|
|
int addr_matches __P((char *));
|
1995-07-25 00:02:05 +00:00
|
|
|
int netgr_matches __P((char *, char *, char *));
|
1995-12-18 02:51:30 +00:00
|
|
|
int usergr_matches __P((char *, char *));
|
1996-08-17 22:29:04 +00:00
|
|
|
void init_parser __P((void));
|
1995-03-27 18:26:36 +00:00
|
|
|
|
|
|
|
/*
|
1999-07-12 10:53:09 +00:00
|
|
|
* External globals exported by the parser
|
1995-03-27 18:26:36 +00:00
|
|
|
*/
|
1993-10-04 19:23:33 +00:00
|
|
|
extern FILE *yyin, *yyout;
|
1995-04-06 20:16:01 +00:00
|
|
|
extern int errorlineno, sudolineno;
|
1993-03-02 16:35:47 +00:00
|
|
|
|
1994-05-24 16:02:23 +00:00
|
|
|
/*
|
|
|
|
* Globals
|
|
|
|
*/
|
1994-05-25 03:08:45 +00:00
|
|
|
char **Argv;
|
1996-02-02 06:14:46 +00:00
|
|
|
char **NewArgv = NULL;
|
|
|
|
int NewArgc = 0;
|
1994-03-12 18:39:35 +00:00
|
|
|
char *sudoers = _PATH_SUDO_SUDOERS;
|
1995-03-27 18:26:36 +00:00
|
|
|
char *stmp = _PATH_SUDO_STMP;
|
1994-05-28 20:23:46 +00:00
|
|
|
|
1994-05-25 03:08:45 +00:00
|
|
|
/*
|
1999-07-12 10:53:09 +00:00
|
|
|
* Globals required by the parsing routines
|
1994-05-25 03:08:45 +00:00
|
|
|
*/
|
1995-03-27 18:26:36 +00:00
|
|
|
char host[] = "";
|
1996-03-11 19:05:55 +00:00
|
|
|
char *shost = "";
|
1995-03-27 18:26:36 +00:00
|
|
|
char *cmnd = "";
|
1999-04-10 04:10:01 +00:00
|
|
|
char *cmnd_safe = NULL;
|
1996-07-22 19:29:53 +00:00
|
|
|
char *cmnd_args = NULL;
|
1995-11-24 02:27:27 +00:00
|
|
|
struct passwd *user_pw_ent;
|
1999-07-12 10:53:09 +00:00
|
|
|
char *runas_user = RUNAS_DEFAULT;
|
|
|
|
int parse_error = FALSE;
|
1995-03-24 19:19:14 +00:00
|
|
|
|
|
|
|
|
1999-04-10 04:49:03 +00:00
|
|
|
int
|
|
|
|
main(argc, argv)
|
1993-10-04 19:23:33 +00:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
1993-03-02 16:35:47 +00:00
|
|
|
{
|
1996-11-14 00:21:35 +00:00
|
|
|
char buf[MAXPATHLEN*2]; /* buffer used for copying files */
|
1999-07-12 10:53:09 +00:00
|
|
|
char *Editor = EDITOR; /* editor to use (default is EDITOR */
|
1995-03-27 18:26:36 +00:00
|
|
|
int sudoers_fd; /* sudoers file descriptor */
|
|
|
|
int stmp_fd; /* stmp file descriptor */
|
|
|
|
int n; /* length parameter */
|
1993-10-04 19:23:33 +00:00
|
|
|
|
1995-03-27 18:26:36 +00:00
|
|
|
(void) setbuf(stderr, (char *)NULL); /* unbuffered stderr */
|
|
|
|
|
1994-11-10 00:46:21 +00:00
|
|
|
/*
|
1995-03-27 18:26:36 +00:00
|
|
|
* Parse command line options
|
1994-11-10 00:46:21 +00:00
|
|
|
*/
|
1995-03-27 18:26:36 +00:00
|
|
|
Argv = argv;
|
1993-10-04 19:23:33 +00:00
|
|
|
|
|
|
|
/*
|
1999-07-12 10:53:09 +00:00
|
|
|
* Arg handling. For -V print version, else usage...
|
1993-10-04 19:23:33 +00:00
|
|
|
*/
|
1998-11-18 03:51:10 +00:00
|
|
|
if (argc == 2) {
|
1995-03-27 18:26:36 +00:00
|
|
|
if (!strcmp(Argv[1], "-V")) {
|
|
|
|
(void) printf("visudo version %s\n", version);
|
1995-04-10 23:49:33 +00:00
|
|
|
exit(0);
|
1995-03-27 18:26:36 +00:00
|
|
|
} else {
|
|
|
|
usage();
|
|
|
|
}
|
1998-11-18 03:51:10 +00:00
|
|
|
} else if (argc != 1) {
|
1995-03-27 18:26:36 +00:00
|
|
|
usage();
|
1998-11-18 03:51:10 +00:00
|
|
|
}
|
1993-10-04 19:23:33 +00:00
|
|
|
|
1999-07-12 10:53:09 +00:00
|
|
|
/* user_pw_ent needs to point to something real */
|
1997-11-23 18:28:09 +00:00
|
|
|
if ((user_pw_ent = getpwuid(getuid())) == NULL) {
|
|
|
|
(void) fprintf(stderr, "%s: Can't find you in the passwd database: ",
|
|
|
|
Argv[0]);
|
|
|
|
perror(stmp);
|
|
|
|
exit(1);
|
|
|
|
}
|
1996-04-28 01:03:30 +00:00
|
|
|
|
1994-01-26 23:52:13 +00:00
|
|
|
#ifdef ENV_EDITOR
|
1993-12-03 02:35:54 +00:00
|
|
|
/*
|
1995-03-27 18:26:36 +00:00
|
|
|
* If we are allowing EDITOR and VISUAL envariables set Editor
|
|
|
|
* base on whichever exists...
|
1993-12-03 02:35:54 +00:00
|
|
|
*/
|
1995-03-27 18:26:36 +00:00
|
|
|
if (!(Editor = getenv("EDITOR")))
|
|
|
|
if (!(Editor = getenv("VISUAL")))
|
1993-12-03 02:35:54 +00:00
|
|
|
Editor = EDITOR;
|
1994-01-26 23:52:13 +00:00
|
|
|
#endif /* ENV_EDITOR */
|
1993-12-03 02:35:54 +00:00
|
|
|
|
1993-10-04 19:23:33 +00:00
|
|
|
/*
|
1995-03-27 18:26:36 +00:00
|
|
|
* Copy sudoers file to stmp
|
1993-10-04 19:23:33 +00:00
|
|
|
*/
|
1995-03-27 18:26:36 +00:00
|
|
|
stmp_fd = open(stmp, O_WRONLY | O_CREAT | O_EXCL, 0600);
|
|
|
|
if (stmp_fd < 0) {
|
1993-10-04 19:23:33 +00:00
|
|
|
if (errno == EEXIST) {
|
1995-04-10 23:49:33 +00:00
|
|
|
(void) fprintf(stderr, "%s: sudoers file busy, try again later.\n",
|
|
|
|
Argv[0]);
|
|
|
|
exit(1);
|
1993-10-04 19:23:33 +00:00
|
|
|
}
|
1994-11-10 00:46:21 +00:00
|
|
|
(void) fprintf(stderr, "%s: ", Argv[0]);
|
1995-03-27 18:26:36 +00:00
|
|
|
perror(stmp);
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1995-03-27 18:26:36 +00:00
|
|
|
}
|
|
|
|
|
1999-07-12 10:53:09 +00:00
|
|
|
/* Install signal handlers to clean up stmp if we are killed. */
|
1995-05-02 03:34:07 +00:00
|
|
|
setup_signals();
|
|
|
|
|
1995-03-27 18:26:36 +00:00
|
|
|
sudoers_fd = open(sudoers, O_RDONLY);
|
1996-10-30 23:04:02 +00:00
|
|
|
if (sudoers_fd < 0 && errno != ENOENT) {
|
1995-03-27 18:26:36 +00:00
|
|
|
(void) fprintf(stderr, "%s: ", Argv[0]);
|
|
|
|
perror(sudoers);
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1993-03-02 16:35:47 +00:00
|
|
|
}
|
|
|
|
|
1999-07-12 10:53:09 +00:00
|
|
|
/* Copy sudoers -> stmp */
|
1996-10-30 23:04:02 +00:00
|
|
|
if (sudoers_fd >= 0) {
|
|
|
|
while ((n = read(sudoers_fd, buf, sizeof(buf))) > 0)
|
|
|
|
if (write(stmp_fd, buf, n) != n) {
|
|
|
|
(void) fprintf(stderr, "%s: Write failed: ", Argv[0]);
|
|
|
|
perror("");
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1996-10-30 23:04:02 +00:00
|
|
|
}
|
1994-11-10 00:46:21 +00:00
|
|
|
|
1996-10-30 23:04:02 +00:00
|
|
|
(void) close(sudoers_fd);
|
|
|
|
}
|
1995-03-27 18:26:36 +00:00
|
|
|
(void) close(stmp_fd);
|
1993-03-02 16:35:47 +00:00
|
|
|
|
1995-03-27 18:26:36 +00:00
|
|
|
/*
|
|
|
|
* Edit the temp file and parse it (for sanity checking)
|
|
|
|
*/
|
1993-10-04 19:23:33 +00:00
|
|
|
do {
|
|
|
|
/*
|
1995-03-27 18:26:36 +00:00
|
|
|
* Build up a buffer to execute
|
1993-10-04 19:23:33 +00:00
|
|
|
*/
|
1996-11-14 00:21:35 +00:00
|
|
|
if (strlen(Editor) + strlen(stmp) + 30 > sizeof(buf)) {
|
|
|
|
(void) fprintf(stderr, "%s: Buffer too short (line %d).\n",
|
1998-05-02 18:16:03 +00:00
|
|
|
Argv[0], __LINE__);
|
1996-11-14 00:21:35 +00:00
|
|
|
Exit(-1);
|
|
|
|
}
|
1995-03-27 18:26:36 +00:00
|
|
|
if (parse_error == TRUE)
|
|
|
|
(void) sprintf(buf, "%s +%d %s", Editor, errorlineno, stmp);
|
1994-12-17 23:18:26 +00:00
|
|
|
else
|
1995-03-27 18:26:36 +00:00
|
|
|
(void) sprintf(buf, "%s %s", Editor, stmp);
|
1993-10-04 19:23:33 +00:00
|
|
|
|
1999-07-12 10:53:09 +00:00
|
|
|
/* Do the edit -- some SYSV editors exit with 1 instead of 0 */
|
1996-02-04 21:36:17 +00:00
|
|
|
n = system(buf);
|
1999-04-02 21:02:57 +00:00
|
|
|
if (n != -1 && ((n >> 8) == 0 || (n >> 8) == 1)) {
|
1995-03-27 18:26:36 +00:00
|
|
|
struct stat statbuf; /* for sanity checking */
|
1993-10-04 19:23:33 +00:00
|
|
|
|
1999-07-12 10:53:09 +00:00
|
|
|
/*
|
|
|
|
* Sanity checks.
|
|
|
|
*/
|
1995-03-27 18:26:36 +00:00
|
|
|
if (stat(stmp, &statbuf) < 0) {
|
1995-03-24 19:19:14 +00:00
|
|
|
(void) fprintf(stderr,
|
1995-03-27 18:26:36 +00:00
|
|
|
"%s: Can't stat temporary file (%s), %s unchanged.\n",
|
|
|
|
Argv[0], stmp, sudoers);
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1993-10-04 19:23:33 +00:00
|
|
|
}
|
1995-03-27 18:26:36 +00:00
|
|
|
if (statbuf.st_size == 0) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
"%s: Zero length temporary file (%s), %s unchanged.\n",
|
|
|
|
Argv[0], stmp, sudoers);
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1993-10-04 19:23:33 +00:00
|
|
|
}
|
|
|
|
|
1995-03-27 18:26:36 +00:00
|
|
|
/*
|
1999-07-12 10:53:09 +00:00
|
|
|
* Passed sanity checks so reopen stmp file and check
|
1995-03-27 18:26:36 +00:00
|
|
|
* for parse errors.
|
|
|
|
*/
|
|
|
|
yyout = stdout;
|
1995-03-29 22:22:20 +00:00
|
|
|
if (parse_error)
|
|
|
|
yyin = freopen(stmp, "r", yyin);
|
|
|
|
else
|
|
|
|
yyin = fopen(stmp, "r");
|
1995-03-27 18:26:36 +00:00
|
|
|
if (yyin == NULL) {
|
1995-03-24 19:19:14 +00:00
|
|
|
(void) fprintf(stderr,
|
1995-03-27 18:26:36 +00:00
|
|
|
"%s: Can't re-open temporary file (%s), %s unchanged.\n",
|
|
|
|
Argv[0], stmp, sudoers);
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1993-10-04 19:23:33 +00:00
|
|
|
}
|
1995-03-24 19:19:14 +00:00
|
|
|
|
1999-07-12 10:53:09 +00:00
|
|
|
/* Clean slate for each parse */
|
1996-08-17 22:29:04 +00:00
|
|
|
init_parser();
|
1995-03-26 06:12:30 +00:00
|
|
|
|
1999-07-12 10:53:09 +00:00
|
|
|
/* Parse the sudoers file */
|
1996-11-14 00:21:35 +00:00
|
|
|
if (yyparse() && parse_error != TRUE) {
|
1995-03-27 18:26:36 +00:00
|
|
|
(void) fprintf(stderr,
|
1996-11-14 00:21:35 +00:00
|
|
|
"%s: Failed to parse temporary file (%s), unknown error.\n",
|
1998-05-02 18:16:03 +00:00
|
|
|
Argv[0], stmp);
|
1996-11-14 00:21:35 +00:00
|
|
|
parse_error = TRUE;
|
1993-10-04 19:23:33 +00:00
|
|
|
}
|
1995-03-27 18:26:36 +00:00
|
|
|
} else {
|
1999-04-02 21:02:57 +00:00
|
|
|
(void) fprintf(stderr,
|
|
|
|
"%s: Editor (%s) failed with exit status %d, %s unchanged.\n",
|
|
|
|
Argv[0], Editor, n, sudoers);
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1993-10-04 19:23:33 +00:00
|
|
|
}
|
1995-03-27 18:26:36 +00:00
|
|
|
|
1995-03-27 19:54:53 +00:00
|
|
|
/*
|
1999-07-12 10:53:09 +00:00
|
|
|
* Got an error, prompt the user for what to do now
|
1995-03-27 19:54:53 +00:00
|
|
|
*/
|
|
|
|
if (parse_error == TRUE) {
|
|
|
|
switch (whatnow()) {
|
|
|
|
case 'q' : parse_error = FALSE; /* ignore parse error */
|
|
|
|
break;
|
|
|
|
case 'x' : Exit(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1995-03-27 18:26:36 +00:00
|
|
|
} while (parse_error == TRUE);
|
1993-03-02 16:35:47 +00:00
|
|
|
|
1996-08-22 18:00:46 +00:00
|
|
|
/*
|
|
|
|
* Change mode and ownership of temp file so when
|
|
|
|
* we move it to sudoers things are kosher.
|
|
|
|
*/
|
|
|
|
if (chown(stmp, SUDOERS_UID, SUDOERS_GID)) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
"%s: Unable to set (uid, gid) of %s to (%d, %d): ",
|
|
|
|
Argv[0], stmp, SUDOERS_UID, SUDOERS_GID);
|
|
|
|
perror("");
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1996-08-22 18:00:46 +00:00
|
|
|
}
|
|
|
|
if (chmod(stmp, SUDOERS_MODE)) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
"%s: Unable to change mode of %s to %o: ",
|
|
|
|
Argv[0], stmp, SUDOERS_MODE);
|
|
|
|
perror("");
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1996-08-22 18:00:46 +00:00
|
|
|
}
|
|
|
|
|
1993-10-04 19:23:33 +00:00
|
|
|
/*
|
1999-07-12 10:53:09 +00:00
|
|
|
* Now that we have a sane stmp file (parses ok) it needs to be
|
1995-03-27 18:26:36 +00:00
|
|
|
* rename(2)'d to sudoers. If the rename(2) fails we try using
|
|
|
|
* mv(1) in case stmp and sudoers are on different filesystems.
|
1993-10-04 19:23:33 +00:00
|
|
|
*/
|
1998-11-18 03:51:10 +00:00
|
|
|
if (rename(stmp, sudoers)) {
|
1995-03-27 18:26:36 +00:00
|
|
|
if (errno == EXDEV) {
|
|
|
|
char *tmpbuf;
|
|
|
|
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
"%s: %s and %s not on the same filesystem, using mv to rename.\n",
|
|
|
|
Argv[0], stmp, sudoers);
|
|
|
|
|
|
|
|
/* Allocate just enough space for tmpbuf */
|
|
|
|
n = sizeof(char) * (strlen(_PATH_MV) + strlen(stmp) +
|
|
|
|
strlen(sudoers) + 4);
|
|
|
|
if ((tmpbuf = (char *) malloc(n)) == NULL) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
"%s: Cannot alocate memory, %s unchanged: ",
|
|
|
|
Argv[0], sudoers);
|
|
|
|
perror("");
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1995-03-27 18:26:36 +00:00
|
|
|
}
|
1994-12-16 02:06:56 +00:00
|
|
|
|
1995-03-27 18:26:36 +00:00
|
|
|
/* Build up command and execute it */
|
|
|
|
(void) sprintf(tmpbuf, "%s %s %s", _PATH_MV, stmp, sudoers);
|
|
|
|
if (system(tmpbuf)) {
|
|
|
|
(void) fprintf(stderr,
|
|
|
|
"%s: Command failed: '%s', %s unchanged.\n",
|
|
|
|
Argv[0], tmpbuf, sudoers);
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1995-03-27 18:26:36 +00:00
|
|
|
}
|
1999-04-10 04:40:57 +00:00
|
|
|
free(tmpbuf);
|
1995-03-27 18:26:36 +00:00
|
|
|
} else {
|
|
|
|
(void) fprintf(stderr, "%s: Error renaming %s, %s unchanged: ",
|
|
|
|
Argv[0], stmp, sudoers);
|
1994-12-16 02:06:56 +00:00
|
|
|
perror("");
|
1996-11-12 16:58:35 +00:00
|
|
|
Exit(-1);
|
1994-12-16 02:06:56 +00:00
|
|
|
}
|
1998-11-18 03:51:10 +00:00
|
|
|
}
|
1994-12-16 02:06:56 +00:00
|
|
|
|
1995-03-27 18:26:36 +00:00
|
|
|
return(0);
|
1993-03-02 16:35:47 +00:00
|
|
|
}
|
1994-05-25 03:08:45 +00:00
|
|
|
|
1999-07-12 10:53:09 +00:00
|
|
|
/*
|
|
|
|
* Dummy *_matches routines.
|
|
|
|
* These exist to allow us to use the same parser as sudo(8).
|
1994-05-25 03:08:45 +00:00
|
|
|
*/
|
1999-04-10 04:49:03 +00:00
|
|
|
int
|
|
|
|
command_matches(cmnd, user_args, path, sudoers_args)
|
1996-02-02 06:14:46 +00:00
|
|
|
char *cmnd;
|
1996-07-22 19:50:59 +00:00
|
|
|
char *user_args;
|
1996-02-02 06:14:46 +00:00
|
|
|
char *path;
|
1996-07-22 19:50:59 +00:00
|
|
|
char *sudoers_args;
|
1995-03-27 18:26:36 +00:00
|
|
|
{
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
1999-04-10 04:49:03 +00:00
|
|
|
int
|
|
|
|
addr_matches(n)
|
1995-03-27 18:26:36 +00:00
|
|
|
char *n;
|
|
|
|
{
|
|
|
|
return(TRUE);
|
|
|
|
}
|
1994-05-25 03:08:45 +00:00
|
|
|
|
1999-04-10 04:49:03 +00:00
|
|
|
int
|
|
|
|
usergr_matches(g, u)
|
1995-12-18 02:51:30 +00:00
|
|
|
char *g, *u;
|
|
|
|
{
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
1999-04-10 04:49:03 +00:00
|
|
|
int
|
|
|
|
netgr_matches(n, h, u)
|
1995-07-25 00:02:05 +00:00
|
|
|
char *n, *h, *u;
|
|
|
|
{
|
|
|
|
return(TRUE);
|
|
|
|
}
|
|
|
|
|
1999-07-12 10:53:09 +00:00
|
|
|
/*
|
|
|
|
* Assuming a parse error occurred, prompt the user for what they want
|
|
|
|
* to do now. Returns the first letter of their choice.
|
1995-03-27 19:54:53 +00:00
|
|
|
*/
|
1999-04-10 04:49:03 +00:00
|
|
|
static char
|
|
|
|
whatnow()
|
1995-03-27 19:54:53 +00:00
|
|
|
{
|
1999-07-12 10:53:09 +00:00
|
|
|
int choice, c;
|
1995-03-27 19:54:53 +00:00
|
|
|
|
1999-07-12 10:53:09 +00:00
|
|
|
for (;;) {
|
1996-11-14 00:21:35 +00:00
|
|
|
(void) fputs("What now? ", stdout);
|
1999-07-12 10:53:09 +00:00
|
|
|
choice = getchar();
|
|
|
|
for (c = choice; c != '\n' && c != EOF;)
|
|
|
|
c = getchar();
|
1995-03-27 19:54:53 +00:00
|
|
|
|
1996-11-14 00:21:35 +00:00
|
|
|
if (choice == 'e' || choice == 'x' || choice == 'Q')
|
1999-07-12 10:53:09 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
1995-03-27 19:54:53 +00:00
|
|
|
|
|
|
|
return(choice);
|
|
|
|
}
|
|
|
|
|
1999-07-12 10:53:09 +00:00
|
|
|
/*
|
|
|
|
* Install signal handlers for visudo.
|
1995-05-02 03:34:07 +00:00
|
|
|
*/
|
1999-04-10 04:49:03 +00:00
|
|
|
static void
|
|
|
|
setup_signals()
|
1995-05-02 03:34:07 +00:00
|
|
|
{
|
|
|
|
#ifdef POSIX_SIGNALS
|
1999-07-12 10:53:09 +00:00
|
|
|
struct sigaction action; /* POSIX signal structure */
|
1995-05-02 03:34:07 +00:00
|
|
|
#endif /* POSIX_SIGNALS */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup signal handlers
|
|
|
|
*/
|
|
|
|
#ifdef POSIX_SIGNALS
|
|
|
|
(void) memset((VOID *)&action, 0, sizeof(action));
|
|
|
|
action.sa_handler = Exit;
|
|
|
|
action.sa_flags = SA_RESETHAND;
|
|
|
|
(void) sigaction(SIGILL, &action, NULL);
|
|
|
|
(void) sigaction(SIGTRAP, &action, NULL);
|
|
|
|
(void) sigaction(SIGBUS, &action, NULL);
|
|
|
|
(void) sigaction(SIGSEGV, &action, NULL);
|
|
|
|
(void) sigaction(SIGTERM, &action, NULL);
|
|
|
|
|
|
|
|
action.sa_handler = SIG_IGN;
|
|
|
|
action.sa_flags = 0;
|
|
|
|
(void) sigaction(SIGHUP, &action, NULL);
|
|
|
|
(void) sigaction(SIGINT, &action, NULL);
|
|
|
|
(void) sigaction(SIGQUIT, &action, NULL);
|
|
|
|
#else
|
|
|
|
(void) signal(SIGILL, Exit);
|
|
|
|
(void) signal(SIGTRAP, Exit);
|
|
|
|
(void) signal(SIGBUS, Exit);
|
|
|
|
(void) signal(SIGSEGV, Exit);
|
|
|
|
(void) signal(SIGTERM, Exit);
|
|
|
|
|
|
|
|
(void) signal(SIGHUP, SIG_IGN);
|
|
|
|
(void) signal(SIGINT, SIG_IGN);
|
|
|
|
(void) signal(SIGQUIT, SIG_IGN);
|
|
|
|
#endif /* POSIX_SIGNALS */
|
|
|
|
}
|
1999-07-12 10:53:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Unlink the sudoers temp file (if it exists) and exit.
|
|
|
|
* Used in place of a normal exit() and as a signal handler.
|
|
|
|
* A positive parameter is considered to be a signal and is reported.
|
|
|
|
*/
|
|
|
|
static RETSIGTYPE
|
|
|
|
Exit(sig)
|
|
|
|
int sig;
|
|
|
|
{
|
|
|
|
(void) unlink(stmp);
|
|
|
|
|
|
|
|
if (sig > 0)
|
|
|
|
(void) fprintf(stderr, "%s exiting, caught signal %d.\n", Argv[0], sig);
|
|
|
|
|
|
|
|
exit(-sig);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
(void) fprintf(stderr, "usage: %s [-V]\n", Argv[0]);
|
|
|
|
Exit(-1);
|
|
|
|
}
|