summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2019-07-02 09:36:21 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2019-07-02 09:36:21 +0000
commit59598fc3c2aaa7b3fee3d0b8f694423f56c454b8 (patch)
tree20e7f4170101b6f333ecf674826ad888d48b3150 /usr.sbin/smtpd
parentea1640291d949880e348793940b07e1f8606f2c4 (diff)
Replace mkstemp/fdopen/unlink dances with tmpfile.
No functional change. OK gilles@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r--usr.sbin/smtpd/enqueue.c17
-rw-r--r--usr.sbin/smtpd/smtpc.c13
-rw-r--r--usr.sbin/smtpd/smtpctl.c18
3 files changed, 11 insertions, 37 deletions
diff --git a/usr.sbin/smtpd/enqueue.c b/usr.sbin/smtpd/enqueue.c
index bc59989aaac..d894395375f 100644
--- a/usr.sbin/smtpd/enqueue.c
+++ b/usr.sbin/smtpd/enqueue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: enqueue.c,v 1.115 2018/05/31 21:06:12 gilles Exp $ */
+/* $OpenBSD: enqueue.c,v 1.116 2019/07/02 09:36:20 martijn Exp $ */
/*
* Copyright (c) 2005 Henning Brauer <henning@bulabula.org>
@@ -171,8 +171,6 @@ enqueue(int argc, char *argv[], FILE *ofp)
FILE *fp = NULL, *fout;
size_t sz = 0, envid_sz = 0;
ssize_t len;
- int fd;
- char sfn[] = "/tmp/smtpd.XXXXXXXXXX";
char *line;
int dotted;
int inheaders = 1;
@@ -269,16 +267,9 @@ enqueue(int argc, char *argv[], FILE *ofp)
argc--;
}
- if ((fd = mkstemp(sfn)) == -1 ||
- (fp = fdopen(fd, "w+")) == NULL) {
- int saved_errno = errno;
- if (fd != -1) {
- unlink(sfn);
- close(fd);
- }
- errc(EX_UNAVAILABLE, saved_errno, "mkstemp");
- }
- unlink(sfn);
+ if ((fp = tmpfile()) == NULL)
+ err(EX_UNAVAILABLE, "tmpfile");
+
msg.noheader = parse_message(stdin, fake_from == NULL, tflag, fp);
if (msg.rcpt_cnt == 0)
diff --git a/usr.sbin/smtpd/smtpc.c b/usr.sbin/smtpd/smtpc.c
index 2373aa76d49..fa4688546da 100644
--- a/usr.sbin/smtpd/smtpc.c
+++ b/usr.sbin/smtpd/smtpc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpc.c,v 1.5 2019/05/15 05:02:43 eric Exp $ */
+/* $OpenBSD: smtpc.c,v 1.6 2019/07/02 09:36:20 martijn Exp $ */
/*
* Copyright (c) 2018 Eric Faurot <eric@openbsd.org>
@@ -263,19 +263,12 @@ parse_server(char *server)
void
parse_message(FILE *ifp)
{
- char sfn[] = "/tmp/smtp.XXXXXXXXXX";
char *line = NULL;
size_t linesz = 0;
ssize_t len;
- int fd;
- if ((fd = mkstemp(sfn)) == -1)
- fatal("mkstemp");
- unlink(sfn);
-
- mail.fp = fdopen(fd, "w+");
- if ((mail.fp) == NULL)
- fatal("fdopen");
+ if ((mail.fp = tmpfile()) == NULL)
+ fatal("tmpfile");
for (;;) {
if ((len = getline(&line, &linesz, ifp)) == -1) {
diff --git a/usr.sbin/smtpd/smtpctl.c b/usr.sbin/smtpd/smtpctl.c
index 4b44d9dd30a..b719364bddc 100644
--- a/usr.sbin/smtpd/smtpctl.c
+++ b/usr.sbin/smtpd/smtpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpctl.c,v 1.163 2019/01/14 09:37:40 eric Exp $ */
+/* $OpenBSD: smtpctl.c,v 1.164 2019/07/02 09:36:20 martijn Exp $ */
/*
* Copyright (c) 2013 Eric Faurot <eric@openbsd.org>
@@ -1297,20 +1297,10 @@ display(const char *s)
if (is_encrypted_fp(fp)) {
int i;
- int fd;
FILE *ofp = NULL;
- char sfn[] = "/tmp/smtpd.XXXXXXXXXX";
-
- if ((fd = mkstemp(sfn)) == -1 ||
- (ofp = fdopen(fd, "w+")) == NULL) {
- int saved_errno = errno;
- if (fd != -1) {
- unlink(sfn);
- close(fd);
- }
- errc(1, saved_errno, "mkstemp");
- }
- unlink(sfn);
+
+ if ((ofp = tmpfile()) == NULL)
+ err(1, "tmpfile");
for (i = 0; i < 3; i++) {
key = getpass("key> ");