summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r--usr.sbin/smtpd/config.c6
-rw-r--r--usr.sbin/smtpd/control.c6
-rw-r--r--usr.sbin/smtpd/filter.c6
-rw-r--r--usr.sbin/smtpd/ioev.c19
-rw-r--r--usr.sbin/smtpd/ioev.h6
-rw-r--r--usr.sbin/smtpd/mda.c4
-rw-r--r--usr.sbin/smtpd/mproc.c6
-rw-r--r--usr.sbin/smtpd/smtp.c6
-rw-r--r--usr.sbin/smtpd/smtp_session.c4
-rw-r--r--usr.sbin/smtpd/smtpd.h9
-rw-r--r--usr.sbin/smtpd/util.c29
11 files changed, 31 insertions, 70 deletions
diff --git a/usr.sbin/smtpd/config.c b/usr.sbin/smtpd/config.c
index 67a6799abee..633374dd17f 100644
--- a/usr.sbin/smtpd/config.c
+++ b/usr.sbin/smtpd/config.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: config.c,v 1.33 2015/10/14 20:45:30 gilles Exp $ */
+/* $OpenBSD: config.c,v 1.34 2016/03/25 15:06:58 krw Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -117,8 +117,8 @@ init_pipes(void)
fatal("socketpair");
pipes[i][j] = sockpair[0];
pipes[j][i] = sockpair[1];
- session_socket_blockmode(pipes[i][j], BM_NONBLOCK);
- session_socket_blockmode(pipes[j][i], BM_NONBLOCK);
+ io_set_nonblocking(pipes[i][j]);
+ io_set_nonblocking(pipes[j][i]);
}
}
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c
index 1cf6eb0642d..8e66de3bfe1 100644
--- a/usr.sbin/smtpd/control.c
+++ b/usr.sbin/smtpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.111 2016/02/09 10:38:02 gilles Exp $ */
+/* $OpenBSD: control.c,v 1.112 2016/03/25 15:06:58 krw Exp $ */
/*
* Copyright (c) 2012 Gilles Chehade <gilles@poolp.org>
@@ -235,7 +235,7 @@ control_create_socket(void)
fatal("control: chmod");
}
- session_socket_blockmode(fd, BM_NONBLOCK);
+ io_set_nonblocking(fd);
control_state.fd = fd;
return fd;
@@ -358,7 +358,7 @@ control_accept(int listenfd, short event, void *arg)
fatal("control_accept: accept");
}
- session_socket_blockmode(connfd, BM_NONBLOCK);
+ io_set_nonblocking(connfd);
if (getpeereid(connfd, &euid, &egid) == -1)
fatal("getpeereid");
diff --git a/usr.sbin/smtpd/filter.c b/usr.sbin/smtpd/filter.c
index 4d197cf4405..c927e855046 100644
--- a/usr.sbin/smtpd/filter.c
+++ b/usr.sbin/smtpd/filter.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: filter.c,v 1.16 2016/02/03 11:14:08 eric Exp $ */
+/* $OpenBSD: filter.c,v 1.17 2016/03/25 15:06:58 krw Exp $ */
/*
* Copyright (c) 2011 Gilles Chehade <gilles@poolp.org>
@@ -665,8 +665,8 @@ filter_tx(struct filter_session *s, int sink)
return (-1);
}
- io_set_blocking(sp[0], 0);
- io_set_blocking(sp[1], 0);
+ io_set_nonblocking(sp[0]);
+ io_set_nonblocking(sp[1]);
iobuf_init(&s->ibuf, 0, 0);
io_init(&s->iev, sp[0], s, filter_tx_io, &s->ibuf);
diff --git a/usr.sbin/smtpd/ioev.c b/usr.sbin/smtpd/ioev.c
index 437bdae3b69..14771a0a617 100644
--- a/usr.sbin/smtpd/ioev.c
+++ b/usr.sbin/smtpd/ioev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ioev.c,v 1.24 2015/12/28 22:08:30 jung Exp $ */
+/* $OpenBSD: ioev.c,v 1.25 2016/03/25 15:06:58 krw Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -131,30 +131,25 @@ io_strevent(int evt)
}
void
-io_set_blocking(int fd, int blocking)
+io_set_nonblocking(int fd)
{
int flags;
- if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
+ if ((flags = fcntl(fd, F_GETFL)) == -1)
err(1, "io_set_blocking:fcntl(F_GETFL)");
- if (blocking)
- flags &= ~O_NONBLOCK;
- else
- flags |= O_NONBLOCK;
+ flags |= O_NONBLOCK;
if ((flags = fcntl(fd, F_SETFL, flags)) == -1)
err(1, "io_set_blocking:fcntl(F_SETFL)");
}
void
-io_set_linger(int fd, int linger)
+io_set_nolinger(int fd)
{
struct linger l;
memset(&l, 0, sizeof(l));
- l.l_onoff = linger ? 1 : 0;
- l.l_linger = linger;
if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &l, sizeof(l)) == -1)
err(1, "io_set_linger:setsockopt()");
}
@@ -596,8 +591,8 @@ io_connect(struct io *io, const struct sockaddr *sa, const struct sockaddr *bsa)
if ((sock = socket(sa->sa_family, SOCK_STREAM, 0)) == -1)
goto fail;
- io_set_blocking(sock, 0);
- io_set_linger(sock, 0);
+ io_set_nonblocking(sock);
+ io_set_nolinger(sock);
if (bsa && bind(sock, bsa, bsa->sa_len) == -1)
goto fail;
diff --git a/usr.sbin/smtpd/ioev.h b/usr.sbin/smtpd/ioev.h
index dfcc7843cd9..cb630a7af7e 100644
--- a/usr.sbin/smtpd/ioev.h
+++ b/usr.sbin/smtpd/ioev.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ioev.h,v 1.5 2014/12/24 13:51:31 eric Exp $ */
+/* $OpenBSD: ioev.h,v 1.6 2016/03/25 15:06:58 krw Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@openbsd.org>
*
@@ -52,8 +52,8 @@ struct io {
const char *error; /* only valid immediately on callback */
};
-void io_set_blocking(int, int);
-void io_set_linger(int, int);
+void io_set_nonblocking(int);
+void io_set_nolinger(int);
void io_init(struct io*, int, void*, void(*)(struct io*, int), struct iobuf*);
void io_clear(struct io*);
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index c99d1404a35..082e04e2ff6 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.117 2016/02/02 05:45:27 sunil Exp $ */
+/* $OpenBSD: mda.c,v 1.118 2016/03/25 15:06:58 krw Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -431,7 +431,7 @@ mda_imsg(struct mproc *p, struct imsg *imsg)
"for session %016"PRIx64 " evpid %016"PRIx64,
imsg->fd, s->id, s->evp->id);
- io_set_blocking(imsg->fd, 0);
+ io_set_nonblocking(imsg->fd);
io_init(&s->io, imsg->fd, s, mda_io, &s->iobuf);
io_set_write(&s->io);
return;
diff --git a/usr.sbin/smtpd/mproc.c b/usr.sbin/smtpd/mproc.c
index 192e9b36d0b..f422b6bb2d2 100644
--- a/usr.sbin/smtpd/mproc.c
+++ b/usr.sbin/smtpd/mproc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mproc.c,v 1.18 2016/02/10 15:03:37 millert Exp $ */
+/* $OpenBSD: mproc.c,v 1.19 2016/03/25 15:06:58 krw Exp $ */
/*
* Copyright (c) 2012 Eric Faurot <eric@faurot.net>
@@ -52,8 +52,8 @@ mproc_fork(struct mproc *p, const char *path, char *argv[])
if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, sp) < 0)
return (-1);
- session_socket_blockmode(sp[0], BM_NONBLOCK);
- session_socket_blockmode(sp[1], BM_NONBLOCK);
+ io_set_nonblocking(sp[0]);
+ io_set_nonblocking(sp[1]);
if ((p->pid = fork()) == -1)
goto err;
diff --git a/usr.sbin/smtpd/smtp.c b/usr.sbin/smtpd/smtp.c
index 70d73aafc0a..685afcca29d 100644
--- a/usr.sbin/smtpd/smtp.c
+++ b/usr.sbin/smtpd/smtp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp.c,v 1.154 2016/02/13 20:43:07 gilles Exp $ */
+/* $OpenBSD: smtp.c,v 1.155 2016/03/25 15:06:58 krw Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -169,7 +169,7 @@ smtp_setup_events(void)
" ca \"%s\"", ss_to_text(&l->ss), ntohs(l->port),
l->flags, l->pki_name, l->ca_name);
- session_socket_blockmode(l->fd, BM_NONBLOCK);
+ io_set_nonblocking(l->fd);
if (listen(l->fd, SMTPD_BACKLOG) == -1)
fatal("listen");
event_set(&l->ev, l->fd, EV_READ|EV_PERSIST, smtp_accept, l);
@@ -280,7 +280,7 @@ smtp_accept(int fd, short event, void *p)
close(sock);
return;
}
- io_set_blocking(sock, 0);
+ io_set_nonblocking(sock);
sessions++;
stat_increment("smtp.session", 1);
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index 88c912a21d3..78552b9088f 100644
--- a/usr.sbin/smtpd/smtp_session.c
+++ b/usr.sbin/smtpd/smtp_session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp_session.c,v 1.268 2016/02/05 19:15:15 jung Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.269 2016/03/25 15:06:58 krw Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -1178,7 +1178,7 @@ smtp_filter_fd(uint64_t id, int fd)
}
iobuf_init(&s->obuf, 0, 0);
- io_set_blocking(fd, 0);
+ io_set_nonblocking(fd);
io_init(&s->oev, fd, s, smtp_data_io, &s->obuf);
iobuf_fqueue(&s->obuf, "Received: ");
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 783f96f8111..994e630fd84 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.513 2016/02/21 15:17:25 gilles Exp $ */
+/* $OpenBSD: smtpd.h,v 1.514 2016/03/25 15:06:58 krw Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@poolp.org>
@@ -308,11 +308,6 @@ enum imsg_type {
IMSG_CA_PRIVDEC
};
-enum blockmodes {
- BM_NORMAL,
- BM_NONBLOCK
-};
-
enum smtp_proc_type {
PROC_PARENT = 0,
PROC_LKA,
@@ -1506,8 +1501,6 @@ void iobuf_xinit(struct iobuf *, size_t, size_t, const char *);
void iobuf_xfqueue(struct iobuf *, const char *, const char *, ...);
void log_envelope(const struct envelope *, const char *, const char *,
const char *);
-void session_socket_blockmode(int, enum blockmodes);
-void session_socket_no_linger(int);
int session_socket_error(int);
int getmailname(char *, size_t);
int base64_encode(unsigned char const *, size_t, char *, size_t);
diff --git a/usr.sbin/smtpd/util.c b/usr.sbin/smtpd/util.c
index 8e62e941660..4f4094d5b76 100644
--- a/usr.sbin/smtpd/util.c
+++ b/usr.sbin/smtpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.125 2016/01/12 17:29:43 sunil Exp $ */
+/* $OpenBSD: util.c,v 1.126 2016/03/25 15:06:58 krw Exp $ */
/*
* Copyright (c) 2000,2001 Markus Friedl. All rights reserved.
@@ -664,33 +664,6 @@ generate_uid(void)
return (uid);
}
-void
-session_socket_blockmode(int fd, enum blockmodes bm)
-{
- int flags;
-
- if ((flags = fcntl(fd, F_GETFL, 0)) == -1)
- fatal("fcntl F_GETFL");
-
- if (bm == BM_NONBLOCK)
- flags |= O_NONBLOCK;
- else
- flags &= ~O_NONBLOCK;
-
- if ((flags = fcntl(fd, F_SETFL, flags)) == -1)
- fatal("fcntl F_SETFL");
-}
-
-void
-session_socket_no_linger(int fd)
-{
- struct linger lng;
-
- memset(&lng, 0, sizeof(lng));
- if (setsockopt(fd, SOL_SOCKET, SO_LINGER, &lng, sizeof(lng)) == -1)
- fatal("session_socket_no_linger");
-}
-
int
session_socket_error(int fd)
{