summaryrefslogtreecommitdiff
path: root/usr.sbin/smtpd
diff options
context:
space:
mode:
authorPierre-Yves Ritschard <pyr@cvs.openbsd.org>2009-06-05 20:43:58 +0000
committerPierre-Yves Ritschard <pyr@cvs.openbsd.org>2009-06-05 20:43:58 +0000
commit3be738b7e06c753d430cba7c3b07f8e1bcf25cfd (patch)
tree754b5a2d38cc9b71566bab1d58ef1313f5a9620b /usr.sbin/smtpd
parentcdb7f4c34e2b05bcb360d30de4c1fa07e09f1ae4 (diff)
make smtpd's imsg lib ready, just like relayd and ospfd.
ok gilles@, jacekm@
Diffstat (limited to 'usr.sbin/smtpd')
-rw-r--r--usr.sbin/smtpd/buffer.c73
-rw-r--r--usr.sbin/smtpd/control.c70
-rw-r--r--usr.sbin/smtpd/dns.c22
-rw-r--r--usr.sbin/smtpd/enqueue.c4
-rw-r--r--usr.sbin/smtpd/imsg.c112
-rw-r--r--usr.sbin/smtpd/imsg.h109
-rw-r--r--usr.sbin/smtpd/lka.c34
-rw-r--r--usr.sbin/smtpd/mda.c14
-rw-r--r--usr.sbin/smtpd/mfa.c14
-rw-r--r--usr.sbin/smtpd/mta.c10
-rw-r--r--usr.sbin/smtpd/queue.c18
-rw-r--r--usr.sbin/smtpd/runner.c12
-rw-r--r--usr.sbin/smtpd/smtp.c12
-rw-r--r--usr.sbin/smtpd/smtp_session.c6
-rw-r--r--usr.sbin/smtpd/smtpd.c56
-rw-r--r--usr.sbin/smtpd/smtpd.h110
16 files changed, 332 insertions, 344 deletions
diff --git a/usr.sbin/smtpd/buffer.c b/usr.sbin/smtpd/buffer.c
index 81da8e505f5..46e0e9d1013 100644
--- a/usr.sbin/smtpd/buffer.c
+++ b/usr.sbin/smtpd/buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.c,v 1.1 2008/11/01 21:35:28 gilles Exp $ */
+/* $OpenBSD: buffer.c,v 1.2 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -16,24 +16,17 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
#include <sys/param.h>
+#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/uio.h>
-#include <sys/time.h>
#include <errno.h>
-#include <event.h>
-#include <limits.h>
-#include <pwd.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "smtpd.h"
+#include "imsg.h"
int buf_realloc(struct buf *, size_t);
void buf_enqueue(struct msgbuf *, struct buf *);
@@ -94,7 +87,7 @@ buf_realloc(struct buf *buf, size_t len)
}
int
-buf_add(struct buf *buf, void *data, size_t len)
+buf_add(struct buf *buf, const void *data, size_t len)
{
if (buf->wpos + len > buf->size)
if (buf_realloc(buf, len) == -1)
@@ -119,11 +112,32 @@ buf_reserve(struct buf *buf, size_t len)
return (b);
}
-int
+void *
+buf_seek(struct buf *buf, size_t pos, size_t len)
+{
+ /* only allowed to seek in already written parts */
+ if (pos + len > buf->wpos)
+ return (NULL);
+
+ return (buf->buf + pos);
+}
+
+size_t
+buf_size(struct buf *buf)
+{
+ return (buf->wpos);
+}
+
+size_t
+buf_left(struct buf *buf)
+{
+ return (buf->max - buf->wpos);
+}
+
+void
buf_close(struct msgbuf *msgbuf, struct buf *buf)
{
buf_enqueue(msgbuf, buf);
- return (1);
}
void
@@ -153,32 +167,27 @@ msgbuf_clear(struct msgbuf *msgbuf)
int
msgbuf_write(struct msgbuf *msgbuf)
{
- struct iovec iov[IOV_MAX];
- struct buf *buf, *next, *save = NULL;
- int i = 0;
- ssize_t n;
- struct msghdr msg;
- struct cmsghdr *cmsg;
+ struct iovec iov[IOV_MAX];
+ struct buf *buf, *next;
+ unsigned int i = 0;
+ ssize_t n;
+ struct msghdr msg;
+ struct cmsghdr *cmsg;
union {
- struct cmsghdr hdr;
- char buf[CMSG_SPACE(sizeof(int))];
- } cmsgbuf;
+ struct cmsghdr hdr;
+ char buf[CMSG_SPACE(sizeof(int))];
+ } cmsgbuf;
bzero(&iov, sizeof(iov));
bzero(&msg, sizeof(msg));
TAILQ_FOREACH(buf, &msgbuf->bufs, entry) {
if (i >= IOV_MAX)
break;
- if (buf->fd != -1 && i != 0) {
- buf = save;
- break;
- }
iov[i].iov_base = buf->buf + buf->rpos;
- iov[i].iov_len = buf->size - buf->rpos;
+ iov[i].iov_len = buf->wpos - buf->rpos;
i++;
if (buf->fd != -1)
break;
- save = buf;
}
msg.msg_iov = iov;
@@ -207,6 +216,10 @@ msgbuf_write(struct msgbuf *msgbuf)
return (-2);
}
+ /*
+ * assumption: fd got sent if sendmsg sent anything
+ * this works because fds are passed one at a time
+ */
if (buf != NULL && buf->fd != -1) {
close(buf->fd);
buf->fd = -1;
@@ -215,8 +228,8 @@ msgbuf_write(struct msgbuf *msgbuf)
for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0;
buf = next) {
next = TAILQ_NEXT(buf, entry);
- if (buf->rpos + n >= buf->size) {
- n -= buf->size - buf->rpos;
+ if (buf->rpos + n >= buf->wpos) {
+ n -= buf->wpos - buf->rpos;
buf_dequeue(msgbuf, buf);
} else {
buf->rpos += n;
diff --git a/usr.sbin/smtpd/control.c b/usr.sbin/smtpd/control.c
index 5f07380118c..fff8a621fce 100644
--- a/usr.sbin/smtpd/control.c
+++ b/usr.sbin/smtpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.32 2009/06/01 13:20:56 jacekm Exp $ */
+/* $OpenBSD: control.c,v 1.33 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -314,17 +314,17 @@ control_dispatch_ext(int fd, short event, void *arg)
case IMSG_SMTP_ENQUEUE:
if (env->sc_flags & (SMTPD_SMTP_PAUSED |
SMTPD_CONFIGURING | SMTPD_EXITING)) {
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
- imsg_compose(env->sc_ibufs[PROC_SMTP],
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP],
IMSG_SMTP_ENQUEUE, 0, 0, -1, &fd, sizeof(fd));
break;
case IMSG_STATS:
if (euid)
goto badcred;
- imsg_compose(&c->ibuf, IMSG_STATS, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_STATS, 0, 0, -1,
env->stats, sizeof(struct stats));
break;
case IMSG_RUNNER_SCHEDULE: {
@@ -339,12 +339,12 @@ control_dispatch_ext(int fd, short event, void *arg)
s->fd = fd;
if (! valid_message_id(s->mid) && ! valid_message_uid(s->mid)) {
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
- imsg_compose(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_SCHEDULE, 0, 0, -1, s, sizeof(*s));
+ imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_SCHEDULE, 0, 0, -1, s, sizeof(*s));
break;
}
case IMSG_CONF_RELOAD: {
@@ -356,14 +356,14 @@ control_dispatch_ext(int fd, short event, void *arg)
goto badcred;
if (env->sc_flags & SMTPD_CONFIGURING) {
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags |= SMTPD_CONFIGURING;
r.fd = fd;
- imsg_compose(env->sc_ibufs[PROC_PARENT], IMSG_CONF_RELOAD, 0, 0, -1, &r, sizeof(r));
+ imsg_compose_event(env->sc_ibufs[PROC_PARENT], IMSG_CONF_RELOAD, 0, 0, -1, &r, sizeof(r));
break;
}
case IMSG_CTL_SHUTDOWN:
@@ -374,96 +374,96 @@ control_dispatch_ext(int fd, short event, void *arg)
goto badcred;
if (env->sc_flags & SMTPD_EXITING) {
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags |= SMTPD_EXITING;
- imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_MDA_PAUSE:
if (euid)
goto badcred;
if (env->sc_flags & SMTPD_MDA_PAUSED) {
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags |= SMTPD_MDA_PAUSED;
- imsg_compose(env->sc_ibufs[PROC_RUNNER], IMSG_MDA_PAUSE,
+ imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_MDA_PAUSE,
0, 0, -1, NULL, 0);
- imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_MTA_PAUSE:
if (euid)
goto badcred;
if (env->sc_flags & SMTPD_MTA_PAUSED) {
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags |= SMTPD_MTA_PAUSED;
- imsg_compose(env->sc_ibufs[PROC_RUNNER], IMSG_MTA_PAUSE,
+ imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_MTA_PAUSE,
0, 0, -1, NULL, 0);
- imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_SMTP_PAUSE:
if (euid)
goto badcred;
if (env->sc_flags & SMTPD_SMTP_PAUSED) {
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags |= SMTPD_SMTP_PAUSED;
- imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_SMTP_PAUSE,
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_SMTP_PAUSE,
0, 0, -1, NULL, 0);
- imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_MDA_RESUME:
if (euid)
goto badcred;
if (! (env->sc_flags & SMTPD_MDA_PAUSED)) {
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags &= ~SMTPD_MDA_PAUSED;
- imsg_compose(env->sc_ibufs[PROC_RUNNER], IMSG_MTA_RESUME,
+ imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_MTA_RESUME,
0, 0, -1, NULL, 0);
- imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_MTA_RESUME:
if (euid)
goto badcred;
if (!(env->sc_flags & SMTPD_MTA_PAUSED)) {
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags &= ~SMTPD_MTA_PAUSED;
- imsg_compose(env->sc_ibufs[PROC_RUNNER], IMSG_MTA_RESUME,
+ imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_MTA_RESUME,
0, 0, -1, NULL, 0);
- imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
case IMSG_SMTP_RESUME:
if (euid)
goto badcred;
if (!(env->sc_flags & SMTPD_SMTP_PAUSED)) {
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
break;
}
env->sc_flags &= ~SMTPD_SMTP_PAUSED;
- imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_SMTP_RESUME,
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_SMTP_RESUME,
0, 0, -1, NULL, 0);
- imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
break;
default:
log_debug("control_dispatch_ext: "
@@ -474,7 +474,7 @@ control_dispatch_ext(int fd, short event, void *arg)
continue;
badcred:
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1,
NULL, 0);
}
@@ -527,9 +527,9 @@ control_dispatch_parent(int sig, short event, void *p)
}
if (r->ret)
- imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
else
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0);
break;
}
default:
@@ -717,9 +717,9 @@ control_dispatch_runner(int sig, short event, void *p)
}
if (s->ret)
- imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0, -1, NULL, 0);
else
- imsg_compose(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_FAIL, 0, 0, -1, NULL, 0);
break;
}
default:
@@ -780,8 +780,8 @@ control_dispatch_smtp(int sig, short event, void *p)
return;
}
- imsg_compose(&c->ibuf, IMSG_CTL_OK, 0, 0,
- imsg_get_fd(ibuf, &imsg), NULL, 0);
+ imsg_compose_event(&c->ibuf, IMSG_CTL_OK, 0, 0,
+ imsg_get_fd(ibuf), NULL, 0);
break;
}
default:
diff --git a/usr.sbin/smtpd/dns.c b/usr.sbin/smtpd/dns.c
index 72a254c80db..2352a03d8c2 100644
--- a/usr.sbin/smtpd/dns.c
+++ b/usr.sbin/smtpd/dns.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dns.c,v 1.12 2009/06/01 13:20:56 jacekm Exp $ */
+/* $OpenBSD: dns.c,v 1.13 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -70,7 +70,7 @@ dns_query_a(struct smtpd *env, char *host, int port, u_int64_t id)
query.port = port;
query.id = id;
- imsg_compose(env->sc_ibufs[PROC_LKA], IMSG_DNS_A, 0, 0, -1, &query,
+ imsg_compose_event(env->sc_ibufs[PROC_LKA], IMSG_DNS_A, 0, 0, -1, &query,
sizeof(query));
}
@@ -84,7 +84,7 @@ dns_query_mx(struct smtpd *env, char *host, int port, u_int64_t id)
query.port = port;
query.id = id;
- imsg_compose(env->sc_ibufs[PROC_LKA], IMSG_DNS_MX, 0, 0, -1, &query,
+ imsg_compose_event(env->sc_ibufs[PROC_LKA], IMSG_DNS_MX, 0, 0, -1, &query,
sizeof(query));
}
@@ -97,7 +97,7 @@ dns_query_ptr(struct smtpd *env, struct sockaddr_storage *ss, u_int64_t id)
query.ss = *ss;
query.id = id;
- imsg_compose(env->sc_ibufs[PROC_LKA], IMSG_DNS_PTR, 0, 0, -1, &query,
+ imsg_compose_event(env->sc_ibufs[PROC_LKA], IMSG_DNS_PTR, 0, 0, -1, &query,
sizeof(query));
}
@@ -125,7 +125,7 @@ dns_async(struct smtpd *env, struct imsgbuf *asker, int type, struct dns *query)
rd->ibuf.data);
event_add(&rd->ibuf.ev, NULL);
- imsg_compose(&rd->ibuf, type, 0, 0, -1, query, sizeof(*query));
+ imsg_compose_event(&rd->ibuf, type, 0, 0, -1, query, sizeof(*query));
}
void
@@ -158,13 +158,13 @@ parent_dispatch_dns(int sig, short event, void *p)
switch (imsg.hdr.type) {
case IMSG_DNS_A:
- imsg_compose(rd->asker, IMSG_DNS_A, 0, 0, -1, imsg.data,
+ imsg_compose_event(rd->asker, IMSG_DNS_A, 0, 0, -1, imsg.data,
sizeof(struct dns));
break;
case IMSG_DNS_A_END:
case IMSG_DNS_PTR:
- imsg_compose(rd->asker, imsg.hdr.type, 0, 0, -1,
+ imsg_compose_event(rd->asker, imsg.hdr.type, 0, 0, -1,
imsg.data, sizeof(struct dns));
close(rd->ibuf.fd);
event_del(&ibuf->ev);
@@ -298,14 +298,14 @@ lookup_a(struct imsgbuf *ibuf, struct dns *query, int finalize)
for (res = res0; res; res = res->ai_next) {
memcpy(&query->ss, res->ai_addr, res->ai_addr->sa_len);
- imsg_compose(ibuf, IMSG_DNS_A, 0, 0, -1, query, sizeof(*query));
+ imsg_compose_event(ibuf, IMSG_DNS_A, 0, 0, -1, query, sizeof(*query));
}
freeaddrinfo(res0);
end:
free(port);
if (finalize) {
log_debug("lookup_a %s", query->error ? "failed" : "success");
- imsg_compose(ibuf, IMSG_DNS_A_END, 0, 0, -1, query,
+ imsg_compose_event(ibuf, IMSG_DNS_A_END, 0, 0, -1, query,
sizeof(*query));
}
}
@@ -343,7 +343,7 @@ lookup_mx(struct imsgbuf *ibuf, struct dns *query)
end:
log_debug("lookup_mx %s", query->error ? "failed" : "success");
- imsg_compose(ibuf, IMSG_DNS_A_END, 0, 0, -1, query, sizeof(*query));
+ imsg_compose_event(ibuf, IMSG_DNS_A_END, 0, 0, -1, query, sizeof(*query));
}
int
@@ -504,5 +504,5 @@ lookup_ptr(struct imsgbuf *ibuf, struct dns *query)
}
end:
log_debug("lookup_ptr %s", query->error ? "failed" : "success");
- imsg_compose(ibuf, IMSG_DNS_PTR, 0, 0, -1, query, sizeof(*query));
+ imsg_compose_event(ibuf, IMSG_DNS_PTR, 0, 0, -1, query, sizeof(*query));
}
diff --git a/usr.sbin/smtpd/enqueue.c b/usr.sbin/smtpd/enqueue.c
index eadcfb5e0d6..3102c1d3bb3 100644
--- a/usr.sbin/smtpd/enqueue.c
+++ b/usr.sbin/smtpd/enqueue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: enqueue.c,v 1.16 2009/05/25 11:17:32 jacekm Exp $ */
+/* $OpenBSD: enqueue.c,v 1.17 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2005 Henning Brauer <henning@bulabula.org>
@@ -540,7 +540,7 @@ open_connection(void)
errx(1, "unexpected imsg reply type");
}
- fd = imsg_get_fd(ibuf, &imsg);
+ fd = imsg_get_fd(ibuf);
imsg_free(&imsg);
break;
diff --git a/usr.sbin/smtpd/imsg.c b/usr.sbin/smtpd/imsg.c
index bf32c79cde6..3224027fd67 100644
--- a/usr.sbin/smtpd/imsg.c
+++ b/usr.sbin/smtpd/imsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: imsg.c,v 1.2 2008/12/04 17:24:13 cloder Exp $ */
+/* $OpenBSD: imsg.c,v 1.3 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -16,26 +16,17 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/queue.h>
-#include <sys/tree.h>
#include <sys/param.h>
+#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <errno.h>
-#include <event.h>
-#include <pwd.h>
-#include <stdarg.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "smtpd.h"
-
-static u_int32_t imsgid = 1;
+#include "imsg.h"
void
imsg_init(struct imsgbuf *ibuf, int fd, void (*handler)(int, short, void *))
@@ -57,9 +48,9 @@ imsg_read(struct imsgbuf *ibuf)
struct msghdr msg;
struct cmsghdr *cmsg;
union {
- struct cmsghdr hdr;
- char buf[CMSG_SPACE(sizeof(int) * 16)];
- } cmsgbuf;
+ struct cmsghdr hdr;
+ char buf[CMSG_SPACE(sizeof(int) * 16)];
+ } cmsgbuf;
struct iovec iov;
ssize_t n;
int fd;
@@ -75,12 +66,12 @@ imsg_read(struct imsgbuf *ibuf)
msg.msg_controllen = sizeof(cmsgbuf.buf);
if ((n = recvmsg(ibuf->fd, &msg, 0)) == -1) {
- if (errno != EINTR && errno != EAGAIN && errno != EMSGSIZE) {
- log_warn("imsg_read: pipe read error");
+ if (errno != EINTR && errno != EAGAIN) {
return (-1);
}
return (-2);
}
+
ibuf->r.wpos += n;
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL;
@@ -88,15 +79,14 @@ imsg_read(struct imsgbuf *ibuf)
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS) {
fd = (*(int *)CMSG_DATA(cmsg));
- if ((ifd = calloc(1, sizeof(struct imsg_fd))) == NULL)
- fatal("imsg_read calloc");
- ibuf->id = imsgid++;
+ if ((ifd = calloc(1, sizeof(struct imsg_fd))) == NULL) {
+ /* XXX: this return can leak */
+ return (-1);
+ }
ifd->fd = fd;
- ifd->id = ibuf->id;
TAILQ_INSERT_TAIL(&ibuf->fds, ifd, entry);
- } else
- log_warn("imsg_read: got unexpected ctl data level %d "
- "type %d", cmsg->cmsg_level, cmsg->cmsg_type);
+ }
+ /* we do not handle other ctl data level */
}
return (n);
@@ -115,8 +105,7 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
memcpy(&imsg->hdr, ibuf->r.buf, sizeof(imsg->hdr));
if (imsg->hdr.len < IMSG_HEADER_SIZE ||
imsg->hdr.len > MAX_IMSGSIZE) {
- log_warnx("imsg_get: imsg hdr len %u out of bounds, type=%u",
- imsg->hdr.len, imsg->hdr.type);
+ errno = ERANGE;
return (-1);
}
if (imsg->hdr.len > av)
@@ -124,16 +113,9 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
ibuf->r.rptr = ibuf->r.buf + IMSG_HEADER_SIZE;
if ((imsg->data = malloc(datalen)) == NULL) {
- log_warn("imsg_get");
return (-1);
}
-
memcpy(imsg->data, ibuf->r.rptr, datalen);
- imsg->id = 0;
- if (ibuf->id != 0) {
- imsg->id = ibuf->id;
- ibuf->id = 0;
- }
if (imsg->hdr.len < av) {
left = av - imsg->hdr.len;
@@ -146,11 +128,10 @@ imsg_get(struct imsgbuf *ibuf, struct imsg *imsg)
}
int
-imsg_compose(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid,
+imsg_compose(struct imsgbuf *ibuf, u_int16_t type, u_int32_t peerid,
pid_t pid, int fd, void *data, u_int16_t datalen)
{
struct buf *wbuf;
- int n;
if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL)
return (-1);
@@ -160,18 +141,16 @@ imsg_compose(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid,
wbuf->fd = fd;
- if ((n = imsg_close(ibuf, wbuf)) < 0)
- return (-1);
+ imsg_close(ibuf, wbuf);
- return (n);
+ return (1);
}
int
-imsg_composev(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid,
+imsg_composev(struct imsgbuf *ibuf, u_int16_t type, u_int32_t peerid,
pid_t pid, int fd, const struct iovec *iov, int iovcnt)
{
struct buf *wbuf;
- int n;
int i, datalen = 0;
for (i = 0; i < iovcnt; i++)
@@ -186,15 +165,14 @@ imsg_composev(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid,
wbuf->fd = fd;
- if ((n = imsg_close(ibuf, wbuf)) < 0)
- return (-1);
+ imsg_close(ibuf, wbuf);
- return (n);
+ return (1);
}
/* ARGSUSED */
struct buf *
-imsg_create(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid,
+imsg_create(struct imsgbuf *ibuf, u_int16_t type, u_int32_t peerid,
pid_t pid, u_int16_t datalen)
{
struct buf *wbuf;
@@ -202,9 +180,7 @@ imsg_create(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid,
datalen += IMSG_HEADER_SIZE;
if (datalen > MAX_IMSGSIZE) {
- log_warnx("imsg_create: len %zu > MAX_IMSGSIZE; "
- "type %u peerid %u", datalen + IMSG_HEADER_SIZE,
- type, peerid);
+ errno = ERANGE;
return (NULL);
}
@@ -213,7 +189,6 @@ imsg_create(struct imsgbuf *ibuf, enum imsg_type type, u_int32_t peerid,
if ((hdr.pid = pid) == 0)
hdr.pid = ibuf->pid;
if ((wbuf = buf_dynamic(datalen, MAX_IMSGSIZE)) == NULL) {
- log_warn("imsg_create: buf_open");
return (NULL);
}
if (imsg_add(wbuf, &hdr, sizeof(hdr)) == -1)
@@ -227,46 +202,20 @@ imsg_add(struct buf *msg, void *data, u_int16_t datalen)
{
if (datalen)
if (buf_add(msg, data, datalen) == -1) {
- log_warnx("imsg_add: buf_add error");
buf_free(msg);
return (-1);
}
return (datalen);
}
-int
-imsg_append(struct imsgbuf *ibuf, struct buf *msg)
-{
- int n;
- struct imsg_hdr *hdr;
-
- hdr = (struct imsg_hdr *)msg->buf;
- hdr->len = (u_int16_t)msg->wpos;
- if ((n = buf_close(&ibuf->w, msg)) < 0) {
- log_warnx("imsg_close: buf_close error");
- buf_free(msg);
- return (-1);
- }
-
- return (n);
-}
-
-int
+void
imsg_close(struct imsgbuf *ibuf, struct buf *msg)
{
- int n;
struct imsg_hdr *hdr;
hdr = (struct imsg_hdr *)msg->buf;
hdr->len = (u_int16_t)msg->wpos;
- if ((n = buf_close(&ibuf->w, msg)) < 0) {
- log_warnx("imsg_close: buf_close error");
- buf_free(msg);
- return (-1);
- }
- imsg_event_add(ibuf);
-
- return (n);
+ buf_close(&ibuf->w, msg);
}
void
@@ -276,7 +225,7 @@ imsg_free(struct imsg *imsg)
}
int
-imsg_get_fd(struct imsgbuf *ibuf, struct imsg *imsg)
+imsg_get_fd(struct imsgbuf *ibuf)
{
int fd;
struct imsg_fd *ifd;
@@ -284,16 +233,7 @@ imsg_get_fd(struct imsgbuf *ibuf, struct imsg *imsg)
if ((ifd = TAILQ_FIRST(&ibuf->fds)) == NULL)
return (-1);
- TAILQ_FOREACH(ifd, &ibuf->fds, entry) {
- if (ifd->id == imsg->id)
- break;
- }
-
- if (ifd == NULL)
- return (-1);
-
fd = ifd->fd;
-
TAILQ_REMOVE(&ibuf->fds, ifd, entry);
free(ifd);
diff --git a/usr.sbin/smtpd/imsg.h b/usr.sbin/smtpd/imsg.h
new file mode 100644
index 00000000000..41e41bd0919
--- /dev/null
+++ b/usr.sbin/smtpd/imsg.h
@@ -0,0 +1,109 @@
+/* $OpenBSD: imsg.h,v 1.1 2009/06/05 20:43:57 pyr Exp $ */
+
+/*
+ * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
+ * Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org>
+ * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/tree.h>
+#include <event.h>
+
+#define READ_BUF_SIZE 65535
+#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
+#define MAX_IMSGSIZE 16834
+
+struct buf {
+ TAILQ_ENTRY(buf) entry;
+ u_char *buf;
+ size_t size;
+ size_t max;
+ size_t wpos;
+ size_t rpos;
+ int fd;
+};
+
+struct msgbuf {
+ TAILQ_HEAD(, buf) bufs;
+ u_int32_t queued;
+ int fd;
+};
+
+struct buf_read {
+ u_char buf[READ_BUF_SIZE];
+ u_char *rptr;
+ size_t wpos;
+};
+
+struct imsg_fd {
+ TAILQ_ENTRY(imsg_fd) entry;
+ int fd;
+};
+
+struct imsgbuf {
+ TAILQ_HEAD(, imsg_fd) fds;
+ struct buf_read r;
+ struct msgbuf w;
+ struct event ev;
+ void (*handler)(int, short, void *);
+ int fd;
+ pid_t pid;
+ void *data;
+ short events;
+};
+
+struct imsg_hdr {
+ u_int16_t type;
+ u_int16_t len;
+ u_int32_t peerid;
+ pid_t pid;
+};
+
+struct imsg {
+ struct imsg_hdr hdr;
+ void *data;
+};
+
+
+/* buffer.c */
+struct buf *buf_open(size_t);
+struct buf *buf_dynamic(size_t, size_t);
+int buf_add(struct buf *, const void *, size_t);
+void *buf_reserve(struct buf *, size_t);
+void *buf_seek(struct buf *, size_t, size_t);
+size_t buf_size(struct buf *);
+size_t buf_left(struct buf *);
+void buf_close(struct msgbuf *, struct buf *);
+void buf_free(struct buf *);
+void msgbuf_init(struct msgbuf *);
+void msgbuf_clear(struct msgbuf *);
+int msgbuf_write(struct msgbuf *);
+
+/* imsg.c */
+void imsg_init(struct imsgbuf *, int, void (*)(int, short, void *));
+ssize_t imsg_read(struct imsgbuf *);
+ssize_t imsg_get(struct imsgbuf *, struct imsg *);
+int imsg_compose(struct imsgbuf *, u_int16_t, u_int32_t, pid_t,
+ int, void *, u_int16_t);
+int imsg_composev(struct imsgbuf *, u_int16_t, u_int32_t, pid_t,
+ int, const struct iovec *, int);
+struct buf *imsg_create(struct imsgbuf *, u_int16_t, u_int32_t, pid_t,
+ u_int16_t);
+int imsg_add(struct buf *, void *, u_int16_t);
+void imsg_close(struct imsgbuf *, struct buf *);
+void imsg_free(struct imsg *);
+int imsg_get_fd(struct imsgbuf *);
+int imsg_flush(struct imsgbuf *);
+void imsg_clear(struct imsgbuf *);
diff --git a/usr.sbin/smtpd/lka.c b/usr.sbin/smtpd/lka.c
index 24be12551b2..17e53aa6bed 100644
--- a/usr.sbin/smtpd/lka.c
+++ b/usr.sbin/smtpd/lka.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lka.c,v 1.57 2009/06/03 16:31:55 jacekm Exp $ */
+/* $OpenBSD: lka.c,v 1.58 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -226,7 +226,7 @@ lka_dispatch_parent(int sig, short event, void *p)
lkasession = SPLAY_FIND(lkatree, &env->lka_sessions, &key);
if (lkasession == NULL)
fatal("lka_dispatch_parent: lka session is gone");
- fd = imsg_get_fd(ibuf, &imsg);
+ fd = imsg_get_fd(ibuf);
--lkasession->pending;
if (fd == -1) {
@@ -260,12 +260,12 @@ lka_dispatch_parent(int sig, short event, void *p)
log_debug("expansion failed...");
}
- imsg_compose(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
IMSG_QUEUE_SUBMIT_ENVELOPE, 0, 0, -1,
&message, sizeof(struct message));
if (! lkasession->pending)
- imsg_compose(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
IMSG_QUEUE_COMMIT_ENVELOPES, 0, 0, -1,
&message, sizeof(struct message));
break;
@@ -337,7 +337,7 @@ lka_dispatch_mfa(int sig, short event, void *p)
if (lka_verify_mail(env, &ss->u.path))
ss->code = 250;
- imsg_compose(ibuf, IMSG_LKA_MAIL, 0, 0, -1,
+ imsg_compose_event(ibuf, IMSG_LKA_MAIL, 0, 0, -1,
ss, sizeof(*ss));
break;
@@ -357,17 +357,17 @@ lka_dispatch_mfa(int sig, short event, void *p)
ss->code = 250;
message = ss->msg;
message.recipient = ss->u.path;
- imsg_compose(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
IMSG_QUEUE_SUBMIT_ENVELOPE, 0, 0, -1,
&message, sizeof(struct message));
- imsg_compose(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
IMSG_QUEUE_COMMIT_ENVELOPES, 0, 0, -1,
&message, sizeof(struct message));
break;
}
if (! lka_resolve_path(env, &ss->u.path)) {
- imsg_compose(ibuf, IMSG_LKA_RCPT, 0, 0, -1,
+ imsg_compose_event(ibuf, IMSG_LKA_RCPT, 0, 0, -1,
ss, sizeof(*ss));
break;
}
@@ -390,7 +390,7 @@ lka_dispatch_mfa(int sig, short event, void *p)
if (lkasession->path.flags & F_PATH_ACCOUNT) {
fwreq.id = lkasession->id;
(void)strlcpy(fwreq.pw_name, ss->u.path.pw_name, sizeof(fwreq.pw_name));
- imsg_compose(env->sc_ibufs[PROC_PARENT], IMSG_PARENT_FORWARD_OPEN, 0, 0, -1,
+ imsg_compose_event(env->sc_ibufs[PROC_PARENT], IMSG_PARENT_FORWARD_OPEN, 0, 0, -1,
&fwreq, sizeof(fwreq));
++lkasession->pending;
break;
@@ -407,7 +407,7 @@ lka_dispatch_mfa(int sig, short event, void *p)
if (ret == 0) {
/* No aliases ... */
ss->code = 530;
- imsg_compose(ibuf, IMSG_LKA_RCPT, 0, 0,
+ imsg_compose_event(ibuf, IMSG_LKA_RCPT, 0, 0,
-1, ss, sizeof(*ss));
break;
}
@@ -482,7 +482,7 @@ lka_dispatch_mta(int sig, short event, void *p)
query->host, map);
}
- imsg_compose(ibuf, IMSG_LKA_SECRET, 0, 0, -1, query,
+ imsg_compose_event(ibuf, IMSG_LKA_SECRET, 0, 0, -1, query,
sizeof(*query));
free(secret);
break;
@@ -968,16 +968,16 @@ lka_expand_rcpt(struct smtpd *env, struct aliaseslist *aliases, struct lkasessio
if (lkasession->flags & F_ERROR) {
lka_clear_aliaseslist(&lkasession->aliaseslist);
- imsg_compose(env->sc_ibufs[PROC_MFA], IMSG_LKA_RCPT, 0, 0,
+ imsg_compose_event(env->sc_ibufs[PROC_MFA], IMSG_LKA_RCPT, 0, 0,
-1, &lkasession->ss, sizeof(struct submit_status));
}
else if (TAILQ_FIRST(&lkasession->aliaseslist) == NULL) {
message = lkasession->message;
message.recipient = lkasession->path;
- imsg_compose(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
IMSG_QUEUE_SUBMIT_ENVELOPE, 0, 0, -1,
&message, sizeof(struct message));
- imsg_compose(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
IMSG_QUEUE_COMMIT_ENVELOPES, 0, 0, -1,
&message, sizeof(struct message));
}
@@ -990,14 +990,14 @@ lka_expand_rcpt(struct smtpd *env, struct aliaseslist *aliases, struct lkasessio
lka_resolve_alias(env, &message.recipient, alias);
lka_rcpt_action(env, &message.recipient);
- imsg_compose(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
IMSG_QUEUE_SUBMIT_ENVELOPE, 0, 0, -1,
&message, sizeof(struct message));
TAILQ_REMOVE(&lkasession->aliaseslist, alias, entry);
free(alias);
}
- imsg_compose(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
IMSG_QUEUE_COMMIT_ENVELOPES, 0, 0, -1, &message,
sizeof(struct message));
}
@@ -1037,7 +1037,7 @@ lka_expand_rcpt_iteration(struct smtpd *env, struct aliaseslist *aliases, struct
done = 0;
fwreq.id = lkasession->id;
(void)strlcpy(fwreq.pw_name, alias->u.username, sizeof(fwreq.pw_name));
- imsg_compose(env->sc_ibufs[PROC_PARENT], IMSG_PARENT_FORWARD_OPEN, 0, 0, -1,
+ imsg_compose_event(env->sc_ibufs[PROC_PARENT], IMSG_PARENT_FORWARD_OPEN, 0, 0, -1,
&fwreq, sizeof(fwreq));
++lkasession->pending;
rmalias = alias;
diff --git a/usr.sbin/smtpd/mda.c b/usr.sbin/smtpd/mda.c
index 9c98b571f6c..380f4539ad7 100644
--- a/usr.sbin/smtpd/mda.c
+++ b/usr.sbin/smtpd/mda.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mda.c,v 1.20 2009/06/03 22:04:15 jacekm Exp $ */
+/* $OpenBSD: mda.c,v 1.21 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -109,14 +109,14 @@ mda_dispatch_parent(int sig, short event, void *p)
fatalx("mda_dispatch_parent: internal inconsistency.");
messagep->status = status;
- s->mboxfd = imsg_get_fd(ibuf, &imsg);
+ s->mboxfd = imsg_get_fd(ibuf);
if (s->mboxfd == -1) {
mda_remove_message(env, batchp, messagep);
break;
}
batchp->message = *messagep;
- imsg_compose(env->sc_ibufs[PROC_PARENT],
+ imsg_compose_event(env->sc_ibufs[PROC_PARENT],
IMSG_PARENT_MESSAGE_OPEN, 0, 0, -1, batchp,
sizeof(struct batch));
break;
@@ -144,7 +144,7 @@ mda_dispatch_parent(int sig, short event, void *p)
fatalx("mda_dispatch_parent: internal inconsistency.");
messagep->status = status;
- s->messagefd = imsg_get_fd(ibuf, &imsg);
+ s->messagefd = imsg_get_fd(ibuf);
if (s->messagefd == -1) {
if (s->mboxfd != -1)
close(s->mboxfd);
@@ -159,7 +159,7 @@ mda_dispatch_parent(int sig, short event, void *p)
if (store_message(batchp, messagep, store)) {
if (batchp->message.recipient.rule.r_action == A_MAILDIR)
- imsg_compose(env->sc_ibufs[PROC_PARENT],
+ imsg_compose_event(env->sc_ibufs[PROC_PARENT],
IMSG_PARENT_MAILBOX_RENAME, 0, 0, -1, batchp,
sizeof(struct batch));
}
@@ -327,7 +327,7 @@ mda_dispatch_runner(int sig, short event, void *p)
lookup = *batchp;
TAILQ_FOREACH(messagep, &batchp->messages, entry) {
lookup.message = *messagep;
- imsg_compose(env->sc_ibufs[PROC_PARENT],
+ imsg_compose_event(env->sc_ibufs[PROC_PARENT],
IMSG_PARENT_MAILBOX_OPEN, 0, 0, -1, &lookup,
sizeof(struct batch));
}
@@ -432,7 +432,7 @@ mda(struct smtpd *env)
void
mda_remove_message(struct smtpd *env, struct batch *batchp, struct message *messagep)
{
- imsg_compose(env->sc_ibufs[PROC_QUEUE], IMSG_QUEUE_MESSAGE_UPDATE, 0, 0,
+ imsg_compose_event(env->sc_ibufs[PROC_QUEUE], IMSG_QUEUE_MESSAGE_UPDATE, 0, 0,
-1, messagep, sizeof (struct message));
if ((batchp->message.status & S_MESSAGE_TEMPFAILURE) == 0 &&
diff --git a/usr.sbin/smtpd/mfa.c b/usr.sbin/smtpd/mfa.c
index 04e0283c2a2..0b0aa8cec0f 100644
--- a/usr.sbin/smtpd/mfa.c
+++ b/usr.sbin/smtpd/mfa.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mfa.c,v 1.34 2009/06/01 23:15:48 gilles Exp $ */
+/* $OpenBSD: mfa.c,v 1.35 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -292,7 +292,7 @@ mfa_dispatch_lka(int sig, short event, void *p)
IMSG_SIZE_CHECK(ss);
- imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_MFA_MAIL,
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_MFA_MAIL,
0, 0, -1, ss, sizeof(*ss));
break;
}
@@ -301,7 +301,7 @@ mfa_dispatch_lka(int sig, short event, void *p)
IMSG_SIZE_CHECK(ss);
- imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_MFA_RCPT,
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_MFA_RCPT,
0, 0, -1, ss, sizeof(*ss));
break;
}
@@ -487,13 +487,13 @@ mfa_test_mail(struct smtpd *env, struct message *m)
goto accept;
refuse:
- imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_MFA_MAIL, 0, 0, -1, &ss,
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_MFA_MAIL, 0, 0, -1, &ss,
sizeof(ss));
return;
accept:
ss.code = 250;
- imsg_compose(env->sc_ibufs[PROC_LKA], IMSG_LKA_MAIL, 0,
+ imsg_compose_event(env->sc_ibufs[PROC_LKA], IMSG_LKA_MAIL, 0,
0, -1, &ss, sizeof(ss));
}
@@ -530,13 +530,13 @@ mfa_test_rcpt(struct smtpd *env, struct message *m)
goto accept;
refuse:
- imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_MFA_RCPT, 0, 0, -1, &ss,
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_MFA_RCPT, 0, 0, -1, &ss,
sizeof(ss));
return;
accept:
ss.code = 250;
- imsg_compose(env->sc_ibufs[PROC_LKA], IMSG_LKA_RCPT, 0, 0, -1,
+ imsg_compose_event(env->sc_ibufs[PROC_LKA], IMSG_LKA_RCPT, 0, 0, -1,
&ss, sizeof(ss));
}
diff --git a/usr.sbin/smtpd/mta.c b/usr.sbin/smtpd/mta.c
index 30fb02f8e60..63744dae7d5 100644
--- a/usr.sbin/smtpd/mta.c
+++ b/usr.sbin/smtpd/mta.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mta.c,v 1.57 2009/06/03 22:04:15 jacekm Exp $ */
+/* $OpenBSD: mta.c,v 1.58 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Pierre-Yves Ritschard <pyr@openbsd.org>
@@ -301,7 +301,7 @@ mta_dispatch_queue(int sig, short event, void *p)
IMSG_SIZE_CHECK(batchp);
- if ((fd = imsg_get_fd(ibuf, &imsg)) == -1) {
+ if ((fd = imsg_get_fd(ibuf)) == -1) {
/* NEEDS_FIX - unsure yet how it must be handled */
fatalx("mta_dispatch_queue: imsg_get_fd");
}
@@ -440,7 +440,7 @@ mta_dispatch_runner(int sig, short event, void *p)
batchp->rule.r_value.relayhost.hostname,
sizeof(query.host));
- imsg_compose(env->sc_ibufs[PROC_LKA],
+ imsg_compose_event(env->sc_ibufs[PROC_LKA],
IMSG_LKA_SECRET, 0, 0, -1, &query,
sizeof(query));
} else
@@ -923,7 +923,7 @@ mta_reply_handler(struct bufferevent *bev, void *arg)
}
}
- imsg_compose(env->sc_ibufs[PROC_QUEUE], IMSG_QUEUE_MESSAGE_FD,
+ imsg_compose_event(env->sc_ibufs[PROC_QUEUE], IMSG_QUEUE_MESSAGE_FD,
0, 0, -1, batchp, sizeof(*batchp));
bufferevent_disable(sessionp->s_bev, EV_READ);
}
@@ -1112,7 +1112,7 @@ mta_batch_update_queue(struct batch *batchp)
time(NULL) - messagep->creation);
}
- imsg_compose(env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(env->sc_ibufs[PROC_QUEUE],
IMSG_QUEUE_MESSAGE_UPDATE, 0, 0, -1, messagep,
sizeof(struct message));
TAILQ_REMOVE(&batchp->messages, messagep, entry);
diff --git a/usr.sbin/smtpd/queue.c b/usr.sbin/smtpd/queue.c
index cb25bdc7a0f..b51d706ccd6 100644
--- a/usr.sbin/smtpd/queue.c
+++ b/usr.sbin/smtpd/queue.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: queue.c,v 1.66 2009/06/01 13:20:56 jacekm Exp $ */
+/* $OpenBSD: queue.c,v 1.67 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -166,7 +166,7 @@ queue_dispatch_smtp(int sig, short event, void *p)
if (! f(ss.u.msgid))
ss.code = 421;
- imsg_compose(ibuf, IMSG_QUEUE_CREATE_MESSAGE, 0, 0, -1,
+ imsg_compose_event(ibuf, IMSG_QUEUE_CREATE_MESSAGE, 0, 0, -1,
&ss, sizeof(ss));
break;
}
@@ -208,7 +208,7 @@ queue_dispatch_smtp(int sig, short event, void *p)
else
ss.code = 421;
- imsg_compose(ibuf, IMSG_QUEUE_COMMIT_MESSAGE, 0, 0, -1,
+ imsg_compose_event(ibuf, IMSG_QUEUE_COMMIT_MESSAGE, 0, 0, -1,
&ss, sizeof(ss));
break;
@@ -232,7 +232,7 @@ queue_dispatch_smtp(int sig, short event, void *p)
if (fd == -1)
ss.code = 421;
- imsg_compose(ibuf, IMSG_QUEUE_MESSAGE_FILE, 0, 0, fd,
+ imsg_compose_event(ibuf, IMSG_QUEUE_MESSAGE_FILE, 0, 0, fd,
&ss, sizeof(ss));
break;
}
@@ -281,7 +281,7 @@ queue_dispatch_mda(int sig, short event, void *p)
switch (imsg.hdr.type) {
case IMSG_QUEUE_MESSAGE_UPDATE: {
- imsg_compose(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_UPDATE_ENVELOPE,
+ imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_UPDATE_ENVELOPE,
0, 0, -1, imsg.data, sizeof(struct message));
break;
}
@@ -336,13 +336,13 @@ queue_dispatch_mta(int sig, short event, void *p)
IMSG_SIZE_CHECK(batchp);
fd = queue_open_message_file(batchp->message_id);
- imsg_compose(ibuf, IMSG_QUEUE_MESSAGE_FD, 0, 0, fd, batchp,
+ imsg_compose_event(ibuf, IMSG_QUEUE_MESSAGE_FD, 0, 0, fd, batchp,
sizeof(*batchp));
break;
}
case IMSG_QUEUE_MESSAGE_UPDATE: {
- imsg_compose(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_UPDATE_ENVELOPE,
+ imsg_compose_event(env->sc_ibufs[PROC_RUNNER], IMSG_RUNNER_UPDATE_ENVELOPE,
0, 0, -1, imsg.data, sizeof(struct message));
break;
}
@@ -414,7 +414,7 @@ queue_dispatch_lka(int sig, short event, void *p)
if (! f(messagep)) {
ss.code = 421;
- imsg_compose(env->sc_ibufs[PROC_SMTP],
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP],
IMSG_QUEUE_TEMPFAIL, 0, 0, -1, &ss,
sizeof(ss));
}
@@ -431,7 +431,7 @@ queue_dispatch_lka(int sig, short event, void *p)
ss.id = messagep->session_id;
ss.code = 250;
- imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_QUEUE_COMMIT_ENVELOPES,
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_QUEUE_COMMIT_ENVELOPES,
0, 0, -1, &ss, sizeof(ss));
break;
diff --git a/usr.sbin/smtpd/runner.c b/usr.sbin/smtpd/runner.c
index 237ff9cc773..efd9f3a323e 100644
--- a/usr.sbin/smtpd/runner.c
+++ b/usr.sbin/smtpd/runner.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: runner.c,v 1.50 2009/06/03 22:04:15 jacekm Exp $ */
+/* $OpenBSD: runner.c,v 1.51 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -197,7 +197,7 @@ runner_dispatch_control(int sig, short event, void *p)
else if (valid_message_id(s->mid))
s->ret = runner_force_message_schedule(s->mid);
- imsg_compose(ibuf, IMSG_RUNNER_SCHEDULE, 0, 0, -1, s, sizeof(*s));
+ imsg_compose_event(ibuf, IMSG_RUNNER_SCHEDULE, 0, 0, -1, s, sizeof(*s));
break;
}
default:
@@ -500,7 +500,7 @@ runner_process_offline(struct smtpd *env)
q = qwalk_new(PATH_OFFLINE);
if (qwalk(q, path))
- imsg_compose(env->sc_ibufs[PROC_PARENT],
+ imsg_compose_event(env->sc_ibufs[PROC_PARENT],
IMSG_PARENT_ENQUEUE_OFFLINE, 0, 0, -1, path,
strlen(path) + 1);
@@ -681,18 +681,18 @@ runner_batch_dispatch(struct smtpd *env, struct batch *batchp, time_t curtime)
else if (batchp->type & T_MTA_BATCH)
proctype = PROC_MTA;
- imsg_compose(env->sc_ibufs[proctype], IMSG_BATCH_CREATE, 0, 0, -1,
+ imsg_compose_event(env->sc_ibufs[proctype], IMSG_BATCH_CREATE, 0, 0, -1,
batchp, sizeof (struct batch));
while ((messagep = TAILQ_FIRST(&batchp->messages))) {
- imsg_compose(env->sc_ibufs[proctype], IMSG_BATCH_APPEND, 0, 0,
+ imsg_compose_event(env->sc_ibufs[proctype], IMSG_BATCH_APPEND, 0, 0,
-1, messagep, sizeof (struct message));
TAILQ_REMOVE(&batchp->messages, messagep, entry);
bzero(messagep, sizeof(struct message));
free(messagep);
}
- imsg_compose(env->sc_ibufs[proctype], IMSG_BATCH_CLOSE, 0, 0, -1,
+ imsg_compose_event(env->sc_ibufs[proctype], IMSG_BATCH_CLOSE, 0, 0, -1,
batchp, sizeof(struct batch));
}
diff --git a/usr.sbin/smtpd/smtp.c b/usr.sbin/smtpd/smtp.c
index b3e97d5a843..f09927d407e 100644
--- a/usr.sbin/smtpd/smtp.c
+++ b/usr.sbin/smtpd/smtp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtp.c,v 1.55 2009/06/02 22:23:36 gilles Exp $ */
+/* $OpenBSD: smtp.c,v 1.56 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -111,7 +111,7 @@ smtp_dispatch_parent(int sig, short event, void *p)
}
if (env->sc_listeners)
smtp_disable_events(env);
- imsg_compose(ibuf, IMSG_PARENT_SEND_CONFIG, 0, 0, -1,
+ imsg_compose_event(ibuf, IMSG_PARENT_SEND_CONFIG, 0, 0, -1,
NULL, 0);
break;
}
@@ -161,7 +161,7 @@ smtp_dispatch_parent(int sig, short event, void *p)
fatal(NULL);
memcpy(l, imsg.data, sizeof(*l));
- if ((l->fd = imsg_get_fd(ibuf, &imsg)) == -1)
+ if ((l->fd = imsg_get_fd(ibuf)) == -1)
fatal("cannot get fd");
(void)strlcpy(key.ssl_name, l->ssl_cert_name,
@@ -396,7 +396,7 @@ smtp_dispatch_queue(int sig, short event, void *p)
IMSG_SIZE_CHECK(ss);
- fd = imsg_get_fd(ibuf, &imsg);
+ fd = imsg_get_fd(ibuf);
if ((s = session_lookup(env, ss->id)) == NULL) {
close(fd);
@@ -508,7 +508,7 @@ smtp_dispatch_control(int sig, short event, void *p)
env->sc_maxconn) {
log_warnx("denying local connection, too many"
" sessions active");
- imsg_compose(ibuf, IMSG_SMTP_ENQUEUE, 0, 0, -1,
+ imsg_compose_event(ibuf, IMSG_SMTP_ENQUEUE, 0, 0, -1,
imsg.data, sizeof(int));
break;
}
@@ -547,7 +547,7 @@ smtp_dispatch_control(int sig, short event, void *p)
session_init(s->s_l, s);
- imsg_compose(ibuf, IMSG_SMTP_ENQUEUE, 0, 0, fd[1],
+ imsg_compose_event(ibuf, IMSG_SMTP_ENQUEUE, 0, 0, fd[1],
imsg.data, sizeof(int));
break;
}
diff --git a/usr.sbin/smtpd/smtp_session.c b/usr.sbin/smtpd/smtp_session.c
index a5959204f83..a7eca55d5aa 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.105 2009/06/01 14:53:18 gilles Exp $ */
+/* $OpenBSD: smtp_session.c,v 1.106 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -954,7 +954,7 @@ session_destroy(struct session *s)
fclose(s->datafp);
if (s->s_msg.message_id[0] != '\0' && s->s_state != S_DONE)
- imsg_compose(s->s_env->sc_ibufs[PROC_QUEUE],
+ imsg_compose_event(s->s_env->sc_ibufs[PROC_QUEUE],
IMSG_QUEUE_REMOVE_MESSAGE, 0, 0, -1, &s->s_msg,
sizeof(s->s_msg));
@@ -1141,7 +1141,7 @@ session_imsg(struct session *s, enum smtp_proc_type proc, enum imsg_type type,
*/
s->s_flags |= F_WRITEONLY;
bufferevent_disable(s->s_bev, EV_READ);
- imsg_compose(s->s_env->sc_ibufs[proc], type, peerid, pid, fd, data,
+ imsg_compose_event(s->s_env->sc_ibufs[proc], type, peerid, pid, fd, data,
datalen);
}
diff --git a/usr.sbin/smtpd/smtpd.c b/usr.sbin/smtpd/smtpd.c
index 9c49ca130dc..8ef4f4a986c 100644
--- a/usr.sbin/smtpd/smtpd.c
+++ b/usr.sbin/smtpd/smtpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.c,v 1.73 2009/06/03 18:16:29 gilles Exp $ */
+/* $OpenBSD: smtpd.c,v 1.74 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -133,7 +133,7 @@ parent_send_config_listeners(struct smtpd *env)
int opt;
log_debug("parent_send_config: configuring smtp");
- imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_CONF_START,
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_CONF_START,
0, 0, -1, NULL, 0);
SPLAY_FOREACH(s, ssltree, env->sc_ssl) {
@@ -159,11 +159,11 @@ parent_send_config_listeners(struct smtpd *env)
fatal("setsockopt");
if (bind(l->fd, (struct sockaddr *)&l->ss, l->ss.ss_len) == -1)
fatal("bind");
- imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_CONF_LISTENER,
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_CONF_LISTENER,
0, 0, l->fd, l, sizeof(*l));
}
- imsg_compose(env->sc_ibufs[PROC_SMTP], IMSG_CONF_END,
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP], IMSG_CONF_END,
0, 0, -1, NULL, 0);
}
@@ -174,7 +174,7 @@ parent_send_config_client_certs(struct smtpd *env)
struct iovec iov[3];
log_debug("parent_send_config_client_certs: configuring smtp");
- imsg_compose(env->sc_ibufs[PROC_MTA], IMSG_CONF_START,
+ imsg_compose_event(env->sc_ibufs[PROC_MTA], IMSG_CONF_START,
0, 0, -1, NULL, 0);
SPLAY_FOREACH(s, ssltree, env->sc_ssl) {
@@ -192,7 +192,7 @@ parent_send_config_client_certs(struct smtpd *env)
iov, nitems(iov));
}
- imsg_compose(env->sc_ibufs[PROC_MTA], IMSG_CONF_END,
+ imsg_compose_event(env->sc_ibufs[PROC_MTA], IMSG_CONF_END,
0, 0, -1, NULL, 0);
}
@@ -205,30 +205,30 @@ parent_send_config_ruleset(struct smtpd *env, int proc)
struct mapel *mapel;
log_debug("parent_send_config_ruleset: reloading rules and maps");
- imsg_compose(env->sc_ibufs[proc], IMSG_CONF_START,
+ imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_START,
0, 0, -1, NULL, 0);
TAILQ_FOREACH(m, env->sc_maps, m_entry) {
- imsg_compose(env->sc_ibufs[proc], IMSG_CONF_MAP,
+ imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_MAP,
0, 0, -1, m, sizeof(*m));
TAILQ_FOREACH(mapel, &m->m_contents, me_entry) {
- imsg_compose(env->sc_ibufs[proc], IMSG_CONF_MAP_CONTENT,
+ imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_MAP_CONTENT,
0, 0, -1, mapel, sizeof(*mapel));
}
}
TAILQ_FOREACH(r, env->sc_rules, r_entry) {
- imsg_compose(env->sc_ibufs[proc], IMSG_CONF_RULE,
+ imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_RULE,
0, 0, -1, r, sizeof(*r));
- imsg_compose(env->sc_ibufs[proc], IMSG_CONF_RULE_SOURCE,
+ imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_RULE_SOURCE,
0, 0, -1, &r->r_sources->m_name, sizeof(r->r_sources->m_name));
TAILQ_FOREACH(cond, &r->r_conditions, c_entry) {
- imsg_compose(env->sc_ibufs[proc], IMSG_CONF_CONDITION,
+ imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_CONDITION,
0, 0, -1, cond, sizeof(*cond));
}
}
- imsg_compose(env->sc_ibufs[proc], IMSG_CONF_END,
+ imsg_compose_event(env->sc_ibufs[proc], IMSG_CONF_END,
0, 0, -1, NULL, 0);
}
@@ -277,7 +277,7 @@ parent_dispatch_lka(int fd, short event, void *p)
if (errno == ENOENT)
fwreq->status = 1;
}
- imsg_compose(ibuf, IMSG_PARENT_FORWARD_OPEN, 0, 0, ret, fwreq, sizeof(*fwreq));
+ imsg_compose_event(ibuf, IMSG_PARENT_FORWARD_OPEN, 0, 0, ret, fwreq, sizeof(*fwreq));
break;
}
default:
@@ -454,7 +454,7 @@ parent_dispatch_mda(int fd, short event, void *p)
batchp->message.status |= S_MESSAGE_TEMPFAILURE;
else
batchp->message.status |= S_MESSAGE_PERMFAILURE;
- imsg_compose(ibuf, IMSG_MDA_MAILBOX_FILE, 0, 0,
+ imsg_compose_event(ibuf, IMSG_MDA_MAILBOX_FILE, 0, 0,
-1, batchp, sizeof(struct batch));
break;
}
@@ -463,7 +463,7 @@ parent_dispatch_mda(int fd, short event, void *p)
fatal("privdrop failed");
desc = action_hdl_table[i].handler(file, pw, batchp);
- imsg_compose(ibuf, IMSG_MDA_MAILBOX_FILE, 0, 0,
+ imsg_compose_event(ibuf, IMSG_MDA_MAILBOX_FILE, 0, 0,
desc, batchp, sizeof(struct batch));
if (setegid(0) || seteuid(0))
@@ -479,7 +479,7 @@ parent_dispatch_mda(int fd, short event, void *p)
desc = parent_open_message_file(batchp);
- imsg_compose(ibuf, IMSG_MDA_MESSAGE_FILE, 0, 0,
+ imsg_compose_event(ibuf, IMSG_MDA_MESSAGE_FILE, 0, 0,
desc, batchp, sizeof(struct batch));
break;
@@ -565,7 +565,7 @@ parent_dispatch_smtp(int fd, short event, void *p)
req->success = auth_userokay(req->user, NULL,
"auth-smtp", req->pass);
- imsg_compose(ibuf, IMSG_PARENT_AUTHENTICATE, 0, 0,
+ imsg_compose_event(ibuf, IMSG_PARENT_AUTHENTICATE, 0, 0,
-1, req, sizeof(*req));
break;
}
@@ -614,7 +614,7 @@ parent_dispatch_runner(int sig, short event, void *p)
switch (imsg.hdr.type) {
case IMSG_PARENT_ENQUEUE_OFFLINE:
if (! parent_enqueue_offline(env, imsg.data))
- imsg_compose(ibuf, IMSG_PARENT_ENQUEUE_OFFLINE,
+ imsg_compose_event(ibuf, IMSG_PARENT_ENQUEUE_OFFLINE,
0, 0, -1, NULL, 0);
break;
default:
@@ -678,11 +678,11 @@ parent_dispatch_control(int sig, short event, void *p)
parent_send_config_client_certs(env);
parent_send_config_ruleset(env, PROC_MFA);
parent_send_config_ruleset(env, PROC_LKA);
- imsg_compose(env->sc_ibufs[PROC_SMTP],
+ imsg_compose_event(env->sc_ibufs[PROC_SMTP],
IMSG_CONF_RELOAD, 0, 0, -1, NULL, 0);
r->ret = 1;
}
- imsg_compose(ibuf, IMSG_CONF_RELOAD, 0, 0, -1, r, sizeof(*r));
+ imsg_compose_event(ibuf, IMSG_CONF_RELOAD, 0, 0, -1, r, sizeof(*r));
break;
}
default:
@@ -754,7 +754,7 @@ parent_sig_handler(int sig, short event, void *p)
"message; smtpctl %s", cause);
else
log_debug("offline message enqueued");
- imsg_compose(env->sc_ibufs[PROC_RUNNER],
+ imsg_compose_event(env->sc_ibufs[PROC_RUNNER],
IMSG_PARENT_ENQUEUE_OFFLINE, 0, 0, -1,
NULL, 0);
break;
@@ -1137,6 +1137,18 @@ imsg_event_add(struct imsgbuf *ibuf)
}
int
+imsg_compose_event(struct imsgbuf *ibuf, u_int16_t type, u_int32_t peerid,
+ pid_t pid, int fd, void *data, u_int16_t datalen)
+{
+ int ret;
+
+ if ((ret = imsg_compose(ibuf, type, peerid,
+ pid, fd, data, datalen)) != -1)
+ imsg_event_add(ibuf);
+ return (ret);
+}
+
+int
parent_open_message_file(struct batch *batchp)
{
int fd;
diff --git a/usr.sbin/smtpd/smtpd.h b/usr.sbin/smtpd/smtpd.h
index 7dc51ee2d21..2f9458ec11c 100644
--- a/usr.sbin/smtpd/smtpd.h
+++ b/usr.sbin/smtpd/smtpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: smtpd.h,v 1.125 2009/06/05 08:50:00 pyr Exp $ */
+/* $OpenBSD: smtpd.h,v 1.126 2009/06/05 20:43:57 pyr Exp $ */
/*
* Copyright (c) 2008 Gilles Chehade <gilles@openbsd.org>
@@ -17,10 +17,17 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include "imsg.h"
+
+#define IMSG_SIZE_CHECK(p) do { \
+ if (IMSG_DATA_SIZE(&imsg) != sizeof(*p)) \
+ fatalx("bad length imsg received"); \
+} while (0)
+#define IMSG_DATA_SIZE(imsg) ((imsg)->hdr.len - IMSG_HEADER_SIZE)
+
#define CONF_FILE "/etc/mail/smtpd.conf"
#define MAX_LISTEN 16
#define PROC_COUNT 9
-#define READ_BUF_SIZE 32768
#define MAX_NAME_SIZE 64
#define MAX_HOPS_COUNT 100
@@ -112,61 +119,6 @@ struct mxhost {
struct sockaddr_storage ss;
};
-/* buffer specific headers */
-struct buf {
- TAILQ_ENTRY(buf) entry;
- u_char *buf;
- size_t size;
- size_t max;
- size_t wpos;
- size_t rpos;
- int fd;
-};
-
-struct msgbuf {
- TAILQ_HEAD(, buf) bufs;
- u_int32_t queued;
- int fd;
-};
-
-struct buf_read {
- u_char buf[READ_BUF_SIZE];
- u_char *rptr;
- size_t wpos;
-};
-
-struct imsg_fd {
- TAILQ_ENTRY(imsg_fd) entry;
- int fd;
- u_int32_t id;
-};
-
-struct imsgbuf {
- TAILQ_HEAD(, imsg_fd) fds;
- struct buf_read r;
- struct msgbuf w;
- struct event ev;
- void (*handler)(int, short, void *);
- int fd;
- pid_t pid;
- short events;
- void *data;
- u_int32_t id;
-};
-
-struct imsg_hdr {
- u_int16_t type;
- u_int16_t len;
- u_int32_t peerid;
- pid_t pid;
-};
-
-struct imsg {
- struct imsg_hdr hdr;
- u_int32_t id;
- void *data;
-};
-
enum imsg_type {
IMSG_NONE,
IMSG_CTL_OK, /* answer to smtpctl requests */
@@ -243,15 +195,6 @@ enum imsg_type {
IMSG_DNS_PTR
};
-#define IMSG_HEADER_SIZE sizeof(struct imsg_hdr)
-#define IMSG_DATA_SIZE(imsg) ((imsg)->hdr.len - IMSG_HEADER_SIZE)
-#define MAX_IMSGSIZE 16384
-
-#define IMSG_SIZE_CHECK(p) do { \
- if (IMSG_DATA_SIZE(&imsg) != sizeof(*p)) \
- fatalx("bad length imsg received"); \
-} while (0)
-
enum blockmodes {
BM_NORMAL,
BM_NONBLOCK
@@ -799,18 +742,6 @@ __dead void fatal(const char *);
__dead void fatalx(const char *);
-/* buffer.c */
-struct buf *buf_open(size_t);
-struct buf *buf_dynamic(size_t, size_t);
-int buf_add(struct buf *, void *, size_t);
-void *buf_reserve(struct buf *, size_t);
-int buf_close(struct msgbuf *, struct buf *);
-void buf_free(struct buf *);
-void msgbuf_init(struct msgbuf *);
-void msgbuf_clear(struct msgbuf *);
-int msgbuf_write(struct msgbuf *);
-
-
/* dns.c */
void dns_query_a(struct smtpd *, char *, int, u_int64_t);
void dns_query_mx(struct smtpd *, char *, int, u_int64_t);
@@ -823,29 +754,12 @@ void dns_async(struct smtpd *, struct imsgbuf *, int,
/* forward.c */
int forwards_get(int, struct aliaseslist *);
-
-/* imsg.c */
-void imsg_init(struct imsgbuf *, int, void (*)(int, short, void *));
-ssize_t imsg_read(struct imsgbuf *);
-ssize_t imsg_get(struct imsgbuf *, struct imsg *);
-int imsg_compose(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
- int, void *, u_int16_t);
-int imsg_composev(struct imsgbuf *, enum imsg_type, u_int32_t,
- pid_t, int, const struct iovec *, int);
-struct buf *imsg_create(struct imsgbuf *, enum imsg_type, u_int32_t, pid_t,
- u_int16_t);
-int imsg_add(struct buf *, void *, u_int16_t);
-int imsg_append(struct imsgbuf *, struct buf *);
-int imsg_close(struct imsgbuf *, struct buf *);
-void imsg_free(struct imsg *);
-void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
-int imsg_get_fd(struct imsgbuf *, struct imsg *);
-int imsg_flush(struct imsgbuf *);
-void imsg_clear(struct imsgbuf *);
-
/* smtpd.c */
int child_cmp(struct child *, struct child *);
SPLAY_PROTOTYPE(childtree, child, entry, child_cmp);
+void imsg_event_add(struct imsgbuf *); /* needs to be provided externally */
+int imsg_compose_event(struct imsgbuf *, u_int16_t, u_int32_t, pid_t,
+ int, void *, u_int16_t);
/* lka.c */
pid_t lka(struct smtpd *);