diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2007-09-05 23:55:58 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2007-09-05 23:55:58 +0000 |
commit | 05ed5a77d91b39a2b7282cb779a045e879d72925 (patch) | |
tree | 24259d26923652a5ffe9426ddffad80c0811492c /usr.bin/sudo/visudo.c | |
parent | 6f031074ca5a429bd69be560206d4cb86f8595e7 (diff) |
update to sudo 1.6.9p5
Diffstat (limited to 'usr.bin/sudo/visudo.c')
-rw-r--r-- | usr.bin/sudo/visudo.c | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/usr.bin/sudo/visudo.c b/usr.bin/sudo/visudo.c index f8fbea7445a..0310d84d4cd 100644 --- a/usr.bin/sudo/visudo.c +++ b/usr.bin/sudo/visudo.c @@ -78,7 +78,7 @@ #include "version.h" #ifndef lint -__unused static const char rcsid[] = "$Sudo: visudo.c,v 1.166.2.9 2007/07/22 19:21:01 millert Exp $"; +__unused static const char rcsid[] = "$Sudo: visudo.c,v 1.166.2.10 2007/09/01 13:39:13 millert Exp $"; #endif /* lint */ struct sudoersfile { @@ -98,7 +98,7 @@ static RETSIGTYPE Exit __P((int)); static void edit_sudoers __P((struct sudoersfile *, char *, char *, int)); static void visudo __P((struct sudoersfile *, char *, char *)); static void setup_signals __P((void)); -static void install_sudoers __P((struct sudoersfile *)); +static void install_sudoers __P((struct sudoersfile *, int)); static int check_syntax __P(()); static int run_command __P((char *, char **)); static char *get_args __P((char *)); @@ -141,7 +141,7 @@ main(argc, argv) char **argv; { char *args, *editor; - int ch, checkonly, n; + int ch, checkonly, n, oldperms; /* Initialize sudoers struct. */ sudoers.path = _PATH_SUDOERS; @@ -158,7 +158,7 @@ main(argc, argv) /* * Arg handling. */ - checkonly = 0; + checkonly = oldperms = FALSE; while ((ch = getopt(argc, argv, "Vcf:sq")) != -1) { switch (ch) { case 'V': @@ -170,6 +170,7 @@ main(argc, argv) case 'f': /* sudoers file path */ sudoers.path = optarg; easprintf(&sudoers.tpath, "%s.tmp", optarg); + oldperms = TRUE; break; case 's': pedantic++; /* strict mode */ @@ -215,7 +216,7 @@ main(argc, argv) visudo(&sudoers, editor, args); /* Install the new sudoers file. */ - install_sudoers(&sudoers); + install_sudoers(&sudoers, oldperms); exit(0); } @@ -383,21 +384,36 @@ visudo(sp, editor, args) * move it into place. Returns TRUE on success, else FALSE. */ static void -install_sudoers(sp) +install_sudoers(sp, oldperms) struct sudoersfile *sp; + int oldperms; { + struct stat sb; + /* * Change mode and ownership of temp file so when * we move it to sp->path things are kosher. */ - if (chown(sp->tpath, SUDOERS_UID, SUDOERS_GID) != 0) { - warn("unable to set (uid, gid) of %s to (%d, %d)", - sp->tpath, SUDOERS_UID, SUDOERS_GID); - Exit(-1); - } - if (chmod(sp->tpath, SUDOERS_MODE) != 0) { - warn("unable to change mode of %s to 0%o", sp->tpath, SUDOERS_MODE); - Exit(-1); + if (oldperms) { + /* Use perms of the existing file. */ +#ifdef HAVE_FSTAT + if (fstat(sp->fd, &sb) == -1) +#else + if (stat(sp->path, &sb) == -1) +#endif + err(1, "can't stat %s", sp->path); + (void) chown(sp->tpath, sb.st_uid, sb.st_gid); + (void) chmod(sp->tpath, sb.st_mode & 0777); + } else { + if (chown(sp->tpath, SUDOERS_UID, SUDOERS_GID) != 0) { + warn("unable to set (uid, gid) of %s to (%d, %d)", + sp->tpath, SUDOERS_UID, SUDOERS_GID); + Exit(-1); + } + if (chmod(sp->tpath, SUDOERS_MODE) != 0) { + warn("unable to change mode of %s to 0%o", sp->tpath, SUDOERS_MODE); + Exit(-1); + } } /* |