From 587e684e7683c73f595df5162dd468acc5093e52 Mon Sep 17 00:00:00 2001 From: deraadt Date: Mon, 12 Oct 2015 07:58:19 +0000 Subject: [PATCH] do not umask() [with the wrong umask] around mkstemp() calls, no matter how broken other systems are. ok guenther gilles --- usr.sbin/smtpd/makemap.c | 5 +---- usr.sbin/smtpd/smtpctl.c | 5 +---- usr.sbin/smtpd/smtpd.c | 5 +---- usr.sbin/smtpd/util.c | 5 +---- 4 files changed, 4 insertions(+), 16 deletions(-) diff --git a/usr.sbin/smtpd/makemap.c b/usr.sbin/smtpd/makemap.c index 641d4698c97..f54bd57b41c 100644 --- a/usr.sbin/smtpd/makemap.c +++ b/usr.sbin/smtpd/makemap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: makemap.c,v 1.53 2015/10/06 06:04:46 gilles Exp $ */ +/* $OpenBSD: makemap.c,v 1.54 2015/10/12 07:58:19 deraadt Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -97,7 +97,6 @@ main(int argc, char *argv[]) int ch; DBTYPE dbtype = DB_HASH; char *p; - mode_t omode; log_init(1); @@ -185,10 +184,8 @@ main(int argc, char *argv[]) if (! bsnprintf(dbname, sizeof(dbname), "%s.XXXXXXXXXXX", oflag)) errx(1, "path too long"); - omode = umask(07077); if (mkstemp(dbname) == -1) err(1, "mkstemp"); - umask(omode); db = dbopen(dbname, O_EXLOCK|O_RDWR|O_SYNC, 0644, dbtype, NULL); if (db == NULL) { diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c index b53d2c20326..27e454eca39 100644 --- a/usr.sbin/smtpd/smtpctl.c +++ b/usr.sbin/smtpd/smtpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpctl.c,v 1.128 2015/10/09 14:37:38 gilles Exp $ */ +/* $OpenBSD: smtpctl.c,v 1.129 2015/10/12 07:58:19 deraadt Exp $ */ /* * Copyright (c) 2013 Eric Faurot @@ -139,7 +139,6 @@ FILE * offline_file(void) { char path[PATH_MAX]; - mode_t omode; int fd; FILE *fp; @@ -147,13 +146,11 @@ offline_file(void) PATH_OFFLINE, (long long int) time(NULL))) err(EX_UNAVAILABLE, "snprintf"); - omode = umask(07077); if ((fd = mkstemp(path)) == -1 || (fp = fdopen(fd, "w+")) == NULL) { if (fd != -1) unlink(path); err(EX_UNAVAILABLE, "cannot create temporary file %s", path); } - umask(omode); if (fchmod(fd, 0600) == -1) { unlink(path); diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c index 47235c00ea2..ff8685f3594 100644 --- a/usr.sbin/smtpd/smtpd.c +++ b/usr.sbin/smtpd/smtpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: smtpd.c,v 1.243 2015/10/09 17:44:25 gilles Exp $ */ +/* $OpenBSD: smtpd.c,v 1.244 2015/10/12 07:58:19 deraadt Exp $ */ /* * Copyright (c) 2008 Gilles Chehade @@ -907,7 +907,6 @@ forkmda(struct mproc *p, uint64_t id, struct deliver *deliver) struct child *child; pid_t pid; int allout, pipefd[2]; - mode_t omode; log_debug("debug: smtpd: forking mda for session %016"PRIx64 ": \"%s\" as %s", id, deliver->to, deliver->user); @@ -943,9 +942,7 @@ forkmda(struct mproc *p, uint64_t id, struct deliver *deliver) /* prepare file which captures stdout and stderr */ (void)strlcpy(sfn, "/tmp/smtpd.out.XXXXXXXXXXX", sizeof(sfn)); - omode = umask(07077); allout = mkstemp(sfn); - umask(omode); if (allout < 0) { (void)snprintf(ebuf, sizeof ebuf, "mkstemp: %s", strerror(errno)); m_create(p_pony, IMSG_MDA_DONE, 0, 0, -1); diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c index a2d9cc6ce2e..a4810fd89ab 100644 --- a/usr.sbin/smtpd/util.c +++ b/usr.sbin/smtpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.119 2015/10/10 11:42:49 jung Exp $ */ +/* $OpenBSD: util.c,v 1.120 2015/10/12 07:58:19 deraadt Exp $ */ /* * Copyright (c) 2000,2001 Markus Friedl. All rights reserved. @@ -377,7 +377,6 @@ mktmpfile(void) { char path[PATH_MAX]; int fd; - mode_t omode; if (! bsnprintf(path, sizeof(path), "%s/smtpd.XXXXXXXXXX", PATH_TEMPORARY)) { @@ -385,12 +384,10 @@ mktmpfile(void) fatal("exiting"); } - omode = umask(07077); if ((fd = mkstemp(path)) == -1) { log_warn("cannot create temporary file %s", path); fatal("exiting"); } - umask(omode); unlink(path); return (fd); } -- 2.20.1