diff options
-rw-r--r-- | usr.sbin/cron/crontab.1 | 13 | ||||
-rw-r--r-- | usr.sbin/cron/crontab.c | 47 |
2 files changed, 54 insertions, 6 deletions
diff --git a/usr.sbin/cron/crontab.1 b/usr.sbin/cron/crontab.1 index 1dedc76d908..7d1a9edd124 100644 --- a/usr.sbin/cron/crontab.1 +++ b/usr.sbin/cron/crontab.1 @@ -17,9 +17,9 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT .\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.\" $OpenBSD: crontab.1,v 1.26 2009/02/08 17:15:11 jmc Exp $ +.\" $OpenBSD: crontab.1,v 1.27 2011/01/31 18:02:56 millert Exp $ .\" -.Dd $Mdocdate: February 8 2009 $ +.Dd $Mdocdate: January 31 2011 $ .Dt CRONTAB 1 .Os .Sh NAME @@ -116,6 +116,15 @@ you should always use the .Fl u option for safety's sake. .El +.Sh ENVIRONMENT +.Bl -tag -width "TMPDIR" +.It Ev TMPDIR +Directory in which to place temporary files used by +.Nm Fl e . +If unset, +.Pa /tmp +is used. +.El .Sh FILES .Bl -tag -width "/var/cron/cron.allow" -compact .It Pa /var/cron/cron.allow diff --git a/usr.sbin/cron/crontab.c b/usr.sbin/cron/crontab.c index 497aa9c0fa1..5b67592b039 100644 --- a/usr.sbin/cron/crontab.c +++ b/usr.sbin/cron/crontab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: crontab.c,v 1.58 2009/10/27 23:52:16 deraadt Exp $ */ +/* $OpenBSD: crontab.c,v 1.59 2011/01/31 18:02:56 millert Exp $ */ /* Copyright 1988,1990,1993,1994 by Paul Vixie * All rights reserved @@ -288,6 +288,7 @@ check_error(const char *msg) { static void edit_cmd(void) { char n[MAX_FNAME], q[MAX_TEMPSTR]; + const char *tmpdir; FILE *f; int ch, t; struct stat statbuf, xstatbuf; @@ -329,12 +330,26 @@ edit_cmd(void) { (void)signal(SIGINT, SIG_IGN); (void)signal(SIGQUIT, SIG_IGN); - if (snprintf(Filename, sizeof Filename, "%scrontab.XXXXXXXXXX", - _PATH_TMP) >= sizeof(Filename)) { + tmpdir = getenv("TMPDIR"); + if (tmpdir == NULL || tmpdir[0] == '\0') + tmpdir = _PATH_TMP; + for (t = strlen(tmpdir); t != 0 && tmpdir[t - 1] == '/'; t--) + continue; + if (snprintf(Filename, sizeof Filename, "%.*s/crontab.XXXXXXXXXX", + t, tmpdir) >= sizeof(Filename)) { fprintf(stderr, "path too long\n"); goto fatal; } - if (-1 == (t = mkstemp(Filename))) { + if (swap_gids() < OK) { + perror("swapping gids"); + exit(ERROR_EXIT); + } + t = mkstemp(Filename); + if (swap_gids_back() < OK) { + perror("swapping gids back"); + exit(ERROR_EXIT); + } + if (t == -1) { perror(Filename); goto fatal; } @@ -366,7 +381,15 @@ edit_cmd(void) { fprintf(stderr, "%s: error while writing new crontab to %s\n", ProgramName, Filename); fatal: + if (swap_gids() < OK) { + perror("swapping gids"); + exit(ERROR_EXIT); + } unlink(Filename); + if (swap_gids_back() < OK) { + perror("swapping gids back"); + exit(ERROR_EXIT); + } exit(ERROR_EXIT); } @@ -387,11 +410,19 @@ edit_cmd(void) { goto fatal; } if (timespeccmp(&mtimespec, &statbuf.st_mtimespec, -) == 0) { + if (swap_gids() < OK) { + perror("swapping gids"); + exit(ERROR_EXIT); + } if (lstat(Filename, &xstatbuf) == 0 && statbuf.st_ino != xstatbuf.st_ino) { fprintf(stderr, "%s: crontab temp file moved, editor " "may create backup files improperly\n", ProgramName); } + if (swap_gids_back() < OK) { + perror("swapping gids back"); + exit(ERROR_EXIT); + } fprintf(stderr, "%s: no changes made to crontab\n", ProgramName); goto remove; @@ -432,7 +463,15 @@ edit_cmd(void) { goto fatal; } remove: + if (swap_gids() < OK) { + perror("swapping gids"); + exit(ERROR_EXIT); + } unlink(Filename); + if (swap_gids_back() < OK) { + perror("swapping gids back"); + exit(ERROR_EXIT); + } done: log_it(RealUser, Pid, "END EDIT", User); } |